Skip to content

Commit

Permalink
Merge pull request #797 from cbrianbet/feat/ahd-improvements
Browse files Browse the repository at this point in the history
Added ahd nutrition apis
  • Loading branch information
cbrianbet authored Feb 20, 2025
2 parents 4245eb8 + cc69b5b commit 1712221
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 2 deletions.
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();
}
}
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();
}
}
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 src/care-treatment/ahd/queries/impl/get-ahd-outcomes.query.ts
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[];
}
94 changes: 93 additions & 1 deletion src/care-treatment/care-treatment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ import { GetVlUptakeUToUQuery } from './viral-load/queries/impl/get-vl-uptake-U-
import { GetVlCategorizationUToUQuery } from './viral-load/queries/impl/get-vl-categorization-U-to-U.query';
import { GetAlhivOnArtByAgeSexQuery } from './otz/queries/impl/get-alhiv-on-art-by-age-sex.query';
import { GetOtzTotalWithDurableVlQuery } from './otz/queries/impl/get-otz-total-with-durable-vl.query';
import { GetAhdScreeningQuery } from './current-on-art/queries/impl/get-ahd-screening.query';
import { GetAhdScreeningQuery } from './ahd/queries/impl/get-ahd-screening.query';
import { GetAhdNutritionAssessmentQuery } from './ahd/queries/impl/get-ahd-nutrition-assessment.query';
import { GetAhdOutcomesQuery } from './ahd/queries/impl/get-ahd-outcomes.query';


@Controller('care-treatment')
Expand Down Expand Up @@ -14044,6 +14046,96 @@ export class CareTreatmentController {
return this.queryBus.execute(query);
}

@Get('getAHDNutritionAssessment')
async getAHDNutritionAssessment(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
@Query('year') year,
@Query('month') month,
@Query('gender') gender,
@Query('datimAgeGroup') datimAgeGroup,
): Promise<any> {
const query = new GetAhdNutritionAssessmentQuery();

if (county) {
query.county = county;
}

if (subCounty) {
query.subCounty = subCounty;
}

if (facility) {
query.facility = facility;
}

if (partner) {
query.partner = partner;
}

if (agency) {
query.agency = agency;
}

if (gender) {
query.gender = gender;
}

if (datimAgeGroup) {
query.datimAgeGroup = datimAgeGroup;
}

return this.queryBus.execute(query);
}

@Get('getAHDOutcomes')
async getAHDOutcomes(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
@Query('year') year,
@Query('month') month,
@Query('gender') gender,
@Query('datimAgeGroup') datimAgeGroup,
): Promise<any> {
const query = new GetAhdOutcomesQuery();

if (county) {
query.county = county;
}

if (subCounty) {
query.subCounty = subCounty;
}

if (facility) {
query.facility = facility;
}

if (partner) {
query.partner = partner;
}

if (agency) {
query.agency = agency;
}

if (gender) {
query.gender = gender;
}

if (datimAgeGroup) {
query.datimAgeGroup = datimAgeGroup;
}

return this.queryBus.execute(query);
}

@Get('getArtVerificationByPartner')
async getArtVerificationByPartner(
@Query('county') county,
Expand Down
6 changes: 5 additions & 1 deletion src/care-treatment/care-treatment.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ import { GetIITTracingOutcomesHandler } from './treatment-outcomes/queries/handl
import { GetAlhivOnArtByAgeSexHandler } from './otz/queries/handlers/get-alhiv-on-art-by-age-sex.handler';
import { GetOtzTotalWithDurableVlHandler } from './otz/queries/handlers/get-otz-total-with-durable-vl.handler';

import { GetAhdScreeningHandler } from './current-on-art/queries/handlers/get-ahd-screening.handler';
import { GetAhdScreeningHandler } from './ahd/queries/handlers/get-ahd-screening.handler';
import { GetAhdNutritionAssessmentHandler } from './ahd/queries/handlers/get-ahd-nutrition-assessment.handler';
import { GetAhdOutcomesHandler } from './ahd/queries/handlers/get-ahd-outcomes.handler';


@Module({
Expand Down Expand Up @@ -688,6 +690,8 @@ import { GetAhdScreeningHandler } from './current-on-art/queries/handlers/get-ah
GetArtVerificationReasonsHandler,

GetAhdScreeningHandler,
GetAhdNutritionAssessmentHandler,
GetAhdOutcomesHandler
],
controllers: [CareTreatmentController],
})
Expand Down

0 comments on commit 1712221

Please sign in to comment.