jeniferfleurant

Positive under 5 by age and gender

Oct 10th, 2018
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.80 KB | None | 0 0
  1. USE caris_db;
  2. SET @start_date= '2016-10-01';
  3. SET @end_date='2017-09-30';
  4.  
  5. select left(patient_code,8) as hospital,
  6. count(*) as total,
  7. sum(if(gender = 1,if(timestampdiff(month,dob,date)<12 and timestampdiff(month,dob,date)>=6,1,0),0)) as m_6_11,
  8. sum(if(gender = 2,if(timestampdiff(month,dob,date)<12 and timestampdiff(month,dob,date)>=6,1,0),0)) as f_6_11,
  9. sum(if(gender = 1,if(timestampdiff(month,dob,date)<60 and timestampdiff(month,dob,date)>=12,1,0),0)) as m_12_59,
  10. sum(if(gender = 2,if(timestampdiff(month,dob,date)<60 and timestampdiff(month,dob,date)>=12,1,0),0)) as f_12_59
  11.  
  12. from
  13. (
  14. select distinct patient_code, dob, gender, date from tracking_followup left join patient on patient.id=tracking_followup.id_patient
  15. left join tracking_infant on patient.id=tracking_infant.id_patient
  16.  where date between @start_date and @end_date and (mid_arm_circumference>0 or weight>0) and timestampdiff(month,dob,date)<60 and timestampdiff(month,dob,date)>=6
  17. union
  18. select distinct odk_child_visit.patient_code, dob, gender, date_of_visit as date from openfn.odk_child_visit
  19. left join patient on patient.patient_code=odk_child_visit.patient_code
  20. left join tracking_infant on patient.id=id_patient
  21. where
  22. date_of_visit between @start_date and @end_date and (muac>0 or weight_kg>0) and timestampdiff(month,dob,date_of_visit)<60 and timestampdiff(month,dob,date_of_visit)>=6
  23. union
  24. select patient_code, infant_dob as dob, infant_gender as gender, date from testing_mereenfant
  25. left join testing_specimen on testing_specimen.id_patient=testing_mereenfant.id_patient
  26. left join patient on patient.id=testing_mereenfant.id_patient
  27. where pcr_result=1 and infant_weight>0 and date between @start_date and @end_date and timestampdiff(month,infant_dob,date)<60 and timestampdiff(month,infant_dob,date)>=6
  28. )a
  29. group by left(patient_code,8)
Advertisement
Add Comment
Please, Sign In to add comment