Skip to content

Commit

Permalink
Merge pull request #733 from cbrianbet/feat/new-reporting-layer
Browse files Browse the repository at this point in the history
Feat/new reporting layer
  • Loading branch information
cbrianbet authored Jun 12, 2024
2 parents 5323891 + 5967309 commit 47991db
Show file tree
Hide file tree
Showing 23 changed files with 9,317 additions and 20 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GetProportionOfPLHIVWithAeWhoseRegimenWasNotAlteredQuery } from '../imp
import { InjectRepository } from '@nestjs/typeorm';
import { FactTransAeActionDrug } from '../../entities/fact-trans-ae-action-drug.model';
import { Repository } from 'typeorm';
import { AggregateAdverseEvents } from './../../entities/aggregate-adverse-events.model';
import { AggregateAdverseEvents } from '../../entities/aggregate-adverse-events.model';

@QueryHandler(GetProportionOfPLHIVWithAeWhoseRegimenWasNotAlteredQuery)
export class GetProportionOfPLHIVWithAeWhoseRegimenWasNotAlteredHandler implements IQueryHandler<GetProportionOfPLHIVWithAeWhoseRegimenWasNotAlteredQuery> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ export class GetVlOverallGt1000CopiesReceivedEacHandler
@InjectRepository(LinelistFACTART, 'mssql')
private readonly repository: Repository<LinelistFACTART>,
) {}
//TODO::Add fact Enhanced Ahearacnce counceling
async execute(
query: GetVlOverallUptakeGt1000CopiesReceivedEacQuery,
): Promise<any> {
const vlOverallUptakeGt1000 = this.repository
.createQueryBuilder('art')
.select([`art.SiteCode, art.PatientPKHash, ValidVLResultCategory1`])
.where(
`art.ARTOutcomeDescription ='Active' AND DATEDIFF( MONTH, lastVLDate, GETDATE( ) ) <= 14 AND ValidVLResult IS NOT NULL`,
`art.ARTOutcomeDescription ='Active' AND DATEDIFF( MONTH, lastVLDate, GETDATE( ) ) <= 12 AND ValidVLResult IS NOT NULL`,
);

if (query.county) {
Expand Down Expand Up @@ -122,7 +121,7 @@ export class GetVlOverallGt1000CopiesReceivedEacHandler
COUNT(EACVisitDate_2) AS EACVisitDate_2,
COUNT(EACVisitDate_3) AS EACVisitDate_3
FROM combined_dataset
WHERE ValidVLResultCategory1 IN ('>1000')
WHERE ValidVLResultCategory1 IN ('200-999', '>1000')
GROUP BY ValidVLResultCategory1;`;
};
vlOverallUptakeGt1000.getParameters = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class GetVlOverallGt1000CopiesHandler
.select([
`LastVL, lastVLDate, CASE WHEN ISNUMERIC(ValidVLResult)=1 THEN CASE
WHEN CAST(Replace(ValidVLResult,',','')AS FLOAT) >= 1000 THEN '>1000 Copies'
WHEN CAST(Replace(ValidVLResult,',','')AS FLOAT) >=200 AND CAST(Replace(ValidVLResult,',','')AS FLOAT) < 1000 THEN '200-999'
END
ELSE NULL END AS [Last12MVLResult]`,
])
Expand Down Expand Up @@ -71,7 +72,7 @@ export class GetVlOverallGt1000CopiesHandler
const originalParams = vlOverallUptakeGt1000.getParameters;
vlOverallUptakeGt1000.getQuery = () => {
const a = originalQuery.call(vlOverallUptakeGt1000);
return `WITH VL AS (${a}) SELECT Last12MVLResult, Count(*) Num FROM VL WHERE Last12MVLResult in ('>1000 Copies') Group by Last12MVLResult`;
return `WITH VL AS (${a}) SELECT Last12MVLResult, Count(*) Num FROM VL WHERE Last12MVLResult in ('200-999', '>1000 Copies') Group by Last12MVLResult`;
};
vlOverallUptakeGt1000.getParameters = () => {
return originalParams.call(vlOverallUptakeGt1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,28 @@ export class GetVlOverallNumberWithFollowVlTestsAtGt1000CopiesSecondLineRegiment
}

async execute(query: GetVlOverallNumberWithFollowTestsAtGt1000CopiesSecondlineRegimentQuery): Promise<any> {
// const vlOverallUptakeAndSuppressionBySex = this.repository.createQueryBuilder('f')
// .select(['Last12MVLResult, Gender gender, COUNT ( * ) Num'])
// .where('f.MFLCode > 0')
// .andWhere('Last12MVLResult IS NOT NULL');

const vlOverallNumberFollowSecondlineRegiment = this.repository
.createQueryBuilder('cohort')
.select([
`cohort.SiteCode,cohort.PatientIDHash,cohort.County,cohort.SubCounty,DOB,cohort.Gender,LatestVL1 as LastVL,LatestVLDate2Key,LatestVLDate1Key,ARTOutcomeDescription,CurrentRegimenLine As CurrentARTLine,
`cohort.SiteCode, cohort.PatientIDHash, cohort.County, cohort.SubCounty, DOB, cohort.Gender,LatestVL1 as LastVL,
LatestVLDate2Key, LatestVLDate1Key, ARTOutcomeDescription, CurrentRegimenLine As CurrentARTLine, SwitchedToSecondLineLast12Months,
CASE
WHEN ISNUMERIC(LatestVL1)=1 THEN
CASE
WHEN CAST(Replace(LatestVL1,',','')AS FLOAT) >=1000 THEN '>1000 Copies'
WHEN CAST(Replace(LatestVL1,',','')AS FLOAT) >=200 AND CAST(Replace(LatestVL1,',','')AS FLOAT) < 1000 THEN '200-999'
END
END AS [LastVLResult],
END AS [LastVLResult],
LatestVLDate1Key as DateLAstVL,
LatestVL2,
CASE
WHEN ISNUMERIC(LatestVL2)=1 THEN
CASE
WHEN CAST(Replace(LatestVL2,',','')AS FLOAT) >=1000 THEN '>1000 Copies'
WHEN CAST(Replace(LatestVL2,',','')AS FLOAT) >=200 AND CAST(Replace(LatestVL2,',','')AS FLOAT) < 1000 THEN '200-999'
END
END AS [VL2Result]`,
END AS [VL2Result]`,
])
.leftJoin(
'LineListViralLoad',
Expand Down Expand Up @@ -97,7 +96,7 @@ export class GetVlOverallNumberWithFollowVlTestsAtGt1000CopiesSecondLineRegiment
const a = originalQuery.call(
vlOverallNumberFollowSecondlineRegiment,
);
return `WITH VL AS (${a}) SELECT VL2Result, Count (*) Num FROM VL WHERE ARTOutcomeDescription ='Active' and VL2Result in ('>1000 Copies') and DATEDIFF(MONTH,LatestVLDate2Key,GETDATE())<= 14 and currentARTline='Second Line' Group by VL2Result`;
return `WITH VL AS (${a}) SELECT VL2Result, Count (*) Num FROM VL WHERE ARTOutcomeDescription ='Active' and VL2Result in ('200-999', '>1000 Copies') and DATEDIFF(MONTH,LatestVLDate2Key,GETDATE())<= 12 and SwitchedToSecondLineLast12Months = 1 Group by VL2Result`;
};

vlOverallNumberFollowSecondlineRegiment.getParameters = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { InjectRepository } from '@nestjs/typeorm';
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import { Repository } from 'typeorm';
import { FactTransVLOverallUptake } from '../../entities/fact-trans-vl-overall-uptake.model';
import { GetVlOverallUptakeAndSuppressionLdlQuery } from '../impl/get-vl-overall-uptake-and-suppression-ldl.query';
import { FactTransNewCohort } from '../../../new-on-art/entities/fact-trans-new-cohort.model';
import { LinelistFACTART } from './../../../common/entities/linelist-fact-art.model';
import { LinelistFACTART } from '../../../common/entities/linelist-fact-art.model';

@QueryHandler(GetVlOverallUptakeAndSuppressionLdlQuery)
export class GetVlOverallUptakeAndSuppressionLdlHandler
Expand All @@ -26,8 +24,6 @@ export class GetVlOverallUptakeAndSuppressionLdlHandler
"ARTOutcomeDescription ='Active' and DATEDIFF(MONTH,lastVLDate,GETDATE())<= 14",
);

// const vlOverallUptakeAndSuppressinLDL = "With VL AS (SELECT LastVL, lastVLDate, CASE WHEN ISNUMERIC(LastVL)=1 THEN CASE WHEN CAST(Replace(LastVL,',','')AS FLOAT) <=50.90 THEN '<50 Copies' WHEN CAST(Replace(LastVL,',','') AS FLOAT) between 51.00 and 399.00 THEN '51-399' WHEN CAST(Replace(LastVL,',','')AS FLOAT) between 400.00 and 999.00 THEN '400-999' WHEN CAST(Replace(LastVL,',','')AS FLOAT) >=1000 THEN '>1000 Copies' END WHEN LastVL IN ('undetectable','NOT DETECTED','0 copies/ml','LDL','ND','Target Not Detected',' Not detected','Target Not Detected.','Less than Low Detectable Level') THEN '<50 Copies' ELSE NULL END AS [Last12MVLResult] FROM PortalDev.dbo.Fact_Trans_New_Cohort where ARTOutcome='V' and DATEDIFF(MONTH,lastVLDate,GETDATE())<= 14 ) SELECT Last12MVLResult, Count(*) Num FROM VL where Last12MVLResult in ('<50 Copies','400-999','51-399') Group by Last12MVLResult"

if (query.county) {
vlOverallUptakeAndSuppressinLDL.andWhere(
'f.County IN (:...counties)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class GetVlOverallUptakeReceivedFollowTestsAllHandler implements IQueryHa
WHEN ISNUMERIC(LatestVL1)=1 THEN
CASE
WHEN CAST(Replace(LatestVL1,',','')AS FLOAT) >=1000 THEN '>1000 Copies'
WHEN CAST(Replace(LatestVL1,',','')AS FLOAT) >=200 AND CAST(Replace(LatestVL1,',','')AS FLOAT) < 1000 THEN '200-999'
END
END AS [LastVLResult],
LatestVLDate1Key as DateLAstVL,
Expand All @@ -29,6 +30,7 @@ export class GetVlOverallUptakeReceivedFollowTestsAllHandler implements IQueryHa
WHEN ISNUMERIC(LatestVL2)=1 THEN
CASE
WHEN CAST(Replace(LatestVL2,',','')AS FLOAT) >=1000 THEN '>1000 Copies'
WHEN CAST(Replace(LatestVL2,',','')AS FLOAT) >=200 AND CAST(Replace(LatestVL2,',','')AS FLOAT) < 1000 THEN '200-999'
END
END AS [VL2Result]`,
])
Expand Down Expand Up @@ -91,7 +93,7 @@ export class GetVlOverallUptakeReceivedFollowTestsAllHandler implements IQueryHa
const originalParams = vlOverallUptakeReceivedFollowAll.getParameters;
vlOverallUptakeReceivedFollowAll.getQuery = () => {
const a = originalQuery.call(vlOverallUptakeReceivedFollowAll);
return `WITH VL AS (${a}) SELECT Count (*) Num FROM VL WHERE ARTOutcomeDescription='Active' and VL2Result in ('>1000 Copies') and LastVLResult is not null and DATEDIFF(MONTH,LatestVLDate2Key,GETDATE())<= 14`;
return `WITH VL AS (${a}) SELECT Count (*) Num FROM VL WHERE ARTOutcomeDescription='Active' and VL2Result in ('200-999', '>1000 Copies') and LastVLResult is not null and DATEDIFF(MONTH,LatestVLDate2Key,GETDATE())<= 12`;
};

