-
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 #797 from cbrianbet/feat/ahd-improvements
Added ahd nutrition apis
- Loading branch information
Showing
8 changed files
with
275 additions
and
2 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
src/care-treatment/ahd/queries/handlers/get-ahd-nutrition-assessment.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,88 @@ | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { LinelistFACTART } from '../../../common/entities/linelist-fact-art.model'; | ||
import { GetAhdNutritionAssessmentQuery } from '../impl/get-ahd-nutrition-assessment.query'; | ||
|
||
@QueryHandler(GetAhdNutritionAssessmentQuery) | ||
export class GetAhdNutritionAssessmentHandler implements IQueryHandler<GetAhdNutritionAssessmentQuery> { | ||
constructor( | ||
@InjectRepository(LinelistFACTART, 'mssql') | ||
private readonly repository: Repository<LinelistFACTART>, | ||
) {} | ||
|
||
async execute(query: GetAhdNutritionAssessmentQuery): Promise<any> { | ||
const ahdAssessment = this.repository | ||
.createQueryBuilder('f') | ||
.select([`TOP 1 | ||
(SELECT | ||
SUM(CASE WHEN IsRTTLast12MonthsAfter3monthsIIT = 1 THEN 1 ELSE 0 END) + | ||
SUM(CASE WHEN ConfirmedTreatmentFailure = 1 THEN 1 ELSE 0 END) + | ||
SUM(CASE WHEN NewPatient = 1 THEN 1 ELSE 0 END) AS TotalCount | ||
FROM REPORTING.dbo.linelist_FactART | ||
WHERE AHD=1 and age <15) AS ChildrenWithAHD, | ||
(SELECT | ||
SUM(CASE WHEN IsRTTLast12MonthsAfter3monthsIIT = 1 THEN 1 ELSE 0 END) + | ||
SUM(CASE WHEN ConfirmedTreatmentFailure = 1 THEN 1 ELSE 0 END) + | ||
SUM(CASE WHEN NewPatient = 1 THEN 1 ELSE 0 END) AS TotalCount | ||
FROM REPORTING.dbo.linelist_FactART | ||
WHERE AHD=1 and age <15 and ScreenedForMalnutrition=1) AS ScreenedForMalnutrition, | ||
(SELECT | ||
SUM(CASE WHEN IsRTTLast12MonthsAfter3monthsIIT = 1 THEN 1 ELSE 0 END) + | ||
SUM(CASE WHEN ConfirmedTreatmentFailure = 1 THEN 1 ELSE 0 END) + | ||
SUM(CASE WHEN NewPatient = 1 THEN 1 ELSE 0 END) AS TotalCount | ||
FROM REPORTING.dbo.linelist_FactART | ||
WHERE AHD=1 and age <15 and SAM=1) AS NumberWithSAM, | ||
(SELECT | ||
SUM(CASE WHEN IsRTTLast12MonthsAfter3monthsIIT = 1 THEN 1 ELSE 0 END) + | ||
SUM(CASE WHEN ConfirmedTreatmentFailure = 1 THEN 1 ELSE 0 END) + | ||
SUM(CASE WHEN NewPatient = 1 THEN 1 ELSE 0 END) AS TotalCount | ||
FROM REPORTING.dbo.linelist_FactART | ||
WHERE AHD=1 and age <15 and MAM=1) AS NumberWithMAM | ||
`]) | ||
|
||
if (query.county) { | ||
ahdAssessment.andWhere('f.County IN (:...counties)', { | ||
counties: query.county, | ||
}); | ||
} | ||
|
||
if (query.subCounty) { | ||
ahdAssessment.andWhere('f.Subcounty IN (:...subCounties)', { | ||
subCounties: query.subCounty, | ||
}); | ||
} | ||
|
||
if (query.facility) { | ||
ahdAssessment.andWhere('f.FacilityName IN (:...facilities)', { | ||
facilities: query.facility, | ||
}); | ||
} | ||
|
||
if (query.partner) { | ||
ahdAssessment.andWhere('f.PartnerName IN (:...partners)', { | ||
partners: query.partner, | ||
}); | ||
} | ||
|
||
if (query.agency) { | ||
ahdAssessment.andWhere('f.AgencyName IN (:...agencies)', { | ||
agencies: query.agency, | ||
}); | ||
} | ||
|
||
if (query.datimAgeGroup) { | ||
ahdAssessment.andWhere('f.AgeGroup IN (:...ageGroups)', { | ||
ageGroups: query.datimAgeGroup, | ||
}); | ||
} | ||
|
||
if (query.gender) { | ||
ahdAssessment.andWhere('f.Gender IN (:...genders)', { | ||
genders: query.gender, | ||
}); | ||
} | ||
|
||
return await ahdAssessment.getRawOne(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/care-treatment/ahd/queries/handlers/get-ahd-outcomes.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,71 @@ | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { LinelistFACTART } from '../../../common/entities/linelist-fact-art.model'; | ||
import { GetAhdOutcomesQuery } from '../impl/get-ahd-outcomes.query'; | ||
|
||
@QueryHandler(GetAhdOutcomesQuery) | ||
export class GetAhdOutcomesHandler implements IQueryHandler<GetAhdOutcomesQuery> { | ||
constructor( | ||
@InjectRepository(LinelistFACTART, 'mssql') | ||
private readonly repository: Repository<LinelistFACTART>, | ||
) {} | ||
|
||
async execute(query: GetAhdOutcomesQuery): Promise<any> { | ||
const ahdAssessment = this.repository | ||
.createQueryBuilder('f') | ||
.select([` | ||
ARTOutcomeDescription, | ||
Count (*) as AHDOutcomes | ||
`]) | ||
.where('AHD=1') | ||
.andWhere("ARTOutcomeDescription NOT IN ('Others', 'LOST IN HMIS', 'NEW PATIENT')") | ||
.andWhere("(IsRTTLast12MonthsAfter3monthsIIT=1 OR ConfirmedTreatmentFailure=1 OR NewPatient=1)") | ||
|
||
if (query.county) { | ||
ahdAssessment.andWhere('f.County IN (:...counties)', { | ||
counties: query.county, | ||
}); | ||
} | ||
|
||
if (query.subCounty) { | ||
ahdAssessment.andWhere('f.Subcounty IN (:...subCounties)', { | ||
subCounties: query.subCounty, | ||
}); | ||
} | ||
|
||
if (query.facility) { | ||
ahdAssessment.andWhere('f.FacilityName IN (:...facilities)', { | ||
facilities: query.facility, | ||
}); | ||
} | ||
|
||
if (query.partner) { | ||
ahdAssessment.andWhere('f.PartnerName IN (:...partners)', { | ||
partners: query.partner, | ||
}); | ||
} | ||
|
||
if (query.agency) { | ||
ahdAssessment.andWhere('f.AgencyName IN (:...agencies)', { | ||
agencies: query.agency, | ||
}); | ||
} | ||
|
||
if (query.datimAgeGroup) { | ||
ahdAssessment.andWhere('f.AgeGroup IN (:...ageGroups)', { | ||
ageGroups: query.datimAgeGroup, | ||
}); | ||
} | ||
|
||
if (query.gender) { | ||
ahdAssessment.andWhere('f.Gender IN (:...genders)', { | ||
genders: query.gender, | ||
}); | ||
} | ||
|
||
return await ahdAssessment | ||
.groupBy('ARTOutcomeDescription') | ||
.getRawMany(); | ||
} | ||
} |
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
src/care-treatment/ahd/queries/impl/get-ahd-nutrition-assessment.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 GetAhdNutritionAssessmentQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
agency?: string[]; | ||
gender?: string[]; | ||
datimAgeGroup?: string[]; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/care-treatment/ahd/queries/impl/get-ahd-outcomes.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 GetAhdOutcomesQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
agency?: string[]; | ||
gender?: string[]; | ||
datimAgeGroup?: string[]; | ||
} |
File renamed without changes.
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