-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #750 from palladiumkenya/feat/new-reporting-layer
his deployment apis added
- Loading branch information
Showing
12 changed files
with
384 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/common/queries/handlers/get-county-coverage-hts.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { AllEmrSites } from '../../../care-treatment/common/entities/all-emr-sites.model'; | ||
import { GetCountyCoverageHtsQuery } from '../impl/get-county-coverage-hts.query'; | ||
|
||
@QueryHandler(GetCountyCoverageHtsQuery) | ||
export class GetCountyCoverageHtsHandler implements IQueryHandler<GetCountyCoverageHtsQuery> { | ||
constructor( | ||
@InjectRepository(AllEmrSites, 'mssql') | ||
private readonly repository: Repository<AllEmrSites>, | ||
) {} | ||
|
||
async execute(query: GetCountyCoverageHtsQuery): Promise<any> { | ||
const htsCountyCoverage = this.repository | ||
.createQueryBuilder('q') | ||
.select([ | ||
'q.County', | ||
'COALESCE(SUM(Tested_Total), 0) AS Tested_DHIS', | ||
'coalesce (Sum(Tested),0) as Tested_NDW', | ||
'coalesce (Sum(Positive_Total),0) as Positive_DHIS', | ||
'coalesce (Sum(Positive),0) as Positive_NDW' | ||
]) | ||
.leftJoin( | ||
`(Select MFLCode, sum (Tested) as Tested, sum (Positive) as Positive, AsOfDate FROM REPORTING.dbo.AggregateHTSUptake WHERE AsOfDate =EOMONTH(DATEADD(mm,-1,GETDATE())) group by MFLcode,AsOfDate)`, | ||
'ndw', | ||
'q.MFLCode = ndw.MFLCode' | ||
) | ||
.leftJoin( | ||
`(Select MFLCode, ReportMonth_Year as reporting_month_HTS, Tested_Total, Positive_Total FROM REPORTING.dbo.AggregateFACT_HTS_DHIS2 dhis where Tested_Total is not null and datediff( mm, cast(concat(ReportMonth_Year, '01') as date), (select max(cast(concat(ReportMonth_Year, '01') as date)) from ODS.dbo.HTS_DHIS2)) = 0 group by MFLCode, ReportMonth_Year, Tested_Total, Positive_Total)`, | ||
'hts', | ||
'q.MFLCode = hts.MFLCode' | ||
) | ||
.where(`EMR_Status='Active'`); | ||
|
||
if (query.county) { | ||
htsCountyCoverage.andWhere('q.County IN (:...county)', { | ||
county: [query.county], | ||
}); | ||
} | ||
|
||
if (query.subCounty) { | ||
htsCountyCoverage.andWhere('q.SubCounty IN (:...subCounty)', { | ||
subCounty: [query.subCounty], | ||
}); | ||
} | ||
|
||
return await htsCountyCoverage | ||
.groupBy('q.County') | ||
.orderBy('q.County') | ||
.getRawMany(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/common/queries/handlers/get-facility-art-hts-mnch.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { AllEmrSites } from '../../../care-treatment/common/entities/all-emr-sites.model'; | ||
import { GetFacilityArtHtsMnchQuery } from '../impl/get-facility-art-hts-mnch.query'; | ||
|
||
@QueryHandler(GetFacilityArtHtsMnchQuery) | ||
export class GetFacilityArtHtsMnchHandler implements IQueryHandler<GetFacilityArtHtsMnchQuery> { | ||
constructor( | ||
@InjectRepository(AllEmrSites, 'mssql') | ||
private readonly repository: Repository<AllEmrSites>, | ||
) {} | ||
|
||
async execute(query: GetFacilityArtHtsMnchQuery): Promise<any> { | ||
const facilitiesLineList = this.repository | ||
.createQueryBuilder('q') | ||
.select([ | ||
'q.KEPH_Level', | ||
'q.MFLCode as SiteCode', | ||
'ISNULL(dhis_CT.CurrentOnART_Total, 0) as CurrentOnART_Total', | ||
'ISNULL(KHIS_HTS.Tested_Total, 0) as Tested_Total', | ||
'ISNULL(KHIS_PMTCT.onMaternalHAARTtotal, 0) as onMaternalHAARTtotal' | ||
]) | ||
.leftJoin( | ||
`(SELECT SiteCode, CurrentOnART_Total, ReportMonth_Year as reporting_month_CT FROM ODS.dbo.CT_DHIS2 dhis WHERE CurrentOnART_Total IS NOT NULL AND DATEDIFF(mm, CAST(CONCAT(ReportMonth_Year, '01') AS DATE), (SELECT MAX(CAST(CONCAT(ReportMonth_Year, '01') AS DATE)) FROM ODS.dbo.CT_DHIS2)) = 0 GROUP BY SiteCode, ReportMonth_Year, CurrentOnART_Total)`, | ||
'dhis_CT', | ||
'q.MFLCode = dhis_CT.SiteCode' | ||
) | ||
.leftJoin( | ||
`(SELECT SiteCode, Tested_Total, ReportMonth_Year as reporting_month_HTS FROM ODS.dbo.HTS_DHIS2 dhis WHERE Tested_Total IS NOT NULL AND DATEDIFF(mm, CAST(CONCAT(ReportMonth_Year, '01') AS DATE), (SELECT MAX(CAST(CONCAT(ReportMonth_Year, '01') AS DATE)) FROM ODS.dbo.HTS_DHIS2)) = 0 GROUP BY SiteCode, ReportMonth_Year, Tested_Total)`, | ||
'KHIS_HTS', | ||
'q.MFLCode = KHIS_HTS.SiteCode' | ||
) | ||
.leftJoin( | ||
`(SELECT SiteCode, onMaternalHAARTtotal, ReportMonth_Year as reporting_month_PMTCT FROM ODS.dbo.MNCH_DHIS2 dhis WHERE onMaternalHAARTtotal IS NOT NULL AND DATEDIFF(mm, CAST(CONCAT(ReportMonth_Year, '01') AS DATE), (SELECT MAX(CAST(CONCAT(ReportMonth_Year, '01') AS DATE)) FROM ODS.dbo.HTS_DHIS2)) = 0 GROUP BY SiteCode, ReportMonth_Year, onMaternalHAARTtotal)`, | ||
'KHIS_PMTCT', | ||
'q.MFLCode = KHIS_PMTCT.SiteCode' | ||
); | ||
|
||
if (query.county) { | ||
facilitiesLineList.andWhere('q.County IN (:...county)', { | ||
county: [query.county], | ||
}); | ||
} | ||
|
||
if (query.subCounty) { | ||
facilitiesLineList.andWhere('q.SubCounty IN (:...subCounty)', { | ||
subCounty: [query.subCounty], | ||
}); | ||
} | ||
|
||
return await facilitiesLineList | ||
.orderBy('q.MFLCode') | ||
.getRawMany(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/common/queries/handlers/get-facility-by-infrastructure-county.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { AllEmrSites } from '../../../care-treatment/common/entities/all-emr-sites.model'; | ||
import { GetFacilityByInfrastructureCountyQuery } from '../impl/get-facility-by-infrastructure-county.query'; | ||
|
||
@QueryHandler(GetFacilityByInfrastructureCountyQuery) | ||
export class GetFacilityByInfrastructureCountyHandler implements IQueryHandler<GetFacilityByInfrastructureCountyQuery> { | ||
constructor( | ||
@InjectRepository(AllEmrSites, 'mssql') | ||
private readonly repository: Repository<AllEmrSites>, | ||
) {} | ||
|
||
async execute(query: GetFacilityByInfrastructureCountyQuery): Promise<any> { | ||
const facilitiesInfrastructure = this.repository | ||
.createQueryBuilder('q') | ||
.select('COUNT(1) facilities, InfrastructureType, County') | ||
.where(`InfrastructureType is not null AND EMR_Status = 'Active'`); | ||
|
||
if (query.county) { | ||
facilitiesInfrastructure.andWhere('q.County IN (:...county)', { | ||
county: [query.county], | ||
}); | ||
} | ||
|
||
if (query.subCounty) { | ||
facilitiesInfrastructure.andWhere('q.SubCounty IN (:...subCounty)', { | ||
subCounty: [query.subCounty], | ||
}); | ||
} | ||
|
||
|
||
return await facilitiesInfrastructure | ||
.groupBy('q.InfrastructureType, County') | ||
.orderBy('County') | ||
.distinct(true) | ||
.getRawMany(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/common/queries/handlers/get-facility-status-by-county.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { AllEmrSites } from '../../../care-treatment/common/entities/all-emr-sites.model'; | ||
import { GetFacilityStatusByCountyQuery } from '../impl/get-facility-status-by-county.query'; | ||
|
||
@QueryHandler(GetFacilityStatusByCountyQuery) | ||
export class GetFacilityStatusByCountyHandler implements IQueryHandler<GetFacilityStatusByCountyQuery> { | ||
constructor( | ||
@InjectRepository(AllEmrSites, 'mssql') | ||
private readonly repository: Repository<AllEmrSites>, | ||
) {} | ||
|
||
async execute(query: GetFacilityStatusByCountyQuery): Promise<any> { | ||
const facilitiesStatus = this.repository | ||
.createQueryBuilder('q') | ||
.select('COUNT(1) facilities, EMR_Status, County') | ||
.where('EMR_Status is not null'); | ||
|
||
if (query.county) { | ||
facilitiesStatus.andWhere('q.County IN (:...county)', { | ||
county: [query.county], | ||
}); | ||
} | ||
|
||
if (query.subCounty) { | ||
facilitiesStatus.andWhere('q.SubCounty IN (:...subCounty)', { | ||
subCounty: [query.subCounty], | ||
}); | ||
} | ||
|
||
return await facilitiesStatus | ||
.groupBy('q.EMR_Status, County') | ||
.orderBy('County') | ||
.distinct(true) | ||
.getRawMany(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class GetCountyCoverageHtsQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
agency?: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class GetFacilityArtHtsMnchQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
agency?: string[]; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/common/queries/impl/get-facility-by-infrastructure-county.query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class GetFacilityByInfrastructureCountyQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
agency?: string[]; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/common/queries/impl/get-facility-status-by-county.query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class GetFacilityStatusByCountyQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
agency?: string[]; | ||
} |
Oops, something went wrong.