Skip to content

Commit 00ff2df

Browse files
chore: drop concept SQL changes for separate PRs
Per maintainer feedback on MIT-LCP#2124, keep load-path / transpile / CI fixes here and move concept logic to individual PRs. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3a43427 commit 00ff2df

56 files changed

Lines changed: 175 additions & 526 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

mimic-iii/concepts/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The scripts are intended to be run against the BigQuery instantiation of MIMIC-I
55
Concepts are categorized into folders if possible, otherwise they remain in the top-level directory.
66
A table of contents is provided below: [List of concepts](#list-of-concepts).
77

8-
You can read about cloud access to MIMIC-III, including via Google BigQuery, on the [cloud page](https://mimic.physionet.org/gettingstarted/cloud/).
8+
You can read about cloud access to MIMIC-III, including via Google BigQuery, on the [cloud page](https://mimic.mit.edu/docs/gettingstarted/cloud/).
99

1010
The rest of this README describes:
1111

@@ -14,7 +14,7 @@ The rest of this README describes:
1414

1515
## Generating the concepts in BigQuery
1616

17-
You do not need to generate the concepts if you are using BigQuery! They have already been generated for you. If you have access to MIMIC-III on BigQuery, look under `physionet-data.mimic_derived`. If you would like to generate the concepts again, for example on your own dataset, you must modify the `TARGET_DATASET` variable within the [make-concepts.sh](/concepts/make-concepts.sh) script. The script assumes you have installed and configured the [Google Cloud SDK](https://cloud.google.com/sdk/docs/install).
17+
You do not need to generate the concepts if you are using BigQuery! They have already been generated for you. If you have access to MIMIC-III on BigQuery, look under `physionet-data.mimiciii_derived`. If you would like to generate the concepts again, for example on your own dataset, you must modify the `TARGET_DATASET` variable within the [make-concepts.sh](/mimic-iii/concepts/make-concepts.sh) script. The script assumes you have installed and configured the [Google Cloud SDK](https://cloud.google.com/sdk/docs/install).
1818

1919
## Generating the concepts in PostgreSQL or DuckDB
2020

@@ -42,6 +42,7 @@ Folder | Table | Description
4242
--- | --- | ---
4343
. | [echo_data](echo_data.sql) | Text extracted from echocardiography reports using regular expressions.
4444
. | [code_status](code_status.sql) | Whether the patient has restrictions on life saving resuscitation.
45+
. | [rrt](rrt.sql) | Whether the patient received any dialysis during their ICU stay.
4546
comorbidity | [elixhauser_ahrq_v37](comorbidity/elixhauser_ahrq_v37.sql) | Comorbidities in categories proposed by Elixhauser et al. AHRQ produced the mapping.
4647
comorbidity | [elixhauser_ahrq_v37_no_drg](comorbidity/elixhauser_ahrq_v37_no_drg.sql) | As above, but DRG codes are not used to exclude primary conditions.
4748
comorbidity | [elixhauser_quan](comorbidity/elixhauser_quan.sql) | Comorbidities in categories proposed by Elixhauser et al. using an algorithm by Quan et al.
@@ -76,7 +77,7 @@ durations | [neuroblock_dose](durations/neuroblock_dose.sql)
7677
durations | [norepinephrine_dose](durations/norepinephrine_dose.sql) | Dose administered with start/stop times for norepinephrine.
7778
durations | [phenylephrine_dose](durations/phenylephrine_dose.sql) | Dose administered with start/stop times for phenylephrine.
7879
durations | [vasopressin_dose](durations/vasopressin_dose.sql) | Dose administered with start/stop times for vasopressin.
79-
durations | [ventilation_classification](durations/ventilation_classification.sql) | Classifies patient settings as implying mechanical ventilation.
80+
durations | [ventilation_classification](durations/ventilation_classification.sql) | Classifies ventilator settings (tidal volume, PEEP, etc.) as implying mechanical ventilation.
8081
durations | [ventilation_durations](durations/ventilation_durations.sql) | Start and stop times for mechanical ventilation.
8182
durations | [weight_durations](durations/weight_durations.sql) | Start and stop times for daily weight measurements.
8283
**firstday** | | The first day subfolder contains scripts to summarizes a patient's health on their first ICU day.
@@ -93,6 +94,8 @@ firstday | [weight_first_day](firstday/weight_first_day.sql)
9394
**fluid_balance** | | Tables which track fluid input and output for the patient.
9495
fluid_balance | [colloid_bolus](fluid_balance/colloid_bolus.sql) | Times at which a patient received a bolus of colloidal fluid.
9596
fluid_balance | [crystalloid_bolus](fluid_balance/crystalloid_bolus.sql) | Times at which a patient received a bolus of crystalloid fluid.
97+
fluid_balance | [ffp_transfusion](fluid_balance/ffp_transfusion.sql) | Times at which a patient received a transfusion of fresh frozen plasma.
98+
fluid_balance | [rbc_transfusion](fluid_balance/rbc_transfusion.sql) | Times at which a patient received a transfusion of red blood cells.
9699
fluid_balance | [urine_output](fluid_balance/urine_output.sql) | Urine output for a patient with the time of documentation.
97100
**organfailure** | | Summarizations of the degree of organ failure for single organ systems.
98101
organfailure | [kdigo_creatinine](organfailure/kdigo_creatinine.sql) | Creatinine values with baseline creatinine as defined by KDIGO.
@@ -103,6 +106,7 @@ organfailure | [kdigo_stages_7day](organfailure/kdigo_stages_7day.sql)
103106
organfailure | [meld](organfailure/meld.sql) | The MELD score, often used to assess health of liver transplant candidates.
104107
**pivot** | | Pivoted views contain the patient `icustay_id`, the `charttime`, and a number of variables. They are useful to acquiring a time series of values for patient stays.
105108
pivot | [pivoted_bg](pivot/pivoted_bg.sql) | Blood gas measurements.
109+
pivot | [pivoted_bg_art](pivot/pivoted_bg_art.sql) | Arterial blood gas measurements, explicitly labelled or inferred from SpO2.
106110
pivot | [pivoted_fio2](pivot/pivoted_fio2.sql) | Fraction of inspired oxygen.
107111
pivot | [pivoted_gcs](pivot/pivoted_gcs.sql) | Glasgow Coma Scale.
108112
pivot | [pivoted_height](pivot/pivoted_height.sql) | Height.
@@ -113,7 +117,6 @@ pivot | [pivoted_oasis](pivot/pivoted_oasis.sql)
113117
pivot | [pivoted_rrt](pivot/pivoted_rrt.sql) | Renal replacement therapy.
114118
pivot | [pivoted_sofa](pivot/pivoted_sofa.sql) | The Sequential Organ Failure Assessment (SOFA) scale.
115119
pivot | [pivoted_uo](pivot/pivoted_uo.sql) | Urine output.
116-
pivot | [pivoted_vent_setting](pivot/pivoted_vent_setting.sql) | Ventilator settings (tidal volume, PEEP, etc).
117120
pivot | [pivoted_vital](pivot/pivoted_vital.sql) | Vital signs.
118121
**sepsis** | | Definitions of sepsis, a common cause of mortality for intensive care unit patients.
119122
sepsis | [angus](sepsis/angus.sql) | Sepsis defined using billing codes validated by Angus et al.

mimic-iii/concepts/comorbidity/elixhauser_ahrq_v37.sql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,8 @@ select hadm_id, seq_num, icd9_code
384384
when icd9_code = '3091' then 1
385385
when icd9_code = '311' then 1
386386
end as depress /* Depression */
387-
from (
388-
select hadm_id, seq_num, RTRIM(icd9_code) as icd9_code
389-
from `physionet-data.mimiciii_clinical.diagnoses_icd`
390-
) icd
387+
from `physionet-data.mimiciii_clinical.diagnoses_icd` icd
388+
WHERE seq_num = 1
391389
)
392390
-- collapse the icd9_code specific flags into hadm_id specific flags
393391
-- this groups comorbidities together for a single patient admission

mimic-iii/concepts/comorbidity/elixhauser_ahrq_v37_no_drg.sql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,8 @@ select hadm_id, seq_num, icd9_code
390390
when icd9_code = '3091' then 1
391391
when icd9_code = '311' then 1
392392
end as depress /* Depression */
393-
from (
394-
select hadm_id, seq_num, RTRIM(icd9_code) as icd9_code
395-
from `physionet-data.mimiciii_clinical.diagnoses_icd`
396-
where seq_num != 1
397-
) icd
393+
from `physionet-data.mimiciii_clinical.diagnoses_icd` icd
394+
WHERE seq_num = 1
398395
)
399396
-- collapse the icd9_code specific flags into hadm_id specific flags
400397
-- this groups comorbidities together for a single patient admission

mimic-iii/concepts/comorbidity/elixhauser_quan.sql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,7 @@ select hadm_id, seq_num, icd9_code
174174
when SUBSTR(icd9_code, 1, 4) in ('2962','2963','2965','3004') then 1
175175
when SUBSTR(icd9_code, 1, 3) in ('309','311') then 1
176176
else 0 end as depress /* Depression */
177-
from (
178-
select hadm_id, seq_num, RTRIM(icd9_code) as icd9_code
179-
from `physionet-data.mimiciii_clinical.diagnoses_icd`
180-
) icd
177+
from `physionet-data.mimiciii_clinical.diagnoses_icd` icd
181178
where seq_num != 1 -- we do not include the primary icd-9 code
182179
)
183180
-- collapse the icd9_code specific flags into hadm_id specific flags

mimic-iii/concepts/diagnosis/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The Clinical Classification Software (CCS) categorizes ICD-9 coded diagnoses int
44

55
The `ccs_multi_dx.csv.gz` data file must be uploaded to `physionet-data.mimiciii_derived.ccs_multi_dx`.
66

7-
The BigQuery schema definition is available in this folder as [ccs_multi_dx.json](/ccs_multi_dx.json).
7+
The BigQuery schema definition is available in this folder as [ccs_multi_dx.json](ccs_multi_dx.json).
88

99
## Creation of the ccs_multi_dx.csv.gz file
1010

@@ -24,7 +24,7 @@ Use Python to convert all apostrophes in `ccs_multi_dx_tool_2015.csv` into doubl
2424

2525
```python
2626
import pandas as pd
27-
df = pd.read_csv('ccs_multi_dx_tool_2015.csv.gz')
27+
df = pd.read_csv('ccs_multi_dx_tool_2015.csv')
2828
# remove apostrophes from header names and relabel
2929
df.rename(columns={"'ICD-9-CM CODE'": "icd9_code", "'CCS LVL 1'": "ccs_level1", "'CCS LVL 1 LABEL'": "ccs_group1", "'CCS LVL 2'": "ccs_level2", "'CCS LVL 2 LABEL'": "ccs_group2", "'CCS LVL 3'": "ccs_level3", "'CCS LVL 3 LABEL'": "ccs_group3", "'CCS LVL 4'": "ccs_level4", "'CCS LVL 4 LABEL'": "ccs_group4", }, inplace=True)
3030

mimic-iii/concepts/diagnosis/ccs_dx.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- add in matched ID, name, and ccs_id
2-
-- matched id (ccs_mid): the ccs ID with the hierachy, e.g. 7.1.2.1
2+
-- matched id (ccs_mid): the ccs ID with the hierarchy, e.g. 7.1.2.1
33
-- name (ccs_name): the most granular CCS category the diagnosis is in
44
-- ID (ccs_id): the CCS identifier for the ICD-9 code (integer)
55
SELECT

mimic-iii/concepts/durations/adenosine_durations.sql

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -198,39 +198,11 @@ and
198198
(
199199
select
200200
icustay_id, linkorderid
201-
-- Keep each MV row: min/max by linkorderid includes pause gaps (#1808).
202-
, starttime, endtime
201+
, min(starttime) as starttime, max(endtime) as endtime
203202
FROM `physionet-data.mimiciii_clinical.inputevents_mv`
204203
where itemid = 221282 -- adenosine
205204
and statusdescription != 'Rewritten' -- only valid orders
206-
)
207-
208-
, vasomv_grp as
209-
(
210-
-- Merge overlapping/abutting intervals; pause gaps stay separate (#1808).
211-
SELECT
212-
s1.icustay_id
213-
, s1.starttime
214-
, MIN(t1.endtime) AS endtime
215-
FROM vasomv s1
216-
INNER JOIN vasomv t1
217-
ON s1.icustay_id = t1.icustay_id
218-
AND s1.starttime <= t1.endtime
219-
AND NOT EXISTS
220-
(
221-
SELECT 1 FROM vasomv t2
222-
WHERE t1.icustay_id = t2.icustay_id
223-
AND t1.endtime >= t2.starttime
224-
AND t1.endtime < t2.endtime
225-
)
226-
WHERE NOT EXISTS
227-
(
228-
SELECT 1 FROM vasomv s2
229-
WHERE s1.icustay_id = s2.icustay_id
230-
AND s1.starttime > s2.starttime
231-
AND s1.starttime <= s2.endtime
232-
)
233-
GROUP BY s1.icustay_id, s1.starttime
205+
group by icustay_id, linkorderid
234206
)
235207

236208
select
@@ -252,6 +224,6 @@ select
252224
, DATETIME_DIFF(endtime, starttime, HOUR) AS duration_hours
253225
-- add durations
254226
from
255-
vasomv_grp
227+
vasomv
256228

257229
order by icustay_id, vasonum;

mimic-iii/concepts/durations/arterial_line_durations.sql

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -163,45 +163,16 @@ with mv as
163163
group by icustay_id, arterial_line_rownum
164164
having min(charttime) != max(charttime)
165165
)
166-
-- collapse overlapping MetaVision arterial line intervals (#371)
167-
, mv_dur as
168-
(
169-
SELECT
170-
s1.icustay_id
171-
, s1.starttime
172-
, MIN(t1.endtime) AS endtime
173-
, DATETIME_DIFF(MIN(t1.endtime), s1.starttime, HOUR) AS duration_hours
174-
FROM mv s1
175-
INNER JOIN mv t1
176-
ON s1.icustay_id = t1.icustay_id
177-
AND s1.arterial_line = 1
178-
AND t1.arterial_line = 1
179-
AND s1.starttime <= t1.endtime
180-
AND NOT EXISTS
181-
(
182-
SELECT 1 FROM mv t2
183-
WHERE t1.icustay_id = t2.icustay_id
184-
AND t2.arterial_line = 1
185-
AND t1.endtime >= t2.starttime
186-
AND t1.endtime < t2.endtime
187-
)
188-
WHERE s1.arterial_line = 1
189-
AND NOT EXISTS
190-
(
191-
SELECT 1 FROM mv s2
192-
WHERE s1.icustay_id = s2.icustay_id
193-
AND s2.arterial_line = 1
194-
AND s1.starttime > s2.starttime
195-
AND s1.starttime <= s2.endtime
196-
)
197-
GROUP BY s1.icustay_id, s1.starttime
198-
)
199166
select icustay_id
200167
-- , arterial_line_rownum
201168
, starttime, endtime, duration_hours
202169
from cv_dur
203170
UNION ALL
171+
--TODO: collapse metavision durations if they overlap
204172
select icustay_id
205-
, starttime, endtime, duration_hours
206-
from mv_dur
173+
-- , ROW_NUMBER() over (PARTITION BY icustay_id ORDER BY starttime) as arterial_line_rownum
174+
, starttime, endtime
175+
, DATETIME_DIFF(endtime, starttime, HOUR) AS duration_hours
176+
from mv
177+
where arterial_line = 1
207178
order by icustay_id, starttime;

mimic-iii/concepts/durations/central_line_durations.sql

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -158,45 +158,16 @@ with mv as
158158
group by icustay_id, central_line_rownum
159159
having min(charttime) != max(charttime)
160160
)
161-
-- collapse overlapping MetaVision central line intervals (#371)
162-
, mv_dur as
163-
(
164-
SELECT
165-
s1.icustay_id
166-
, s1.starttime
167-
, MIN(t1.endtime) AS endtime
168-
, DATETIME_DIFF(MIN(t1.endtime), s1.starttime, HOUR) AS duration_hours
169-
FROM mv s1
170-
INNER JOIN mv t1
171-
ON s1.icustay_id = t1.icustay_id
172-
AND s1.central_line = 1
173-
AND t1.central_line = 1
174-
AND s1.starttime <= t1.endtime
175-
AND NOT EXISTS
176-
(
177-
SELECT 1 FROM mv t2
178-
WHERE t1.icustay_id = t2.icustay_id
179-
AND t2.central_line = 1
180-
AND t1.endtime >= t2.starttime
181-
AND t1.endtime < t2.endtime
182-
)
183-
WHERE s1.central_line = 1
184-
AND NOT EXISTS
185-
(
186-
SELECT 1 FROM mv s2
187-
WHERE s1.icustay_id = s2.icustay_id
188-
AND s2.central_line = 1
189-
AND s1.starttime > s2.starttime
190-
AND s1.starttime <= s2.endtime
191-
)
192-
GROUP BY s1.icustay_id, s1.starttime
193-
)
194161
select icustay_id
195162
-- , central_line_rownum
196163
, starttime, endtime, duration_hours
197164
from cv_dur
198165
UNION ALL
166+
--TODO: collapse metavision durations if they overlap
199167
select icustay_id
200-
, starttime, endtime, duration_hours
201-
from mv_dur
168+
-- , ROW_NUMBER() over (PARTITION BY icustay_id ORDER BY starttime) as central_line_rownum
169+
, starttime, endtime
170+
, DATETIME_DIFF(endtime, starttime, HOUR) AS duration_hours
171+
from mv
172+
where central_line = 1
202173
order by icustay_id, starttime;

mimic-iii/concepts/durations/dobutamine_durations.sql

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -195,39 +195,11 @@ and
195195
(
196196
select
197197
icustay_id, linkorderid
198-
-- Keep each MV row: min/max by linkorderid includes pause gaps (#1808).
199-
, starttime, endtime
198+
, min(starttime) as starttime, max(endtime) as endtime
200199
FROM `physionet-data.mimiciii_clinical.inputevents_mv`
201200
where itemid = 221653 -- dobutamine
202201
and statusdescription != 'Rewritten' -- only valid orders
203-
)
204-
205-
, vasomv_grp as
206-
(
207-
-- Merge overlapping/abutting intervals; pause gaps stay separate (#1808).
208-
SELECT
209-
s1.icustay_id
210-
, s1.starttime
211-
, MIN(t1.endtime) AS endtime
212-
FROM vasomv s1
213-
INNER JOIN vasomv t1
214-
ON s1.icustay_id = t1.icustay_id
215-
AND s1.starttime <= t1.endtime
216-
AND NOT EXISTS
217-
(
218-
SELECT 1 FROM vasomv t2
219-
WHERE t1.icustay_id = t2.icustay_id
220-
AND t1.endtime >= t2.starttime
221-
AND t1.endtime < t2.endtime
222-
)
223-
WHERE NOT EXISTS
224-
(
225-
SELECT 1 FROM vasomv s2
226-
WHERE s1.icustay_id = s2.icustay_id
227-
AND s1.starttime > s2.starttime
228-
AND s1.starttime <= s2.endtime
229-
)
230-
GROUP BY s1.icustay_id, s1.starttime
202+
group by icustay_id, linkorderid
231203
)
232204

233205
select
@@ -249,6 +221,6 @@ select
249221
, DATETIME_DIFF(endtime, starttime, HOUR) AS duration_hours
250222
-- add durations
251223
from
252-
vasomv_grp
224+
vasomv
253225

254226
order by icustay_id, vasonum;

0 commit comments

Comments
 (0)