SELECT Cath.SS_Event_Cath_ID AS SS_Event_ID, --dbo.idxCathSites.FriendlySite AS Hospital, Cath.SS_Patient_ID, CaseType = case when interventionperformed = 1 then 'Interventional' end, Demographics.Patient_ID AS MRN, Demographics.Last_Name, Demographics.First_Name, Demographics.Date_of_Birth AS DOB, Cath.Date_of_Cath AS EventDate, MONTH(Cath.Date_of_Cath) AS EventMonth, YEAR(Cath.Date_of_Cath) AS EventYear, CASE WHEN dbo.ufn_Age(Demographics.Date_of_Birth, Cath.Date_of_Cath) < 18 THEN 'Pediatric' ELSE 'Adult' END AS PatientType, Cath.Monitor AS Tech, Cath.Admission_Date AS DateOfAdmission, Cath.Discharge_Date AS DateOfDischarge, ProcedureStatus FROM Apollo_Prod_Repl.dbo.Demographics AS Demographics INNER JOIN Apollo_Prod_Repl.dbo.Event_Cath AS Cath ON Demographics.SS_Patient_ID = Cath.SS_Patient_ID INNER JOIN Apollo_Prod_Repl.dbo.Cath_Extension AS Cath_Extension ON Cath.SS_Event_Cath_ID = Cath_Extension.SS_Event_Cath_ID WHERE Cath.Date_of_Cath between '20131001' and '20131031' and interventionperformed = 1 and (ISNULL(Cath.ProcedureStatus, 100) > 20) ----------------- ---------------- EP/ICD/Pace Statistical Query TSQL Select Distinct Demographics.Patient_ID AS MR, Patient_LName = Demographics.Last_Name, PatientFName = Demographics.First_Name, Event_EP.SS_Event_EP_ID, Event_EP.SS_Patient_ID, Event_EP.EventDate, PtIDElectrophysiologist, MONTH(Event_EP.EventDate) AS EventMonth, --convert(varchar(3),datename(month, Event_EP.EventDate),100)AS EventMonth, YEAR(Event_EP.EventDate) AS EventYear, CASE WHEN MMC_Hospital LIKE '%moses%' THEN 'Moses Lab' WHEN MMC_Hospital LIKE '%weiler%' THEN 'Weiler Lab' ELSE MMC_Hospital END AS MMC_Hospital, ProcedureType = (select max(EP_Procedures.ProcedureType) from EP_Procedures where Event_EP.SS_Event_EP_ID = EP_Procedures.SS_Event_EP_ID), ProcName = (select max(EP_Procedures.ProcName) from EP_Procedures where Event_EP.SS_Event_EP_ID = EP_Procedures.SS_Event_EP_ID), TotalProcedures = count(Event_EP.SS_Event_EP_ID) FROM (Demographics INNER JOIN Event_EP ON Demographics.SS_Patient_ID = Event_EP.SS_Patient_ID) INNER JOIN EP_Extension on Event_EP.SS_Event_EP_ID = EP_Extension.SS_Event_EP_ID Where eventdate between @startdate and @enddate and Event_EP.ProcedureType in ('Cardiac Pacemaker', 'ICD') and (ISNULL(Event_EP.ProcedureStatus, 100) > 20) group by Demographics.Patient_ID, Demographics.Last_Name, Demographics.First_Name, Event_EP.SS_Event_EP_ID, Event_EP.SS_Patient_ID, Event_EP.EventDate, PtIDElectrophysiologist, MMC_Hospital ---------------------------------------- union all ----------------------------------------- SELECT Distinct Demographics.Patient_ID AS MR, Patient_LName = Demographics.Last_Name, PatientFName = Demographics.First_Name, Event_ICD.SS_Event_ICD_ID, Event_ICD.SS_Patient_ID, Event_ICD.EventDate,Event_ICD.ImplantingPhysician, MONTH(Event_ICD.EventDate) AS EventMonth, --convert(varchar(3),datename(month, Event_ICD.EventDate),100)AS EventMonth, YEAR(Event_ICD.EventDate) AS EventYear, CASE WHEN Event_ICD.ImplantingHospital LIKE '%moses%' THEN 'Moses Lab' WHEN Event_ICD.ImplantingHospital LIKE '%weiler%' THEN 'Weiler Lab' ELSE Event_ICD.ImplantingHospital END AS MMC_Hospital, ProcedureType = 'ICD', ProcName = ICD_Implant.ICDType, TotalProcedures = count(Event_ICD.SS_Event_ICD_ID) FROM Apollo_Prod_Repl.dbo.Event_ICD AS Event_ICD INNER JOIN Apollo_Prod_Repl.dbo.Demographics AS Demographics ON Event_ICD.SS_Patient_ID = Demographics.SS_Patient_ID LEFT OUTER JOIN Apollo_Prod_Repl.dbo.ICD_Implant AS ICD_Implant ON Event_ICD.SS_Event_ICD_ID = ICD_Implant.SS_Event_ICD_ID WHERE ISNULL(Event_ICD.ProcedureStatus, 100) > 20 AND (Event_ICD.EventDate IS NOT NULL) and ICDProcedureDate between @startdate and @enddate group by Demographics.Patient_ID, Demographics.Last_Name, Demographics.First_Name, Event_ICD.SS_Event_ICD_ID, Event_ICD.SS_Patient_ID, Event_ICD.EventDate,Event_ICD.ImplantingPhysician, Event_ICD.ImplantingHospital, ICDTYPE --------------------------------------- union all --------------------------------------- SELECT Distinct Demographics.Patient_ID AS MR, Patient_LName = Demographics.Last_Name, PatientFName = Demographics.First_Name, Event_Pacer.SS_Event_Pacer_ID, Event_Pacer.SS_Patient_ID, Event_Pacer.EventDate,Event_Pacer.ImplantingPhysician, MONTH(Event_Pacer.EventDate) AS EventMonth, --convert(varchar(3),datename(month, Event_Pacer.EventDate),100)AS EventMonth, YEAR(Event_Pacer.EventDate) AS EventYear, CASE WHEN Event_Pacer.ImplantingHospital LIKE '%moses%' THEN 'Moses Lab' WHEN Event_Pacer.ImplantingHospital LIKE '%Weiler%' THEN 'Weiler Lab' ELSE Event_Pacer.ImplantingHospital END AS MMC_Hospital, ProcedureType = 'Pacemaker', ProcName = Pacer_Implant.PacemakerType, TotalProcedures = count(Event_Pacer.SS_Event_Pacer_ID) FROM Apollo_Prod_Repl.dbo.Event_Pacer AS Event_Pacer INNER JOIN Apollo_Prod_Repl.dbo.Demographics AS Demographics ON Event_Pacer.SS_Patient_ID = Demographics.SS_Patient_ID INNER JOIN Apollo_Prod_Repl.dbo.Pacer_Implant AS Pacer_Implant ON Event_Pacer.SS_Event_Pacer_ID = Pacer_Implant.SS_Event_Pacer_ID WHERE ISNULL(Event_Pacer.ProcedureStatus, 100) > 20 AND (Event_Pacer.EventDate IS NOT NULL) AND (Event_Pacer.PM_FU Is Null Or Event_Pacer.PM_FU = 0) and Event_Pacer.EventDate between @startdate and @enddate group by Demographics.Patient_ID, Demographics.Last_Name, Demographics.First_Name, Event_Pacer.SS_Event_Pacer_ID, Event_Pacer.SS_Patient_ID, Event_Pacer.EventDate,Event_Pacer.ImplantingPhysician, Event_Pacer.ImplantingHospital , Pacer_Implant.PacemakerType order by 6 --------------- --------------- Cath Procedure Names --------------- --------------- Select * from Event_Cath ec inner join Cath_procedures cp On ec.SS_Event_Cath_ID = cp.SS_Event_Cath_ID where Account_Number = '264761834'