Skip to content

Commit 5a21e13

Browse files
authored
Merge pull request #1203 from MIT-LCP/vasopressor_agg
aggregate vasoactive agents
2 parents d10c765 + f214349 commit 5a21e13

File tree

11 files changed

+274
-14
lines changed

11 files changed

+274
-14
lines changed

mimic-iv/concepts/make_concepts.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,32 @@ do
1616
# table name is file name minus extension
1717
tbl=`echo $fn | rev | cut -d. -f2- | rev`
1818

19-
# skip first_day_sofa as it depends on other firstday queries
20-
if [[ "${tbl}" == "first_day_sofa" ]]; then
21-
continue
22-
# kdigo_stages needs to be run after creat/uo
23-
elif [[ "${tbl}" == "kdigo_stages" ]]; then
24-
continue
19+
# skip certain tables where order matters - generated at the end of the script
20+
skip=0
21+
for skip_table in first_day_sofa kdigo_stages vasoactive_agent norepinephrine_eqivalent_dose
22+
do
23+
if [[ "${tbl}" == "${skip_table}" ]]; then
24+
skip=1
25+
break
26+
fi
27+
done;
28+
if [[ "${skip}" == "1" ]]; then
29+
continue
2530
fi
31+
32+
# not skipping - so generate the table on bigquery
2633
echo "Generating ${TARGET_DATASET}.${tbl}"
2734
bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.${tbl} < ${d}/${fn}
2835
fi
2936
done
3037
done
3138

32-
# generate first_day_sofa table last
33-
echo "Generating ${TARGET_DATASET}.first_day_sofa"
34-
bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.first_day_sofa < firstday/first_day_sofa.sql
39+
echo "Now generating tables which were skipped due to depending on other tables."
40+
# generate tables after the above, and in a specific order to ensure dependencies are met
41+
for table_path in firstday/first_day_sofa organfailure/kdigo_stages medication/vasoactive_agent medication/norepinephrine_equivalent_dose;
42+
do
43+
table=`echo $table_path | rev | cut -d/ -f1 | rev`
3544

36-
# generate first_day_sofa table last
37-
echo "Generating ${TARGET_DATASET}.kdigo_stages"
38-
bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.kdigo_stages < organfailure/kdigo_stages.sql
45+
echo "Generating ${TARGET_DATASET}.${table}"
46+
bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.${table} < ${table_path}.sql
47+
done

mimic-iv/concepts/medication/dobutamine.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- This query extracts dose+durations of dopamine administration
22
select
33
stay_id, linkorderid
4+
-- all rows in mcg/kg/min
45
, rate as vaso_rate
56
, amount as vaso_amount
67
, starttime

mimic-iv/concepts/medication/dopamine.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- This query extracts dose+durations of dopamine administration
22
select
33
stay_id, linkorderid
4+
-- all rows in mcg/kg/min
45
, rate as vaso_rate
56
, amount as vaso_amount
67
, starttime

mimic-iv/concepts/medication/epinephrine.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- This query extracts dose+durations of epinephrine administration
22
select
33
stay_id, linkorderid
4+
-- all rows in mcg/kg/min
45
, rate as vaso_rate
56
, amount as vaso_amount
67
, starttime
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- This query extracts dose+durations of milrinone administration
2+
select
3+
stay_id, linkorderid
4+
-- all rows in mcg/kg/min
5+
, rate as vaso_rate
6+
, amount as vaso_amount
7+
, starttime
8+
, endtime
9+
from `physionet-data.mimic_icu.inputevents`
10+
where itemid = 221986 -- milrinone

