Skip to content

Commit f9de3b7

Browse files
committed
mimic-iv/concepts/postgres/medication: add remaining files
The following auto generated files for PostgreSQL were not added to the repo yet: postgres/medication/milrinone.sql postgres/medication/norepinephrine_equivalent_dose.sql postgres/medication/vasoactive_agent.sql
1 parent f689125 commit f9de3b7

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
2+
DROP TABLE IF EXISTS milrinone; CREATE TABLE milrinone AS
3+
-- This query extracts dose+durations of milrinone administration
4+
select
5+
stay_id, linkorderid
6+
-- all rows in mcg/kg/min
7+
, rate as vaso_rate
8+
, amount as vaso_amount
9+
, starttime
10+
, endtime
11+
from mimiciv_icu.inputevents
12+
where itemid = 221986 -- milrinone
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
2+
DROP TABLE IF EXISTS norepinephrine_equivalent_dose; CREATE TABLE norepinephrine_equivalent_dose AS
3+
-- This query calculates norepinephrine equivalent dose for vasopressors.
4+
-- Based on "Vasopressor dose equivalence: A scoping review and suggested formula"
5+
-- by Goradia et al. 2020.
6+
SELECT stay_id, starttime, endtime
7+
-- calculate the dose
8+
, ROUND( CAST( COALESCE(norepinephrine, 0)
9+
+ COALESCE(epinephrine, 0)
10+
+ COALESCE(phenylephrine/10, 0)
11+
+ COALESCE(dopamine/100, 0)
12+
-- + metaraminol/8 -- metaraminol not used in BIDMC
13+
+ COALESCE(vasopressin*2.5, 0)
14+
-- angotensin_ii*10 -- angitensin ii rarely used, currently not incorporated
15+
-- (it could be included due to norepinephrine sparing effects)
16+
as numeric), 4) AS norepinephrine_equivalent_dose
17+
-- angotensin_ii*10 -- angitensin ii rarely used, currently not incorporated
18+
-- (it could be included due to norepinephrine sparing effects)
19+
FROM mimiciv_derived.vasoactive_agent
20+
WHERE norepinephrine IS NOT NULL
21+
OR epinephrine IS NOT NULL
22+
OR phenylephrine IS NOT NULL
23+
OR dopamine IS NOT NULL
24+
OR vasopressin IS NOT NULL;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
2+
DROP TABLE IF EXISTS vasoactive_agent; CREATE TABLE vasoactive_agent AS
3+
-- This query creates a single table with ongoing doses of vasoactive agents.
4+
-- TBD: rarely angiotensin II, methylene blue, and isoprenaline/isoproterenol are used.
5+
-- these are not in the query currently (they don't appear to be documented in MetaVision).
6+
7+
-- collect all vasopressor administration times
8+
-- create a single table with these as start/stop times
9+
WITH tm AS
10+
(
11+
SELECT stay_id, starttime AS vasotime FROM mimiciv_derived.dobutamine
12+
UNION DISTINCT
13+
SELECT stay_id, starttime AS vasotime FROM mimiciv_derived.dopamine
14+
UNION DISTINCT
15+
SELECT stay_id, starttime AS vasotime FROM mimiciv_derived.epinephrine
16+
UNION DISTINCT
17+
SELECT stay_id, starttime AS vasotime FROM mimiciv_derived.norepinephrine
18+
UNION DISTINCT
19+
SELECT stay_id, starttime AS vasotime FROM mimiciv_derived.phenylephrine
20+
UNION DISTINCT
21+
SELECT stay_id, starttime AS vasotime FROM mimiciv_derived.vasopressin
22+
UNION DISTINCT
23+
SELECT stay_id, starttime AS vasotime FROM mimiciv_derived.milrinone
24+
UNION DISTINCT
25+
-- combine end times from the same tables
26+
SELECT stay_id, endtime AS vasotime FROM mimiciv_derived.dobutamine
27+
UNION DISTINCT
28+
SELECT stay_id, endtime AS vasotime FROM mimiciv_derived.dopamine
29+
UNION DISTINCT
30+
SELECT stay_id, endtime AS vasotime FROM mimiciv_derived.epinephrine
31+
UNION DISTINCT
32+
SELECT stay_id, endtime AS vasotime FROM mimiciv_derived.norepinephrine
33+
UNION DISTINCT
34+
SELECT stay_id, endtime AS vasotime FROM mimiciv_derived.phenylephrine
35+
UNION DISTINCT
36+
SELECT stay_id, endtime AS vasotime FROM mimiciv_derived.vasopressin
37+
UNION DISTINCT
38+
SELECT stay_id, endtime AS vasotime FROM mimiciv_derived.milrinone
39+
)
40+
-- create starttime/endtime from all possible times collected
41+
, tm_lag AS
42+
(
43+
SELECT stay_id
44+
, vasotime AS starttime
45+
-- note: the last row for each partition (stay_id) will have a NULL endtime
46+
-- we can drop this row later, as we know that no vasopressor will start at this time
47+
-- (otherwise, we would have a later end time, which would mean it's not the last row!)
48+
-- QED? :)
49+
, LEAD(vasotime, 1) OVER (PARTITION BY stay_id ORDER BY vasotime) AS endtime
50+
FROM tm
51+
)
52+
-- left join to raw data tables to combine doses
53+
SELECT t.stay_id, t.starttime, t.endtime
54+
-- inopressors/vasopressors
55+
, dop.vaso_rate AS dopamine
56+
, epi.vaso_rate AS epinephrine
57+
, nor.vaso_rate AS norepinephrine
58+
, phe.vaso_rate AS phenylephrine
59+
, vas.vaso_rate AS vasopressin
60+
-- inodialators
61+
, dob.vaso_rate AS dobutamine
62+
, mil.vaso_rate AS milrinone
63+
-- isoproterenol is used in CCU/CVICU but not in metavision
64+
-- other drugs not included here but (rarely) used in the BIDMC:
65+
-- angiotensin II, methylene blue
66+
FROM tm_lag t
67+
LEFT JOIN mimiciv_derived.dobutamine dob
68+
ON t.stay_id = dob.stay_id
69+
AND t.starttime >= dob.starttime
70+
AND t.endtime <= dob.endtime
71+
LEFT JOIN mimiciv_derived.dopamine dop
72+
ON t.stay_id = dop.stay_id
73+
AND t.starttime >= dop.starttime
74+
AND t.endtime <= dop.endtime
75+
LEFT JOIN mimiciv_derived.epinephrine epi
76+
ON t.stay_id = epi.stay_id
77+
AND t.starttime >= epi.starttime
78+
AND t.endtime <= epi.endtime
79+
LEFT JOIN mimiciv_derived.norepinephrine nor
80+
ON t.stay_id = nor.stay_id
81+
AND t.starttime >= nor.starttime
82+
AND t.endtime <= nor.endtime
83+
LEFT JOIN mimiciv_derived.phenylephrine phe
84+
ON t.stay_id = phe.stay_id
85+
AND t.starttime >= phe.starttime
86+
AND t.endtime <= phe.endtime
87+
LEFT JOIN mimiciv_derived.vasopressin vas
88+
ON t.stay_id = vas.stay_id
89+
AND t.starttime >= vas.starttime
90+
AND t.endtime <= vas.endtime
91+
LEFT JOIN mimiciv_derived.milrinone mil
92+
ON t.stay_id = mil.stay_id
93+
AND t.starttime >= mil.starttime
94+
AND t.endtime <= mil.endtime
95+
-- remove the final row for each stay_id
96+
-- it will not have any infusions associated with it
97+
WHERE t.endtime IS NOT NULL;

0 commit comments

Comments
 (0)