Skip to content

Commit 7c2c8bd

Browse files
Add diagnostic-delay concept module (cohort + delay measures + data-quality report)
New `mimic-iv/concepts/diagnosticdelay/` module: - suspected_sepsis_cohort.sql: one row per ICU stay for adults admitted via the ED with >= 1 suspected-infection episode (antibiotic + microbiology culture pair, per suspicion_of_infection). - diagnostic_delay.sql: delay in hours between admission (hospital/ICU) and first recognition of infection (suspected-infection time, first antibiotic, first culture); onset-window classification (pre_admission / present_on_admission / hospital_onset); and temporal-plausibility flags for out-of-order or missing timestamps. - data_quality_report.py: renders a Markdown/JSON data-quality report (cohort coverage, missingness, flag prevalence, delay distributions) from the two tables above; runs on DuckDB or PostgreSQL. - README.md documents the cohort definition, measures, validation, and limitations. ICD codes carry no timestamp in MIMIC, so diagnosis time is proxied by the clinically observable recognition events used in the Sepsis-3 definition (see #1843); ordering checks surface implausible values of the kind reported in #2168 instead of silently averaging them in. Validated without credentialed MIMIC-IV access: sqlglot parse (BigQuery dialect, same as CI), sqlfluff 4.1.0 with the repo config, transpile to DuckDB/PostgreSQL via mimic_utils, execution of the DuckDB build on hand-built synthetic fixtures (16 assertions), and a run of the report script against the fixture database. End-to-end run on real MIMIC-IV data is still outstanding.
1 parent 303d26c commit 7c2c8bd

5 files changed

Lines changed: 672 additions & 0 deletions

File tree

‎mimic-iv/concepts/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Concepts in this folder:
2020
│   ├── icustay_hourly.sql
2121
│   ├── icustay_times.sql
2222
│   └── weight_durations.sql
23+
├── diagnosticdelay
24+
│   ├── suspected_sepsis_cohort.sql
25+
│   └── diagnostic_delay.sql
2326
├── firstday
2427
│   ├── first_day_bg.sql
2528
│   ├── first_day_bg_art.sql
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Diagnostic delay
2+
3+
Reproducible cohort extraction and diagnostic-delay measurement for
4+
MIMIC-IV, plus a data-quality report generator.
5+
6+
## What this is
7+
8+
ICD codes in MIMIC carry no timestamp, so "when was this diagnosed?" is
9+
a recurring community question (e.g.
10+
[#1843](https://github.com/MIT-LCP/mimic-code/issues/1843)). This
11+
module answers a tractable version of it: for ICU stays with a
12+
*suspected-infection* episode (an antibiotic paired with a microbiology
13+
culture, per the `suspicion_of_infection` concept), it measures the
14+
delay between hospital/ICU admission and the first clinically
15+
observable recognition event (first antibiotic order, first culture
16+
draw, suspected-infection time).
17+
18+
Contents:
19+
20+
| File | Description |
21+
|---|---|
22+
| `suspected_sepsis_cohort.sql` | Cohort concept: one row per ICU stay for adults admitted via the ED with >= 1 suspected-infection episode. |
23+
| `diagnostic_delay.sql` | Delay measures (hours), onset-window classification, and temporal-plausibility flags, one row per cohort stay. |
24+
| `data_quality_report.py` | Generates a Markdown/JSON data-quality report (coverage, missingness, flag prevalence, delay distributions) from the two tables above. |
25+
26+
The SQL is written in the BigQuery dialect, following the repository's
27+
concept conventions; PostgreSQL and DuckDB versions are generated
28+
automatically on merge (see the top-level README).
29+
30+
## Cohort definition (`suspected_sepsis_cohort`)
31+
32+
* Source: `mimiciv_icu.icustays` x `mimiciv_hosp.admissions` x
33+
`mimiciv_hosp.patients`, inner-joined to
34+
`mimiciv_derived.suspicion_of_infection` (suspected_infection = 1),
35+
aggregated to one row per `stay_id`.
36+
* Inclusion: admission age >= 18 (same `anchor_age` formula as
37+
`age.sql`); `admissions.admission_location = 'EMERGENCY ROOM'`.
38+
* Carries: `subject_id, hadm_id, stay_id, gender, admission_age, race,
39+
admittime, dischtime, admission_type, admission_location,
40+
hospital_expire_flag, hospstay_seq, icu_intime, icu_outtime,
41+
icustay_seq, n_suspicion_episodes, first_suspicion_time,
42+
first_antibiotic_time, first_culture_time`.
43+
44+
## Delay measures (`diagnostic_delay`)
45+
46+
All delays are in hours (1 decimal):
47+
48+
* `admission_to_suspicion_hours`, `icu_to_suspicion_hours`,
49+
`admission_to_antibiotic_hours`, `admission_to_culture_hours`,
50+
`culture_to_antibiotic_hours` (positive = antibiotic after culture).
51+
* `onset_window`: `pre_admission` (suspicion before `admittime`),
52+
`present_on_admission` (within 48 h of admission), `hospital_onset`
53+
(after 48 h).
54+
* Plausibility flags (1 = implausible, 0 = plausible, NULL =
55+
unassessable): `flag_suspicion_before_admission`,
56+
`flag_suspicion_after_icu_outtime`, `flag_suspicion_after_discharge`,
57+
`flag_missing_culture_time`, `flag_missing_antibiotic_time`.
58+
59+
## Data-quality report
60+
61+
```bash
62+
python data_quality_report.py \
63+
--duckdb ~/data/mimic-iv.duckdb \
64+
--schema mimiciv_derived \
65+
--raw-schema mimiciv_icu \
66+
--output delay_data_quality.md \
67+
--json-output delay_data_quality.json
68+
```
69+
70+
`--postgres-dsn` (requires `psycopg2`) can be used instead of
71+
`--duckdb`. `--raw-schema` is optional; when given, the report adds
72+
the cohort capture rate against adult ED ICU stays from the raw
73+
tables.
74+
75+
## Validation
76+
77+
Real MIMIC-IV data requires credentialed PhysioNet access, so the
78+
logic was validated without it:
79+
80+
1. `sqlglot` parse check of both queries (BigQuery dialect) -- the
81+
same check CI runs (`.github/scripts/check_sql_syntax.py`).
82+
2. `sqlfluff` lint with the repository's `.sqlfluff` config.
83+
3. Transpiled both queries to DuckDB with the repo's `mimic_utils`
84+
transpiler and executed them against hand-built synthetic fixtures
85+
mirroring the MIMIC-IV schema (admissions, icustays, patients,
86+
derived suspicion_of_infection). Fixtures cover: a standard
87+
present-on-admission case, a hospital-onset case, a
88+
pre-admission-suspicion case (flagged), multiple episodes per stay,
89+
a pediatric exclusion, a non-ED admission exclusion, a stay with no
90+
suspected infection (excluded), and a NULL `icu_outtime` case
91+
(flag unassessable).
92+
4. Ran `data_quality_report.py` against the resulting DuckDB database
93+
and verified the Markdown/JSON outputs against hand-computed
94+
expectations.
95+
96+
What still needs real data: end-to-end execution against MIMIC-IV
97+
(v3.1), sanity of the delay distributions at scale, and the capture
98+
rate of the cohort definition.
99+
100+
## Limitations
101+
102+
* "Diagnosis time" is proxied by recognition events (antibiotic /
103+
culture); true clinical diagnosis time is not recorded in MIMIC.
104+
* ED arrival time is not used: the module only depends on
105+
`mimiciv_hosp` + `mimiciv_icu` + derived concepts so it runs without
106+
the separate MIMIC-IV-ED module.
107+
* Implausible raw values (see
108+
[#2168](https://github.com/MIT-LCP/mimic-code/issues/2168)) are
109+
flagged via ordering checks, not range-checked here.

0 commit comments

Comments
 (0)