mimic-iv/concepts/medication/norepinephrine.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
-- This query extracts dose+durations of norepinephrine administration
22
select
33
stay_id, linkorderid
4+
-- two rows in mg/kg/min... rest in mcg/kg/min
5+
-- the rows in mg/kg/min are documented incorrectly
6+
, CASE WHEN rateuom = 'mg/kg/min' AND patientweight = 1 THEN rate
7+
-- below row is written for completion, but doesn't impact rows
8+
WHEN rateuom = 'mg/kg/min' THEN rate * 1000.0
9+
ELSE rate END AS vaso_rate
410
, rate as vaso_rate
511
, amount as vaso_amount
612
, starttime
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- This query calculates norepinephrine equivalent dose for vasopressors.
2+
-- Based on "Vasopressor dose equivalence: A scoping review and suggested formula"
3+
-- by Goradia et al. 2020.
4+
SELECT stay_id, starttime, endtime
5+
-- calculate the dose
6+
, ROUND(COALESCE(norepinephrine, 0)
7+
+ COALESCE(epinephrine, 0)
8+
+ COALESCE(phenylephrine/10, 0)
9+
+ COALESCE(dopamine/100, 0)
10+
-- + metaraminol/8 -- metaraminol not used in BIDMC
11+
+ COALESCE(vasopressin*2.5, 0)
12+
-- angotensin_ii*10 -- angitensin ii rarely used, currently not incorporated
13+
-- (it could be included due to norepinephrine sparing effects)
14+
, 4) AS norepinephrine_equivalent_dose
15+
-- angotensin_ii*10 -- angitensin ii rarely used, currently not incorporated
16+
-- (it could be included due to norepinephrine sparing effects)
17+
AS norepinephrine_equivalent_dose
18+
FROM mimic_derived.vasoactive_agent
19+
WHERE norepinephrine IS NOT NULL
20+
OR epinephrine IS NOT NULL
21+
OR phenylephrine IS NOT NULL
22+
OR dopamine IS NOT NULL
23+
OR vasopressin IS NOT NULL;

