Skip to content

Commit

Permalink
Merge pull request #771 from cbrianbet/feat/new-reporting-layer
Browse files Browse the repository at this point in the history
ahd api added
  • Loading branch information
cbrianbet authored Sep 26, 2024
2 parents b67925a + 3ea96bd commit 360a627
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/care-treatment/care-treatment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ 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';


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


@Get('getAHDScreened')
async getAHDScreening(
@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 GetAhdScreeningQuery();

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
4 changes: 4 additions & 0 deletions src/care-treatment/care-treatment.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ 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';


@Module({
imports: [
Expand Down Expand Up @@ -684,6 +686,8 @@ import { GetOtzTotalWithDurableVlHandler } from './otz/queries/handlers/get-otz-
GetArtVerificationPendingSurveysByPartnerHandler,
GetArtVerificationPendingSurveysByCountyHandler,
GetArtVerificationReasonsHandler,

GetAhdScreeningHandler,
],
controllers: [CareTreatmentController],
})
Expand Down
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();
}
}
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[];
}

0 comments on commit 360a627

Please sign in to comment.