From 5844a358a1fcc28f745814704106819621a159b9 Mon Sep 17 00:00:00 2001 From: gabu90 Date: Tue, 29 Oct 2024 18:19:51 +0300 Subject: [PATCH] Revise the NCD column in Active on ART to pick the most current HIV greencard --- .../evaluator/art/NCDDateDataEvaluator.java | 10 +-- .../evaluator/art/NCDSDataEvaluator.java | 67 ++++++++++--------- .../evaluator/art/NCDStatusDataEvaluator.java | 20 ++++-- 3 files changed, 52 insertions(+), 45 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDDateDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDDateDataEvaluator.java index 6733f9c53c..72bbd3d096 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDDateDataEvaluator.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDDateDataEvaluator.java @@ -34,11 +34,11 @@ public class NCDDateDataEvaluator implements PersonDataEvaluator { public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) throws EvaluationException { EvaluatedPersonData c = new EvaluatedPersonData(definition, context); - String qry = "select ci.patient_id,\n" + - " group_concat(ci.chronic_illness_onset_date) as ChronicIllness_onset\n" + - "from kenyaemr_etl.etl_allergy_chronic_illness ci\n" + - "where ci.visit_date <= date(:endDate)\n" + - "group by ci.patient_id;"; + String qry = "SELECT ci.patient_id,\n" + + " DATE(MAX(ci.chronic_illness_onset_date)) AS ChronicIllness_onset\n" + + "FROM kenyaemr_etl.etl_allergy_chronic_illness ci\n" + + "WHERE ci.visit_date <= DATE(:endDate)\n" + + "GROUP BY ci.patient_id;"; SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); queryBuilder.append(qry); diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDSDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDSDataEvaluator.java index b8926c65ac..a422ae91f0 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDSDataEvaluator.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDSDataEvaluator.java @@ -33,39 +33,40 @@ public class NCDSDataEvaluator implements PersonDataEvaluator { public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) throws EvaluationException { EvaluatedPersonData c = new EvaluatedPersonData(definition, context); - String qry = "\n" + - "select ci.patient_id,group_concat( case ci.chronic_illness\n" + - " when 149019 then 'Alzheimers Disease and other Dementias'\n" + - " when 148432 then 'Arthritis'\n" + - " when 153754 then 'Asthma'\n" + - " when 159351 then 'Cancer'\n" + - " when 119270 then 'Cardiovascular diseases'\n" + - " when 120637 then 'Chronic Hepatitis'\n" + - " when 145438 then 'Chronic Kidney Disease'\n" + - " when 1295 then 'Chronic Obstructive Pulmonary Disease(COPD)'\n" + - " when 120576 then 'Chronic Renal Failure'\n" + - " when 119692 then 'Cystic Fibrosis'\n" + - " when 120291 then 'Deafness and Hearing impairment'\n" + - " when 119481 then 'Diabetes'\n" + - " when 118631 then 'Endometriosis'\n" + - " when 117855 then 'Epilepsy'\n" + - " when 117789 then 'Glaucoma'\n" + - " when 139071 then 'Heart Disease'\n" + - " when 115728 then 'Hyperlipidaemia'\n" + - " when 117399 then 'Hypertension'\n" + - " when 117321 then 'Hypothyroidism'\n" + - " when 151342 then 'Mental illness'\n" + - " when 133687 then 'Multiple Sclerosis'\n" + - " when 115115 then 'Obesity'\n" + - " when 114662 then 'Osteoporosis'\n" + - " when 117703 then 'Sickle Cell Anaemia'\n" + - " when 118976 then 'Thyroid disease'\n" + - " when 141623 then 'Dyslipidemia'\n" + - " end SEPARATOR\n" + - " ',') as ChronicIllness\n" + - " from kenyaemr_etl.etl_allergy_chronic_illness ci\n" + - " where ci.visit_date <= date(:endDate)\n" + - " group by ci.patient_id;"; + String qry = "SELECT ci.patient_id,\n" + + " SUBSTRING_INDEX(\n" + + " MAX(CONCAT(visit_date, ',', \n" + + " COALESCE(CASE ci.chronic_illness\n" + + " WHEN 149019 THEN 'Alzheimers Disease and other Dementias'\n" + + " WHEN 148432 THEN 'Arthritis'\n" + + " WHEN 153754 THEN 'Asthma'\n" + + " WHEN 159351 THEN 'Cancer'\n" + + " WHEN 119270 THEN 'Cardiovascular diseases'\n" + + " WHEN 120637 THEN 'Chronic Hepatitis'\n" + + " WHEN 145438 THEN 'Chronic Kidney Disease'\n" + + " WHEN 1295 THEN 'Chronic Obstructive Pulmonary Disease(COPD)'\n" + + " WHEN 120576 THEN 'Chronic Renal Failure'\n" + + " WHEN 119692 THEN 'Cystic Fibrosis'\n" + + " WHEN 120291 THEN 'Deafness and Hearing impairment'\n" + + " WHEN 119481 THEN 'Diabetes'\n" + + " WHEN 118631 THEN 'Endometriosis'\n" + + " WHEN 117855 THEN 'Epilepsy'\n" + + " WHEN 117789 THEN 'Glaucoma'\n" + + " WHEN 139071 THEN 'Heart Disease'\n" + + " WHEN 115728 THEN 'Hyperlipidaemia'\n" + + " WHEN 117399 THEN 'Hypertension'\n" + + " WHEN 117321 THEN 'Hypothyroidism'\n" + + " WHEN 151342 THEN 'Mental illness'\n" + + " WHEN 133687 THEN 'Multiple Sclerosis'\n" + + " WHEN 115115 THEN 'Obesity'\n" + + " WHEN 114662 THEN 'Osteoporosis'\n" + + " WHEN 117703 THEN 'Sickle Cell Anaemia'\n" + + " WHEN 118976 THEN 'Thyroid disease'\n" + + " WHEN 141623 THEN 'Dyslipidemia'\n" + + " END))), ',', -1) AS ChronicIllness\n" + + "FROM kenyaemr_etl.etl_allergy_chronic_illness ci\n" + + "WHERE ci.visit_date <= DATE(:endDate)\n" + + "GROUP BY ci.patient_id;"; SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); queryBuilder.append(qry); diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDStatusDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDStatusDataEvaluator.java index beb29db25b..bb41c5f519 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDStatusDataEvaluator.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/NCDStatusDataEvaluator.java @@ -34,13 +34,19 @@ public class NCDStatusDataEvaluator implements PersonDataEvaluator { public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) throws EvaluationException { EvaluatedPersonData c = new EvaluatedPersonData(definition, context); - String qry = "select ci.patient_id,\n" + - " group_concat(case ci.is_chronic_illness_controlled\n" + - " when 1065 then 'Controlled'\n" + - " when 1066 then 'Not controlled' end) as controlled_status\n" + - "from kenyaemr_etl.etl_allergy_chronic_illness ci\n" + - "where ci.visit_date <= date(:endDate)\n" + - "group by ci.patient_id;"; + String qry = "SELECT ci.patient_id,\n" + + " (CASE ci.is_chronic_illness_controlled\n" + + " WHEN 1065 THEN 'Controlled'\n" + + " WHEN 1066 THEN 'Not controlled'\n" + + " END) AS controlled_status\n" + + "FROM kenyaemr_etl.etl_allergy_chronic_illness ci\n" + + "JOIN (\n" + + " SELECT patient_id, MAX(visit_date) AS latest_visit_date\n" + + " FROM kenyaemr_etl.etl_allergy_chronic_illness\n" + + " WHERE visit_date <= DATE(:endDate)\n" + + " GROUP BY patient_id\n" + + ") latest ON ci.patient_id = latest.patient_id AND ci.visit_date = latest.latest_visit_date\n" + + "GROUP BY ci.patient_id;"; SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); queryBuilder.append(qry);