jeniferfleurant

PMTCT EID reviewed

Nov 16th, 2016
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. USE caris_db;
  2. SET @start_date="2016-07-01";
  3. SET @end_date="2016-09-31";
  4. ###PMTCT_EID
  5. SELECT
  6. hc,
  7. numb_positive_pregnant_women,
  8. virologic_HIV_test_within_12_months,
  9. virologic_test_within_2_months_of_birth,
  10. (virologic_HIV_test_within_12_months-virologic_test_within_2_months_of_birth) as virologic_HIV_test_bet_2_and_12_months,
  11. positive_virologic_test_within_12_months,
  12. positive_virologic_test_within_2_months,
  13. (positive_virologic_test_within_12_months-positive_virologic_test_within_2_months) as positive_virologic_test_bet_2_and_12_months
  14. FROM (
  15.  
  16. SELECT b.*
  17. FROM(
  18.  
  19. SELECT DISTINCT(a.hc), IF(abc00.numb_positive_pregnant_women IS NULL,0,abc00.numb_positive_pregnant_women) as numb_positive_pregnant_women,
  20. IF(abc01.virologic_test_within_2_months_of_birth IS NULL,0,abc01.virologic_test_within_2_months_of_birth) as virologic_test_within_2_months_of_birth,
  21. IF(abc02.virologic_HIV_test_within_12_months IS NULL,0,abc02.virologic_HIV_test_within_12_months) as virologic_HIV_test_within_12_months,
  22. IF(abc03.positive_virologic_test_within_2_months IS NULL,0,abc03.positive_virologic_test_within_2_months) as positive_virologic_test_within_2_months,
  23. IF(abc04.positive_virologic_test_within_12_months IS NULL,0,abc04.positive_virologic_test_within_12_months) as positive_virologic_test_within_12_months
  24.  
  25. FROM (SELECT CONCAT(city_code, "/", hospital_code) AS hc , hospital_code AS hcode_nocity FROM lookup_hospital) a LEFT JOIN
  26. (
  27.  
  28. SELECT count(*) AS 'numb_positive_pregnant_women' , CONCAT(city_code, "/", hospital_code) AS hc from patient
  29. WHERE
  30. id IN (
  31. SELECT id_patient_mother FROM tracking_pregnancy where (dpa between (@start_date) and (@end_date + interval 9 month)
  32. or
  33. ddr between (@start_date - interval 9 month) and (@end_date - interval 2 week))
  34. )
  35. GROUP BY hc
  36. ) abc00 ON abc00.hc=a.hc
  37. ### INFANT VIROLOGY
  38. #WITHING 2 MONTHS
  39. LEFT JOIN (
  40. SELECT count(*) AS `virologic_test_within_2_months_of_birth`, CONCAT(city_code, "/", hospital_code) AS hc
  41. from patient
  42. WHERE
  43. id IN (SELECT id_patient FROM testing_specimen WHERE date_blood_taken >= @start_date
  44. AND date_blood_taken <= @end_date AND DATEDIFF(date_blood_taken,date_of_birth) <= 61
  45. AND DATEDIFF(date_blood_taken,date_of_birth) > 0 AND which_pcr = 1
  46. ) GROUP BY hc
  47. ) abc01 on abc01.hc=a.hc
  48. # BETWEEN 0 12
  49. LEFT JOIN (
  50. SELECT count(*) AS "virologic_HIV_test_within_12_months", CONCAT(city_code, "/", hospital_code) AS hc
  51. from patient
  52. WHERE
  53. id IN (SELECT id_patient FROM testing_specimen WHERE date_blood_taken >= @start_date
  54. AND date_blood_taken <= @end_date AND DATEDIFF(date_blood_taken,date_of_birth) >= 0
  55. AND DATEDIFF(date_blood_taken,date_of_birth) <= 365 AND which_pcr = 1
  56. )
  57. GROUP BY hc
  58. ) abc02 on abc02.hc=a.hc
  59. #POSITIVE WITHIN 2 MONTHS
  60. LEFT JOIN (
  61. SELECT count(*) AS "positive_virologic_test_within_2_months", CONCAT(city_code, "/", hospital_code) AS hc
  62. from patient WHERE id IN (SELECT id_patient FROM testing_specimen WHERE date_blood_taken >= @start_date
  63. AND date_blood_taken <= @end_date AND DATEDIFF(date_blood_taken,date_of_birth) <= 61
  64. AND DATEDIFF(date_blood_taken,date_of_birth) > 0 AND pcr_result=1 and which_pcr = 1
  65. ) GROUP BY hc
  66. ) abc03 on abc03.hc=a.hc
  67.  
  68. # POSITIVE BETWEEN 0 12
  69. LEFT JOIN (
  70. SELECT count(*) AS "positive_virologic_test_within_12_months", CONCAT(city_code, "/", hospital_code) AS hc
  71. from patient
  72. WHERE
  73. id IN (SELECT id_patient FROM testing_specimen WHERE date_blood_taken >= @start_date
  74. AND date_blood_taken <= @end_date AND DATEDIFF(date_blood_taken,date_of_birth) >= 0
  75. AND DATEDIFF(date_blood_taken,date_of_birth) <= 365 and pcr_result = 1 and which_pcr = 1
  76. )
  77. GROUP BY hc
  78. ) abc04 on abc04.hc=a.hc
  79.  
  80.  
  81. ) b
  82.  
  83. ) c
  84. ORDER BY c.hc
Advertisement
Add Comment
Please, Sign In to add comment