From 44eeb4a5b0d8e5980278682ee7485feacc4ddc1e Mon Sep 17 00:00:00 2001 From: njorocs Date: Thu, 26 Sep 2024 15:12:50 +0300 Subject: [PATCH 1/2] Fixing query to fetch case manager correctly in Active on ART line list --- .../evaluator/art/ETLCaseManagerDataEvaluator.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ETLCaseManagerDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ETLCaseManagerDataEvaluator.java index 664b8f9e00..cabff219fd 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ETLCaseManagerDataEvaluator.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ETLCaseManagerDataEvaluator.java @@ -36,11 +36,11 @@ public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationC EvaluatedPersonData c = new EvaluatedPersonData(definition, context); - String qry = "SELECT t.patient_id, t.latest_case_manager from (SELECT r.person_a AS patient_id, mid(max(concat(date(r.start_date)," + - " concat_ws( ' ', pn.family_name, pn.given_name, pn.middle_name ))), 11) as latest_case_manager, max(r.start_date)" + - " as start_date FROM relationship r INNER JOIN relationship_type t ON r.relationship = t.relationship_type_id " + - "INNER JOIN person_name pn ON r.person_b = pn.person_id WHERE t.uuid = '9065e3c6-b2f5-4f99-9cbf-f67fd9f82ec5' " + - "and date(r.start_date) <= (:endDate) GROUP BY patient_id having date(start_date) <= (:endDate)) as t;"; + String qry = "SELECT t.patient_id, t.latest_case_manager from (SELECT r.person_b as patient_id,r.person_b AS case_manager_id, mid(max(concat(date(r.start_date),\n" + + " concat_ws( ' ', pn.family_name, pn.given_name, pn.middle_name ))), 11) as latest_case_manager, max(r.start_date)\n" + + " as start_date FROM relationship r INNER JOIN relationship_type t ON r.relationship = t.relationship_type_id\n" + + " INNER JOIN person_name pn ON r.person_a = pn.person_id WHERE t.uuid = '9065e3c6-b2f5-4f99-9cbf-f67fd9f82ec5'\n" + + " and date(r.start_date) <= (:endDate) GROUP BY case_manager_id) as t;"; SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); queryBuilder.append(qry); From 8ca3b7d036d367c399afef5bb67fbfdff822f653 Mon Sep 17 00:00:00 2001 From: njorocs Date: Thu, 26 Sep 2024 15:27:06 +0300 Subject: [PATCH 2/2] Excluding voided relationships --- .../definition/evaluator/art/ETLCaseManagerDataEvaluator.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/ETLCaseManagerDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ETLCaseManagerDataEvaluator.java index cabff219fd..47b954c16c 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ETLCaseManagerDataEvaluator.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/ETLCaseManagerDataEvaluator.java @@ -40,7 +40,7 @@ public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationC " concat_ws( ' ', pn.family_name, pn.given_name, pn.middle_name ))), 11) as latest_case_manager, max(r.start_date)\n" + " as start_date FROM relationship r INNER JOIN relationship_type t ON r.relationship = t.relationship_type_id\n" + " INNER JOIN person_name pn ON r.person_a = pn.person_id WHERE t.uuid = '9065e3c6-b2f5-4f99-9cbf-f67fd9f82ec5'\n" + - " and date(r.start_date) <= (:endDate) GROUP BY case_manager_id) as t;"; + " and date(r.start_date) <= (:endDate) and r.end_date is null and r.voided = 0 GROUP BY case_manager_id) as t;"; SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); queryBuilder.append(qry);