Good Afternoon,
The intent of this report is to calculate the following:
- Average Length of stay (In hours) for all Observation patients.
- Median Length of stay (In hours) for all Observation patients.
- Percent of Observation patient whose stay were greater than 48 hours.
I've written the below report:
USE livedb
DROP TABLE #MaxAdm, #MaxObs
--ADMISSIONS
SELECT
Max(EventSeqID) AS MaxSeqAdm,
EventSeqID, VisitID, Code,
CONVERT(VARCHAR(10),(EffectiveDateTime),101) as Date,
CONVERT(VARCHAR(10),(EffectiveDateTime),108) as Time
INTO #MaxAdm
FROM AdmVisitEvents
WHERE EventDateTime BETWEEN '01/01/17 00:00:00' AND '01/31/17 23:59:59'
AND Code = 'ENADMOB'
GROUP BY EventSeqID, VisitID, Code, EffectiveDateTime
--DISCHARGES
SELECT Max(EventSeqID) AS MaxSeqAdm,
EventSeqID, VisitID, Code,
CONVERT(VARCHAR(10),(EffectiveDateTime),101) as Date,
CONVERT(VARCHAR(10),(EffectiveDateTime),108) as Time
INTO #MaxObs
FROM AdmVisitEvents
WHERE EventDateTime BETWEEN '01/01/17 00:00:00' AND '01/31/17 23:59:59'
AND Code = 'ENDISOB'
GROUP BY EventSeqID, VisitID, Code, EffectiveDateTime
--JOIN
SELECT *
FROM #MaxAdm A LEFT JOIN #MaxObs O ON A.VisitID = O.VisitID
This takes the most recent EventDateTime of the Admit, and Discharge, of observation patients, with the exception when the time is different for the same account. Basically someone edits the account to a slightly different time, and because I need the time for calculation mentioned above, I get duplicates, like below:
EventSeqID VisitID Code Date Time
10 AcctNo ENADMOB 1/3/2017 20:40:00
8 AcctNo ENADMOB 1/3/2017 20:48:00
Would someone explain, maybe even tweak my code, to accomplish this? At the end of the day I need the most recent activity for the Adm and Dis.
Thank you for your help,
Frank