Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

Commit d959247

Browse files
authored
Merge pull request #2339 from njorocs/moh705_717_204-alignment
Revision of MOH 711, Moh 717 indicators as per the guideline.Revised …
2 parents 655fdf8 + fe08742 commit d959247

File tree

13 files changed

+742
-695
lines changed

13 files changed

+742
-695
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected DataSetDefinition caseSurveillance() {
6363
cohortDsd.addColumn("HEI (6-8 weeks) without DNA PCR results", "", ReportUtils.map(publicHealthActionIndicatorLibrary.heiSixToEightWeeksMissingPCRTestsCs(), "startDate=${startDate},endDate=${endDate}"), "");
6464
cohortDsd.addColumn("HEI (24 months) without a final documented outcome", "", ReportUtils.map(publicHealthActionIndicatorLibrary.hei24MonthsUndocumentedOutcomeCs(), "startDate=${startDate},endDate=${endDate}"), "");
6565
cohortDsd.addColumn("Delayed viral load testing (Visited facility were eligible for vl but sample not taken)", "", ReportUtils.map(publicHealthActionIndicatorLibrary.delayedVLTestingZeroGracePeriod(), "startDate=${startDate},endDate=${endDate}"), "");
66-
cohortDsd.addColumn("Virally Unsuppressed without Enhanced Adherence Counselling", "(No EAC past 2 weeks)", ReportUtils.map(publicHealthActionIndicatorLibrary.txCUrrUnsuppressedWithoutEACCs(), "startDate=${startDate},endDate=${endDate}"), "");
66+
cohortDsd.addColumn("Virally Unsuppressed without Enhanced Adherence Counselling", "(No EAC past 2 weeks)", ReportUtils.map(publicHealthActionIndicatorLibrary.txCUrrUnsuppressedWithoutEACs(), "startDate=${startDate},endDate=${endDate}"), "");
6767

6868
return cohortDsd;
6969

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class MOH717ReportBuilder extends AbstractReportBuilder {
5757
static final String UNDER_5_YEARS = "<5";
5858
static final String BTWN_5_AND_59_YEARS = "BETWEEN 5 AND 59";
5959
static final String _5_YEARS_AND_ABOVE = ">=5";
60-
static final String _60_YEARS_AND_ABOVE = "BETWEEN 5 AND 59";
60+
static final String _60_YEARS_AND_ABOVE = ">=60";
6161
static final String NEW_VISIT_STR = "New visit";
6262
static final String RE_ATT_STR = "Revisit";
6363

@@ -778,7 +778,8 @@ private DataSetDefinition moh717DatasetDefinition() {
778778
ReportUtils.map(moh717IndicatorLibrary.getPatientsClinicalEncounterWithinReportingPeriod(BTWN_5_AND_59_YEARS, MALE, NEW_VISIT_STR), indParams),"");
779779
dsd.addColumn( "General OP New (Female 5-59)", "",
780780
ReportUtils.map(moh717IndicatorLibrary.getPatientsClinicalEncounterWithinReportingPeriod(BTWN_5_AND_59_YEARS, FEMALE, NEW_VISIT_STR), indParams),"");
781-
781+
dsd.addColumn( "General OP New (60+)", "",
782+
ReportUtils.map(moh717IndicatorLibrary.getPatientsClinicalEncounterWithinReportingPeriodAged60AndAbove(_60_YEARS_AND_ABOVE, NEW_VISIT_STR), indParams),"");
782783
dsd.addColumn( "General OP RE-ATT (Male <5)", "",
783784
ReportUtils.map(moh717IndicatorLibrary.getPatientsClinicalEncounterWithinReportingPeriod(UNDER_5_YEARS, MALE, RE_ATT_STR), indParams),"");
784785
dsd.addColumn( "General OP RE-ATT (Female <5)", "",
@@ -787,10 +788,8 @@ private DataSetDefinition moh717DatasetDefinition() {
787788
ReportUtils.map(moh717IndicatorLibrary.getPatientsClinicalEncounterWithinReportingPeriod(BTWN_5_AND_59_YEARS, MALE, RE_ATT_STR), indParams),"");
788789
dsd.addColumn( "General OP RE-ATT (Female 5-59)", "",
789790
ReportUtils.map(moh717IndicatorLibrary.getPatientsClinicalEncounterWithinReportingPeriod(BTWN_5_AND_59_YEARS, FEMALE, RE_ATT_STR), indParams),"");
790-
dsd.addColumn( "General OP New (60+)", "",
791-
ReportUtils.map(moh717IndicatorLibrary.getPatientsClinicalEncounterWithinReportingPeriod(_60_YEARS_AND_ABOVE, FEMALE, RE_ATT_STR), indParams),"");
792791
dsd.addColumn( "General OP RE-ATT (60+)", "",
793-
ReportUtils.map(moh717IndicatorLibrary.getPatientsClinicalEncounterWithinReportingPeriod(_60_YEARS_AND_ABOVE, FEMALE, RE_ATT_STR), indParams),"");
792+
ReportUtils.map(moh717IndicatorLibrary.getPatientsClinicalEncounterWithinReportingPeriodAged60AndAbove(_60_YEARS_AND_ABOVE, RE_ATT_STR), indParams),"");
794793

795794
dsd.addColumn("New CWC Visits", "",
796795
ReportUtils.map(moh717IndicatorLibrary.newCWCVisits(), indParams), "");

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

Lines changed: 47 additions & 34 deletions
Large diffs are not rendered by default.

api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/evaluator/ANCRegisterCohortDefinitionEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public EncounterQueryResult evaluate(EncounterQuery definition, EvaluationContex
4242

4343
String qry = "SELECT v.encounter_id\n" +
4444
"from kenyaemr_etl.etl_mch_antenatal_visit v\n" +
45-
"where date(v.visit_date) BETWEEN date(:startDate) AND date(:endDate);";
45+
"where v.anc_visit_number >= 1 and date(v.visit_date) BETWEEN date(:startDate) AND date(:endDate);";
4646

4747
SqlQueryBuilder builder = new SqlQueryBuilder();
4848
builder.append(qry);

api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/evaluator/PNCRegisterCohortDefinitionEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public EncounterQueryResult evaluate(EncounterQuery definition, EvaluationContex
4040
context = ObjectUtil.nvl(context, new EvaluationContext());
4141
EncounterQueryResult queryResult = new EncounterQueryResult(definition, context);
4242

43-
String qry = "SELECT pv.encounter_id from kenyaemr_etl.etl_mch_postnatal_visit pv where date(pv.visit_date) BETWEEN date(:startDate) AND date(:endDate);";
43+
String qry = "SELECT pv.encounter_id from kenyaemr_etl.etl_mch_postnatal_visit pv where pv.pnc_visit_no >= 1 and date(pv.visit_date) BETWEEN date(:startDate) AND date(:endDate);";
4444

4545
SqlQueryBuilder builder = new SqlQueryBuilder();
4646
builder.append(qry);

api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ETLLastVLResultValidityDataEvaluator.java

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,69 @@ public class ETLLastVLResultValidityDataEvaluator implements PersonDataEvaluator
3535
public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) throws EvaluationException {
3636
EvaluatedPersonData c = new EvaluatedPersonData(definition, context);
3737

38-
String qry = "select vt.patient_id,\n" +
39-
" if((vt.vl_result >= 200 and timestampdiff(MONTH, date(vt.date_test_requested), date(:endDate)) >= 3)\n" +
40-
" OR (timestampdiff(YEAR, d.DOB, date(vt.date_test_requested)) between 0 and 24 and\n" +
41-
" ((vt.lab_test = 856 and vt.vl_result < 200) OR (vt.lab_test = 1305 and vt.vl_result = 1302)) and\n" +
42-
" timestampdiff(MONTH, date(vt.date_test_requested), date(:endDate)) >= 6)\n" +
43-
" OR (timestampdiff(MONTH, vt.date_started_art, date(:endDate)) >= 3 and vt.vl_result is null and\n" +
44-
" vt.previous_test_result is null and vt.base_viral_load_test_result is null)\n" +
45-
" OR (TIMESTAMPDIFF(MONTH, date(vt.date_started_art), date(:endDate)) >= 3 and\n" +
46-
" (vt.breastfeeding_status = 1065 or vt.pregnancy_status = 1065) and\n" +
47-
" (vt.latest_hiv_followup_visit > vt.date_test_requested OR vt.date_test_requested is null))\n" +
48-
" OR (timestampdiff(MONTH, vt.date_test_requested, date(:endDate)) >= 6 and\n" +
49-
" timestampdiff(YEAR, d.DOB, date(vt.date_test_requested)) between 0 and 24 and\n" +
50-
" timestampdiff(MONTH, vt.date_started_art, date(:endDate)) >= 3 and\n" +
51-
" ((vt.lab_test = 856 and vt.vl_result < 200) OR (vt.lab_test = 1305 and vt.vl_result = 1302)))\n" +
52-
" OR (timestampdiff(YEAR, d.DOB, date(vt.date_test_requested)) > 24 and\n" +
53-
" TIMESTAMPDIFF(MONTH, date(vt.date_started_art), date(:endDate)) >= 3 and\n" +
54-
" ((vt.lab_test = 856 and vt.vl_result < 200) OR (vt.lab_test = 1305 and vt.vl_result = 1302)) and\n" +
55-
" timestampdiff(MONTH, date(vt.date_test_requested), date(:endDate)) >= 12)\n" +
56-
" OR (vt.pregnancy_status = 1065 or vt.breastfeeding_status = 1065 and\n" +
57-
" ((vt.lab_test = 856 and vt.vl_result < 200) OR\n" +
58-
" (vt.lab_test = 1305 and vt.vl_result = 1302)) and\n" +
59-
" vt.previous_order_reason in (1434, 159882))\n" +
60-
" and timestampdiff(MONTH, date(vt.date_test_requested), date(:endDate)) >= 6, 'Invalid',\n" +
61-
" 'Valid') as vl_status\n" +
62-
"from kenyaemr_etl.etl_viral_load_validity_tracker vt\n" +
63-
" inner join kenyaemr_etl.etl_patient_demographics d on d.patient_id = vt.patient_id\n" +
64-
"group by vt.patient_id;";
38+
String qry = "SELECT\n" +
39+
" t.patient_id, CASE\n" +
40+
" -- 1. If everything is null but there is a request, it's the 1st VL pending results\n" +
41+
" WHEN t.vl_result IS NULL\n" +
42+
" AND t.date_test_result_received IS NULL\n" +
43+
" AND t.previous_test_result IS NULL\n" +
44+
" AND t.previous_date_test_requested IS NULL\n" +
45+
" AND t.date_test_requested IS NOT NULL\n" +
46+
" THEN '1st vl pending results'\n" +
47+
" -- 2. Validity Logic using effective (substituted) values\n" +
48+
" WHEN (\n" +
49+
" (TIMESTAMPDIFF(MONTH, t.date_started_art, :endDate) >= 3 AND t.base_viral_load_test_result IS NULL) -- First VL new on ART\n" +
50+
" OR\n" +
51+
" ((t.pregnancy_status = 1065 OR t.breastfeeding_status = 1065)\n" +
52+
" AND TIMESTAMPDIFF(MONTH, t.date_started_art, :endDate) >= 3\n" +
53+
" AND (t.effective_vl_result IS NOT NULL AND t.effective_date_requested < :endDate)\n" +
54+
" AND (t.order_reason NOT IN (159882, 1434, 2001237, 163718))\n" +
55+
" ) -- Immediate for PG & BF\n" +
56+
" OR\n" +
57+
" (t.lab_test = 856 AND t.effective_vl_result >= 200\n" +
58+
" AND TIMESTAMPDIFF(MONTH, t.effective_date_requested, :endDate) >= 3\n" +
59+
" ) -- Unsuppressed VL\n" +
60+
" OR\n" +
61+
" (((t.lab_test = 1305 AND t.effective_vl_result = 1302) OR t.effective_vl_result < 200)\n" +
62+
" AND TIMESTAMPDIFF(MONTH, t.effective_date_requested, :endDate) >= 6\n" +
63+
" AND TIMESTAMPDIFF(YEAR, t.DOB, t.effective_date_requested) BETWEEN 0 AND 24\n" +
64+
" ) -- 0-24 with last suppressed VL\n" +
65+
" OR\n" +
66+
" (((t.lab_test = 1305 AND t.effective_vl_result = 1302) OR t.effective_vl_result < 200)\n" +
67+
" AND TIMESTAMPDIFF(MONTH, t.effective_date_requested, :endDate) >= 12\n" +
68+
" AND TIMESTAMPDIFF(YEAR, t.DOB, t.effective_date_requested) > 24\n" +
69+
" ) -- > 24 with last suppressed VL\n" +
70+
" OR\n" +
71+
" ((t.pregnancy_status = 1065 OR t.breastfeeding_status = 1065)\n" +
72+
" AND TIMESTAMPDIFF(MONTH, t.date_started_art, :endDate) >= 3\n" +
73+
" AND (t.order_reason IN (159882, 1434, 2001237, 163718) AND TIMESTAMPDIFF(MONTH, t.effective_date_requested, :endDate) >= 6)\n" +
74+
" AND ((t.lab_test = 1305 AND t.effective_vl_result = 1302) OR (t.effective_vl_result < 200))\n" +
75+
" ) -- PG & BF after baseline < 200\n" +
76+
" ) THEN 'Invalid'\n" +
77+
" ELSE 'Valid'\n" +
78+
" END AS vl_status\n" +
79+
"FROM (\n" +
80+
" SELECT\n" +
81+
" v.*,\n" +
82+
" d.DOB,\n" +
83+
" -- Substitution Logic: If current is null and requested is later than base/previous, use previous\n" +
84+
" IF(v.vl_result IS NULL\n" +
85+
" AND v.date_test_result_received IS NULL\n" +
86+
" AND v.date_test_requested > GREATEST(COALESCE(v.base_viral_load_test_date, '1900-01-01'), COALESCE(v.previous_date_test_requested, '1900-01-01')),\n" +
87+
" v.previous_test_result,\n" +
88+
" v.vl_result\n" +
89+
" ) AS effective_vl_result,\n" +
90+
" IF(v.vl_result IS NULL\n" +
91+
" AND v.date_test_result_received IS NULL\n" +
92+
" AND v.date_test_requested > GREATEST(COALESCE(v.base_viral_load_test_date, '1900-01-01'), COALESCE(v.previous_date_test_requested, '1900-01-01')),\n" +
93+
" v.previous_date_test_requested,\n" +
94+
" v.date_test_requested\n" +
95+
" ) AS effective_date_requested\n" +
96+
" FROM kenyaemr_etl.etl_viral_load_validity_tracker v\n" +
97+
" INNER JOIN kenyaemr_etl.etl_patient_demographics d ON v.patient_id = d.patient_id\n" +
98+
" WHERE v.date_test_requested <= date(:endDate)\n" +
99+
" ) t\n" +
100+
"ORDER BY t.patient_id ASC;";
65101

66102
SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
67103
queryBuilder.append(qry);

0 commit comments

Comments
 (0)