Skip to content

Commit 31cccd0

Browse files
committed
Added VL eligibility and missed vl indictors
1 parent 3bb0b79 commit 31cccd0

File tree

5 files changed

+954
-881
lines changed

5 files changed

+954
-881
lines changed

api/src/main/java/org/openmrs/module/kenyaemr/FacilityDashboardUtil.java

+151-7
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,163 @@ public static Long getPregnantPostpartumNotInPrep() {
208208
Context.removeProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS);
209209
}
210210
}
211+
212+
/**
213+
* Surveillance dashboards
214+
* 3. Delayed viral load testing. Eligible without VL test taken
215+
* @return long value
216+
*/
217+
public static Long getEligibleForVl() {
218+
String eligibleForVlQuery = "select count(b.patient_id) as eligible_for_vl\n" +
219+
"from (select fup.visit_date,\n" +
220+
" fup.patient_id,\n" +
221+
" min(e.visit_date) as enroll_date,\n" +
222+
" max(fup.visit_date) as latest_vis_date,\n" +
223+
" mid(max(concat(fup.visit_date, fup.next_appointment_date)), 11) as latest_tca,\n" +
224+
" max(d.visit_date) as date_discontinued,\n" +
225+
" d.patient_id as disc_patient,\n" +
226+
" de.patient_id as started_on_drugs\n" +
227+
" from kenyaemr_etl.etl_patient_hiv_followup fup\n" +
228+
" join kenyaemr_etl.etl_patient_demographics p on p.patient_id = fup.patient_id\n" +
229+
" join kenyaemr_etl.etl_hiv_enrollment e on fup.patient_id = e.patient_id\n" +
230+
" left outer join kenyaemr_etl.etl_drug_event de\n" +
231+
" on e.patient_id = de.patient_id and date(date_started) <= CURRENT_DATE\n" +
232+
" left outer JOIN\n" +
233+
" (select patient_id, visit_date\n" +
234+
" from kenyaemr_etl.etl_patient_program_discontinuation\n" +
235+
" where date(visit_date) <= CURRENT_DATE\n" +
236+
" and program_name = 'HIV'\n" +
237+
" group by patient_id) d on d.patient_id = fup.patient_id\n" +
238+
" where fup.visit_date <= CURRENT_DATE\n" +
239+
" group by patient_id\n" +
240+
" having (started_on_drugs is not null and started_on_drugs <> \"\")\n" +
241+
" and (\n" +
242+
" (date(latest_tca) > CURRENT_DATE and\n" +
243+
" (date(latest_tca) > date(date_discontinued) or disc_patient is null)) or\n" +
244+
" (((date(latest_tca) between date_sub(CURRENT_DATE, interval 3 MONTH) and CURRENT_DATE) and\n" +
245+
" (date(latest_vis_date) >= date(latest_tca)))) and\n" +
246+
" (date(latest_tca) > date(date_discontinued) or disc_patient is null))) e\n" +
247+
" INNER JOIN (select v.patient_id\n" +
248+
" from kenyaemr_etl.etl_viral_load_validity_tracker v\n" +
249+
" inner join kenyaemr_etl.etl_patient_demographics d on v.patient_id = d.patient_id\n" +
250+
" where (TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" +
251+
" v.base_viral_load_test_result is null) -- First VL new on ART\n" +
252+
" OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" +
253+
" TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" +
254+
" (v.vl_result is not null and\n" +
255+
" v.date_test_requested < v.latest_hiv_followup_visit)) -- immediate for PG & BF\n" +
256+
" OR (v.vl_result >= 200 AND\n" +
257+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" +
258+
" 3) -- Unsuppressed VL\n" +
259+
" OR (v.vl_result < 200 AND\n" +
260+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 6 and\n" +
261+
" TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) BETWEEN 0 AND 24) -- 0-24 with last suppressed vl\n" +
262+
" OR (v.vl_result < 200 AND\n" +
263+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" +
264+
" 12 and\n" +
265+
" TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) > 24) -- > 24 with last suppressed vl\n" +
266+
" OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" +
267+
" TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3\n" +
268+
" and (v.order_reason in (159882, 1434) and\n" +
269+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" +
270+
" 12) and\n" +
271+
" v.vl_result < 200) -- PG & BF after PG/BF baseline < 200\n" +
272+
") b on e.patient_id = b.patient_id;\n" +
273+
"\n" +
274+
"-- Eligible for VL sample not taken\n" +
275+
"select count(v.patient_id) as eligible_for_vl\n" +
276+
"from kenyaemr_etl.etl_viral_load_validity_tracker v\n" +
277+
" inner join kenyaemr_etl.etl_patient_demographics d on v.patient_id = d.patient_id\n" +
278+
"where ((TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" +
279+
" v.base_viral_load_test_result is null) -- First VL new on ART\n" +
280+
" OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" +
281+
" TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" +
282+
" (v.vl_result is not null and v.date_test_requested < v.latest_hiv_followup_visit)) -- immediate for PG & BF\n" +
283+
" OR (v.vl_result >= 200 AND\n" +
284+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3) -- Unsuppressed VL\n" +
285+
" OR (v.vl_result < 200 AND\n" +
286+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 6 and\n" +
287+
" TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) BETWEEN 0 AND 24) -- 0-24 with last suppressed vl\n" +
288+
" OR (v.vl_result < 200 AND\n" +
289+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 12 and\n" +
290+
" TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) > 24) -- > 24 with last suppressed vl\n" +
291+
" OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" +
292+
" TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3\n" +
293+
" and (v.order_reason in (159882, 1434) and\n" +
294+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 12) and\n" +
295+
" v.vl_result < 200)) -- PG & BF after PG/BF baseline < 200\n" +
296+
" and v.latest_hiv_followup_visit != v.date_test_requested;";
297+
298+
try {
299+
Context.addProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS);
300+
return (Long) Context.getAdministrationService().executeSQL(eligibleForVlQuery, true).get(0).get(0);
301+
}
302+
finally {
303+
Context.removeProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS);
304+
}
305+
}
211306
/**
212307
* Surveillance dashboards
213308
* 3. Delayed viral load testing. Eligible without VL test taken
214309
* @return long value
215310
*/
216311
public static Long getEligibleForVlSampleNotTaken() {
217-
String eligibleForVlSampleNotTakenQuery = "select count(t.patient_id) from kenyaemr_etl.etl_hts_test t left join\n" +
218-
" (select l.patient_id, l.ccc_number from kenyaemr_etl.etl_hts_referral_and_linkage l \n" +
219-
" where date(l.visit_date) <= date('2020-01-01') group by l.patient_id) l on t.patient_id = l.patient_id\n" +
220-
" left join (select e.patient_id from kenyaemr_etl.etl_hiv_enrollment e \n" +
221-
" where date(e.visit_date) <= date('2020-01-01'))e on e.patient_id = t.patient_id\n" +
222-
" where t.final_test_result='Positive' and t.test_type = 2 \n" +
223-
" and date(t.visit_date) between date('2020-01-01') and date('2025-01-01') and l.ccc_number is null and e.patient_id is null;";
312+
String eligibleForVlSampleNotTakenQuery = "select count(b.patient_id) as eligible_for_vl_sample_not_taken\n" +
313+
"from (select fup.visit_date,\n" +
314+
" fup.patient_id,\n" +
315+
" min(e.visit_date) as enroll_date,\n" +
316+
" max(fup.visit_date) as latest_vis_date,\n" +
317+
" mid(max(concat(fup.visit_date, fup.next_appointment_date)), 11) as latest_tca,\n" +
318+
" max(d.visit_date) as date_discontinued,\n" +
319+
" d.patient_id as disc_patient,\n" +
320+
" de.patient_id as started_on_drugs\n" +
321+
" from kenyaemr_etl.etl_patient_hiv_followup fup\n" +
322+
" join kenyaemr_etl.etl_patient_demographics p on p.patient_id = fup.patient_id\n" +
323+
" join kenyaemr_etl.etl_hiv_enrollment e on fup.patient_id = e.patient_id\n" +
324+
" left outer join kenyaemr_etl.etl_drug_event de\n" +
325+
" on e.patient_id = de.patient_id and date(date_started) <= CURRENT_DATE\n" +
326+
" left outer JOIN\n" +
327+
" (select patient_id, visit_date\n" +
328+
" from kenyaemr_etl.etl_patient_program_discontinuation\n" +
329+
" where date(visit_date) <= CURRENT_DATE\n" +
330+
" and program_name = 'HIV'\n" +
331+
" group by patient_id) d on d.patient_id = fup.patient_id\n" +
332+
" where fup.visit_date <= CURRENT_DATE\n" +
333+
" group by patient_id\n" +
334+
" having (started_on_drugs is not null and started_on_drugs <> \"\")\n" +
335+
" and (\n" +
336+
" (date(latest_tca) > CURRENT_DATE and\n" +
337+
" (date(latest_tca) > date(date_discontinued) or disc_patient is null)) or\n" +
338+
" (((date(latest_tca) between date_sub(CURRENT_DATE, interval 3 MONTH) and CURRENT_DATE) and\n" +
339+
" (date(latest_vis_date) >= date(latest_tca)))) and\n" +
340+
" (date(latest_tca) > date(date_discontinued) or disc_patient is null))) e\n" +
341+
" INNER JOIN (select v.patient_id\n" +
342+
" from kenyaemr_etl.etl_viral_load_validity_tracker v\n" +
343+
" inner join kenyaemr_etl.etl_patient_demographics d on v.patient_id = d.patient_id\n" +
344+
" where ((TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" +
345+
" v.base_viral_load_test_result is null) -- First VL new on ART\n" +
346+
" OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" +
347+
" TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" +
348+
" (v.vl_result is not null and\n" +
349+
" v.date_test_requested < v.latest_hiv_followup_visit)) -- immediate for PG & BF\n" +
350+
" OR (v.vl_result >= 200 AND\n" +
351+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" +
352+
" 3) -- Unsuppressed VL\n" +
353+
" OR (v.vl_result < 200 AND\n" +
354+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" +
355+
" 6 and\n" +
356+
" TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) BETWEEN 0 AND 24) -- 0-24 with last suppressed vl\n" +
357+
" OR (v.vl_result < 200 AND\n" +
358+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" +
359+
" 12 and\n" +
360+
" TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) > 24) -- > 24 with last suppressed vl\n" +
361+
" OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" +
362+
" TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3\n" +
363+
" and (v.order_reason in (159882, 1434) and\n" +
364+
" TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" +
365+
" 12) and\n" +
366+
" v.vl_result < 200)) -- PG & BF after PG/BF baseline < 200\n" +
367+
" and v.latest_hiv_followup_visit > v.date_test_requested) b on e.patient_id = b.patient_id;";
224368

225369
try {
226370
Context.addProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS);

api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/PublicHealthActionReportBuilder.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ protected DataSetDefinition publicHealthAction() {
6060
cohortDsd.addColumn("Current on ART without valid VL", "", ReportUtils.map(publicHealthActionIndicatorLibrary.invalidVL(), "startDate=${startDate},endDate=${endDate}"), "");
6161
cohortDsd.addColumn("Current on ART with Unsuppressed Valid VL", "", ReportUtils.map(publicHealthActionIndicatorLibrary.unsuppressedWithValidVL(), "endDate=${endDate}"), "");
6262
cohortDsd.addColumn("Current on ART with Unsuppressed invalid VL", "", ReportUtils.map(publicHealthActionIndicatorLibrary.unsuppressedWithoutValidVL(), "startDate=${startDate},endDate=${endDate}"), "");
63-
cohortDsd.addColumn("Virally Unsuppressed without Enhanced Adherence Counselling", "", ReportUtils.map(publicHealthActionIndicatorLibrary.txCUrrUnsuppressedWithoutEAC(), "startDate=${startDate},endDate=${endDate}"), "");
64-
// cohortDsd.addColumn("Delayed viral load testing (Visited facility were eligible for vl but sample not taken)", "", ReportUtils.map(publicHealthActionIndicatorLibrary.delayedVLTesting(), "startDate=${startDate},endDate=${endDate}"), "");
63+
cohortDsd.addColumn("Virally Unsuppressed without Enhanced Adherence Counselling", "(No EAC past 2 weeks)", ReportUtils.map(publicHealthActionIndicatorLibrary.txCUrrUnsuppressedWithoutEAC(), "startDate=${startDate},endDate=${endDate}"), "");
64+
cohortDsd.addColumn("Delayed viral load testing (Visited facility were eligible for vl but sample not taken)", "(Eligible within past 7 days)", ReportUtils.map(publicHealthActionIndicatorLibrary.delayedVLTesting(), "startDate=${startDate},endDate=${endDate}"), "");
6565
cohortDsd.addColumn("Current on ART Clients without NUPI", "", ReportUtils.map(publicHealthActionIndicatorLibrary.txCurrclientsWithoutNUPI(), "startDate=${startDate},endDate=${endDate}"), "");
6666
cohortDsd.addColumn("Recent defaulters", " (Missed appointment within 30 days)", ReportUtils.map(publicHealthActionIndicatorLibrary.recentDefaulters(), "startDate=${startDate},endDate=${endDate}"), "");
6767
cohortDsd.addColumn("Undocumented LTFU/IIT", "", ReportUtils.map(publicHealthActionIndicatorLibrary.undocumentedLTFU(), "startDate=${startDate},endDate=${endDate}"), "");
@@ -73,9 +73,9 @@ protected DataSetDefinition publicHealthAction() {
7373
cohortDsd.addColumn("HEI with undocumented HIV status", "", ReportUtils.map(publicHealthActionIndicatorLibrary.undocumentedHEIStatus(), "startDate=${startDate},endDate=${endDate}"), "");
7474
cohortDsd.addColumn("HEI not Linked to Mothers", "", ReportUtils.map(publicHealthActionIndicatorLibrary.unlinkedHEI(), "startDate=${startDate},endDate=${endDate}"), "");
7575
cohortDsd.addColumn("HEI with Missed HIV Tests", " (Please run HEI Missed HIV Tests linelist)", ReportUtils.map(publicHealthActionIndicatorLibrary.heiMissedHIVTests(), ""), "");
76-
cohortDsd.addColumn("HEI (6-8 weeks) without DNA PCR results", "", ReportUtils.map(publicHealthActionIndicatorLibrary.heiSixToEightWeeksMissingPCRTests(), ""), "");
77-
cohortDsd.addColumn("HEI (24 months) without a final documented outcome", "", ReportUtils.map(publicHealthActionIndicatorLibrary.hei24MonthsUndocumentedOutcome(), ""), "");
78-
cohortDsd.addColumn("Pregnant and postpartum women at high risk (ML-based) not linked to PrEP", "", ReportUtils.map(publicHealthActionIndicatorLibrary.pregnantPostPartumNotLinkedToPrep(), ""), "");
76+
cohortDsd.addColumn("HEI (6-8 weeks) without DNA PCR results", "(Turning 6-8 weeks within past 7 days", ReportUtils.map(publicHealthActionIndicatorLibrary.heiSixToEightWeeksMissingPCRTests(), ""), "");
77+
cohortDsd.addColumn("HEI (24 months) without a final documented outcome", "(Turning 24 months within past 7 days)", ReportUtils.map(publicHealthActionIndicatorLibrary.hei24MonthsUndocumentedOutcome(), ""), "");
78+
cohortDsd.addColumn("Pregnant and postpartum women at high risk (ML-based) not linked to PrEP", "(Tested within past 7 days)", ReportUtils.map(publicHealthActionIndicatorLibrary.pregnantPostPartumNotLinkedToPrep(), ""), "");
7979
cohortDsd.addColumn("HIV+ and NOT Linked", "", ReportUtils.map(publicHealthActionIndicatorLibrary.notLinked(), "startDate=${startDate},endDate=${endDate}"), "");
8080
cohortDsd.addColumn("Children of HIV infected adults with undocumented HIV status", " (Please run Children of HIV infected adults with undocumented HIV status for linelist)", ReportUtils.map(publicHealthActionIndicatorLibrary.childrenContactsUndocumentedHIVStatus(), "startDate=${startDate},endDate=${endDate}"), "");
8181
cohortDsd.addColumn("PNS Contacts with undocumented HIV status", " (Please run PNS contacts with undocumented HIV status for linelist)", ReportUtils.map(publicHealthActionIndicatorLibrary.contactsUndocumentedHIVStatus(), "startDate=${startDate},endDate=${endDate}"), "");

0 commit comments

Comments
 (0)