I'm trying to display in a Tableau Dashboard readmission rates per month in general and also by discharging service line. I have a table of MRN (ID, unique per patient), FIN (unique per encounter/stay but some patients will have multiple encounters), admission date, admitting service line (NICU, CCU, etc.), discharge date, discharging service line. The admitting and discharge service lines are most likely not going to be the same.
A readmission is defined as an admission after being discharged within 30 days.
Readmission rate is = # readmissions / # discharges.
| MRN | FIN | Admission Date | Admitting Service | Discharge Date | Discharging Service |
| ------------ | ------------ | ------------ | ------------ | ------------ | ------------ |
| 707893 | 8072751999 | 2018-07-19 | NICU | 2018-07-30 | PCRS |
| 707893 | 8082751951 | 2018-08-15 | CCU | 2018-08-23 | CCU |
| 707812 | 8092884664 | 2018-12-02 | CCU | 2019-01-15 | PCRS |
I tried some code from another question just to get the normal readmission rate (not including service lines) but could not get it work. I want a table like the below as my end result to start, with eventually adding the service lines in there (discharging service line)
Month/Year | Total Number of Readmissions | Total Number of Discharges | Readmission Rate |
---|---|---|---|
Jan 2019 | 3 | 15 | .20 |
Feb 2019 | 2 | 20 | .10 |
March 2019 | 5 | 18 | .27 |
Code I tried below (reg dt tm = admission date) with the following error:
(Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Warning: Null value is eliminated by an aggregate or other SET operation.)
WITH mnths AS (
SELECT cast(1 AS int) m
UNION ALL SELECT m+1 FROM mnths WHERE m<48
), admdis AS (
SELECT *, 12*(YEAR(reg_dt_tm)-2018)+MONTH(reg_dt_tm)a, 12*(YEAR(disch_dt_tm)-2018)+MONTH(disch_dt_tm) d,
(SELECT 1 FROM inpatient_pop WHERE med_rec_no=t.med_rec_no AND disch_dt_tm>DATEADD(day, -30, t.reg_dt_tm) AND FIN<t.FIN) readm
FROM inpatient_pop t
)
SELECT (m-1)/12+2018 yr, 1+(m-1)%12 mn, COUNT(med_rec_no) totl ,COUNT(readm) readm,
CASE WHEN COUNT(med_rec_no)>0 THEN (0.+COUNT(readm))/ COUNT(med_rec_no) ELSE 0 END rate
FROM mnths
LEFT JOIN admdis ON a=m
GROUP BY m
1条答案
按热度按时间6jjcrrmo1#
It's really helpful when you ask questions like this to include easily reproducible DDL/DML. I understand medical data is pretty sensitive, but there's nothing stopping you making some up. It might not be super realistic, but it gives us something to work with.
Exactly how you do it is going to come down to what a readmission is qualified as. If you have a somewhat simplified rule of the same MRN is next admitted in a 10 day window, for example, you could try something like this:
Here we're using a
LAG
windowed function to literally look back at the last discharge date, and returning a 1 if it fits the criteria. You should be able to make this fit what ever your actual rules are by adjusting theCASE
expression.