jeniferfleurant

Education data request_ Niveau club

Jun 6th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.76 KB | None | 0 0
  1. use caris_db;
  2. set @start_date = '2018-05-01';
  3. set @end_date = '2018-05-31';
  4. select patient_code, if(tracking_infant.first_name is not null,tracking_infant.first_name, tracking_motherbasicinfo.first_name) as first_name,
  5. if(tracking_infant.last_name is not null,tracking_infant.last_name, tracking_motherbasicinfo.last_name) as last_name
  6. ,if(tracking_infant.id_patient is not null, if(tracking_infant.gender=1,'male',if(tracking_infant.gender=2,'female','')),'female') as gender
  7. ,if(tracking_infant.dob is not null,tracking_infant.dob, tracking_motherbasicinfo.dob) as dob
  8. ,left(patient_code,8) as hospital_code
  9. ,lookup_hospital.name as hospital_name
  10. ,lookup_hospital.office as office
  11. ,club.name as club_name
  12. ,lookup_club_type.name as club_type
  13. , lookup_club_topic.name_fr as topic
  14. , club_session.date as training_date
  15. , if(s.id_patient is not null, 'yes','no') as on_arv
  16. from club_session
  17. left join session on session.id_club_session=club_session.id
  18. left join club_patient on club_patient.id_patient=session.id_patient
  19. left join club on club.id=club_session.id_club
  20. left join patient on patient.id=session.id_patient
  21. left join tracking_infant on tracking_infant.id_patient=session.id_patient
  22. left join tracking_motherbasicinfo on tracking_motherbasicinfo.id_patient=session.id_patient
  23. left join lookup_club_type on lookup_club_type.id=club_type
  24. left join lookup_club_topic on lookup_club_topic.id=topic
  25. left join lookup_hospital on concat(lookup_hospital.city_code,'/',lookup_hospital.hospital_code)=left(patient_code,8)
  26. left join (select distinct id_patient from tracking_regime union select distinct id_patient from tracking_followup where on_arv=1)s on s.id_patient=patient.id
  27. where club_session.date between @start_date and @end_date and is_present=1 and linked_to_id_patient=0
Add Comment
Please, Sign In to add comment