Skip to content

Commit

Permalink
Merge pull request #731 from cbrianbet/feat/new-reporting-layer
Browse files Browse the repository at this point in the history
update backend API for unsuppressed vl
  • Loading branch information
cbrianbet authored May 16, 2024
2 parents 9a735f8 + 78e4bc0 commit 834558e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
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

0 comments on commit 834558e

Please sign in to comment.