jeniferfleurant

PMTCT_EID_HEI_POS_detailed

Jun 22nd, 2018
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.50 KB | None | 0 0
  1. USE caris_db;
  2. SET @start_date="2018-04-01";
  3. SET @end_date="2018-06-31";
  4. # this code will only work for patient after 2014
  5. select patient_code, hospital, date_of_birth, gender, start_date as arv_start, lab, date_blood_taken, date_caris_received_sample, date_lab_received_sample, result, office,
  6. if(timestampdiff(day,date_of_birth,date_blood_taken)<=61,if(timestampdiff(day,date_of_birth,date_blood_taken)>=0,'0_2',''),if(timestampdiff(day,date_of_birth,date_blood_taken)<=365,if(timestampdiff(day,date_of_birth,date_blood_taken)>61,'2_12',''),'')) as tranche_age
  7. ,if(arv is not null,'yes','') as on_arv
  8. ,if(pcr_result=1,if(patient_info is not null,if(is_abandoned=0 and is_dead=0,'no','yes'),''),'') as pos_dead_abandon
  9. ,death_date
  10. ,abandoned_date
  11. ,pcr_result_date
  12. from(
  13. select patient_code, date_of_birth, tracking_infant.id_patient as patient_info, office, date_blood_taken, pcr_result,arv.id_patient as arv, is_dead, is_abandoned, death_date, abandoned_date, pcr_result_date, date_caris_received_sample, date_lab_received_sample,
  14. lookup_testing_specimen_result.name as result, lookup_hospital.name as hospital, lookup_testing_gender.name as gender, tracking_regime.start_date, lookup_lab.name as lab from(
  15.     select * from testing_specimen t1 where timestampdiff(day,date_of_birth,date_blood_taken)<=365 and date_blood_taken between @start_date and @end_date
  16.     and date_blood_taken=(select min(date_blood_taken) from testing_specimen t2 where t1.id_patient=t2.id_patient)
  17. )test_1
  18. left join patient pa on pa.id=test_1.id_patient
  19. left join
  20. (select * from(
  21.     select id_patient from tracking_followup where on_arv=1
  22.     union
  23.     select id_patient from tracking_regime where category='regime_infant_treatment'
  24.     )o
  25. )arv on arv.id_patient=test_1.id_patient
  26. left join tracking_infant on tracking_infant.id_patient=test_1.id_patient
  27. left join testing_mereenfant on testing_mereenfant.id_patient=test_1.id_patient
  28. left join lookup_testing_specimen_result on pcr_result=lookup_testing_specimen_result.id
  29. left join lookup_hospital on concat(lookup_hospital.city_code,'/',lookup_hospital.hospital_code)=left(patient_code,8)
  30. left join tracking_regime on tracking_regime.id_patient=arv.id_patient
  31. left join lookup_testing_gender on lookup_testing_gender.id=infant_gender
  32. left join lookup_lab on lookup_hospital.id_lab=lookup_lab.id
  33. where timestampdiff(day,test_1.date_of_birth,test_1.date_blood_taken)<=365 and test_1.date_blood_taken between @start_date and @end_date and linked_to_id_patient=0
  34. group by test_1.id_patient
  35. )final
Advertisement
Add Comment
Please, Sign In to add comment