Provider Analytics Path · Mission 21 of 25Expert

Readmission cohort deep dive

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

Back to Provider 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 & columns available

fact_encountersfact10 columns
ColumnTypeKey
encounter_idINTPK
patient_idINTFK → dim_patients
provider_idINTFK → dim_providers
department_idINTFK → dim_departments
admit_dateTEXT
discharge_dateTEXT
diagnosis_codeTEXT
diagnosis_descriptionTEXT
encounter_typeTEXT
discharge_dispositionTEXT
dim_patientsdim9 columns
ColumnTypeKey
patient_idINTPK
first_nameTEXT
last_nameTEXT
date_of_birthTEXT
genderTEXT
insurance_typeTEXT
zip_codeTEXT
primary_languageTEXT
is_deceasedINT

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(___)`