Skip to content

Commit

Permalink
Merge pull request #232 from makombe/new-updates
Browse files Browse the repository at this point in the history
New updates
  • Loading branch information
makombe authored Feb 29, 2024
2 parents 12335a3 + 6ae92fb commit f6793a1
Show file tree
Hide file tree
Showing 40 changed files with 1,608 additions and 487 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,25 @@ public static String getTXCURRQuery() {
String totalTXCurrQry = "select distinct FLOOR(1 + (RAND() * 999999)) as index_no, t.patient_id\n"
+ "from(\n"
+ " select fup.visit_date,fup.patient_id, max(e.visit_date) as enroll_date,\n"
+ " mid(max(concat(e.visit_date, e.patient_type)), 11) as patient_type,\n"
+ " greatest(max(fup.visit_date), ifnull(max(d.visit_date),'0000-00-00')) as latest_vis_date,\n"
+ " greatest(mid(max(concat(fup.visit_date,fup.next_appointment_date)),11), ifnull(max(d.visit_date),'0000-00-00')) as latest_tca,\n"
+ " p.dob as dob,\n"
+ " d.patient_id as disc_patient,\n"
+ " d.effective_disc_date as effective_disc_date,\n"
+ " max(d.visit_date) as date_discontinued,\n"
+ " de.patient_id as started_on_drugs,\n"
+ " mid(max(concat(date(de.date_started), ifnull(de.discontinued, 0))), 11) as on_drugs\n"
+ " de.patient_id as started_on_drugs\n"
+ " from kenyaemr_etl.etl_patient_hiv_followup fup\n"
+ " join kenyaemr_etl.etl_patient_demographics p on p.patient_id=fup.patient_id\n"
+ " join kenyaemr_etl.etl_hiv_enrollment e on fup.patient_id=e.patient_id\n"
+ " inner join kenyaemr_etl.etl_drug_event de on e.patient_id = de.patient_id and de.program='HIV' and date(date_started) <= date(:endDate)\n"
+ " left join kenyaemr_etl.etl_drug_event de on e.patient_id = de.patient_id and de.program='HIV' and date(date_started) <= date(:endDate)\n"
+ " left outer JOIN\n"
+ " (select patient_id, coalesce(date(effective_discontinuation_date),visit_date) visit_date,max(date(effective_discontinuation_date)) as effective_disc_date from kenyaemr_etl.etl_patient_program_discontinuation\n"
+ " where date(visit_date) <= date(:endDate) and program_name='HIV'\n"
+ " group by patient_id\n"
+ " ) d on d.patient_id = fup.patient_id\n"
+ " where fup.visit_date <= date(:endDate)\n"
+ " group by patient_id\n"
+ " having patient_type != 164931 and on_drugs != 1 and (\n"
+ " having (started_on_drugs is not null and started_on_drugs <> '') and (\n"
+ " (\n"
+ " (timestampdiff(DAY,date(latest_tca),date(:endDate)) <= 30 and ((date(d.effective_disc_date) > date(:endDate) or date(enroll_date) > date(d.effective_disc_date)) or d.effective_disc_date is null))\n"
+ " and (date(latest_vis_date) >= date(date_discontinued) or date(latest_tca) >= date(date_discontinued) or disc_patient is null)\n"
Expand All @@ -60,27 +58,25 @@ public static String getChildrenBelow15Query() {
String below15qry = "select distinct FLOOR(1 + (RAND() * 999999)) as index_no, t.patient_id\n"
+ "from(\n"
+ " select fup.visit_date,fup.patient_id, max(e.visit_date) as enroll_date,\n"
+ " mid(max(concat(e.visit_date, e.patient_type)), 11) as patient_type,\n"
+ " greatest(max(fup.visit_date), ifnull(max(d.visit_date),'0000-00-00')) as latest_vis_date,\n"
+ " greatest(mid(max(concat(fup.visit_date,fup.next_appointment_date)),11), ifnull(max(d.visit_date),'0000-00-00')) as latest_tca,\n"
+ " p.dob as dob,\n"
+ " d.patient_id as disc_patient,\n"
+ " d.effective_disc_date as effective_disc_date,\n"
+ " max(d.visit_date) as date_discontinued,\n"
+ " de.patient_id as started_on_drugs,\n"
+ " mid(max(concat(date(de.date_started), ifnull(de.discontinued, 0))), 11) as on_drugs\n"
+ " de.patient_id as started_on_drugs\n"
+ " from kenyaemr_etl.etl_patient_hiv_followup fup\n"
+ " join kenyaemr_etl.etl_patient_demographics p on p.patient_id=fup.patient_id\n"
+ " join kenyaemr_etl.etl_hiv_enrollment e on fup.patient_id=e.patient_id\n"
+ " inner join kenyaemr_etl.etl_drug_event de on e.patient_id = de.patient_id and de.program='HIV' and date(date_started) <= date(:endDate)\n"
+ " left join kenyaemr_etl.etl_drug_event de on e.patient_id = de.patient_id and de.program='HIV' and date(date_started) <= date(:endDate)\n"
+ " left outer JOIN\n"
+ " (select patient_id, coalesce(date(effective_discontinuation_date),visit_date) visit_date,max(date(effective_discontinuation_date)) as effective_disc_date from kenyaemr_etl.etl_patient_program_discontinuation\n"
+ " where date(visit_date) <= date(:endDate) and program_name='HIV'\n"
+ " group by patient_id\n"
+ " ) d on d.patient_id = fup.patient_id\n"
+ " where fup.visit_date <= date(:endDate)\n"
+ " group by patient_id\n"
+ " having timestampdiff(YEAR ,dob,date(:endDate)) <= 14 and patient_type != 164931 and on_drugs != 1 and (\n"
+ " having timestampdiff(YEAR ,dob,date(:endDate)) <= 14 and (started_on_drugs is not null and started_on_drugs <> '') and (\n"
+ " (\n"
+ " (timestampdiff(DAY,date(latest_tca),date(:endDate)) <= 30 and ((date(d.effective_disc_date) > date(:endDate) or date(enroll_date) > date(d.effective_disc_date)) or d.effective_disc_date is null))\n"
+ " and (date(latest_vis_date) >= date(date_discontinued) or date(latest_tca) >= date(date_discontinued) or disc_patient is null)\n"
Expand All @@ -98,27 +94,25 @@ public static String getAdultAbove15Query() {
String generalPopQry = "select distinct FLOOR(1 + (RAND() * 999999)) as index_no, t.patient_id\n"
+ "from(\n"
+ " select fup.visit_date,fup.patient_id, max(e.visit_date) as enroll_date,\n"
+ " mid(max(concat(e.visit_date, e.patient_type)), 11) as patient_type,\n"
+ " greatest(max(fup.visit_date), ifnull(max(d.visit_date),'0000-00-00')) as latest_vis_date,\n"
+ " greatest(mid(max(concat(fup.visit_date,fup.next_appointment_date)),11), ifnull(max(d.visit_date),'0000-00-00')) as latest_tca,\n"
+ " p.dob as dob,\n"
+ " d.patient_id as disc_patient,\n"
+ " d.effective_disc_date as effective_disc_date,\n"
+ " max(d.visit_date) as date_discontinued,\n"
+ " de.patient_id as started_on_drugs,\n"
+ " mid(max(concat(date(de.date_started), ifnull(de.discontinued, 0))), 11) as on_drugs\n"
+ " de.patient_id as started_on_drugs\n"
+ " from kenyaemr_etl.etl_patient_hiv_followup fup\n"
+ " join kenyaemr_etl.etl_patient_demographics p on p.patient_id=fup.patient_id\n"
+ " join kenyaemr_etl.etl_hiv_enrollment e on fup.patient_id=e.patient_id\n"
+ " inner join kenyaemr_etl.etl_drug_event de on e.patient_id = de.patient_id and de.program='HIV' and date(date_started) <= date(:endDate)\n"
+ " left join kenyaemr_etl.etl_drug_event de on e.patient_id = de.patient_id and de.program='HIV' and date(date_started) <= date(:endDate)\n"
+ " left outer JOIN\n"
+ " (select patient_id, coalesce(date(effective_discontinuation_date),visit_date) visit_date,max(date(effective_discontinuation_date)) as effective_disc_date from kenyaemr_etl.etl_patient_program_discontinuation\n"
+ " where date(visit_date) <= date(:endDate) and program_name='HIV'\n"
+ " group by patient_id\n"
+ " ) d on d.patient_id = fup.patient_id\n"
+ " where fup.visit_date <= date(:endDate)\n"
+ " group by patient_id\n"
+ " having timestampdiff(YEAR ,dob,date(:endDate)) >= 15 and patient_type != 164931 and on_drugs != 1 and (\n"
+ " having timestampdiff(YEAR ,dob,date(:endDate)) >= 15 and (started_on_drugs is not null and started_on_drugs <> '') and (\n"
+ " (\n"
+ " (timestampdiff(DAY,date(latest_tca),date(:endDate)) <= 30 and ((date(d.effective_disc_date) > date(:endDate) or date(enroll_date) > date(d.effective_disc_date)) or d.effective_disc_date is null))\n"
+ " and (date(latest_vis_date) >= date(date_discontinued) or date(latest_tca) >= date(date_discontinued) or disc_patient is null)\n"
Expand All @@ -135,31 +129,29 @@ public static String getPMTCTQuery() {
String pmtctQry = "select distinct FLOOR(1 + (RAND() * 999999)) as index_no, t.patient_id\n"
+ "from(\n"
+ " select fup.visit_date,fup.patient_id, max(e.visit_date) as enroll_date,\n"
+ " mid(max(concat(e.visit_date, e.patient_type)), 11) as patient_type,\n"
+ " greatest(max(fup.visit_date), ifnull(max(d.visit_date),'0000-00-00')) as latest_vis_date,\n"
+ " greatest(mid(max(concat(fup.visit_date,fup.next_appointment_date)),11), ifnull(max(d.visit_date),'0000-00-00')) as latest_tca,\n"
+ " d.patient_id as disc_patient,\n"
+ " p.dob as dob,\n"
+ " d.effective_disc_date as effective_disc_date,\n"
+ " max(d.visit_date) as date_discontinued,\n"
+ " de.patient_id as started_on_drugs,\n"
+ " mid(max(concat(date(de.date_started), ifnull(de.discontinued, 0))), 11) as on_drugs\n"
+ " de.patient_id as started_on_drugs\n"
+ " from kenyaemr_etl.etl_patient_hiv_followup fup\n"
+ " join kenyaemr_etl.etl_patient_demographics p on p.patient_id=fup.patient_id\n"
+ " join kenyaemr_etl.etl_hiv_enrollment e on fup.patient_id=e.patient_id\n"
+ " inner join kenyaemr_etl.etl_patient_program pp on pp.patient_id=fup.patient_id and program='MCH-Mother Services' and (\n"
+ " date(date_enrolled) between date(:startDate) and date(:endDate) or \n"
+ " date(date_completed) between date(:startDate) and date(:endDate) or\n"
+ " (date(date_enrolled) < date(:startDate) and (date_completed is null or date(date_completed) > date(:endDate))) )\n"
+ " inner join kenyaemr_etl.etl_drug_event de on e.patient_id = de.patient_id and de.program='HIV' and date(date_started) <= date(:endDate)\n"
+ " left join kenyaemr_etl.etl_drug_event de on e.patient_id = de.patient_id and de.program='HIV' and date(date_started) <= date(:endDate)\n"
+ " left outer JOIN\n"
+ " (select patient_id, coalesce(date(effective_discontinuation_date),visit_date) visit_date,max(date(effective_discontinuation_date)) as effective_disc_date from kenyaemr_etl.etl_patient_program_discontinuation\n"
+ " where date(visit_date) <= date(:endDate) and program_name='HIV'\n"
+ " group by patient_id\n"
+ " ) d on d.patient_id = fup.patient_id\n"
+ " where fup.visit_date <= date(:endDate)\n"
+ " group by patient_id\n"
+ " having timestampdiff(YEAR ,dob,date(:endDate)) >= 15 and patient_type != 164931 and on_drugs != 1 and (\n"
+ " having timestampdiff(YEAR ,dob,date(:endDate)) >= 15 and (started_on_drugs is not null and started_on_drugs <> '') and (\n"
+ " (\n"
+ " (timestampdiff(DAY,date(latest_tca),date(:endDate)) <= 30 and ((date(d.effective_disc_date) > date(:endDate) or date(enroll_date) > date(d.effective_disc_date)) or d.effective_disc_date is null))\n"
+ " and (date(latest_vis_date) >= date(date_discontinued) or date(latest_tca) >= date(date_discontinued) or disc_patient is null)\n"
Expand Down
Loading

0 comments on commit f6793a1

Please sign in to comment.