Advertisement
jdcrowe

sandisql

Aug 6th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 63.33 KB | None | 0 0
  1. USE [PFR]
  2. GO
  3.  
  4. /****** Object:  View [dbo].[vwComplaintCognosDrillDownA]    Script Date: 8/6/2018 2:33:16 PM ******/
  5. SET ANSI_NULLS ON
  6. GO
  7.  
  8. SET QUOTED_IDENTIFIER ON
  9. GO
  10.  
  11.  
  12.  
  13. ALTER VIEW [dbo].[vwComplaintCognosDrillDownA]
  14. AS
  15. SELECT  
  16. dbo.tblComplaints.ComplaintID
  17. ,DepartmentFullName = case
  18.     when (dbo.tblComplaints.Dept='USGB'
  19.         and (DOS >=   '2009-01-01')
  20.         and FAC='ESCANABA') then
  21.         'BayCare Clinic - Urological Surgeons (USES)'
  22.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  23. end
  24. ,DEPT = case     
  25.      when (dbo.tblComplaints.Dept='USGB'
  26.         and (DOS >=   '2009-01-01')
  27.         and FAC='ESCANABA') then
  28.         'USES'
  29.      else dbo.tblComplaints.Dept
  30. end
  31. ,isnull(dbo.tblComplaints.FAC,
  32.     case(Dept) when 'GBEC' then 'WMOB'
  33.     when 'OMGB' then 'OMGB'
  34. --  when 'USGB' then
  35. --      case(FAC) when 'ESCANABA' then
  36. --          set DEPT = 'USES'
  37. --      end
  38.     else 'EPOB'
  39. end
  40. ) as FAC
  41. ,MgrGroup=case(tblComplaints.notify) when 1 then
  42.     dbo.tblResponsible.MgrGroup
  43.     else
  44.     MgrGroupLowComplexCount
  45.   end  
  46. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  47. , LogDate
  48. ,dbo.tblComplaints.LogDate as OrderDate
  49. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  50.     dbo.tblPtInfo.ComplaintStatus
  51.     else
  52.     'Closed'
  53. end
  54. ,DOS
  55. ,dbo.tblComplaints.notify
  56. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  57. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  58. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  59. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  60. ,Classification = 'Compliment'
  61. ,ComplaintType =(case(tblComplaints.CompStaff) when 1 then
  62.     'Compliment Staff'
  63.   end )
  64. , Category =''
  65. ,SubCategory = ''
  66. FROM         dbo.tblComplaints
  67. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  68. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  69. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  70. Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  71. and CompStaff = 1
  72.  
  73. Union
  74.  
  75. SELECT  
  76. dbo.tblComplaints.ComplaintID
  77. ,DepartmentFullName = case
  78.     when (dbo.tblComplaints.Dept='USGB'
  79.         and (DOS >=   '2009-01-01')
  80.         and FAC='ESCANABA') then
  81.         'BayCare Clinic - Urological Surgeons (USES)'
  82.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  83. end
  84. ,DEPT = case     
  85.      when (dbo.tblComplaints.Dept='USGB'
  86.         and (DOS >=   '2009-01-01')
  87.         and FAC='ESCANABA') then
  88.         'USES'
  89.      else dbo.tblComplaints.Dept
  90. end
  91. ,isnull(dbo.tblComplaints.FAC,
  92.     case(Dept) when 'GBEC' then 'WMOB'
  93.     when 'OMGB' then 'OMGB'
  94.     else 'EPOB'
  95. end
  96. ) as FAC
  97. ,MgrGroup=case(tblComplaints.notify) when 1 then
  98.     dbo.tblResponsible.MgrGroup
  99.     else
  100.     MgrGroupLowComplexCount
  101.   end  
  102. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  103. ,LogDate
  104. ,dbo.tblComplaints.LogDate as OrderDate
  105. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  106.     dbo.tblPtInfo.ComplaintStatus
  107.     else
  108.     'Closed'
  109. end
  110. ,DOS
  111. ,dbo.tblComplaints.notify
  112. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  113. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  114. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  115. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  116. ,Classification = 'Compliment'
  117. ,ComplaintType =(
  118. case(tblComplaints.CompProcess) when 1 then
  119.     'Compliment Process'
  120.   end ), Category=''
  121. ,SubCategory = ''
  122.  
  123. FROM         dbo.tblComplaints
  124. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  125. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  126. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  127.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  128. and CompProcess = 1
  129.  
  130. Union
  131.  
  132. SELECT  
  133. dbo.tblComplaints.ComplaintID
  134. ,DepartmentFullName = case
  135.     when (dbo.tblComplaints.Dept='USGB'
  136.         and (DOS >=   '2009-01-01')
  137.         and FAC='ESCANABA') then
  138.         'BayCare Clinic - Urological Surgeons (USES)'
  139.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  140. end
  141. ,DEPT = case     
  142.      when (dbo.tblComplaints.Dept='USGB'
  143.         and (DOS >=   '2009-01-01')
  144.         and FAC='ESCANABA') then
  145.         'USES'
  146.      else dbo.tblComplaints.Dept
  147. end
  148. ,isnull(dbo.tblComplaints.FAC,
  149.     case(Dept) when 'GBEC' then 'WMOB'
  150.     when 'OMGB' then 'OMGB'
  151.     else 'EPOB'
  152. end
  153. ) as FAC
  154. ,MgrGroup=case(tblComplaints.notify) when 1 then
  155.     dbo.tblResponsible.MgrGroup
  156.     else
  157.     MgrGroupLowComplexCount
  158.   end  
  159. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  160. ,LogDate
  161. ,dbo.tblComplaints.LogDate as OrderDate
  162. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  163.     dbo.tblPtInfo.ComplaintStatus
  164.     else
  165.     'Closed'
  166. end
  167. ,DOS
  168. ,dbo.tblComplaints.notify
  169. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  170. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  171. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  172. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  173. ,Classification = 'Procedural/Process'
  174. ,case(tblComplaints.RecWait) when 1 then
  175.     'Wait Time - In Reception'
  176.   end as ComplaintType
  177. ,Category = ''
  178. ,SubCategory = ''
  179. FROM         dbo.tblComplaints
  180. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  181. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  182. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  183.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  184. and RecWait = 1
  185.  
  186. Union
  187.  
  188. SELECT  
  189. dbo.tblComplaints.ComplaintID
  190. ,DepartmentFullName = case
  191.     when (dbo.tblComplaints.Dept='USGB'
  192.         and (DOS >=   '2009-01-01')
  193.         and FAC='ESCANABA') then
  194.         'BayCare Clinic - Urological Surgeons (USES)'
  195.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  196. end
  197. ,DEPT = case     
  198.      when (dbo.tblComplaints.Dept='USGB'
  199.         and (DOS >=   '2009-01-01')
  200.         and FAC='ESCANABA') then
  201.         'USES'
  202.      else dbo.tblComplaints.Dept
  203. end
  204. ,isnull(dbo.tblComplaints.FAC,
  205.     case(Dept) when 'GBEC' then 'WMOB'
  206.     when 'OMGB' then 'OMGB'
  207.     else 'EPOB'
  208. end
  209. ) as FAC
  210. ,MgrGroup=case(tblComplaints.notify) when 1 then
  211.     dbo.tblResponsible.MgrGroup
  212.     else
  213.     MgrGroupLowComplexCount
  214.   end  
  215. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  216. ,LogDate
  217. ,dbo.tblComplaints.LogDate as OrderDate
  218. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  219.     dbo.tblPtInfo.ComplaintStatus
  220.     else
  221.     'Closed'
  222. end
  223. ,DOS
  224. ,dbo.tblComplaints.notify
  225. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  226. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  227. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  228. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  229. ,Classification = 'Procedural/Process'
  230. ,case(tblComplaints.ExamWait) when 1 then
  231.     'Wait Time - In Exam'
  232.   end as ComplaintType
  233. ,Category = ''
  234. ,SubCategory = ''
  235. FROM         dbo.tblComplaints
  236. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  237. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  238. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  239.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  240. and ExamWait=1
  241.  
  242. Union
  243.  
  244. ---------****************;
  245. SELECT  
  246. dbo.tblComplaints.ComplaintID
  247. ,DepartmentFullName = case
  248.     when (dbo.tblComplaints.Dept='USGB'
  249.         and (DOS >=   '2009-01-01')
  250.         and FAC='ESCANABA') then
  251.         'BayCare Clinic - Urological Surgeons (USES)'
  252.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  253. end
  254. ,DEPT = case     
  255.      when (dbo.tblComplaints.Dept='USGB'
  256.         and (DOS >=   '2009-01-01')
  257.         and FAC='ESCANABA') then
  258.         'USES'
  259.      else dbo.tblComplaints.Dept
  260. end
  261. ,isnull(dbo.tblComplaints.FAC,
  262.     case(Dept) when 'GBEC' then 'WMOB'
  263.     when 'OMGB' then 'OMGB'
  264.     else 'EPOB'
  265. end
  266. ) as FAC
  267. ,MgrGroup=case(tblComplaints.notify) when 1 then
  268.     dbo.tblResponsible.MgrGroup
  269.     else
  270.     MgrGroupLowComplexCount
  271.   end  
  272. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  273. ,LogDate
  274. ,dbo.tblComplaints.LogDate as OrderDate
  275. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  276.     dbo.tblPtInfo.ComplaintStatus
  277.     else
  278.     'Closed'
  279. end
  280. ,DOS
  281. ,dbo.tblComplaints.notify
  282. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  283. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  284. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  285. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  286. ,Classification = 'Procedural/Process'
  287. ,case(tblComplaints.PhoneWait) when 1 then
  288.     'Wait Time - Phone On Hold'
  289.   end as ComplaintType
  290. ,Category = isnull(tblddlnameadds.providerFullName,'Other')
  291. ,SubCategory = ''
  292. FROM         dbo.tblComplaints
  293. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  294. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  295. Left Outer Join dbo.tblStaffNames on (dbo.tblComplaints.ComplaintID = dbo.tblStaffNames.fkComplaintID and tblStaffNames.sectionID = 4)
  296. Left Outer Join dbo.tblDDLnameAdds on (dbo.tblStaffNames.StaffName = ProviderFullName)
  297. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  298.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  299. and  PhoneWait=1 and tblStaffNames.sectionID = 4
  300.  
  301. Union
  302.  
  303. SELECT  
  304. dbo.tblComplaints.ComplaintID
  305. ,DepartmentFullName = case
  306.     when (dbo.tblComplaints.Dept='USGB'
  307.         and (DOS >=   '2009-01-01')
  308.         and FAC='ESCANABA') then
  309.         'BayCare Clinic - Urological Surgeons (USES)'
  310.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  311. end
  312. ,DEPT = case     
  313.      when (dbo.tblComplaints.Dept='USGB'
  314.         and (DOS >=   '2009-01-01')
  315.         and FAC='ESCANABA') then
  316.         'USES'
  317.      else dbo.tblComplaints.Dept
  318. end
  319. ,isnull(dbo.tblComplaints.FAC,
  320.     case(Dept) when 'GBEC' then 'WMOB'
  321.     when 'OMGB' then 'OMGB'
  322.     else 'EPOB'
  323. end
  324. ) as FAC
  325. ,MgrGroup=case(tblComplaints.notify) when 1 then
  326.     dbo.tblResponsible.MgrGroup
  327.     else
  328.     MgrGroupLowComplexCount
  329.   end  
  330. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  331. ,LogDate
  332. ,dbo.tblComplaints.LogDate as OrderDate
  333. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  334.     dbo.tblPtInfo.ComplaintStatus
  335.     else
  336.     'Closed'
  337. end
  338. ,DOS
  339. ,dbo.tblComplaints.notify
  340. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  341. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  342. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  343. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  344. ,Classification = 'Procedural/Process'
  345. ,case(tblComplaints.Appt) when 1 then
  346.     'Time to Next Available Appointment'
  347.   end as ComplaintType
  348. ,Category = ''
  349. ,SubCategory = ''
  350. FROM         dbo.tblComplaints
  351. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  352. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  353. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  354.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  355. and  Appt=1
  356.  
  357. Union
  358.  
  359. SELECT  
  360. dbo.tblComplaints.ComplaintID
  361. ,DepartmentFullName = case
  362.     when (dbo.tblComplaints.Dept='USGB'
  363.         and (DOS >=   '2009-01-01')
  364.         and FAC='ESCANABA') then
  365.         'BayCare Clinic - Urological Surgeons (USES)'
  366.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  367. end
  368. ,DEPT = case     
  369.      when (dbo.tblComplaints.Dept='USGB'
  370.         and (DOS >=   '2009-01-01')
  371.         and FAC='ESCANABA') then
  372.         'USES'
  373.      else dbo.tblComplaints.Dept
  374. end
  375. ,isnull(dbo.tblComplaints.FAC,
  376.     case(Dept) when 'GBEC' then 'WMOB'
  377.     when 'OMGB' then 'OMGB'
  378.     else 'EPOB'
  379. end
  380. ) as FAC
  381. ,MgrGroup=case(tblComplaints.notify) when 1 then
  382.     dbo.tblResponsible.MgrGroup
  383.     else
  384.     MgrGroupLowComplexCount
  385.   end  
  386. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  387. ,LogDate
  388. ,dbo.tblComplaints.LogDate as OrderDate
  389. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  390.     dbo.tblPtInfo.ComplaintStatus
  391.     else
  392.     'Closed'
  393. end
  394. ,DOS
  395. ,dbo.tblComplaints.notify
  396. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  397. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  398. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  399. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  400. ,Classification = 'Procedural/Process'
  401. ,case(tblComplaints.TestRequest) when 1 then
  402.     'Time to Receipt of Test Results'
  403.   end as ComplaintType
  404. ,Category = isnull(tblDDLnameAdds.providerFullName,'Other')
  405. ,SubCategory = ''
  406. FROM         dbo.tblComplaints
  407. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  408. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  409. Left Outer Join dbo.tblStaffNames on (dbo.tblComplaints.ComplaintID = dbo.tblStaffNames.fkComplaintID and tblStaffNames.sectionID = 7 )
  410. Left Outer Join dbo.tblDDLnameAdds on (dbo.tblStaffNames.StaffName = ProviderFullName)
  411. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  412.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  413. and  TestRequest=1
  414.  
  415. Union
  416.  
  417. SELECT  
  418. dbo.tblComplaints.ComplaintID
  419. ,DepartmentFullName = case
  420.     when (dbo.tblComplaints.Dept='USGB'
  421.         and (DOS >=   '2009-01-01')
  422.         and FAC='ESCANABA') then
  423.         'BayCare Clinic - Urological Surgeons (USES)'
  424.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  425. end
  426. ,DEPT = case     
  427.      when (dbo.tblComplaints.Dept='USGB'
  428.         and (DOS >=   '2009-01-01')
  429.         and FAC='ESCANABA') then
  430.         'USES'
  431.      else dbo.tblComplaints.Dept
  432. end
  433. ,isnull(dbo.tblComplaints.FAC,
  434.     case(Dept) when 'GBEC' then 'WMOB'
  435.     when 'OMGB' then 'OMGB'
  436.     else 'EPOB'
  437. end
  438. ) as FAC
  439. ,MgrGroup=case(tblComplaints.notify) when 1 then
  440.     dbo.tblResponsible.MgrGroup
  441.     else
  442.     MgrGroupLowComplexCount
  443.   end  
  444. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  445. ,LogDate
  446. ,dbo.tblComplaints.LogDate as OrderDate
  447. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  448.     dbo.tblPtInfo.ComplaintStatus
  449.     else
  450.     'Closed'
  451. end
  452. ,DOS
  453. ,dbo.tblComplaints.notify
  454. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  455. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  456. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  457. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  458. ,Classification = 'Procedural/Process'
  459. ,case(tblComplaints.Contact) when 1 then
  460.     'Time to Contact for Requested Info'
  461.   end as ComplaintType
  462. ,Category = isnull(tblDDLnameAdds.providerFullName,'Other')
  463. ,SubCategory = ''
  464. FROM         dbo.tblComplaints
  465. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  466. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  467. Left Outer Join dbo.tblStaffNames on (dbo.tblComplaints.ComplaintID = dbo.tblStaffNames.fkComplaintID and tblStaffNames.sectionID = 9 )
  468. Left Outer Join dbo.tblDDLnameAdds on (dbo.tblStaffNames.StaffName = ProviderFullName)
  469. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  470.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  471. and Contact=1
  472.  
  473. Union
  474.  
  475. SELECT  
  476. dbo.tblComplaints.ComplaintID
  477. ,DepartmentFullName = case
  478.     when (dbo.tblComplaints.Dept='USGB'
  479.         and (DOS >=   '2009-01-01')
  480.         and FAC='ESCANABA') then
  481.         'BayCare Clinic - Urological Surgeons (USES)'
  482.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  483. end
  484. ,DEPT = case     
  485.      when (dbo.tblComplaints.Dept='USGB'
  486.         and (DOS >=   '2009-01-01')
  487.         and FAC='ESCANABA') then
  488.         'USES'
  489.      else dbo.tblComplaints.Dept
  490. end
  491. ,isnull(dbo.tblComplaints.FAC,
  492.     case(Dept) when 'GBEC' then 'WMOB'
  493.     when 'OMGB' then 'OMGB'
  494.     else 'EPOB'
  495. end
  496. ) as FAC
  497. ,MgrGroup=case(tblComplaints.notify) when 1 then
  498.     dbo.tblResponsible.MgrGroup
  499.     else
  500.     MgrGroupLowComplexCount
  501.   end  
  502. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  503. ,LogDate
  504. ,dbo.tblComplaints.LogDate as OrderDate
  505. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  506.     dbo.tblPtInfo.ComplaintStatus
  507.     else
  508.     'Closed'
  509. end
  510. ,DOS
  511. ,dbo.tblComplaints.notify
  512. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  513. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  514. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  515. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  516. ,Classification = 'Billing'
  517. ,case(tblComplaints.Cost) when 1 then
  518.     'Cost of Service'  
  519. end as ComplaintType
  520. ,Category = isnull(tblddlnameadds.providerFullName,'Other')
  521. ,SubCategory = ''
  522. FROM         dbo.tblComplaints
  523. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  524. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  525. Left Outer Join dbo.tblStaffNames on (dbo.tblComplaints.ComplaintID = dbo.tblStaffNames.fkComplaintID and tblStaffNames.sectionID = 6 )
  526. Left Outer Join dbo.tblDDLnameAdds on (dbo.tblStaffNames.StaffName = ProviderFullName)
  527. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  528.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  529. and  Cost=1
  530.  
  531. Union
  532.  
  533. SELECT  
  534. dbo.tblComplaints.ComplaintID
  535. ,DepartmentFullName = case
  536.     when (dbo.tblComplaints.Dept='USGB'
  537.         and (DOS >=   '2009-01-01')
  538.         and FAC='ESCANABA') then
  539.         'BayCare Clinic - Urological Surgeons (USES)'
  540.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  541. end
  542. ,DEPT = case     
  543.      when (dbo.tblComplaints.Dept='USGB'
  544.         and (DOS >=   '2009-01-01')
  545.         and FAC='ESCANABA') then
  546.         'USES'
  547.      else dbo.tblComplaints.Dept
  548. end
  549. ,isnull(dbo.tblComplaints.FAC,
  550.     case(Dept) when 'GBEC' then 'WMOB'
  551.     when 'OMGB' then 'OMGB'
  552.     else 'EPOB'
  553. end
  554. ) as FAC
  555. ,MgrGroup=case(tblComplaints.notify) when 1 then
  556.     dbo.tblResponsible.MgrGroup
  557.     else
  558.     MgrGroupLowComplexCount
  559.   end  
  560. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  561. ,LogDate
  562. ,dbo.tblComplaints.LogDate as OrderDate
  563. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  564.     dbo.tblPtInfo.ComplaintStatus
  565.     else
  566.     'Closed'
  567. end
  568. ,DOS
  569. ,dbo.tblComplaints.notify
  570. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  571. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  572. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  573. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  574. ,Classification = 'DME'
  575. ,case(tblComplaints.CatDME) when 1 then
  576.      'Quality of Optical/DME/Supplies'
  577. end as ComplaintType
  578. ,Category = ''
  579. ,SubCategory = ''
  580. FROM         dbo.tblComplaints
  581. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  582. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  583. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  584.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  585. and  catDME=1
  586.  
  587. Union
  588.  
  589. SELECT  
  590. dbo.tblComplaints.ComplaintID
  591. ,DepartmentFullName = case
  592.     when (dbo.tblComplaints.Dept='USGB'
  593.         and (DOS >=   '2009-01-01')
  594.         and FAC='ESCANABA') then
  595.         'BayCare Clinic - Urological Surgeons (USES)'
  596.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  597. end
  598. ,DEPT = case     
  599.      when (dbo.tblComplaints.Dept='USGB'
  600.         and (DOS >=   '2009-01-01')
  601.         and FAC='ESCANABA') then
  602.         'USES'
  603.      else dbo.tblComplaints.Dept
  604. end
  605. ,isnull(dbo.tblComplaints.FAC,
  606.     case(Dept) when 'GBEC' then 'WMOB'
  607.     when 'OMGB' then 'OMGB'
  608.     else 'EPOB'
  609. end
  610. ) as FAC
  611. ,MgrGroup=case(tblComplaints.notify) when 1 then
  612.     dbo.tblResponsible.MgrGroup
  613.     else
  614.     MgrGroupLowComplexCount
  615.   end  
  616. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  617. ,LogDate
  618. ,dbo.tblComplaints.LogDate as OrderDate
  619. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  620.     dbo.tblPtInfo.ComplaintStatus
  621.     else
  622.     'Closed'
  623. end
  624. ,DOS
  625. ,dbo.tblComplaints.notify
  626. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  627. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  628. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  629. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  630. ,Classification = 'Billing'
  631. ,ComplaintType='Billing Issues'
  632. ,Category =  'Actual Billing Error'
  633. ,case(tblComplaints.BillCoding) when 1 then
  634.      'Coding Error'
  635. end as SubCategory
  636. FROM         dbo.tblComplaints
  637. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  638. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  639. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  640.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  641. and  BillCoding=1
  642.  
  643. Union
  644.  
  645. SELECT  
  646. dbo.tblComplaints.ComplaintID
  647. ,DepartmentFullName = case
  648.     when (dbo.tblComplaints.Dept='USGB'
  649.         and (DOS >=   '2009-01-01')
  650.         and FAC='ESCANABA') then
  651.         'BayCare Clinic - Urological Surgeons (USES)'
  652.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  653. end
  654. ,DEPT = case     
  655.      when (dbo.tblComplaints.Dept='USGB'
  656.         and (DOS >=   '2009-01-01')
  657.         and FAC='ESCANABA') then
  658.         'USES'
  659.      else dbo.tblComplaints.Dept
  660. end
  661. ,isnull(dbo.tblComplaints.FAC,
  662.     case(Dept) when 'GBEC' then 'WMOB'
  663.     when 'OMGB' then 'OMGB'
  664.     else 'EPOB'
  665. end
  666. ) as FAC
  667. ,MgrGroup=case(tblComplaints.notify) when 1 then
  668.     dbo.tblResponsible.MgrGroup
  669.     else
  670.     MgrGroupLowComplexCount
  671.   end  
  672. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  673. ,LogDate
  674. ,dbo.tblComplaints.LogDate as OrderDate
  675. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  676.     dbo.tblPtInfo.ComplaintStatus
  677.     else
  678.     'Closed'
  679. end
  680. ,DOS
  681. ,dbo.tblComplaints.notify
  682. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  683. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  684. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  685. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  686. ,Classification = 'Billing'
  687. ,ComplaintType='Billing Issues'
  688. ,Category =  'Actual Billing Error'
  689. ,case(tblComplaints.BillCharging) when 1 then
  690.      'Charging Error'
  691. end as SubCategory
  692. FROM         dbo.tblComplaints
  693. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  694. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  695. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  696.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  697. and  BillCharging=1
  698.  
  699. Union
  700.  
  701. SELECT  
  702. dbo.tblComplaints.ComplaintID
  703. ,DepartmentFullName = case
  704.     when (dbo.tblComplaints.Dept='USGB'
  705.         and (DOS >=   '2009-01-01')
  706.         and FAC='ESCANABA') then
  707.         'BayCare Clinic - Urological Surgeons (USES)'
  708.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  709. end
  710. ,DEPT = case     
  711.      when (dbo.tblComplaints.Dept='USGB'
  712.         and (DOS >=   '2009-01-01')
  713.         and FAC='ESCANABA') then
  714.         'USES'
  715.      else dbo.tblComplaints.Dept
  716. end
  717. ,isnull(dbo.tblComplaints.FAC,
  718.     case(Dept) when 'GBEC' then 'WMOB'
  719.     when 'OMGB' then 'OMGB'
  720.     else 'EPOB'
  721. end
  722. ) as FAC
  723. ,MgrGroup=case(tblComplaints.notify) when 1 then
  724.     dbo.tblResponsible.MgrGroup
  725.     else
  726.     MgrGroupLowComplexCount
  727.   end  
  728. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  729. ,LogDate
  730. ,dbo.tblComplaints.LogDate as OrderDate
  731. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  732.     dbo.tblPtInfo.ComplaintStatus
  733.     else
  734.     'Closed'
  735. end
  736. ,DOS
  737. ,dbo.tblComplaints.notify
  738. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  739. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  740. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  741. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  742. ,Classification = 'Billing'
  743. ,ComplaintType='Billing Issues'
  744. ,Category =  'Actual Billing Error'
  745. ,case(tblComplaints.BillPosting) when 1 then
  746.      'Posting Error'
  747. end as SubCategory
  748. FROM         dbo.tblComplaints
  749. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  750. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  751. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  752.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  753. and  BillPosting = 1
  754.  
  755. Union
  756.  
  757. SELECT  
  758. dbo.tblComplaints.ComplaintID
  759. ,DepartmentFullName = case
  760.     when (dbo.tblComplaints.Dept='USGB'
  761.         and (DOS >=   '2009-01-01')
  762.         and FAC='ESCANABA') then
  763.         'BayCare Clinic - Urological Surgeons (USES)'
  764.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  765. end
  766. ,DEPT = case     
  767.      when (dbo.tblComplaints.Dept='USGB'
  768.         and (DOS >=   '2009-01-01')
  769.         and FAC='ESCANABA') then
  770.         'USES'
  771.      else dbo.tblComplaints.Dept
  772. end
  773. ,isnull(dbo.tblComplaints.FAC,
  774.     case(Dept) when 'GBEC' then 'WMOB'
  775.     when 'OMGB' then 'OMGB'
  776.     else 'EPOB'
  777. end
  778. ) as FAC
  779. ,MgrGroup=case(tblComplaints.notify) when 1 then
  780.     dbo.tblResponsible.MgrGroup
  781.     else
  782.     MgrGroupLowComplexCount
  783.   end  
  784. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  785. ,LogDate
  786. ,dbo.tblComplaints.LogDate as OrderDate
  787. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  788.     dbo.tblPtInfo.ComplaintStatus
  789.     else
  790.     'Closed'
  791. end
  792. ,DOS
  793. ,dbo.tblComplaints.notify
  794. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  795. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  796. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  797. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  798. ,Classification = 'Billing'
  799. ,ComplaintType='Billing Issues'
  800. ,Category =  'Statement'
  801. ,case(tblComplaints.BillStmtRecd) when 1 then
  802.      'Received, Already Paid'
  803. end as SubCategory
  804. FROM         dbo.tblComplaints
  805. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  806. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  807. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  808.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  809. and  BillStmtRecd = 1
  810.  
  811. Union
  812.  
  813. SELECT  
  814. dbo.tblComplaints.ComplaintID
  815. ,DepartmentFullName = case
  816.     when (dbo.tblComplaints.Dept='USGB'
  817.         and (DOS >=   '2009-01-01')
  818.         and FAC='ESCANABA') then
  819.         'BayCare Clinic - Urological Surgeons (USES)'
  820.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  821. end
  822. ,DEPT = case     
  823.      when (dbo.tblComplaints.Dept='USGB'
  824.         and (DOS >=   '2009-01-01')
  825.         and FAC='ESCANABA') then
  826.         'USES'
  827.      else dbo.tblComplaints.Dept
  828. end
  829. ,isnull(dbo.tblComplaints.FAC,
  830.     case(Dept) when 'GBEC' then 'WMOB'
  831.     when 'OMGB' then 'OMGB'
  832.     else 'EPOB'
  833. end
  834. ) as FAC
  835. ,MgrGroup=case(tblComplaints.notify) when 1 then
  836.     dbo.tblResponsible.MgrGroup
  837.     else
  838.     MgrGroupLowComplexCount
  839.   end  
  840. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  841. ,LogDate
  842. ,dbo.tblComplaints.LogDate as OrderDate
  843. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  844.     dbo.tblPtInfo.ComplaintStatus
  845.     else
  846.     'Closed'
  847. end
  848. ,DOS
  849. ,dbo.tblComplaints.notify
  850. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  851. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  852. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  853. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  854. ,Classification = 'Billing'
  855. ,ComplaintType='Billing Issues'
  856. ,Category =  'Statement'
  857. ,case(tblComplaints.BillStmtDetail) when 1 then
  858.      'Not Enough Detail'
  859. end as SubCategory
  860. FROM         dbo.tblComplaints
  861. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  862. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  863. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  864.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  865. and  BillStmtDetail = 1
  866.  
  867. Union
  868.  
  869. SELECT  
  870. dbo.tblComplaints.ComplaintID
  871. ,DepartmentFullName = case
  872.     when (dbo.tblComplaints.Dept='USGB'
  873.         and (DOS >=   '2009-01-01')
  874.         and FAC='ESCANABA') then
  875.         'BayCare Clinic - Urological Surgeons (USES)'
  876.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  877. end
  878. ,DEPT = case     
  879.      when (dbo.tblComplaints.Dept='USGB'
  880.         and (DOS >=   '2009-01-01')
  881.         and FAC='ESCANABA') then
  882.         'USES'
  883.      else dbo.tblComplaints.Dept
  884. end
  885. ,isnull(dbo.tblComplaints.FAC,
  886.     case(Dept) when 'GBEC' then 'WMOB'
  887.     when 'OMGB' then 'OMGB'
  888.     else 'EPOB'
  889. end
  890. ) as FAC
  891. ,MgrGroup=case(tblComplaints.notify) when 1 then
  892.     dbo.tblResponsible.MgrGroup
  893.     else
  894.     MgrGroupLowComplexCount
  895.   end  
  896. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  897. ,LogDate
  898. ,dbo.tblComplaints.LogDate as OrderDate
  899. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  900.     dbo.tblPtInfo.ComplaintStatus
  901.     else
  902.     'Closed'
  903. end
  904. ,DOS
  905. ,dbo.tblComplaints.notify
  906. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  907. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  908. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  909. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  910. ,Classification = 'Billing'
  911. ,ComplaintType='Billing Issues'
  912. ,Category =  'Statement'
  913. ,case(tblComplaints.BillStmtLayout) when 1 then
  914.      'Layout/Process'
  915. end as SubCategory
  916. FROM         dbo.tblComplaints
  917. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  918. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  919. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  920.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  921. and  BillStmtLayout=1
  922.  
  923. Union
  924.  
  925. SELECT  
  926. dbo.tblComplaints.ComplaintID
  927. ,DepartmentFullName = case
  928.     when (dbo.tblComplaints.Dept='USGB'
  929.         and (DOS >=   '2009-01-01')
  930.         and FAC='ESCANABA') then
  931.         'BayCare Clinic - Urological Surgeons (USES)'
  932.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  933. end
  934. ,DEPT = case     
  935.      when (dbo.tblComplaints.Dept='USGB'
  936.         and (DOS >=   '2009-01-01')
  937.         and FAC='ESCANABA') then
  938.         'USES'
  939.      else dbo.tblComplaints.Dept
  940. end
  941. ,isnull(dbo.tblComplaints.FAC,
  942.     case(Dept) when 'GBEC' then 'WMOB'
  943.     when 'OMGB' then 'OMGB'
  944.     else 'EPOB'
  945. end
  946. ) as FAC
  947. ,MgrGroup=case(tblComplaints.notify) when 1 then
  948.     dbo.tblResponsible.MgrGroup
  949.     else
  950.     MgrGroupLowComplexCount
  951.   end  
  952. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  953. ,LogDate
  954. ,dbo.tblComplaints.LogDate as OrderDate
  955. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  956.     dbo.tblPtInfo.ComplaintStatus
  957.     else
  958.     'Closed'
  959. end
  960. ,DOS
  961. ,dbo.tblComplaints.notify
  962. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  963. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  964. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  965. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  966. ,Classification = 'Billing'
  967. ,ComplaintType='Billing Issues'
  968. ,Category =  'Insurance Coverage'
  969. ,case(tblComplaints.BillPreCert) when 1 then
  970.      'PreCertification'
  971. end as SubCategory
  972. FROM         dbo.tblComplaints
  973. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  974. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  975. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  976.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  977. and  BillPreCert = 1
  978.  
  979. Union
  980.  
  981. SELECT  
  982. dbo.tblComplaints.ComplaintID
  983. ,DepartmentFullName = case
  984.     when (dbo.tblComplaints.Dept='USGB'
  985.         and (DOS >=   '2009-01-01')
  986.         and FAC='ESCANABA') then
  987.         'BayCare Clinic - Urological Surgeons (USES)'
  988.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  989. end
  990. ,DEPT = case     
  991.      when (dbo.tblComplaints.Dept='USGB'
  992.         and (DOS >=   '2009-01-01')
  993.         and FAC='ESCANABA') then
  994.         'USES'
  995.      else dbo.tblComplaints.Dept
  996. end
  997. ,isnull(dbo.tblComplaints.FAC,
  998.     case(Dept) when 'GBEC' then 'WMOB'
  999.     when 'OMGB' then 'OMGB'
  1000.     else 'EPOB'
  1001. end
  1002. ) as FAC
  1003. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1004.     dbo.tblResponsible.MgrGroup
  1005.     else
  1006.     MgrGroupLowComplexCount
  1007.   end  
  1008. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1009. ,LogDate
  1010. ,dbo.tblComplaints.LogDate as OrderDate
  1011. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1012.     dbo.tblPtInfo.ComplaintStatus
  1013.     else
  1014.     'Closed'
  1015. end
  1016. ,DOS
  1017. ,dbo.tblComplaints.notify
  1018. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1019. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1020. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1021. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1022. ,Classification = 'Billing'
  1023. ,ComplaintType='Billing Issues'
  1024. ,Category =  'Insurance Coverage'
  1025. ,case(tblComplaints.BillPTUnderstand) when 1 then
  1026.      'PT Lacks Understanding or Dissatisfied With Coverage'
  1027. end as SubCategory
  1028. FROM         dbo.tblComplaints
  1029. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1030. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1031. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1032.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1033. and  billPTUnderstand = 1
  1034.  
  1035. Union
  1036.  
  1037. SELECT  
  1038. dbo.tblComplaints.ComplaintID
  1039. ,DepartmentFullName = case
  1040.     when (dbo.tblComplaints.Dept='USGB'
  1041.         and (DOS >=   '2009-01-01')
  1042.         and FAC='ESCANABA') then
  1043.         'BayCare Clinic - Urological Surgeons (USES)'
  1044.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1045. end
  1046. ,DEPT = case     
  1047.      when (dbo.tblComplaints.Dept='USGB'
  1048.         and (DOS >=   '2009-01-01')
  1049.         and FAC='ESCANABA') then
  1050.         'USES'
  1051.      else dbo.tblComplaints.Dept
  1052. end
  1053. ,isnull(dbo.tblComplaints.FAC,
  1054.     case(Dept) when 'GBEC' then 'WMOB'
  1055.     when 'OMGB' then 'OMGB'
  1056.     else 'EPOB'
  1057. end
  1058. ) as FAC
  1059. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1060.     dbo.tblResponsible.MgrGroup
  1061.     else
  1062.     MgrGroupLowComplexCount
  1063.   end  
  1064. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1065. ,LogDate
  1066. ,dbo.tblComplaints.LogDate as OrderDate
  1067. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1068.     dbo.tblPtInfo.ComplaintStatus
  1069.     else
  1070.     'Closed'
  1071. end
  1072. ,DOS
  1073. ,dbo.tblComplaints.notify
  1074. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1075. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1076. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1077. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1078. ,Classification = 'Billing'
  1079. ,ComplaintType='Billing Issues'
  1080. ,case(tblComplaints.BillErr) when 1 then
  1081.             'Error In Discount'
  1082. end as Catetory
  1083. ,SubCategory = 'Contract'
  1084. FROM         dbo.tblComplaints
  1085. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1086. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1087. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1088.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1089. and  BillErr=1
  1090.  
  1091. Union
  1092.  
  1093. SELECT  
  1094. dbo.tblComplaints.ComplaintID
  1095. ,DepartmentFullName = case
  1096.     when (dbo.tblComplaints.Dept='USGB'
  1097.         and (DOS >=   '2009-01-01')
  1098.         and FAC='ESCANABA') then
  1099.         'BayCare Clinic - Urological Surgeons (USES)'
  1100.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1101. end
  1102. ,DEPT = case     
  1103.      when (dbo.tblComplaints.Dept='USGB'
  1104.         and (DOS >=   '2009-01-01')
  1105.         and FAC='ESCANABA') then
  1106.         'USES'
  1107.      else dbo.tblComplaints.Dept
  1108. end
  1109. ,isnull(dbo.tblComplaints.FAC,
  1110.     case(Dept) when 'GBEC' then 'WMOB'
  1111.     when 'OMGB' then 'OMGB'
  1112.     else 'EPOB'
  1113. end
  1114. ) as FAC
  1115. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1116.     dbo.tblResponsible.MgrGroup
  1117.     else
  1118.     MgrGroupLowComplexCount
  1119.   end  
  1120. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1121. ,LogDate
  1122. ,dbo.tblComplaints.LogDate as OrderDate
  1123. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1124.     dbo.tblPtInfo.ComplaintStatus
  1125.     else
  1126.     'Closed'
  1127. end
  1128. ,DOS
  1129. ,dbo.tblComplaints.notify
  1130. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1131. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1132. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1133. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1134. ,Classification = 'Billing'
  1135. ,ComplaintType = 'Billing Issues'
  1136. ,Category=  'Other'
  1137. ,SubCategory = ''
  1138. FROM         dbo.tblComplaints
  1139. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1140. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1141. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1142.  Where (validated = 1 and notify=1 and categoryValidated = 1 and billing=1)
  1143. and  Billcoding =0 and billcharging = 0 and billposting=0 and billsiteres=1 and billstmt = 0 and
  1144. billinscov = 0 and billprecert = 0 and billptunderstand=0 and billerr=0 and billothertype=0 and
  1145. other = 0
  1146.  
  1147. Union
  1148.  
  1149. SELECT  
  1150. dbo.tblComplaints.ComplaintID
  1151. ,DepartmentFullName = case
  1152.     when (dbo.tblComplaints.Dept='USGB'
  1153.         and (DOS >=   '2009-01-01')
  1154.         and FAC='ESCANABA') then
  1155.         'BayCare Clinic - Urological Surgeons (USES)'
  1156.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1157. end
  1158. ,DEPT = case     
  1159.      when (dbo.tblComplaints.Dept='USGB'
  1160.         and (DOS >=   '2009-01-01')
  1161.         and FAC='ESCANABA') then
  1162.         'USES'
  1163.      else dbo.tblComplaints.Dept
  1164. end
  1165. ,isnull(dbo.tblComplaints.FAC,
  1166.     case(Dept) when 'GBEC' then 'WMOB'
  1167.     when 'OMGB' then 'OMGB'
  1168.     else 'EPOB'
  1169. end
  1170. ) as FAC
  1171. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1172.     dbo.tblResponsible.MgrGroup
  1173.     else
  1174.     MgrGroupLowComplexCount
  1175.   end  
  1176. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1177. ,LogDate
  1178. ,dbo.tblComplaints.LogDate as OrderDate
  1179. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1180.     dbo.tblPtInfo.ComplaintStatus
  1181.     else
  1182.     'Closed'
  1183. end
  1184. ,DOS
  1185. ,dbo.tblComplaints.notify
  1186. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1187. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1188. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1189. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1190. ,Classification = 'Billing'
  1191. ,ComplaintType = 'Billing Issues'
  1192. ,case(tblComplaints.BillOtherType) when 1 then
  1193.             'Other'
  1194. end as Category
  1195. ,SubCategory = ''
  1196. FROM         dbo.tblComplaints
  1197. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1198. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1199. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1200.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1201. and  BillOtherType = 1
  1202.  
  1203. --Union
  1204. --
  1205. --SELECT  
  1206. --dbo.tblComplaints.ComplaintID
  1207. --,DepartmentFullName = case
  1208. --  when (dbo.tblComplaints.Dept='USGB'
  1209. --      and (DOS >=   '2009-01-01')
  1210. --      and FAC='ESCANABA') then
  1211. --      'BayCare Clinic - Urological Surgeons (USES)'
  1212. --  else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1213. --end
  1214. --,DEPT = case   
  1215. --   when (dbo.tblComplaints.Dept='USGB'
  1216. --      and (DOS >=   '2009-01-01')
  1217. --      and FAC='ESCANABA') then
  1218. --      'USES'
  1219. --   else dbo.tblComplaints.Dept
  1220. --end
  1221. --,isnull(dbo.tblComplaints.FAC,
  1222. --  case(Dept) when 'GBEC' then 'WMOB'
  1223. --  when 'OMGB' then 'OMGB'
  1224. --  else 'EPOB'
  1225. --end
  1226. --) as FAC
  1227. --,MgrGroup=case(tblComplaints.notify) when 1 then
  1228. --  dbo.tblResponsible.MgrGroup
  1229. --  else
  1230. --  MgrGroupLowComplexCount
  1231. --  end  
  1232. --,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1233. --,LogDate
  1234. --,dbo.tblComplaints.LogDate as OrderDate
  1235. --,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1236. --  dbo.tblPtInfo.ComplaintStatus
  1237. --  else
  1238. --  'Closed'
  1239. --end
  1240. --,DOS
  1241. --,dbo.tblComplaints.notify
  1242. --,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1243. --,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1244. --,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1245. --,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1246. --,Classification = 'Procedural/Process'
  1247. --,case(tblComplaints.Other) when 1 then
  1248. --   'Other'
  1249. --  end as ComplaintType
  1250. --,Category = ''
  1251. --,SubCategory = ''
  1252. --FROM         dbo.tblComplaints
  1253. --Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1254. --Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1255. --Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1256. -- Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1257. --and  tblComplaints.other = 1
  1258. --and  tblComplaints.catclinical = 0
  1259. --and  tblComplaints.catProf = 0
  1260. --and  tblComplaints.catprocedure = 0
  1261. --and  tblComplaints.catmissDir = 0
  1262.  
  1263.  
  1264. Union
  1265.  
  1266. SELECT  
  1267. dbo.tblComplaints.ComplaintID
  1268. ,DepartmentFullName = case
  1269.     when (dbo.tblComplaints.Dept='USGB'
  1270.         and (DOS >=   '2009-01-01')
  1271.         and FAC='ESCANABA') then
  1272.         'BayCare Clinic - Urological Surgeons (USES)'
  1273.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1274. end
  1275. ,DEPT = case     
  1276.      when (dbo.tblComplaints.Dept='USGB'
  1277.         and (DOS >=   '2009-01-01')
  1278.         and FAC='ESCANABA') then
  1279.         'USES'
  1280.      else dbo.tblComplaints.Dept
  1281. end
  1282. ,isnull(dbo.tblComplaints.FAC,
  1283.     case(Dept) when 'GBEC' then 'WMOB'
  1284.     when 'OMGB' then 'OMGB'
  1285.     else 'EPOB'
  1286. end
  1287. ) as FAC
  1288. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1289.     dbo.tblResponsible.MgrGroup
  1290.     else
  1291.     MgrGroupLowComplexCount
  1292.   end  
  1293. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1294. ,LogDate
  1295. ,dbo.tblComplaints.LogDate as OrderDate
  1296. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1297.     dbo.tblPtInfo.ComplaintStatus
  1298.     else
  1299.     'Closed'
  1300. end
  1301. ,DOS
  1302. ,dbo.tblComplaints.notify
  1303. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1304. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1305. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1306. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1307. ,Classification = 'Procedural/Process'
  1308. ,case(tblComplaints.CatProcEnv) when 1 then
  1309.      'Environmental'
  1310.   end as ComplaintType
  1311. ,Category = ''
  1312. ,SubCategory = ''
  1313. FROM         dbo.tblComplaints
  1314. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1315. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1316. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1317.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1318. and  tblComplaints.CatProcEnv = 1
  1319.  
  1320. Union
  1321.  
  1322. SELECT  
  1323. dbo.tblComplaints.ComplaintID
  1324. ,DepartmentFullName = case
  1325.     when (dbo.tblComplaints.Dept='USGB'
  1326.         and (DOS >=   '2009-01-01')
  1327.         and FAC='ESCANABA') then
  1328.         'BayCare Clinic - Urological Surgeons (USES)'
  1329.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1330. end
  1331. ,DEPT = case     
  1332.      when (dbo.tblComplaints.Dept='USGB'
  1333.         and (DOS >=   '2009-01-01')
  1334.         and FAC='ESCANABA') then
  1335.         'USES'
  1336.      else dbo.tblComplaints.Dept
  1337. end
  1338. ,isnull(dbo.tblComplaints.FAC,
  1339.     case(Dept) when 'GBEC' then 'WMOB'
  1340.     when 'OMGB' then 'OMGB'
  1341.     else 'EPOB'
  1342. end
  1343. ) as FAC
  1344. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1345.     dbo.tblResponsible.MgrGroup
  1346.     else
  1347.     MgrGroupLowComplexCount
  1348.   end  
  1349. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1350. ,LogDate
  1351. ,dbo.tblComplaints.LogDate as OrderDate
  1352. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1353.     dbo.tblPtInfo.ComplaintStatus
  1354.     else
  1355.     'Closed'
  1356. end
  1357. ,DOS
  1358. ,dbo.tblComplaints.notify
  1359. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1360. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1361. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1362. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1363. ,Classification = 'Procedural/Process'
  1364. ,case(tblComplaints.CatProcWork) when 1 then
  1365.      'Current Work Process'
  1366.   end as ComplaintType
  1367. ,Category = ''
  1368. ,SubCategory = ''
  1369. FROM         dbo.tblComplaints
  1370. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1371. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1372. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1373.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1374. and  tblComplaints.CatProcWork = 1
  1375.  
  1376. Union
  1377.  
  1378. SELECT  
  1379. dbo.tblComplaints.ComplaintID
  1380. ,DepartmentFullName = case
  1381.     when (dbo.tblComplaints.Dept='USGB'
  1382.         and (DOS >=   '2009-01-01')
  1383.         and FAC='ESCANABA') then
  1384.         'BayCare Clinic - Urological Surgeons (USES)'
  1385.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1386. end
  1387. ,DEPT = case     
  1388.      when (dbo.tblComplaints.Dept='USGB'
  1389.         and (DOS >=   '2009-01-01')
  1390.         and FAC='ESCANABA') then
  1391.         'USES'
  1392.      else dbo.tblComplaints.Dept
  1393. end
  1394. ,isnull(dbo.tblComplaints.FAC,
  1395.     case(Dept) when 'GBEC' then 'WMOB'
  1396.     when 'OMGB' then 'OMGB'
  1397.     else 'EPOB'
  1398. end
  1399. ) as FAC
  1400. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1401.     dbo.tblResponsible.MgrGroup
  1402.     else
  1403.     MgrGroupLowComplexCount
  1404.   end  
  1405. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1406. ,LogDate
  1407. ,dbo.tblComplaints.LogDate as OrderDate
  1408. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1409.     dbo.tblPtInfo.ComplaintStatus
  1410.     else
  1411.     'Closed'
  1412. end
  1413. ,DOS
  1414. ,dbo.tblComplaints.notify
  1415. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1416. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1417. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1418. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1419. ,Classification = 'Procedural/Process'
  1420. ,case(tblComplaints.CatProcPerf) when 1 then
  1421.      'Performance'
  1422.   end as ComplaintType
  1423. ,Category = ''
  1424. ,SubCategory = ''
  1425. FROM         dbo.tblComplaints
  1426. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1427. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1428. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1429.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1430. and  tblComplaints.CatProcPerf = 1
  1431.  
  1432. Union
  1433.  
  1434. SELECT  
  1435. dbo.tblComplaints.ComplaintID
  1436. ,DepartmentFullName = case
  1437.     when (dbo.tblComplaints.Dept='USGB'
  1438.         and (DOS >=   '2009-01-01')
  1439.         and FAC='ESCANABA') then
  1440.         'BayCare Clinic - Urological Surgeons (USES)'
  1441.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1442. end
  1443. ,DEPT = case     
  1444.      when (dbo.tblComplaints.Dept='USGB'
  1445.         and (DOS >=   '2009-01-01')
  1446.         and FAC='ESCANABA') then
  1447.         'USES'
  1448.      else dbo.tblComplaints.Dept
  1449. end
  1450. ,isnull(dbo.tblComplaints.FAC,
  1451.     case(Dept) when 'GBEC' then 'WMOB'
  1452.     when 'OMGB' then 'OMGB'
  1453.     else 'EPOB'
  1454. end
  1455. ) as FAC
  1456. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1457.     dbo.tblResponsible.MgrGroup
  1458.     else
  1459.     MgrGroupLowComplexCount
  1460.   end  
  1461. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1462. ,LogDate
  1463. ,dbo.tblComplaints.LogDate as OrderDate
  1464. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1465.     dbo.tblPtInfo.ComplaintStatus
  1466.     else
  1467.     'Closed'
  1468. end
  1469. ,DOS
  1470. ,dbo.tblComplaints.notify
  1471. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1472. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1473. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1474. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1475. ,Classification = 'Procedural/Process'
  1476. ,ComplaintType = 'Other'
  1477. ,Category = ''
  1478. ,SubCategory = ''
  1479. FROM         dbo.tblComplaints
  1480. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1481. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1482. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1483.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1484. and  tblComplaints.CatProcOther > ''
  1485.  
  1486. Union
  1487.  
  1488. SELECT  
  1489. dbo.tblComplaints.ComplaintID
  1490. ,DepartmentFullName = case
  1491.     when (dbo.tblComplaints.Dept='USGB'
  1492.         and (DOS >=   '2009-01-01')
  1493.         and FAC='ESCANABA') then
  1494.         'BayCare Clinic - Urological Surgeons (USES)'
  1495.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1496. end
  1497. ,DEPT = case     
  1498.      when (dbo.tblComplaints.Dept='USGB'
  1499.         and (DOS >=   '2009-01-01')
  1500.         and FAC='ESCANABA') then
  1501.         'USES'
  1502.      else dbo.tblComplaints.Dept
  1503. end
  1504. ,isnull(dbo.tblComplaints.FAC,
  1505.     case(Dept) when 'GBEC' then 'WMOB'
  1506.     when 'OMGB' then 'OMGB'
  1507.     else 'EPOB'
  1508. end
  1509. ) as FAC
  1510. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1511.     dbo.tblResponsible.MgrGroup
  1512.     else
  1513.     MgrGroupLowComplexCount
  1514.   end  
  1515. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1516. ,LogDate
  1517. ,dbo.tblComplaints.LogDate as OrderDate
  1518. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1519.     dbo.tblPtInfo.ComplaintStatus
  1520.     else
  1521.     'Closed'
  1522. end
  1523. ,DOS
  1524. ,dbo.tblComplaints.notify
  1525. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1526. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1527. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1528. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1529. ,Classification = 'Misdirected Hospital'
  1530. ,ComplaintType = ''
  1531. ,Category=''
  1532. ,SubCategory = ''
  1533. FROM         dbo.tblComplaints
  1534. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1535. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1536. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1537.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1538. and  tblComplaints.CatMissdir = 1
  1539.  
  1540. Union
  1541.  
  1542. SELECT  
  1543. dbo.tblComplaints.ComplaintID
  1544. ,DepartmentFullName = case
  1545.     when (dbo.tblComplaints.Dept='USGB'
  1546.         and (DOS >=   '2009-01-01')
  1547.         and FAC='ESCANABA') then
  1548.         'BayCare Clinic - Urological Surgeons (USES)'
  1549.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1550. end
  1551. ,DEPT = case     
  1552.      when (dbo.tblComplaints.Dept='USGB'
  1553.         and (DOS >=   '2009-01-01')
  1554.         and FAC='ESCANABA') then
  1555.         'USES'
  1556.      else dbo.tblComplaints.Dept
  1557. end
  1558. ,isnull(dbo.tblComplaints.FAC,
  1559.     case(Dept) when 'GBEC' then 'WMOB'
  1560.     when 'OMGB' then 'OMGB'
  1561.     else 'EPOB'
  1562. end
  1563. ) as FAC
  1564. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1565.     dbo.tblResponsible.MgrGroup
  1566.     else
  1567.     MgrGroupLowComplexCount
  1568.   end  
  1569. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1570. ,LogDate
  1571. ,dbo.tblComplaints.LogDate as OrderDate
  1572. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1573.     dbo.tblPtInfo.ComplaintStatus
  1574.     else
  1575.     'Closed'
  1576. end
  1577. ,DOS
  1578. ,dbo.tblComplaints.notify
  1579. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1580. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1581. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1582. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1583. ,Classification = 'Clinical'
  1584. ,ComplaintType = case(tblComplaints.CatClinicalTreat) when 1 then
  1585.      'Treatment'
  1586.   end
  1587. ,Category = ''
  1588. ,SubCategory = ''
  1589. FROM         dbo.tblComplaints
  1590. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1591. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1592. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1593.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1594. and  tblComplaints.CatClinicalTreat = 1
  1595.  
  1596. Union
  1597. SELECT  
  1598. dbo.tblComplaints.ComplaintID
  1599. ,DepartmentFullName = case
  1600.     when (dbo.tblComplaints.Dept='USGB'
  1601.         and (DOS >=   '2009-01-01')
  1602.         and FAC='ESCANABA') then
  1603.         'BayCare Clinic - Urological Surgeons (USES)'
  1604.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1605. end
  1606. ,DEPT = case     
  1607.      when (dbo.tblComplaints.Dept='USGB'
  1608.         and (DOS >=   '2009-01-01')
  1609.         and FAC='ESCANABA') then
  1610.         'USES'
  1611.      else dbo.tblComplaints.Dept
  1612. end
  1613. ,isnull(dbo.tblComplaints.FAC,
  1614.     case(Dept) when 'GBEC' then 'WMOB'
  1615.     when 'OMGB' then 'OMGB'
  1616.     else 'EPOB'
  1617. end
  1618. ) as FAC
  1619. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1620.     dbo.tblResponsible.MgrGroup
  1621.     else
  1622.     MgrGroupLowComplexCount
  1623.   end  
  1624. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1625. ,LogDate
  1626. ,dbo.tblComplaints.LogDate as OrderDate
  1627. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1628.     dbo.tblPtInfo.ComplaintStatus
  1629.     else
  1630.     'Closed'
  1631. end
  1632. ,DOS
  1633. ,dbo.tblComplaints.notify
  1634. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1635. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1636. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1637. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1638. ,Classification = 'Clinical'
  1639. ,ComplaintType = case(tblComplaints.CatClinicalPain) when 1 then
  1640.      'Pain'
  1641.   end
  1642. ,Category = ''
  1643. ,SubCategory = ''
  1644. FROM         dbo.tblComplaints
  1645. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1646. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1647. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1648.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1649. and  tblComplaints.CatClinicalPain = 1
  1650.  
  1651. Union
  1652.  
  1653. SELECT  
  1654. dbo.tblComplaints.ComplaintID
  1655. ,DepartmentFullName = case
  1656.     when (dbo.tblComplaints.Dept='USGB'
  1657.         and (DOS >=   '2009-01-01')
  1658.         and FAC='ESCANABA') then
  1659.         'BayCare Clinic - Urological Surgeons (USES)'
  1660.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1661. end
  1662. ,DEPT = case     
  1663.      when (dbo.tblComplaints.Dept='USGB'
  1664.         and (DOS >=   '2009-01-01')
  1665.         and FAC='ESCANABA') then
  1666.         'USES'
  1667.      else dbo.tblComplaints.Dept
  1668. end
  1669. ,isnull(dbo.tblComplaints.FAC,
  1670.     case(Dept) when 'GBEC' then 'WMOB'
  1671.     when 'OMGB' then 'OMGB'
  1672.     else 'EPOB'
  1673. end
  1674. ) as FAC
  1675. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1676.     dbo.tblResponsible.MgrGroup
  1677.     else
  1678.     MgrGroupLowComplexCount
  1679.   end  
  1680. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1681. ,LogDate
  1682. ,dbo.tblComplaints.LogDate as OrderDate
  1683. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1684.     dbo.tblPtInfo.ComplaintStatus
  1685.     else
  1686.     'Closed'
  1687. end
  1688. ,DOS
  1689. ,dbo.tblComplaints.notify
  1690. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1691. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1692. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1693. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1694. ,Classification = 'Clinical'
  1695. ,ComplaintType =case(tblComplaints.CatClinicalDiagnosis) when 1 then
  1696.      'Diagnosis'
  1697.   end
  1698. ,Category = ''
  1699. ,SubCategory = ''
  1700. FROM         dbo.tblComplaints
  1701. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1702. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1703. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1704.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1705. and  tblComplaints.CatClinicalDiagnosis = 1
  1706.  
  1707. Union
  1708.  
  1709. SELECT  
  1710. dbo.tblComplaints.ComplaintID
  1711. ,DepartmentFullName = case
  1712.     when (dbo.tblComplaints.Dept='USGB'
  1713.         and (DOS >=   '2009-01-01')
  1714.         and FAC='ESCANABA') then
  1715.         'BayCare Clinic - Urological Surgeons (USES)'
  1716.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1717. end
  1718. ,DEPT = case     
  1719.      when (dbo.tblComplaints.Dept='USGB'
  1720.         and (DOS >=   '2009-01-01')
  1721.         and FAC='ESCANABA') then
  1722.         'USES'
  1723.      else dbo.tblComplaints.Dept
  1724. end
  1725. ,isnull(dbo.tblComplaints.FAC,
  1726.     case(Dept) when 'GBEC' then 'WMOB'
  1727.     when 'OMGB' then 'OMGB'
  1728.     else 'EPOB'
  1729. end
  1730. ) as FAC
  1731. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1732.     dbo.tblResponsible.MgrGroup
  1733.     else
  1734.     MgrGroupLowComplexCount
  1735.   end  
  1736. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1737. ,LogDate
  1738. ,dbo.tblComplaints.LogDate as OrderDate
  1739. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1740.     dbo.tblPtInfo.ComplaintStatus
  1741.     else
  1742.     'Closed'
  1743. end
  1744. ,DOS
  1745. ,dbo.tblComplaints.notify
  1746. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1747. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1748. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1749. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1750. ,Classification = 'Clinical'
  1751. ,ComplaintType = 'Other'
  1752. ,Category = ''
  1753. ,SubCategory = ''
  1754. FROM         dbo.tblComplaints
  1755. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1756. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1757. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1758.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1759. and tblComplaints.CatClinicalOther > ''
  1760.  
  1761. Union
  1762.  
  1763. SELECT  
  1764. dbo.tblComplaints.ComplaintID
  1765. ,DepartmentFullName = case
  1766.     when (dbo.tblComplaints.Dept='USGB'
  1767.         and (DOS >=   '2009-01-01')
  1768.         and FAC='ESCANABA') then
  1769.         'BayCare Clinic - Urological Surgeons (USES)'
  1770.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1771. end
  1772. ,DEPT = case     
  1773.      when (dbo.tblComplaints.Dept='USGB'
  1774.         and (DOS >=   '2009-01-01')
  1775.         and FAC='ESCANABA') then
  1776.         'USES'
  1777.      else dbo.tblComplaints.Dept
  1778. end
  1779. ,isnull(dbo.tblComplaints.FAC,
  1780.     case(Dept) when 'GBEC' then 'WMOB'
  1781.     when 'OMGB' then 'OMGB'
  1782.     else 'EPOB'
  1783. end
  1784. ) as FAC
  1785. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1786.     dbo.tblResponsible.MgrGroup
  1787.     else
  1788.     MgrGroupLowComplexCount
  1789.   end  
  1790. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1791. ,LogDate
  1792. ,dbo.tblComplaints.LogDate as OrderDate
  1793. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1794.     dbo.tblPtInfo.ComplaintStatus
  1795.     else
  1796.     'Closed'
  1797. end
  1798. ,DOS
  1799. ,dbo.tblComplaints.notify
  1800. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1801. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1802. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1803. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1804. ,Classification = 'Communication Style/Professional Conduct'
  1805. ,ComplaintType= 'Time Spent'
  1806. ,Category= ''
  1807. ,SubCategory = ''
  1808.  
  1809. FROM         dbo.tblComplaints
  1810. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1811. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1812. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1813.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1814. and  tblComplaints.CatProfTime = 1
  1815.  
  1816. Union
  1817.  
  1818. SELECT  
  1819. dbo.tblComplaints.ComplaintID
  1820. ,DepartmentFullName = case
  1821.     when (dbo.tblComplaints.Dept='USGB'
  1822.         and (DOS >=   '2009-01-01')
  1823.         and FAC='ESCANABA') then
  1824.         'BayCare Clinic - Urological Surgeons (USES)'
  1825.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1826. end
  1827. ,DEPT = case     
  1828.      when (dbo.tblComplaints.Dept='USGB'
  1829.         and (DOS >=   '2009-01-01')
  1830.         and FAC='ESCANABA') then
  1831.         'USES'
  1832.      else dbo.tblComplaints.Dept
  1833. end
  1834. ,isnull(dbo.tblComplaints.FAC,
  1835.     case(Dept) when 'GBEC' then 'WMOB'
  1836.     when 'OMGB' then 'OMGB'
  1837.     else 'EPOB'
  1838. end
  1839. ) as FAC
  1840. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1841.     dbo.tblResponsible.MgrGroup
  1842.     else
  1843.     MgrGroupLowComplexCount
  1844.   end  
  1845. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1846. ,LogDate
  1847. ,dbo.tblComplaints.LogDate as OrderDate
  1848. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1849.     dbo.tblPtInfo.ComplaintStatus
  1850.     else
  1851.     'Closed'
  1852. end
  1853. ,DOS
  1854. ,dbo.tblComplaints.notify
  1855. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1856. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1857. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1858. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1859. ,Classification = 'Communication Style/Professional Conduct'
  1860. ,ComplaintType= 'Sensitivity/Empathy/Rude'
  1861. ,Category= ''
  1862. ,SubCategory = ''
  1863.  
  1864. FROM         dbo.tblComplaints
  1865. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1866. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1867. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1868.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1869. and  (tblComplaints.CatProfSensitive = 1 or  tblComplaints.CatProfRude = 1)
  1870.  
  1871. Union
  1872.  
  1873. SELECT  
  1874. dbo.tblComplaints.ComplaintID
  1875. ,DepartmentFullName = case
  1876.     when (dbo.tblComplaints.Dept='USGB'
  1877.         and (DOS >=   '2009-01-01')
  1878.         and FAC='ESCANABA') then
  1879.         'BayCare Clinic - Urological Surgeons (USES)'
  1880.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1881. end
  1882. ,DEPT = case     
  1883.      when (dbo.tblComplaints.Dept='USGB'
  1884.         and (DOS >=   '2009-01-01')
  1885.         and FAC='ESCANABA') then
  1886.         'USES'
  1887.      else dbo.tblComplaints.Dept
  1888. end
  1889. ,isnull(dbo.tblComplaints.FAC,
  1890.     case(Dept) when 'GBEC' then 'WMOB'
  1891.     when 'OMGB' then 'OMGB'
  1892.     else 'EPOB'
  1893. end
  1894. ) as FAC
  1895. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1896.     dbo.tblResponsible.MgrGroup
  1897.     else
  1898.     MgrGroupLowComplexCount
  1899.   end  
  1900. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1901. ,LogDate
  1902. ,dbo.tblComplaints.LogDate as OrderDate
  1903. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1904.     dbo.tblPtInfo.ComplaintStatus
  1905.     else
  1906.     'Closed'
  1907. end
  1908. ,DOS
  1909. ,dbo.tblComplaints.notify
  1910. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1911. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1912. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1913. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1914. ,Classification = 'Communication Style/Professional Conduct'
  1915. ,ComplaintType= 'Too Difficult to Understand'
  1916. ,Category= ''
  1917. ,SubCategory = ''
  1918.  
  1919. FROM         dbo.tblComplaints
  1920. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1921. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1922. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1923.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1924. and  tblComplaints.CatProfComm = 1
  1925.  
  1926. Union
  1927.  
  1928. SELECT  
  1929. dbo.tblComplaints.ComplaintID
  1930. ,DepartmentFullName = case
  1931.     when (dbo.tblComplaints.Dept='USGB'
  1932.         and (DOS >=   '2009-01-01')
  1933.         and FAC='ESCANABA') then
  1934.         'BayCare Clinic - Urological Surgeons (USES)'
  1935.     else  (BCM.Department + ' (' + rtrim(Dept) + ')')
  1936. end
  1937. ,DEPT = case     
  1938.      when (dbo.tblComplaints.Dept='USGB'
  1939.         and (DOS >=   '2009-01-01')
  1940.         and FAC='ESCANABA') then
  1941.         'USES'
  1942.      else dbo.tblComplaints.Dept
  1943. end
  1944. ,isnull(dbo.tblComplaints.FAC,
  1945.     case(Dept) when 'GBEC' then 'WMOB'
  1946.     when 'OMGB' then 'OMGB'
  1947.     else 'EPOB'
  1948. end
  1949. ) as FAC
  1950. ,MgrGroup=case(tblComplaints.notify) when 1 then
  1951.     dbo.tblResponsible.MgrGroup
  1952.     else
  1953.     MgrGroupLowComplexCount
  1954.   end  
  1955. ,isnull(dbo.tblResponsible.PrimaryContact,0) as Prime
  1956. ,LogDate
  1957. ,dbo.tblComplaints.LogDate as OrderDate
  1958. ,ComplaintStatus = case(tblComplaints.notify) when 1 then
  1959.     dbo.tblPtInfo.ComplaintStatus
  1960.     else
  1961.     'Closed'
  1962. end
  1963. ,DOS
  1964. ,dbo.tblComplaints.notify
  1965. ,isnull(dbo.tblPtInfo.PtSatisfied,0) as PtSatisfied
  1966. ,isnull(dbo.tblPtInfo.PtAccount,'') as PtAccount
  1967. ,isnull(dbo.tblPtInfo.PtLastName,'') as PtLastName
  1968. ,isnull(dbo.tblPtInfo.PtFirstName,'') as PtFirstName
  1969. ,Classification = 'Communication Style/Professional Conduct'
  1970. ,ComplaintType= 'Other'
  1971. ,Category= ''
  1972. ,SubCategory = ''
  1973.  
  1974. FROM         dbo.tblComplaints
  1975. Left Outer Join dbo.tblPtInfo on dbo.tblComplaints.ComplaintID = dbo.tblPtinfo.fkComplaintID
  1976. Left Outer Join dbo.tblResponsible on (dbo.tblComplaints.ComplaintID = dbo.tblResponsible.fkComplaintID and dbo.tblResponsible.PrimaryContact=1)
  1977. Left Outer Join BayCareMaster..tblBCDepts BCM on dbo.tblComplaints.Dept = BCM.DepartmentNameShort
  1978.  Where ((validated = 1 and notify=0) or (notify=1 and categoryValidated = 1))
  1979. and  not(tblComplaints.CatProfOther) is null
  1980.  
  1981. --select* from vwComplaintCognosDrillDown where dept = 'BCOS'  
  1982.  
  1983.  
  1984. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement