Hospital Readmission and Utilization Risk Stratification Pipeline
Develop an operational SQL pipeline to index inpatient admissions, track 30-day readmissions, and assign utilization risk scores.
Use this template when designing health system SQL queries for inpatient operations, capacity management, or value-based care reporting. It builds a standardized pipeline to index inpatient stays and calculate readmission intervals.
Role: Senior Healthcare Operations Analytics Specialist specializing in hospital capacity modeling and claims data engines.
Context
- Health network: {{hospital_network}}
- Facility care setting: {{target_facility_type}}
- Analytical warehouse platform: {{sql_warehouse_platform}}
- Re-encounter evaluation threshold: {{readmission_window_days}}
- Inpatient specialty domain: {{drg_specialty_focus}}
- Risk classification bands: {{risk_stratification_tiers}}
Task
Construct an end-to-end hospital encounter stratification SQL framework for {{hospital_network}} to track readmissions within {{readmission_window_days}} days across {{drg_specialty_focus}} services in {{sql_warehouse_platform}}.
Method
- Define inpatient encounter boundaries in {{target_facility_type}} by filtering acute stay encounter types with valid discharge dates.
- Implement lead/lag window functions partitioned by patient master identifier to calculate inter-encounter time deltas.
- Identify index admissions by excluding planned elective readmissions, transfers, and in-hospital mortality events.
- Map diagnostic case-mix codes and comorbid condition counts during the index encounter using diagnosis tables.
- Compute an operational readmission flag matching the {{readmission_window_days}} threshold against subsequent admissions.
- Create conditional risk scoring logic to assign encounters into {{risk_stratification_tiers}} based on comorbidity and length of stay.
- Format materialized analytical tables containing patient keys, encounter attributes, risk bands, and follow-up metrics.
Constraints
- MUST use deterministic window functions rather than self-joins to calculate encounter gaps for performance.
- MUST NOT flag planned maintenance procedures (e.g., chemotherapy, dialysis) as unmanaged readmissions.
- SQL code MUST be fully compatible with {{sql_warehouse_platform}} native syntax.
- Output dataset MUST preserve grain at the unique index-encounter level.
Output format
Deliver the operational framework organized into four sections:
- Pipeline Architecture (encounter definition rules and join schema description)
- Transformation Logic (step-by-step description of window functions and risk tier thresholds)
- Complete SQL Script (production-ready, formatted SQL code with inline documentation)
- Metric Validation Queries (3 SQL validation checks verifying encounter linkage accuracy)
Self-review
- Ensure the window function correctly attributes readmissions only to the immediately preceding qualified index stay.
- Verify all references to {{hospital_network}}, {{sql_warehouse_platform}}, and {{readmission_window_days}} are integrated.
- Confirm that transfer encounters between facilities are consolidated into single continuous episodes.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.