Hello.. I am attempting to find the percentage of patients who in the past 12 months have seen a doctor (within the practice) other than their assigned responsible provider. Does anyone have any good ideas how to query this? Thanks much.
These two queries may get you what you're looking for. Dividing the results of the two queries should get you the %. The queries only count each patient once even if they had multiple visits. To count each visit instead, remove the DISTINCT code from each query. Please let me know if you have any questions.
--- TOTAL UNIQUE PATIENTS WITH APPOINTMENTS
SELECT count(DISTINCT apt.OwnerId) as TotalAppointments
FROM dbo.Appointments AS apt
WHERE apt.ApptKind = 1 AND apt.apptstart BETWEEN '6/14/2011' AND '6/14/2012'
--- TOTAL UNIQUE PATIENTS WITH APPOINTMENTS OTHER THAN RESPONSIBLE DOCTOR
SELECT count(DISTINCT ownerID) as TotalNonResponsible
FROM dbo.Appointments AS apmt INNER JOIN dbo.PatientProfile AS pp ON apmt.OwnerId = pp.PatientProfileId
WHERE apptstart BETWEEN '6/14/2011' AND '6/14/2012' AND pp.DoctorId <> apmt.doctorid
Allen
I'd do this slightly differently.
select pp.PatientProfileId , max(case when pp.DoctorId <> pv.DoctorId then 1 else 0 end) as SeenOther from PatientProfile pp join PatientVisit pv on pp.PatientProfileId = pv.PatientProfileId where pv.Visit >= dateadd(yyyy, -1, getdate()) and pv.Visit < getdate() group by pp.PatientProfileId
Then in Crystal, I'd divide the sum of SeenOther by the count of PatientProfileId to get the percentage. The query I actually used here would be a bit more complex -- I'd probably join in the PatientVisitResource table to get the ResourceId that saw the patient, rather than the Visit.DoctorId, and I'd also include the PatientVisitProcs table to check if there were seen for an encounter code.
I like Serek's solution better. Hard to argue with the logic of a vulcan.
Thanks to both of you.