Skip to content

Commit

Permalink
Merge branch 'master' into POC-522
Browse files Browse the repository at this point in the history
  • Loading branch information
drizzentic authored Oct 5, 2023
2 parents 7be224d + 918352a commit 7a22c1c
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/reporting-framework/hiv/moh-731.report.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Moh731Report extends MultiDatasetPatientlistReport {
}
params.hivMonthlyDatasetSource = 'etl.hiv_monthly_report_dataset_frozen'; // defaults to frozen
params.hivVlDataSource =
'(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.encounter_id = max_dates.encounter_id)';
'(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)';
console.log('creating new moh 731 report service');
super(reportName, params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"alias": "t1"
},
{
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.encounter_id = max_dates.encounter_id)",
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)",
"alias": "fli",
"join": {
"type": "LEFT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"alias": "t1"
},
{
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.encounter_id = max_dates.encounter_id)",
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)",
"alias": "fli",
"join": {
"type": "LEFT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"alias": "t1"
},
{
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.encounter_id = max_dates.encounter_id)",
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)",
"alias": "fli",
"join": {
"type": "LEFT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"alias": "srb"
},
{
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.encounter_id = max_dates.encounter_id)",
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)",
"alias": "fli",
"join": {
"type": "LEFT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"alias": "hmsd"
},
{
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.encounter_id = max_dates.encounter_id)",
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)",
"alias": "fli",
"join": {
"type": "LEFT",
Expand Down
2 changes: 1 addition & 1 deletion dao/patient/etl-patient-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = (function () {
't1.encounter_id = t3.encounter_id'
],
[
'(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN ( SELECT person_id, MAX(test_datetime) AS max_vl_1_date, max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id ) max_dates ON fli.person_id = max_dates.person_id AND fli.encounter_id = max_dates.encounter_id)',
'(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN ( SELECT person_id, MAX(test_datetime) AS max_vl_1_date, max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id ) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)',
'fli',
'fli.person_id = t1.person_id'
]
Expand Down
21 changes: 20 additions & 1 deletion dao/patient/etl-patient-hiv-summary-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var db = require('../../etl-db');

var def = {
getPatientHivSummary: getPatientHivSummary,
getPatientLastEncounter: getPatientLastEncounter
getPatientLastEncounter: getPatientLastEncounter,
getPatientLastVL: getPatientLastVL
};

module.exports = def;
Expand Down Expand Up @@ -61,3 +62,21 @@ function getPatientLastEncounter(patientUuid) {

return db.queryDb(queryObject);
}
function getPatientLastVL(patientUuid) {
var whereClause = ['uuid = ? and hiv_viral_load is not null ', patientUuid];

var queryObject = {
columns: 'MAX(test_datetime),hiv_viral_load',
table: 'etl.flat_labs_and_imaging',
where: whereClause,
order: [
{
column: 'test_datetime',
asc: false
}
],
limit: 1,
group: ['person_id', 'test_datetime']
};
return db.queryDb(queryObject);
}
25 changes: 23 additions & 2 deletions programs/patient-data-resolver.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const availableKeys = {
patientEncounters: getPatientEncounters,
isPatientTransferredOut: checkTransferOut,
dcQualifedVisits: getQualifiedDcVisits,
latestCovidAssessment: getLatestCovidAssessment
latestCovidAssessment: getLatestCovidAssessment,
isViremicHighVL: getLatestVL
};

const def = {
Expand All @@ -31,7 +32,8 @@ const def = {
getPatientEncounters: getPatientEncounters,
checkTransferOut: checkTransferOut,
dcQualifedVisits: getQualifiedDcVisits,
getLatestCovidAssessment: getLatestCovidAssessment
getLatestCovidAssessment: getLatestCovidAssessment,
isViremicHighVL: getLatestVL
};

module.exports = def;
Expand Down Expand Up @@ -198,3 +200,22 @@ function getLatestCovidAssessment(patientUuid) {
});
});
}

function getLatestVL(patientUuid) {
return new Promise((resolve, reject) => {
etlHivSummary
.getPatientLastVL(patientUuid)
.then((result) => {
if (result.size > 0) {
const isViremic =
result.result[0].hiv_viral_load > 200 ? true : false;
resolve(isViremic);
} else {
resolve(false);
}
})
.catch((error) => {
reject(error);
});
});
}
15 changes: 8 additions & 7 deletions programs/patient-program-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4547,7 +4547,8 @@
"patientEnrollment",
"isPatientTransferredOut",
"patientEncounters",
"latestCovidAssessment"
"latestCovidAssessment",
"isViremicHighVL"
],
"enrollmentOptions": {
"requiredProgramQuestions": [
Expand Down Expand Up @@ -4603,25 +4604,25 @@
{
"uuid": "8d5b2be0-c2cc-11de-8d13-0010c6dffd0f",
"display": "ADULTRETURN",
"allowedIf": "screenedForCovidToday && age > 24",
"allowedIf": "!isViremicHighVL && age > 24",
"errors": {
"covidError": "To access clinical forms kindly fill Covid 19 Assessment Form"
"viremiaError": "To access clinical forms kindly fill Enhanced Adherence Encounter Form"
}
},
{
"uuid": "4e7553b4-373d-452f-bc89-3f4ad9a01ce7",
"display": "YOUTHRETURN",
"allowedIf": "screenedForCovidToday && age >= 10 && age <= 24",
"allowedIf": "!isViremicHighVL && age >= 10 && age <= 24",
"errors": {
"covidError": "To access clinical forms kindly fill Covid 19 Assessment Form"
"viremiaError": "To access clinical forms kindly fill Enhanced Adherence Encounter Form"
}
},
{
"uuid": "8d5b3108-c2cc-11de-8d13-0010c6dffd0f",
"display": "PEDSRETURN",
"allowedIf": "screenedForCovidToday && age <= 14",
"allowedIf": "!isViremicHighVL && age <= 14",
"errors": {
"covidError": "To access clinical forms kindly fill Covid 19 Assessment Form"
"viremiaError": "To access clinical forms kindly fill Enhanced Adherence Encounter Form"
}
},
{
Expand Down
11 changes: 9 additions & 2 deletions programs/scope-builder.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ function buildScope(dataDictionary) {
qualifiesMedicationRefillVisit: false,
lastCovidScreeningDate: '',
retroSpective: false,
screenedForCovidToday: false
screenedForCovidToday: false,
isViremicHighVL: false
};
let isStandardDcVisit = false;

Expand Down Expand Up @@ -155,7 +156,13 @@ function buildScope(dataDictionary) {
}
}
}

// Add Restrictions For Users who are not Suppressed vl > 200 System to Restrict Filling of Enhance Adherance Form
if (
dataDictionary.programUuid === 'c4246ff0-b081-460c-bcc5-b0678012659e' &&
dataDictionary.isViremicHighVL
) {
scope.isViremicHighVL = true;
}
// add other methods to build the scope objects
return scope;
}
Expand Down

0 comments on commit 7a22c1c

Please sign in to comment.