Emergency department (ED) throughput is measured in minutes from each visit's timestamps:
- Door to provider:
date_diff('minute', arrival_time, provider_seen_time).
- ED length of stay:
date_diff('minute', arrival_time, departure_time).
SELECT median(date_diff('minute', arrival_time, provider_seen_time)) AS median_wait_min
FROM hd_encounters
WHERE encounter_type = 'emergency';
Waits are skewed: a few very long ones pull the average up, so throughput is reported as the median (median(), or quantile_cont(x, 0.5)). A patient who left without being seen has no provider time. Leave those visits out of wait figures and report them as their own share of visits. Visits that became admissions have the disposition admitted.
The pitfalls: AVG when the task asks for the median, a 0 standing in for a missing provider time, and date_diff('hour', ...), which counts the hour marks crossed rather than whole hours.
Median door-to-provider minutes; median() skips visits with no provider time.