Healthcare Analytics Path · Mission 21 of 25Expert

Readmission cohort deep dive

Use CTEs and self-joins for CMS-style readmission methodology

Back to Healthcare Analytics

The Brief

Dr. Amara OkaforChief Quality Officerquality-analytics

Build me a readmission analysis using CTEs. Step 1: identify all inpatient discharges (exclude current admits). Step 2: flag any where the same patient had another inpatient admission within 30 days of discharge. Step 3: group by insurance type (normalized with LOWER) and show total discharges, readmissions, and rate as a percentage. This is the methodology CMS uses for HRRP.

You'll practice

CTESelf-joinDate window

Tables available

fact_encountersdim_patients

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

Build this in stages: CTE 1 holds inpatient discharges. A self-join on that CTE finds cases where the same patient returned within 30 days

Hint 2

The second admission must be AFTER the first discharge AND within 30 days. And make sure you're not matching a discharge to itself

Hint 3

`ON a.patient_id = b.patient_id AND b.admit_date > ___ AND b.admit_date <= ___ + INTERVAL '30 days' AND a.encounter_id ___ b.encounter_id` — then `GROUP BY LOWER(___)`