select distinct
medicare_tbl.Patient_Number,
Patient_First_Name,
Patient_Last_Name,
Patient_DOB,
Usual_Dr_Name,
MAX(Service_Date_From) AS Last_Appointment
FROM
(
SELECT distinct PM.vwGenPatInfo.Patient_Number,Patient_First_Name,Patient_Last_Name,Patient_DOB,Usual_Dr_Name,Service_Date_From,Location_Abbr
FROM PM.vwGenPatInfo LEFT JOIN
PM.vwGenSvcInfo ON PM.vwGenPatInfo.Patient_Number = PM.vwGenSvcInfo.Patient_Number
WHERE (PM.vwGenPatInfo.Prim_Policy_Carrier_Name IN ('MEDICARE PART B', 'MEDICARE UGS'))
AND PM.vwGenSvcInfo.Service_Date_From >= CONVERT(DATE, DATEADD(MONTH, -24, GETDATE()))
) as medicare_tbl
INNER JOIN
(
SELECT distinct PM.vwGenPatInfo.Patient_Number
FROM PM.vwGenPatInfo LEFT JOIN
PM.vwGenSvcInfo ON PM.vwGenPatInfo.Patient_Number = PM.vwGenSvcInfo.Patient_Number
WHERE
(
(
PM.vwGenPatInfo.PrimM_Policy_Carrier_Reporting_Class_Abbr in ('Table95a', 'Table95b', 'Table94')
AND PM.vwGenPatInfo.SecM_Policy_Carrier_Reporting_Class_Abbr in ('Table92a', 'Table92b', 'Table91')
)
OR
(
PM.vwGenPatInfo.PrimM_Policy_Carrier_Reporting_Class_Abbr in ('Table92a', 'Table92b', 'Table91')
AND PM.vwGenPatInfo.SecM_Policy_Carrier_Reporting_Class_Abbr in ('Table95a', 'Table95b', 'Table94')
)
)
AND PM.vwGenSvcInfo.Service_Date_From >= CONVERT(DATE, DATEADD(MONTH, -24, GETDATE()))
) as dually_eligible_tbl on medicare_tbl.Patient_Number = dually_eligible_tbl.Patient_Number
GROUP BY
medicare_tbl.Patient_Number,
Patient_First_Name,
Patient_Last_Name,
Patient_DOB,
Usual_Dr_Name
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.