diff --git a/app/reporting-framework/hiv/moh-731.report.js b/app/reporting-framework/hiv/moh-731.report.js index 81e681672..92c53808c 100755 --- a/app/reporting-framework/hiv/moh-731.report.js +++ b/app/reporting-framework/hiv/moh-731.report.js @@ -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); } diff --git a/app/reporting-framework/json-reports/clinical-reminder-report.json b/app/reporting-framework/json-reports/clinical-reminder-report.json index af6355db0..af46abd99 100644 --- a/app/reporting-framework/json-reports/clinical-reminder-report.json +++ b/app/reporting-framework/json-reports/clinical-reminder-report.json @@ -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", diff --git a/app/reporting-framework/json-reports/patient-list-template.json b/app/reporting-framework/json-reports/patient-list-template.json index f1c439de7..fb84f3dd8 100755 --- a/app/reporting-framework/json-reports/patient-list-template.json +++ b/app/reporting-framework/json-reports/patient-list-template.json @@ -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", diff --git a/app/reporting-framework/json-reports/patient-list-with-contacts-template.json b/app/reporting-framework/json-reports/patient-list-with-contacts-template.json index 2d1536f60..f7ac08f90 100755 --- a/app/reporting-framework/json-reports/patient-list-with-contacts-template.json +++ b/app/reporting-framework/json-reports/patient-list-with-contacts-template.json @@ -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", diff --git a/app/reporting-framework/json-reports/surge-report-base.json b/app/reporting-framework/json-reports/surge-report-base.json index aa3716467..83e1fca61 100644 --- a/app/reporting-framework/json-reports/surge-report-base.json +++ b/app/reporting-framework/json-reports/surge-report-base.json @@ -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", diff --git a/app/reporting-framework/json-reports/tb-preventive-dataset-base.json b/app/reporting-framework/json-reports/tb-preventive-dataset-base.json index 8192b329a..6a382ff43 100644 --- a/app/reporting-framework/json-reports/tb-preventive-dataset-base.json +++ b/app/reporting-framework/json-reports/tb-preventive-dataset-base.json @@ -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", diff --git a/dao/patient/etl-patient-dao.js b/dao/patient/etl-patient-dao.js index 328e4b6a3..ea647f6a0 100755 --- a/dao/patient/etl-patient-dao.js +++ b/dao/patient/etl-patient-dao.js @@ -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' ] diff --git a/dao/patient/etl-patient-hiv-summary-dao.js b/dao/patient/etl-patient-hiv-summary-dao.js index 039262a08..b84dc9ae3 100755 --- a/dao/patient/etl-patient-hiv-summary-dao.js +++ b/dao/patient/etl-patient-hiv-summary-dao.js @@ -4,7 +4,8 @@ var db = require('../../etl-db'); var def = { getPatientHivSummary: getPatientHivSummary, - getPatientLastEncounter: getPatientLastEncounter + getPatientLastEncounter: getPatientLastEncounter, + getPatientLastVL: getPatientLastVL }; module.exports = def; @@ -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); +} diff --git a/programs/patient-data-resolver.service.js b/programs/patient-data-resolver.service.js index fd3ee96cd..bbb04bbfa 100755 --- a/programs/patient-data-resolver.service.js +++ b/programs/patient-data-resolver.service.js @@ -18,7 +18,8 @@ const availableKeys = { patientEncounters: getPatientEncounters, isPatientTransferredOut: checkTransferOut, dcQualifedVisits: getQualifiedDcVisits, - latestCovidAssessment: getLatestCovidAssessment + latestCovidAssessment: getLatestCovidAssessment, + isViremicHighVL: getLatestVL }; const def = { @@ -31,7 +32,8 @@ const def = { getPatientEncounters: getPatientEncounters, checkTransferOut: checkTransferOut, dcQualifedVisits: getQualifiedDcVisits, - getLatestCovidAssessment: getLatestCovidAssessment + getLatestCovidAssessment: getLatestCovidAssessment, + isViremicHighVL: getLatestVL }; module.exports = def; @@ -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); + }); + }); +} diff --git a/programs/patient-program-config.json b/programs/patient-program-config.json index 07b4a5140..b5f1f8a49 100755 --- a/programs/patient-program-config.json +++ b/programs/patient-program-config.json @@ -4547,7 +4547,8 @@ "patientEnrollment", "isPatientTransferredOut", "patientEncounters", - "latestCovidAssessment" + "latestCovidAssessment", + "isViremicHighVL" ], "enrollmentOptions": { "requiredProgramQuestions": [ @@ -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" } }, { diff --git a/programs/scope-builder.service.js b/programs/scope-builder.service.js index bf5bfaa3f..c9e8f4dfb 100755 --- a/programs/scope-builder.service.js +++ b/programs/scope-builder.service.js @@ -15,7 +15,8 @@ function buildScope(dataDictionary) { qualifiesMedicationRefillVisit: false, lastCovidScreeningDate: '', retroSpective: false, - screenedForCovidToday: false + screenedForCovidToday: false, + isViremicHighVL: false }; let isStandardDcVisit = false; @@ -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; }