From 24787953978a845b43d204b08147ba07a1a90538 Mon Sep 17 00:00:00 2001 From: njorocs Date: Wed, 18 Oct 2023 13:51:21 +0300 Subject: [PATCH] Revised clients tested to include only those who had a valid test result (Positive or Negative) --- .../HTSRegisterCohortDefinitionEvaluator.java | 2 +- .../ETLMoh731GreenCardCohortLibrary.java | 23 ++++++++++--------- .../RevisedDatim/DatimCohortLibrary.java | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/evaluator/HTSRegisterCohortDefinitionEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/evaluator/HTSRegisterCohortDefinitionEvaluator.java index 57971818dc..6f7482a150 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/evaluator/HTSRegisterCohortDefinitionEvaluator.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/evaluator/HTSRegisterCohortDefinitionEvaluator.java @@ -40,7 +40,7 @@ public EncounterQueryResult evaluate(EncounterQuery definition, EvaluationContex context = ObjectUtil.nvl(context, new EvaluationContext()); EncounterQueryResult queryResult = new EncounterQueryResult(definition, context); - String qry = "SELECT encounter_id from kenyaemr_etl.etl_hts_test t inner join person p on p.person_id=t.patient_id and p.voided=0 where t.test_type = 1 and t.voided = 0 and date(t.visit_date) BETWEEN date(:startDate) AND date(:endDate) ; "; + String qry = "SELECT encounter_id from kenyaemr_etl.etl_hts_test t inner join person p on p.person_id=t.patient_id and p.voided=0 where t.test_type = 1 and t.final_test_result in ('Positive','Negative') and t.voided = 0 and date(t.visit_date) BETWEEN date(:startDate) AND date(:endDate) ; "; SqlQueryBuilder builder = new SqlQueryBuilder(); builder.append(qry); diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/MOH731Greencard/ETLMoh731GreenCardCohortLibrary.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/MOH731Greencard/ETLMoh731GreenCardCohortLibrary.java index 49f5b5e46e..714f2e3738 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/MOH731Greencard/ETLMoh731GreenCardCohortLibrary.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/MOH731Greencard/ETLMoh731GreenCardCohortLibrary.java @@ -899,8 +899,9 @@ public CohortDefinition htsNumberTested() { } // HIV testing cohort. includes all those who tested during the reporting period public CohortDefinition htsAllNumberTested() { - String sqlQuery = "select t.patient_id from kenyaemr_etl.etl_hts_test t inner join kenyaemr_etl.etl_patient_demographics d on d.patient_id = t.patient_id where test_type =1 and t.voided = 0 and t.visit_date between date(:startDate) and date(:endDate)\n" + - "group by t.patient_id;"; + String sqlQuery = "select t.patient_id from kenyaemr_etl.etl_hts_test t inner join kenyaemr_etl.etl_patient_demographics d on d.patient_id = t.patient_id where test_type = 1 and\n" + + " t.final_test_result in ('Positive','Negative') and t.voided = 0 and t.visit_date between date (:startDate) and date (:endDate)\n" + + " group by t.patient_id;"; SqlCohortDefinition cd = new SqlCohortDefinition(); cd.setName("htsNumberTested"); cd.setQuery(sqlQuery); @@ -934,7 +935,7 @@ public CohortDefinition htsAllNumberTestedAtFacility() { String sqlQuery = "select patient_id\n" + "from kenyaemr_etl.etl_hts_test\n" + "WHERE test_type = 1\n" + - " AND setting = 'Facility'\n" + + " AND setting = 'Facility' AND final_test_result in ('Positive','Negative')\n" + " AND visit_date between date(:startDate) and date(:endDate);"; SqlCohortDefinition cd = new SqlCohortDefinition(); cd.setName("htsNumberTestedAtFacility"); @@ -969,7 +970,7 @@ public CohortDefinition htsAllNumberTestedAtCommunity() { String sqlQuery = "select patient_id\n" + "FROM kenyaemr_etl.etl_hts_test\n" + "WHERE test_type = 1\n" + - " AND setting = 'Community'\n" + + " AND setting = 'Community' AND final_test_result in ('Positive','Negative')\n" + " AND visit_date between date(:startDate) and date(:endDate);"; SqlCohortDefinition cd = new SqlCohortDefinition(); cd.setName("htsNumberTestedAtCommunity"); @@ -1000,7 +1001,7 @@ protected CohortDefinition htsNumberTestedAsCouple() { * @return */ protected CohortDefinition htsAllNumberTestedAsCouple() { - String sqlQuery = "select patient_id from kenyaemr_etl.etl_hts_test where test_type =1\n" + + String sqlQuery = "select patient_id from kenyaemr_etl.etl_hts_test where test_type =1 AND final_test_result in ('Positive','Negative')\n" + " and client_tested_as ='Couple' and date(visit_date) between date(:startDate) and date(:endDate)"; SqlCohortDefinition cd = new SqlCohortDefinition(); cd.setName("htsNumberTestedAsCouple"); @@ -1030,7 +1031,7 @@ protected CohortDefinition htsNumberTestedKeyPopulation() { * @return */ protected CohortDefinition htsAllNumberTestedKeyPopulation() { - String sqlQuery = "select patient_id from kenyaemr_etl.etl_hts_test where test_type =1 \n" + + String sqlQuery = "select patient_id from kenyaemr_etl.etl_hts_test where test_type =1 AND final_test_result in ('Positive','Negative')\n" + " and population_type ='Key Population' and visit_date between date(:startDate) and date(:endDate)"; SqlCohortDefinition cd = new SqlCohortDefinition(); cd.setName("htsNumberTestedKeyPopulation"); @@ -1133,7 +1134,7 @@ protected CohortDefinition htsNumberTestedDiscordant() { */ public CohortDefinition htsAllNumberTestedDiscordant() { String sqlQuery = "select patient_id from kenyaemr_etl.etl_hts_test where test_type =1\n" + - " and couple_discordant ='Yes' and date(visit_date) between date(:startDate) and date(:endDate)"; + " and couple_discordant ='Yes' and final_test_result in ('Positive','Negative') and date(visit_date) between date(:startDate) and date(:endDate)"; SqlCohortDefinition cd = new SqlCohortDefinition(); cd.setName("htsNumberTestedDiscordant"); cd.setQuery(sqlQuery); @@ -1364,7 +1365,7 @@ public CohortDefinition htsClientsForTheFirstTimeEver() { " patient_id,\n" + " visit_date AS test_date\n" + " FROM kenyaemr_etl.etl_hts_test\n" + - " WHERE test_type = 1\n" + + " WHERE test_type = 1 and final_test_result in ('Positive','Negative')\n" + " and ever_tested_for_hiv = 'No'\n" + " GROUP BY patient_id\n" + " having count(patient_id) = 1\n" + @@ -1388,7 +1389,7 @@ public CohortDefinition htsClientsForTheFirstTimeEver() { public CohortDefinition htsClientsWithPreviousTestOver12MonthsAgo() { String sqlQuery = "SELECT patient_id\n" + "FROM kenyaemr_etl.etl_hts_test\n" + - "WHERE test_type = 1\n" + + "WHERE test_type = 1 AND final_test_result in ('Positive','Negative')\n" + " and ever_tested_for_hiv = 'Yes'\n" + " and months_since_last_test > 12\n" + " and date(visit_date) between date(:startDate) and date(:endDate);"; @@ -1427,7 +1428,7 @@ public CohortDefinition htsRepeatTestsMuxEnc() { " max(visit_date) AS latest_test_date,\n" + " min(visit_date) AS first_test_date\n" + " FROM kenyaemr_etl.etl_hts_test\n" + - " WHERE test_type = 1\n" + + " WHERE test_type = 1 AND final_test_result in ('Positive','Negative')\n" + " GROUP BY patient_id\n" + " having latest_test_date between date(:startDate) and date(:endDate)\n" + " and (latest_test_date > first_test_date and timestampdiff(MONTH,first_test_date,latest_test_date) <= 12)\n" + @@ -1449,7 +1450,7 @@ public CohortDefinition htsRepeatTestsMuxEnc() { public CohortDefinition htsRepeatClientReported() { String sqlQuery = "SELECT patient_id\n" + "FROM kenyaemr_etl.etl_hts_test\n" + - "WHERE test_type = 1\n" + + "WHERE test_type = 1 AND final_test_result in ('Positive','Negative')\n" + " and ever_tested_for_hiv = 'Yes'\n" + " and months_since_last_test <= 12\n" + " and date(visit_date) between date(:startDate) and date(:endDate);"; diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/RevisedDatim/DatimCohortLibrary.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/RevisedDatim/DatimCohortLibrary.java index 4a9564180c..e6783976d9 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/RevisedDatim/DatimCohortLibrary.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/RevisedDatim/DatimCohortLibrary.java @@ -6281,7 +6281,7 @@ public CohortDefinition kpPrevOfferedHTSServices() { public CohortDefinition kpPrevNewlyTestedOrReferredSql() { String sqlQuery = "select a.client_id from (select v.client_id as client_id from (select v.client_id from kenyaemr_etl.etl_clinical_visit v where timestampdiff(MONTH,v.visit_date,date(:endDate)) <3 and v.hiv_tested in ('Yes','Referred for testing'))v\n" + "left join\n" + - " (select t.patient_id from kenyaemr_etl.etl_hts_test t where timestampdiff(MONTH,t.visit_date,date(:endDate)) <3)t on v.client_id = t.patient_id)a group by a.client_id;"; + " (select t.patient_id from kenyaemr_etl.etl_hts_test t where t.final_test_result in ('Positive','Negative') and timestampdiff(MONTH,t.visit_date,date(:endDate)) <3)t on v.client_id = t.patient_id)a group by a.client_id;"; SqlCohortDefinition cd = new SqlCohortDefinition(); cd.setName("kpPrevNewlyTestedOrReferred"); cd.setQuery(sqlQuery);