Advertisement
ryanarnold

Untitled

Jul 25th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. TABLE: HV_LABGEN_ORDERED_TESTS_CV2
  2.  
  3. select 'Clearview' AS SOURCE_CLINIC,
  4. concat(d.indtests) AS INDTESTS,
  5. -- concat(d.testflags) AS TESTFLAGS,
  6. concat(d.results) AS RESULTS,
  7. d.order_recnum + 0 AS ORDER_RECNUM,
  8. d.seq + 0 AS SEQ,
  9. d.recnum + 0 AS RECNUM,
  10. DATE_ADD(e.test_date_time, INTERVAL 0 DAY) AS TEST_COMPLETION_DATE,
  11. CONCAT(e.technician) AS TEST_COMPLETION_TECH,
  12. DATE_ADD(f.test_date_time, INTERVAL 0 DAY) AS TEST_STARTED_DATE,
  13. CONCAT(f.technician) AS TEST_STARTED_TECH
  14. from (select order_recnum,
  15. indtests,
  16. -- min(testflags) as testflags,
  17. min(results) as results,
  18. min(seq) as seq,
  19. min(recnum) as recnum
  20. from (select order_indtests.indtests,
  21. -- order_indtests.testflags,
  22. order_indtests.results,
  23. order_indtests.order_recnum,
  24. order_indtests.seq,
  25. order_indtests.recnum
  26. from order_indtests,
  27. order_
  28. where order_indtests.indtests is not null
  29. and order_.recnum = order_indtests.order_recnum
  30. and order_.entrydt between str_to_date('%%FROM_DATE', '%M %d %Y') and str_to_date('%%TO_DATE', '%M %d %Y')
  31. UNION ALL
  32. select ordext_indtests.indtests,
  33. -- ordext_indtests.testflags,
  34. ordext_indtests.results,
  35. order_.recnum,
  36. ordext_indtests.seq,
  37. ordext_indtests.recnum
  38. from ordext_indtests,
  39. ordext,
  40. order_
  41. where order_.extrec = ordext.recnum
  42. and ordext.recnum = ordext_indtests.ordext_recnum
  43. and ordext_indtests.indtests is not null
  44. and order_.entrydt between str_to_date('%%FROM_DATE', '%M %d %Y') and str_to_date('%%TO_DATE', '%M %d %Y')) xx
  45. group by order_recnum, indtests) d
  46. LEFT JOIN
  47. (
  48. select c.recnum AS ORDER_RECNUM,
  49. MAX(a.tech) AS TECHNICIAN,
  50. b.tests AS TEST_CODE,
  51. MAX(STR_TO_DATE(CONCAT(DATE_FORMAT(resdate,'%Y-%m-%d'),' ',
  52. CASE restime WHEN NULL THEN NULL
  53. ELSE CONCAT(SUBSTRING(restime,1,2),':',SUBSTRING(restime,3,2))
  54. END), '%Y-%m-%d %T')) AS TEST_DATE_TIME
  55. from ordext2 a,
  56. ordext2_tests b,
  57. order_ c
  58. where a.isverify = 'Y'
  59. and b.ordext2_recnum = a.recnum
  60. and c.accession = a.accession
  61. and c.entrydt between str_to_date('%%FROM_DATE', '%M %d %Y') and str_to_date('%%TO_DATE', '%M %d %Y')
  62. group
  63. by c.recnum,
  64. b.tests
  65. ) e on e.order_recnum = d.order_recnum and e.test_code = d.indtests
  66. LEFT JOIN
  67. (
  68. select c.recnum AS ORDER_RECNUM,
  69. MAX(a.tech) AS TECHNICIAN,
  70. b.tests AS TEST_CODE,
  71. MAX(STR_TO_DATE(CONCAT(DATE_FORMAT(resdate,'%Y-%m-%d'),' ',
  72. CASE restime WHEN NULL THEN NULL
  73. ELSE CONCAT(SUBSTRING(restime,1,2),':',SUBSTRING(restime,3,2))
  74. END), '%Y-%m-%d %T')) AS TEST_DATE_TIME
  75. from ordext2 a,
  76. ordext2_tests b,
  77. order_ c
  78. where ifnull(a.isverify,'X') <> 'Y'
  79. and b.ordext2_recnum = a.recnum
  80. and c.accession = a.accession
  81. and c.entrydt between str_to_date('%%FROM_DATE', '%M %d %Y') and str_to_date('%%TO_DATE', '%M %d %Y')
  82. group
  83. by c.recnum,
  84. b.tests
  85. ) f on f.order_recnum = d.order_recnum and f.test_code = d.indtests
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement