Provider Analytics Path · Mission 25 of 25Expert

The CMS Quality Dashboard

Build a multi-CTE pipeline with window functions combining all prior concepts

Back to Provider Analytics

The Brief

Michael TranCEOslack-dm

This is it. The board meets Wednesday. I need one query that produces a 6-month trend of our four key quality metrics: 30-day readmission rate, average ED wait time (filtered for bad data), average patient satisfaction, and complication rate. Show year, month, and all four metrics. Include a 3-month moving average for the readmission rate. The CMS reviewer will see this — every number has to be right.

You'll practice

Multi-CTE pipelineWindow framesCapstone

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
fact_quality_metricsfact7 columns
ColumnTypeKey
metric_idINTPK
encounter_idINTFK → fact_encounters
patient_idINTFK → dim_patients
metric_typeTEXT
metric_valueREAL
measurement_dateTEXT
reported_byTEXT
dim_departmentsdim6 columns
ColumnTypeKey
department_idINTPK
department_nameTEXT
department_typeTEXT
floorINT
bed_countINT
manager_nameTEXT
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

One CTE per metric, each keyed on (year, month). Every data quality lesson from the path applies here — audit your filters for bad waits, bad satisfaction, ED name variants, insurance casing, TRIM

Hint 2

The outer query joins the metric CTEs on (year, month), adds a windowed moving average to the readmission rate, and returns only the last 6 months

Hint 3

`AVG(readmission_rate) OVER (ORDER BY year, month ROWS BETWEEN ___ PRECEDING AND CURRENT ROW) AS readmission_moving_avg` — then `ORDER BY year DESC, month DESC LIMIT ___`