Skip to content

Commit

Permalink
Merge pull request #2035 from gabriel090/KHP3-6372
Browse files Browse the repository at this point in the history
Revise the NCD column in Active on ART to pick the most current HIV greencard
  • Loading branch information
njorocs authored Jan 22, 2025
2 parents 00d814b + 0edf80b commit b6bc884
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,32 @@ 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 ="WITH LatestIllnessDates AS (\n" +
" SELECT\n" +
" patient_id,\n" +
" MAX(chronic_illness_onset_date) AS latest_onset_date,\n" +
" COUNT(*) AS date_count\n" +
" FROM\n" +
" kenyaemr_etl.etl_allergy_chronic_illness\n" +
" WHERE\n" +
" visit_date <= DATE(:endDate)\n" +
" GROUP BY\n" +
" patient_id\n" +
")\n" +
"SELECT\n" +
" ci.patient_id,\n" +
" CASE WHEN lid.date_count > 1 THEN\n" +
" GROUP_CONCAT(ci.chronic_illness_onset_date SEPARATOR ', ')\n" +
" ELSE\n" +
" MAX(ci.chronic_illness_onset_date)\n" +
" END AS ChronicIllness_onset\n" +
"FROM\n" +
" kenyaemr_etl.etl_allergy_chronic_illness ci\n" +
"INNER JOIN LatestIllnessDates lid ON ci.patient_id = lid.patient_id\n" +
"WHERE\n" +
" ci.visit_date <= DATE(:endDate)\n" +
"GROUP BY\n" +
" ci.patient_id;";

SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
queryBuilder.append(qry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,43 @@ 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, " +
" GROUP_CONCAT(CASE ci.chronic_illness " +
" WHEN 149019 THEN 'Alzheimers Disease and other Dementias' " +
" WHEN 148432 THEN 'Arthritis' " +
" WHEN 153754 THEN 'Asthma' " +
" WHEN 159351 THEN 'Cancer' " +
" WHEN 119270 THEN 'Cardiovascular diseases' " +
" WHEN 120637 THEN 'Chronic Hepatitis' " +
" WHEN 145438 THEN 'Chronic Kidney Disease' " +
" WHEN 1295 THEN 'Chronic Obstructive Pulmonary Disease(COPD)' " +
" WHEN 120576 THEN 'Chronic Renal Failure' " +
" WHEN 119692 THEN 'Cystic Fibrosis' " +
" WHEN 120291 THEN 'Deafness and Hearing impairment' " +
" WHEN 119481 THEN 'Diabetes' " +
" WHEN 118631 THEN 'Endometriosis' " +
" WHEN 117855 THEN 'Epilepsy' " +
" WHEN 117789 THEN 'Glaucoma' " +
" WHEN 139071 THEN 'Heart Disease' " +
" WHEN 115728 THEN 'Hyperlipidaemia' " +
" WHEN 117399 THEN 'Hypertension' " +
" WHEN 117321 THEN 'Hypothyroidism' " +
" WHEN 151342 THEN 'Mental illness' " +
" WHEN 133687 THEN 'Multiple Sclerosis' " +
" WHEN 115115 THEN 'Obesity' " +
" WHEN 114662 THEN 'Osteoporosis' " +
" WHEN 117703 THEN 'Sickle Cell Anaemia' " +
" WHEN 118976 THEN 'Thyroid disease' " +
" WHEN 141623 THEN 'Dyslipidemia' " +
" END SEPARATOR ', ') AS ChronicIllness " +
"FROM kenyaemr_etl.etl_allergy_chronic_illness ci " +
"JOIN ( " +
" SELECT patient_id, MAX(visit_date) AS latest_visit_date " +
" FROM kenyaemr_etl.etl_allergy_chronic_illness " +
" WHERE visit_date <= DATE(:endDate)" +
" GROUP BY patient_id " +
") latest ON ci.patient_id = latest.patient_id AND ci.visit_date = latest.latest_visit_date " +
"GROUP BY ci.patient_id, ci.visit_date;";
SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
queryBuilder.append(qry);
Date endDate = (Date)context.getParameterValue("endDate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
" GROUP_CONCAT(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);
Expand Down

0 comments on commit b6bc884

Please sign in to comment.