Skip to content

Commit

Permalink
Merge pull request palladiumkenya#1843 from njorocs/PNC-REGISTER-MYSQL8
Browse files Browse the repository at this point in the history
Fixing failing query due to date validation in mysql 8
  • Loading branch information
patryllus authored Mar 19, 2024
2 parents 118238e + b89f945 commit 0d8827d
Showing 1 changed file with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ public EvaluatedEncounterData evaluate(EncounterDataDefinition definition, Evalu
EvaluatedEncounterData c = new EvaluatedEncounterData(definition, context);

String qry = "select a.encounter_id,\n" +
" if(timestampdiff(WEEK, a.date_of_delivery, a.visit_date) > 6 and tested_at_pnc is not null, 'Yes',\n" +
" 'No') as tested_within_6_weeks\n" +
"from (select v.patient_id,\n" +
" v.encounter_id,\n" +
" coalesce(nullif(v.visit_date, ''), nullif(t.visit_date, '')) as visit_date,\n" +
" coalesce(nullif(d.date_of_delivery, ''), nullif(v.delivery_date, '')) as date_of_delivery,\n" +
" coalesce(nullif(v.final_test_result, ''), nullif(t.final_test_result, '')) as tested_at_pnc\n" +
" from kenyaemr_etl.etl_mch_postnatal_visit v\n" +
" left join (select d.patient_id,\n" +
" mid(max(concat(d.visit_date, date(d.date_of_delivery))), 11) as date_of_delivery\n" +
" from kenyaemr_etl.etl_mchs_delivery d\n" +
" where d.visit_date <= date(:endDate)\n" +
" group by d.patient_id) d\n" +
" on v.patient_id = d.patient_id\n" +
" left join (select t.encounter_id, t.patient_id, t.visit_date, t.hts_entry_point, t.final_test_result\n" +
" from kenyaemr_etl.etl_hts_test t\n" +
" where date(t.visit_date) between date(:startDate) and date(:endDate)) t\n" +
" on v.patient_id = t.patient_id and v.visit_date = t.visit_date\n" +
" where date(v.visit_date) between date(:startDate) and date(:endDate)) a;";
" if(timestampdiff(WEEK, a.date_of_delivery, a.visit_date) > 6 and tested_at_pnc is not null, 'Yes',\n" +
" 'No') as tested_within_6_weeks\n" +
" from (select v.patient_id,\n" +
" v.encounter_id,\n" +
" coalesce(v.visit_date,t.visit_date) as visit_date,\n" +
" coalesce(d.date_of_delivery, v.delivery_date) as date_of_delivery,\n" +
" coalesce(v.final_test_result, t.final_test_result) as tested_at_pnc\n" +
" from kenyaemr_etl.etl_mch_postnatal_visit v\n" +
" left join (select d.patient_id,\n" +
" mid(max(concat(d.visit_date, date(d.date_of_delivery))), 11) as date_of_delivery\n" +
" from kenyaemr_etl.etl_mchs_delivery d\n" +
" where d.visit_date <= date(:endDate)\n" +
" group by d.patient_id) d\n" +
" on v.patient_id = d.patient_id\n" +
" left join (select t.encounter_id, t.patient_id, t.visit_date, t.hts_entry_point, t.final_test_result\n" +
" from kenyaemr_etl.etl_hts_test t\n" +
" where date(t.visit_date) between date(:startDate) and date(:endDate)) t\n" +
" on v.patient_id = t.patient_id and v.visit_date = t.visit_date\n" +
" where date(v.visit_date) between date(:startDate) and date(:endDate)) a;";

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

0 comments on commit 0d8827d

Please sign in to comment.