vlOverallUptakeReceivedFollowAll.getParameters = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class GetVlOverallUptakeReceivedFollowTestsHandler implements IQueryHandl
WHEN ISNUMERIC(LatestVL1)=1 THEN
CASE
WHEN CAST(Replace(LatestVL1,',','')AS FLOAT) >=1000 THEN '>1000 Copies'
WHEN CAST(Replace(LatestVL1,',','')AS FLOAT) >=200 AND CAST(Replace(LatestVL1,',','')AS FLOAT) < 1000 THEN '200-999'
END
END AS [LastVLResult],
LatestVLDate1Key as DateLAstVL,
Expand All @@ -30,6 +31,7 @@ export class GetVlOverallUptakeReceivedFollowTestsHandler implements IQueryHandl
WHEN ISNUMERIC(LatestVL2)=1 THEN
CASE
WHEN CAST(Replace(LatestVL2,',','')AS FLOAT) >=1000 THEN '>1000 Copies'
WHEN CAST(Replace(LatestVL2,',','')AS FLOAT) >=200 AND CAST(Replace(LatestVL2,',','')AS FLOAT) < 1000 THEN '200-999'
END
END AS [VL2Result]`,
])
Expand Down Expand Up @@ -92,7 +94,7 @@ export class GetVlOverallUptakeReceivedFollowTestsHandler implements IQueryHandl
const originalParams = vlOverallUptakeReceivedFollow.getParameters;
vlOverallUptakeReceivedFollow.getQuery = () => {
const a = originalQuery.call(vlOverallUptakeReceivedFollow);
return `WITH VL AS (${a}) SELECT LastVLResult, Count (*) Num FROM VL WHERE ARTOutcomeDescription ='Active' and VL2Result in ('>1000 Copies') and DATEDIFF(MONTH,LatestVLDate2Key,GETDATE())<= 14 group by LastVLResult`;
return `WITH VL AS (${a}) SELECT LastVLResult, Count (*) Num FROM VL WHERE ARTOutcomeDescription ='Active' and VL2Result in ('200-999', '>1000 Copies') and DATEDIFF(MONTH,LatestVLDate2Key,GETDATE())<= 12 group by LastVLResult`;
};

vlOverallUptakeReceivedFollow.getParameters = () => {
Expand Down
169 changes: 169 additions & 0 deletions src/common/common.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { GetPartnersQuery } from './queries/impl/get-partners.query';
import { GetAgenciesQuery } from './queries/impl/get-agencies.query';
import { GetProjectsQuery } from './queries/impl/get-projects.query';
import { GetSitesQuery } from './queries/impl/get-sites.query';
import { GetFacilityStatusQuery } from './queries/impl/get-facility-status.query';
import { GetFacilityStatusByPartnerQuery } from './queries/impl/get-facility-status-by-partner.query';
import { GetFacilityLevelByOwnershipPartnerQuery } from './queries/impl/get-facility-level-by-ownership-partner.query';
import { GetFacilityLevelByOwnershipCountyQuery } from './queries/impl/get-facility-level-by-ownership-county.query';
import { GetFacilityByInfrastructureQuery } from './queries/impl/get-facility-by-infrastructure.query';
import { GetFacilityLinelistQuery } from './queries/impl/get-facility-linelist.query';

@Controller('common')
export class CommonController {
Expand Down Expand Up @@ -198,6 +204,169 @@ export class CommonController {
return this.queryBus.execute(query);
}

@Get('facilityStatus')
async getFacilityStatus(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityStatusQuery();
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;
}
return this.queryBus.execute(query);
}

@Get('facilityStatusByPartner')
async getFacilityStatusByPartner(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityStatusByPartnerQuery();
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;
}
return this.queryBus.execute(query);
}

@Get('facilityLevelByOwnershipPartner')
async getFacilityLevelByOwnershipPartner(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityLevelByOwnershipPartnerQuery();
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;
}
return this.queryBus.execute(query);
}

@Get('facilityLevelByOwnershipCounty')
async getFacilityLevelByOwnershipCounty(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityLevelByOwnershipCountyQuery();
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;
}
return this.queryBus.execute(query);
}

@Get('facilityByInfrastructure')
async getFacilityByInfrastructure(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityByInfrastructureQuery();
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;
}
return this.queryBus.execute(query);
}


@Get('facilityLinelist')
async getFacilityLinelist(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityLinelistQuery();
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;
}
return this.queryBus.execute(query);
}

@Get('sites')
async getSites(): Promise<any> {
return this.queryBus.execute(new GetSitesQuery());
Expand Down
12 changes: 12 additions & 0 deletions src/common/common.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { GetFacilitiesHandler } from './queries/handlers/get-facilities.handler'
import { GetPartnersHandler } from './queries/handlers/get-partners.handler';
import { GetAgenciesHandler } from './queries/handlers/get-agencies.handler';
import { GetSitesHandler } from './queries/handlers/get-sites.handler';
import { GetFacilityStatusHandler } from './queries/handlers/get-facility-status.handler';
import { GetFacilityStatusByPartnerHandler } from './queries/handlers/get-facility-status-by-partner.handler';
import { GetFacilityLevelByOwnershipPartnerHandler } from './queries/handlers/get-facility-level-by-ownership-partner.handler';
import { GetFacilityLevelByOwnershipCountyHandler } from './queries/handlers/get-facility-level-by-ownership-county.handler';
import { GetFacilityByInfrastructureHandler } from './queries/handlers/get-facility-by-infrastructure.handler';
import { GetFacilityLinelistHandler } from './queries/handlers/get-facility-linelist.handler';
import { CommonController } from './common.controller';
import { AllEmrSites } from '../care-treatment/common/entities/all-emr-sites.model';

Expand All @@ -24,6 +30,12 @@ import { AllEmrSites } from '../care-treatment/common/entities/all-emr-sites.mod
GetPartnersHandler,
GetAgenciesHandler,
GetSitesHandler,
GetFacilityStatusHandler,
GetFacilityStatusByPartnerHandler,
GetFacilityLevelByOwnershipPartnerHandler,
GetFacilityLevelByOwnershipCountyHandler,
GetFacilityByInfrastructureHandler,
GetFacilityLinelistHandler,
],
controllers: [CommonController],
})
Expand Down
Loading

0 comments on commit 47991db

Please sign in to comment.