Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise the Active in PMTCT column in the Active on ART Patients Linelist #2023

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,27 @@ public class ActiveInMchDataDefinitionEvaluator implements PersonDataEvaluator {
public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) throws EvaluationException {
EvaluatedPersonData c = new EvaluatedPersonData(definition, context);

String qry = "select pp.patient_id,if(p.name is not null,'Yes','No') from patient_program pp\n" +
" inner join program p on p.program_id = pp.program_id\n" +
"where date(pp.date_completed) is null and p.name in ('MCH - Child Services','MCH - Mother Services')\n" +
"group by pp.patient_id\n" +
"having max(date(pp.date_enrolled)) <= date(:endDate);";
String qry = "SELECT pp.patient_id,\n" +
" CASE \n" +
" WHEN d.gender = 'M' THEN 'N/A'\n" +
" WHEN (pf.pregnant = 'Yes' OR hf.pregnancy_status = 'Yes' OR es.pregnant = 'Yes') THEN 'Pregnant'\n" +
" WHEN (pf.breastfeeding = 'Yes' OR hf.breastfeeding = 'Yes' OR es.breastfeeding_mother = 'Yes') THEN 'Breastfeeding'\n" +
" ELSE 'No'\n" +
" END AS program_status\n" +
"FROM kenyaemr_etl.etl_patient_program pp\n" +
"LEFT JOIN (SELECT patient_id, MAX(visit_date) AS latest_visit_date, pregnant, breastfeeding FROM kenyaemr_etl.etl_prep_followup GROUP BY patient_id) pf \n" +
" ON pp.patient_id = pf.patient_id\n" +
"LEFT JOIN (SELECT patient_id, MAX(visit_date) AS latest_visit_date, pregnancy_status, breastfeeding FROM kenyaemr_etl.etl_patient_hiv_followup GROUP BY patient_id) hf \n" +
" ON pp.patient_id = hf.patient_id\n" +
"LEFT JOIN (SELECT patient_id, MAX(visit_date) AS latest_visit_date, pregnant, breastfeeding_mother FROM kenyaemr_etl.etl_hts_eligibility_screening GROUP BY patient_id) es \n" +
" ON pp.patient_id = es.patient_id\n" +
"LEFT JOIN kenyaemr_etl.etl_patient_demographics d \n" +
" ON pp.patient_id = d.patient_id\n" +
"WHERE DATE(pp.date_completed) IS NULL\n" +
" AND pp.program IN ('MCH-Child Services', 'MCH-Mother Services')\n" +
"GROUP BY pp.patient_id\n" +
"HAVING MID(MAX(DATE(pp.date_enrolled)), 1, 10) <= DATE(:endDate);";


SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
queryBuilder.append(qry);
Expand Down