-
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 #771 from cbrianbet/feat/new-reporting-layer
ahd api added
- Loading branch information
Showing
4 changed files
with
140 additions
and
0 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
80 changes: 80 additions & 0 deletions
80
src/care-treatment/current-on-art/queries/handlers/get-ahd-screening.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,80 @@ | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { GetAhdScreeningQuery } from '../impl/get-ahd-screening.query'; | ||
import { LinelistFACTART } from '../../../common/entities/linelist-fact-art.model'; | ||
|
||
@QueryHandler(GetAhdScreeningQuery) | ||
export class GetAhdScreeningHandler implements IQueryHandler<GetAhdScreeningQuery> { | ||
constructor( | ||
@InjectRepository(LinelistFACTART, 'mssql') | ||
private readonly repository: Repository<LinelistFACTART>, | ||
) {} | ||
|
||
async execute(query: GetAhdScreeningQuery): Promise<any> { | ||
const ahdScreening = this.repository | ||
.createQueryBuilder('f') | ||
.select([` | ||
SUM(NewPatient) as NewPatient, | ||
-- ahd screened | ||
SUM(AHD) AS AHD, | ||
SUM(DoneCD4Test) AS DoneCD4Test, | ||
SUM(CD4Lessthan200) AS less200CD4, | ||
SUM(DoneTBLamTest) AS DoneTBLamTest, | ||
SUM(TBLamPositive) AS TBLamPositive, | ||
-- tb treatment initiated | ||
SUM(OntbTreatment) AS tbInitiated, | ||
SUM(DoneCrAgTest) AS DoneCrAgTest, | ||
SUM(CrAgPositive) AS CrAgPositive, | ||
SUM(CSFCrAg) AS CSFCrAg, | ||
SUM(CSFCrAgPositive) AS CSFCrAgPositive, | ||
SUM(InitiatedCMTreatment) AS InitiatedCMTreatment, | ||
SUM(PreemtiveCMTheraphy) AS PreemtiveCMTheraphy | ||
`]) | ||
.where(`StartARTDate >= DATEADD(MONTH, DATEDIFF(MONTH,0, GETDATE()) -1,0) and StartARTDate <DATEADD(MONTH,DATEDIFF(MONTH, 0, GETDATE()), 0)`); | ||
|
||
if (query.county) { | ||
ahdScreening.andWhere('f.County IN (:...counties)', { | ||
counties: query.county, | ||
}); | ||
} | ||
|
||
if (query.subCounty) { | ||
ahdScreening.andWhere('f.Subcounty IN (:...subCounties)', { | ||
subCounties: query.subCounty, | ||
}); | ||
} | ||
|
||
if (query.facility) { | ||
ahdScreening.andWhere('f.FacilityName IN (:...facilities)', { | ||
facilities: query.facility, | ||
}); | ||
} | ||
|
||
if (query.partner) { | ||
ahdScreening.andWhere('f.PartnerName IN (:...partners)', { | ||
partners: query.partner, | ||
}); | ||
} | ||
|
||
if (query.agency) { | ||
ahdScreening.andWhere('f.AgencyName IN (:...agencies)', { | ||
agencies: query.agency, | ||
}); | ||
} | ||
|
||
if (query.datimAgeGroup) { | ||
ahdScreening.andWhere('f.AgeGroup IN (:...ageGroups)', { | ||
ageGroups: query.datimAgeGroup, | ||
}); | ||
} | ||
|
||
if (query.gender) { | ||
ahdScreening.andWhere('f.Gender IN (:...genders)', { | ||
genders: query.gender, | ||
}); | ||
} | ||
|
||
return await ahdScreening.getRawOne(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/care-treatment/current-on-art/queries/impl/get-ahd-screening.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,9 @@ | ||
export class GetAhdScreeningQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
agency?: string[]; | ||
gender?: string[]; | ||
datimAgeGroup?: string[]; | ||
} |