From 28edb8bc597d96222ac1bdb5a21c847bac5984e5 Mon Sep 17 00:00:00 2001 From: gabu90 Date: Tue, 22 Oct 2024 13:21:36 +0300 Subject: [PATCH 1/3] =?UTF-8?q?Revise=20the=20Active=20in=20PMTCT=20column?= =?UTF-8?q?=20in=20the=20Active=20on=20ART=20Patients=20Linelist=20to=20sh?= =?UTF-8?q?ow=20PMTCT=20mothers=20who=20are=20pregnant=20or=20breastfeedin?= =?UTF-8?q?g.=20Replace=20the=20current=20=E2=80=98Yes=E2=80=99=20with=20e?= =?UTF-8?q?ither=20the=20mother=20is=20pregnant=20or=20Breastfeeding.=20If?= =?UTF-8?q?=20the=20mother=20is=20not=20active=20in=20PMTCT=20retain=20?= =?UTF-8?q?=E2=80=98No=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ActiveInMchDataDefinitionEvaluator.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java index e95419db80..7ec39f628f 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java @@ -36,11 +36,27 @@ public class ActiveInMchDataDefinitionEvaluator implements PersonDataEvaluator { public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) throws EvaluationException { EvaluatedPersonData c = new EvaluatedPersonData(definition, context); - String qry = "select pp.patient_id,if(p.name is not null,'Yes','No') from patient_program pp\n" + - " inner join program p on p.program_id = pp.program_id\n" + - "where date(pp.date_completed) is null and p.name in ('MCH - Child Services','MCH - Mother Services')\n" + - "group by pp.patient_id\n" + - "having max(date(pp.date_enrolled)) <= date(:endDate);"; + String qry = "SELECT pp.patient_id,\n" + + " CASE \n" + + " WHEN d.gender = 'M' THEN 'N/A'\n" + + " WHEN (pf.pregnant = 'Yes' OR hf.pregnancy_status = 'Yes' OR es.pregnant = 'Yes') THEN 'Pregnant'\n" + + " WHEN (pf.breastfeeding = 'Yes' OR hf.breastfeeding = 'Yes' OR es.breastfeeding_mother = 'Yes') THEN 'Breastfeeding'\n" + + " ELSE 'No'\n" + + " END AS program_status\n" + + "FROM kenyaemr_etl.etl_patient_program pp\n" + + "LEFT JOIN kenyaemr_etl.etl_prep_followup pf \n" + + " ON pp.patient_id = pf.patient_id\n" + + "LEFT JOIN kenyaemr_etl.etl_patient_hiv_followup hf \n" + + " ON pp.patient_id = hf.patient_id\n" + + "LEFT JOIN kenyaemr_etl.etl_hts_eligibility_screening es \n" + + " ON pp.patient_id = es.patient_id\n" + + "LEFT JOIN kenyaemr_etl.etl_patient_demographics d\n" + + " ON pp.patient_id = d.patient_id\n" + + "WHERE DATE(pp.date_completed) IS NULL\n" + + " AND pp.program IN ('MCH-Child Services', 'MCH-Mother Services')\n" + + "GROUP BY pp.patient_id\n" + + "HAVING MAX(DATE(pp.date_enrolled)) <= DATE(:endDate);"; + SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); queryBuilder.append(qry); From 18a54cf97fa66fd927e1a5303057bd5e2360d1b7 Mon Sep 17 00:00:00 2001 From: gabu90 Date: Tue, 29 Oct 2024 15:13:34 +0300 Subject: [PATCH 2/3] query to check for the last records of the patient --- .../evaluator/art/ActiveInMchDataDefinitionEvaluator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java index 7ec39f628f..d610435e94 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java @@ -44,13 +44,13 @@ public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationC " ELSE 'No'\n" + " END AS program_status\n" + "FROM kenyaemr_etl.etl_patient_program pp\n" + - "LEFT JOIN kenyaemr_etl.etl_prep_followup pf \n" + + "LEFT JOIN (SELECT patient_id, MAX(visit_date) AS latest_visit_date, pregnant, breastfeeding FROM kenyaemr_etl.etl_prep_followup GROUP BY patient_id) pf \n" + " ON pp.patient_id = pf.patient_id\n" + - "LEFT JOIN kenyaemr_etl.etl_patient_hiv_followup hf \n" + + "LEFT JOIN (SELECT patient_id, MAX(visit_date) AS latest_visit_date, pregnancy_status, breastfeeding FROM kenyaemr_etl.etl_patient_hiv_followup GROUP BY patient_id) hf \n" + " ON pp.patient_id = hf.patient_id\n" + - "LEFT JOIN kenyaemr_etl.etl_hts_eligibility_screening es \n" + + "LEFT JOIN (SELECT patient_id, MAX(visit_date) AS latest_visit_date, pregnant, breastfeeding_mother FROM kenyaemr_etl.etl_hts_eligibility_screening GROUP BY patient_id) es \n" + " ON pp.patient_id = es.patient_id\n" + - "LEFT JOIN kenyaemr_etl.etl_patient_demographics d\n" + + "LEFT JOIN kenyaemr_etl.etl_patient_demographics d \n" + " ON pp.patient_id = d.patient_id\n" + "WHERE DATE(pp.date_completed) IS NULL\n" + " AND pp.program IN ('MCH-Child Services', 'MCH-Mother Services')\n" + From 24f9bc59ff9ba2ca517d2ab029881c39a7c909e2 Mon Sep 17 00:00:00 2001 From: gabu90 Date: Mon, 2 Dec 2024 11:46:47 +0300 Subject: [PATCH 3/3] add mid(max) in the date --- .../evaluator/art/ActiveInMchDataDefinitionEvaluator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java index d610435e94..dee371ac5e 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ActiveInMchDataDefinitionEvaluator.java @@ -55,7 +55,7 @@ public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationC "WHERE DATE(pp.date_completed) IS NULL\n" + " AND pp.program IN ('MCH-Child Services', 'MCH-Mother Services')\n" + "GROUP BY pp.patient_id\n" + - "HAVING MAX(DATE(pp.date_enrolled)) <= DATE(:endDate);"; + "HAVING MID(MAX(DATE(pp.date_enrolled)), 1, 10) <= DATE(:endDate);"; SqlQueryBuilder queryBuilder = new SqlQueryBuilder();