Skip to content

Commit

Permalink
Merge pull request #1711 from njorocs/KHP3-2399
Browse files Browse the repository at this point in the history
Revised clients tested to include only those who had a valid test res…
  • Loading branch information
patryllus authored Oct 19, 2023
2 parents b772131 + 2478795 commit eaf2f8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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" +
Expand All @@ -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);";
Expand Down Expand Up @@ -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" +
Expand All @@ -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);";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit eaf2f8b

Please sign in to comment.