Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added apis for U=U dashboards #671

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions src/care-treatment/care-treatment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ import { GetQuaterlyIITQuery } from './treatment-outcomes/queries/impl/get-quate
import { GetAppointmentKeepingWaterfallQuery } from './treatment-outcomes/queries/impl/get-appointment-keeping-waterfall.query';
import { GetIITTracingQuery } from './treatment-outcomes/queries/impl/get-iit-tracing.query';
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';


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

@Get('vlUptakeUToU')
async getVlUptakeUToU(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
@Query('gender') gender,
@Query('datimAgeGroup') datimAgeGroup,
@Query('pbfw') pbfw,
): Promise<any> {
const query = new GetVlUptakeUToUQuery();
if (county) {
query.county = county;
}

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

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

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

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

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

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

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

return this.queryBus.execute(query);
}

@Get('vlCategorizationUToU')
async getVlCategorizationUToU(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
@Query('gender') gender,
@Query('datimAgeGroup') datimAgeGroup,
@Query('pbfw') pbfw,
): Promise<any> {
const query = new GetVlCategorizationUToUQuery();
if (county) {
query.county = county;
}

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

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

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

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

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

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

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

return this.queryBus.execute(query);
}

@Get('vlOutcomesOverall')
async getVlOutcomesOverall(
@Query('county') county,
Expand Down
152 changes: 75 additions & 77 deletions src/care-treatment/care-treatment.module.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Column, Entity, PrimaryColumn } from 'typeorm';

@Entity('AggregateVLDurable')
export class AggregateVLDurable {
@PrimaryColumn('text')
MFLCode: string;

@Column('text')
FacilityName: string;

@Column('text')
County: string;

@Column('text')
SubCounty: string;

@Column('text')
PartnerName: string;

@Column('text')
AgencyName: string;

@Column('text')
Gender: string;

@Column('text')
ValidVLResultCategory: string;

@Column('int')
PBFWCategory: number;

@Column('text')
AgeGroup: string;

@Column('int')
TXCurr: number;

@Column('int')
EligibleVL: number;

@Column('int')
HasValidVL: number;

@Column('int')
CountEligibleForTwoVLTests: number;

@Column('int')
CountTwoConsecutiveTestsWithinTheYear: number;

@Column('int')
DurableLDL: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { InjectRepository } from '@nestjs/typeorm';
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import { Repository } from 'typeorm';
import { AggregateVLDurable } from '../../entities/aggregate-vl-durable.model';
import { GetVlCategorizationUToUQuery } from '../impl/get-vl-categorization-U-to-U.query';

@QueryHandler(GetVlCategorizationUToUQuery)
export class GetVlCategorizationUToUHandler
implements IQueryHandler<GetVlCategorizationUToUQuery> {
constructor(
@InjectRepository(AggregateVLDurable, 'mssql')
private readonly repository: Repository<AggregateVLDurable>,
) {}

async execute(query: GetVlCategorizationUToUQuery): Promise<any> {
const vlUptake = this.repository
.createQueryBuilder('f')
.select([
`SUM(TXCurr),
CASE WHEN ValidVLResultCategory = 'Undetectable'
THEN '<50'
ELSE ValidVLResultCategory
END ValidVLResultCategory
`,
])
.where('f.Gender IS NOT NULL');

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

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

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

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

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

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

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

if (query.pbfw) {
vlUptake.andWhere('f.PBFWCategory IN (:...pbfws)', {
pbfws: query.pbfw,
});
}

return await vlUptake
.groupBy(
`CASE WHEN ValidVLResultCategory = 'Undetectable' THEN '<50' ELSE ValidVLResultCategory END`,
)
.getRawMany();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { InjectRepository } from '@nestjs/typeorm';
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import { Repository } from 'typeorm';
import { GetVlUptakeUToUQuery } from '../impl/get-vl-uptake-U-to-U.query';
import { AggregateVLDurable } from './../../entities/aggregate-vl-durable.model';

@QueryHandler(GetVlUptakeUToUQuery)
export class GetVlUptakeUToUHandler
implements IQueryHandler<GetVlUptakeUToUQuery> {
constructor(
@InjectRepository(AggregateVLDurable, 'mssql')
private readonly repository: Repository<AggregateVLDurable>,
) {}

async execute(query: GetVlUptakeUToUQuery): Promise<any> {
const vlUptake = this.repository
.createQueryBuilder('f')
.select([
`SUM(TXCurr) TXCurr, SUM(EligibleVL) EligibleVL, SUM(HasValidVL) HasValidVL,
SUM(CountTwoConsecutiveTestsWithinTheYear) TwoConsTests,
SUM(CountEligibleForTwoVLTests) TwoEligibleTests, SUM(CountDurableLDL) DurableLDL,
SUM(CountLDLLastOneTest) LDLLastOneTest`,
])
.where('f.Gender IS NOT NULL');

if (query.county) {
vlUptake.andWhere('f.County IN (:...counties)', {
counties: query.county,

});
}

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

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

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

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

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

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

if (query.pbfw) {
vlUptake.andWhere('f.PBFWCategory IN (:...pbfws)', {
pbfws: query.pbfw,
});
}

return await vlUptake.getRawOne();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export class GetVlCategorizationUToUQuery {
county?: string[];
subCounty?: string[];
facility?: string[];
partner?: string[];
pbfw?: string[];
gender?: string[];
datimAgeGroup?: string[];
agency?: string[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export class GetVlUptakeUToUQuery {
county?: string[];
subCounty?: string[];
facility?: string[];
partner?: string[];
pbfw?: string[];
gender?: string[];
datimAgeGroup?: string[];
agency?: string[];
}