jeniferfleurant

positive children viral load suppression

Feb 26th, 2018
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.83 KB | None | 0 0
  1. USE caris_db;
  2. SET @start_date= "2017-01-01";
  3. SET @end_date="2018-01-01";
  4. select x.id_patient, patient_code, dob, last_followup_date, timestampdiff(month,dob, last_followup_date) as age_en_mois, took_viral_load_test, viral_load_count, charge_virale_indetectable,
  5. if(is_dead=0, "no","yes") as mort,
  6. tracking_infant.death_date, if(is_abandoned=0, "no","yes") as abandon,
  7. if(z.id_patient is not NULL, "yes","non") as on_arv,
  8. tracking_regime.start_date as initiation_date
  9.  from(
  10. select id_patient from testing_specimen where pcr_result=1
  11. union
  12. select id_patient from tracking_regime where category='regime_infant_treatment'
  13. union
  14. select id_patient from tracking_followup
  15. union
  16. select id_patient from testing_result where result=1
  17. )x
  18. left join
  19. (
  20.     select id_patient, date as last_followup_date from tracking_followup f where date=(select max(date) from tracking_followup f1 where f.id_patient=f1.id_patient and date between @start_date and now())
  21. )y on y.id_patient=x.id_patient
  22. left join tracking_infant on tracking_infant.id_patient=x.id_patient
  23. left join patient on patient.id=x.id_patient
  24. left join
  25. (select id_patient, took_viral_load_test, viral_load_count, if(viral_load_indetectable=1, "yes","no") as charge_virale_indetectable from tracking_followup f1
  26. where date=(select max(date) from tracking_followup f3 where f1.id_patient=f3.id_patient and took_viral_load_test=1)) r
  27.  on r.id_patient = x.id_patient
  28. left join
  29. (
  30.    select id_patient from tracking_followup where on_arv=1
  31.    union
  32.    select id_patient from tracking_regime
  33. )z on z.id_patient=x.id_patient
  34. left join tracking_regime on tracking_regime.id_patient=x.id_patient
  35. where linked_to_id_patient=0
  36. and timestampdiff(year,dob,last_followup_date)<18 #and timestampdiff(year,dob,last_followup_date)>=1
  37. and  last_followup_date between @start_date and now()
  38. group by id_patient
Advertisement
Add Comment
Please, Sign In to add comment