Skip to content

Commit

Permalink
Merge pull request #772 from palladiumkenya/feat/new-reporting-layer
Browse files Browse the repository at this point in the history
updating master
  • Loading branch information
cbrianbet authored Sep 26, 2024
2 parents bf23204 + 360a627 commit af7a6bc
Show file tree
Hide file tree
Showing 43 changed files with 867 additions and 153 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
update the .env file

## Installation

Expand Down
167 changes: 167 additions & 0 deletions src/care-treatment/care-treatment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ import { GetIITTracingQuery } from './treatment-outcomes/queries/impl/get-iit-tr
import { GetIITTracingOutcomesQuery } from './treatment-outcomes/queries/impl/get-iit-tracing-outcomes.query';
import { GetVlUptakeUToUQuery } from './viral-load/queries/impl/get-vl-uptake-U-to-U.query';
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 @@ -10513,6 +10516,65 @@ export class CareTreatmentController {
return this.queryBus.execute(query);
}


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

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 (project) {
query.project = project;
}

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

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

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

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

return this.queryBus.execute(query);
}

@Get('getAlhivWithReSuppression')
async getAlhivWithReSuppression(
@Query('county') county,
Expand Down Expand Up @@ -13645,6 +13707,65 @@ export class CareTreatmentController {
return this.queryBus.execute(query);
}


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

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 (project) {
query.project = project;
}

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

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

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

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

return this.queryBus.execute(query);
}

@Get('getOTZNotEnrolledByPartner')
async getOTZNotEnrolledByPartner(
@Query('county') county,
Expand Down Expand Up @@ -13877,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
9 changes: 8 additions & 1 deletion src/care-treatment/care-treatment.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ import { GetOvcDeadHandler } from './ovc/queries/handlers/get-ovc-dead.handler';
import { GetOvcEligibleVlHandler } from './ovc/queries/handlers/get-ovc-eligible-vl.handler';
import { GetOvcVirallySuppressedHandler } from './ovc/queries/handlers/get-ovc-virally-suppressed.handler';
import { GetOvcVldoneHandler } from './ovc/queries/handlers/get-ovc-vldone.handler';
import { GetOTZCalhivOnArtQuery } from './otz/queries/impl/get-calhiv-on-art.query';
import { GetOTZCalhivOnArtHandler } from './otz/queries/handlers/get-calhiv-on-art.handler';
import { GetOtzCalhivVlEligibleHandler } from './otz/queries/handlers/get-otz-calhiv-vl-eligible.handler';
import { GetCovidNumberScreenedHandler } from './covid/queries/handlers/get-covid-number-screened.handler';
Expand Down Expand Up @@ -339,6 +338,10 @@ import { GetAppointmentKeepingWaterfallHandler } from './treatment-outcomes/quer
import { GetQuaterlyIITHandler } from './treatment-outcomes/queries/handlers/get-quaterly-iit.handler';
import { GetIITTracingHandler } from './treatment-outcomes/queries/handlers/get-iit-tracing.handler';
import { GetIITTracingOutcomesHandler } from './treatment-outcomes/queries/handlers/get-iit-tracing-outcomes.handler';
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({
Expand Down Expand Up @@ -665,6 +668,8 @@ import { GetIITTracingOutcomesHandler } from './treatment-outcomes/queries/handl
GetOvcVldoneHandler,
GetOTZCalhivOnArtHandler,
GetOtzCalhivVlEligibleHandler,
GetOtzTotalWithDurableVlHandler,
GetAlhivOnArtByAgeSexHandler,
GetCovidNumberScreenedHandler,
GetCumulativeNumberAdultPlhivWithMissingDateGivenFirstDoseHandler,
GetCovidAdmissionSymptomaticOverallHandler,
Expand All @@ -681,6 +686,8 @@ import { GetIITTracingOutcomesHandler } from './treatment-outcomes/queries/handl
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[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { LineListOTZEligibilityAndEnrollments } from '../../entities/line-list-otz-eligibility-and-enrollments.model';
import { GetAlhivOnArtByAgeSexQuery } from '../impl/get-alhiv-on-art-by-age-sex.query';

@QueryHandler(GetAlhivOnArtByAgeSexQuery)
export class GetAlhivOnArtByAgeSexHandler
implements IQueryHandler<GetAlhivOnArtByAgeSexQuery> {
constructor(
@InjectRepository(LineListOTZEligibilityAndEnrollments, 'mssql')
private readonly repository: Repository<
LineListOTZEligibilityAndEnrollments
>,
) {}

async execute(query: GetAlhivOnArtByAgeSexQuery): Promise<any> {
const CALHIVOnART = this.repository
.createQueryBuilder('f')
.select(['Count (*) CALHIVonART, AgeGroup, Gender']);

if (query.county) {
CALHIVOnART.andWhere('f.County IN (:...counties)', {
counties: query.county,
});
}

if (query.subCounty) {
CALHIVOnART.andWhere('f.SubCounty IN (:...subCounties)', {
subCounties: query.subCounty,
});
}

if (query.facility) {
CALHIVOnART.andWhere('f.FacilityName IN (:...facilities)', {
facilities: query.facility,
});
}

if (query.partner) {
CALHIVOnART.andWhere('f.PartnerName IN (:...partners)', {
partners: query.partner,
});
}

if (query.agency) {
CALHIVOnART.andWhere('f.AgencyName IN (:...agencies)', {
agencies: query.agency,
});
}

if (query.datimAgeGroup) {
CALHIVOnART.andWhere('f.AgeGroup IN (:...ageGroups)', {
ageGroups: query.datimAgeGroup,
});
}

if (query.gender) {
CALHIVOnART.andWhere('f.Gender IN (:...genders)', {
genders: query.gender,
});
}

return await CALHIVOnART.groupBy('AgeGroup, Gender').getRawMany();
}
}
Loading

0 comments on commit af7a6bc

Please sign in to comment.