-
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 #670 from cbrianbet/feat/new-reporting-layer
Added apis for U=U dashboards
- Loading branch information
Showing
7 changed files
with
402 additions
and
77 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
src/care-treatment/viral-load/entities/aggregate-vl-durable.model.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,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; | ||
} |
82 changes: 82 additions & 0 deletions
82
src/care-treatment/viral-load/queries/handlers/get-vl-categorization-U-to-U.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,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(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/care-treatment/viral-load/queries/handlers/get-vl-uptake-U-to-U.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,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(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/care-treatment/viral-load/queries/impl/get-vl-categorization-U-to-U.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,10 @@ | ||
export class GetVlCategorizationUToUQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
pbfw?: string[]; | ||
gender?: string[]; | ||
datimAgeGroup?: string[]; | ||
agency?: string[]; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/care-treatment/viral-load/queries/impl/get-vl-uptake-U-to-U.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,10 @@ | ||
export class GetVlUptakeUToUQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
pbfw?: string[]; | ||
gender?: string[]; | ||
datimAgeGroup?: string[]; | ||
agency?: string[]; | ||
} |