mimic-iv/concepts/medication/phenylephrine.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
-- This query extracts dose+durations of phenylephrine administration
22
select
33
stay_id, linkorderid
4-
, rate as vaso_rate
4+
-- one row in mcg/min, the rest in mcg/kg/min
5+
, CASE WHEN rateuom = 'mcg/min' THEN rate / patientweight
6+
ELSE rate END as vaso_rate
57
, amount as vaso_amount
68
, starttime
79
, endtime
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
-- This query creates a single table with ongoing doses of vasoactive agents.
2+
-- TBD: rarely angiotensin II, methylene blue, and isoprenaline/isoproterenol are used.
3+
-- these are not in the query currently (they don't appear to be documented in MetaVision).
4+
5+
-- collect all vasopressor administration times
6+
-- create a single table with these as start/stop times
7+
WITH tm AS
8+
(
9+
SELECT stay_id, starttime AS vasotime FROM mimic_derived.dobutamine
10+
UNION DISTINCT
11+
SELECT stay_id, starttime AS vasotime FROM mimic_derived.dopamine
12+
UNION DISTINCT
13+
SELECT stay_id, starttime AS vasotime FROM mimic_derived.epinephrine
14+
UNION DISTINCT
15+
SELECT stay_id, starttime AS vasotime FROM mimic_derived.norepinephrine
16+
UNION DISTINCT
17+
SELECT stay_id, starttime AS vasotime FROM mimic_derived.phenylephrine
18+
UNION DISTINCT
19+
SELECT stay_id, starttime AS vasotime FROM mimic_derived.vasopressin
20+
UNION DISTINCT
21+
SELECT stay_id, starttime AS vasotime FROM mimic_derived.milrinone
22+
UNION DISTINCT
23+
-- combine end times from the same tables
24+
SELECT stay_id, endtime AS vasotime FROM mimic_derived.dobutamine
25+
UNION DISTINCT
26+
SELECT stay_id, endtime AS vasotime FROM mimic_derived.dopamine
27+
UNION DISTINCT
28+
SELECT stay_id, endtime AS vasotime FROM mimic_derived.epinephrine
29+
UNION DISTINCT
30+
SELECT stay_id, endtime AS vasotime FROM mimic_derived.norepinephrine
31+
UNION DISTINCT
32+
SELECT stay_id, endtime AS vasotime FROM mimic_derived.phenylephrine
33+
UNION DISTINCT
34+
SELECT stay_id, endtime AS vasotime FROM mimic_derived.vasopressin
35+
UNION DISTINCT
36+
SELECT stay_id, endtime AS vasotime FROM mimic_derived.milrinone
37+
)
38+
-- create starttime/endtime from all possible times collected
39+
, tm_lag AS
40+
(
41+
SELECT stay_id
42+
, vasotime AS starttime
43+
-- note: the last row for each partition (stay_id) will have a NULL endtime
44+
-- we can drop this row later, as we know that no vasopressor will start at this time
45+
-- (otherwise, we would have a later end time, which would mean it's not the last row!)
46+
-- QED? :)
47+
, LEAD(vasotime, 1) OVER (PARTITION BY stay_id ORDER BY vasotime) AS endtime
48+
FROM tm
49+
)
50+
-- left join to raw data tables to combine doses
51+
SELECT t.stay_id, t.starttime, t.endtime
52+
-- inopressors/vasopressors
53+
, dop.vaso_rate AS dopamine
54+
, epi.vaso_rate AS epinephrine
55+
, nor.vaso_rate AS norepinephrine
56+
, phe.vaso_rate AS phenylephrine
57+
, vas.vaso_rate AS vasopressin
58+
-- inodialators
59+
, dob.vaso_rate AS dobutamine
60+
, mil.vaso_rate AS milrinone
61+
-- isoproterenol is used in CCU/CVICU but not in metavision
62+
-- other drugs not included here but (rarely) used in the BIDMC:
63+
-- angiotensin II, methylene blue
64+
FROM tm_lag t
65+
LEFT JOIN mimic_derived.dobutamine dob
66+
ON t.stay_id = dob.stay_id
67+
AND t.starttime >= dob.starttime
68+
AND t.endtime <= dob.endtime
69+
LEFT JOIN mimic_derived.dopamine dop
70+
ON t.stay_id = dop.stay_id
71+
AND t.starttime >= dop.starttime
72+
AND t.endtime <= dop.endtime
73+
LEFT JOIN mimic_derived.epinephrine epi
74+
ON t.stay_id = epi.stay_id
75+
AND t.starttime >= epi.starttime
76+
AND t.endtime <= epi.endtime
77+
LEFT JOIN mimic_derived.norepinephrine nor
78+
ON t.stay_id = nor.stay_id
79+
AND t.starttime >= nor.starttime
80+
AND t.endtime <= nor.endtime
81+
LEFT JOIN mimic_derived.phenylephrine phe
82+
ON t.stay_id = phe.stay_id
83+
AND t.starttime >= phe.starttime
84+
AND t.endtime <= phe.endtime
85+
LEFT JOIN mimic_derived.vasopressin vas
86+
ON t.stay_id = vas.stay_id
87+
AND t.starttime >= vas.starttime
88+
AND t.endtime <= vas.endtime
89+
LEFT JOIN mimic_derived.milrinone mil
90+
ON t.stay_id = mil.stay_id
91+
AND t.starttime >= mil.starttime
92+
AND t.endtime <= mil.endtime
93+
-- remove the final row for each stay_id
94+
-- it will not have any infusions associated with it
95+
WHERE t.endtime IS NOT NULL;

mimic-iv/concepts/medication/vasopressin.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
-- This query extracts dose+durations of vasopressin administration
22
select
33
stay_id, linkorderid
4-
, rate as vaso_rate
4+
-- three rows in units/min, rest in units/hour
5+
-- the three rows in units/min look reasonable and fit with the patient course
6+
, CASE WHEN rateuom = 'units/min' THEN rate * 60.0
7+
ELSE rate END AS vaso_rate
58
, amount as vaso_amount
69
, starttime
710
, endtime

0 commit comments

Comments
 (0)