Skip to content

Commit 04a11ba

Browse files
authored
Merge pull request #1505 from MIT-LCP/tidy_ned_sql
Fix norepinephrine in PSQL, tidy vasoactive code
2 parents 176be33 + 572233c commit 04a11ba

20 files changed

+72
-25
lines changed

mimic-iv/concepts/convert_bigquery_to_postgres.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,24 @@ do
126126
tbl="${fn%????}"
127127
echo -n " ${tbl} "
128128

129-
if [[ "$DIR_AND_TABLES_TO_PREBUILD" =~ "$d.$tbl" ]]; then
129+
# check if var2 is in var1
130+
if echo "$DIR_AND_TABLES_TO_PREBUILD" | grep -wq "$d.$tbl"; then
130131
echo -n "(prebuilt!) .."
131132
continue
132-
elif [[ "$DIR_AND_TABLES_TO_SKIP" =~ "$d.$tbl" ]]; then
133+
elif echo "$DIR_AND_TABLES_TO_SKIP" | grep -wq "$d.$tbl"; then
133134
echo -n "(skipping!) .."
134135
continue
135-
else
136-
echo -n ".."
137136
fi
138137

139138
# re-write the script into psql using regex
140139
# the if statement ensures we do not overwrite tables which are already written in psql
141-
if ! [[ "$DIR_AND_TABLES_ALREADY_IN_PSQL" =~ "$d.$tbl" ]]; then
140+
if ! echo "$DIR_AND_TABLES_ALREADY_IN_PSQL" | grep -wq "$d.$tbl"; then
142141
echo "-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY." > "${TARGET_PATH}/${d}/${tbl}.sql"
143142
echo "DROP TABLE IF EXISTS ${tbl}; CREATE TABLE ${tbl} AS" >> "${TARGET_PATH}/${d}/${tbl}.sql"
144143
cat "${d}/${tbl}.sql" | sed -r -e "${REGEX_ARRAY}" | sed -r -e "${REGEX_HOUR_INTERVAL}" | sed -r -e "${REGEX_INT}" | sed -r -e "${REGEX_DATETIME_DIFF}" | sed -r -e "${REGEX_DATETIME_TRUNC}" | sed -r -e "${REGEX_SCHEMA}" | sed -r -e "${REGEX_INTERVAL}" >> "${TARGET_PATH}/${d}/${fn}"
144+
echo -n ".."
145+
else
146+
echo -n "(psql!) .."
145147
fi
146148

147149
# add statement to generate this table
@@ -167,7 +169,7 @@ do
167169

168170
# convert the bigquery script to psql and output it to the appropriate subfolder
169171
echo -n " ${d}.${tbl} .."
170-
if ! [[ "$DIR_AND_TABLES_ALREADY_IN_PSQL" =~ "$d.$tbl" ]]; then
172+
if ! echo "$DIR_AND_TABLES_ALREADY_IN_PSQL" | grep -wq "$d.$tbl"; then
171173
echo "-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY." > "$TARGET_PATH/${d}/${tbl}.sql"
172174
echo "DROP TABLE IF EXISTS ${tbl}; CREATE TABLE ${tbl} AS" >> "$TARGET_PATH/${d}/${tbl}.sql"
173175

mimic-iv/concepts/medication/dobutamine.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
-- This query extracts dose+durations of dopamine administration
1+
-- This query extracts dose+durations of dobutamine administration
2+
-- Local hospital dosage guidance: 2 mcg/kg/min (low) - 40 mcg/kg/min (max)
23
SELECT
34
stay_id, linkorderid
45
-- all rows in mcg/kg/min

mimic-iv/concepts/medication/dopamine.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-- This query extracts dose+durations of dopamine administration
2+
-- Local hospital dosage guidance: 2 mcg/kg/min (low) - 10 mcg/kg/min (high)
23
SELECT
34
stay_id, linkorderid
45
-- all rows in mcg/kg/min

mimic-iv/concepts/medication/epinephrine.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-- This query extracts dose+durations of epinephrine administration
2+
-- Local hospital dosage guidance: 0.2 mcg/kg/min (low) - 2 mcg/kg/min (high)
23
SELECT
34
stay_id, linkorderid
45
-- all rows in mcg/kg/min

mimic-iv/concepts/medication/milrinone.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-- This query extracts dose+durations of milrinone administration
2+
-- Local hospital dosage guidance: 0.5 mcg/kg/min (usual)
23
SELECT
34
stay_id, linkorderid
45
-- all rows in mcg/kg/min

mimic-iv/concepts/medication/norepinephrine.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
-- This query extracts dose+durations of norepinephrine administration
2+
-- Local hospital dosage guidance: 0.03 mcg/kg/min (low), 0.5 mcg/kg/min (high)
23
SELECT
34
stay_id, linkorderid
45
-- two rows in mg/kg/min... rest in mcg/kg/min
56
-- the rows in mg/kg/min are documented incorrectly
7+
-- all rows converted into mcg/kg/min (equiv to ug/kg/min)
68
, CASE WHEN rateuom = 'mg/kg/min' AND patientweight = 1 THEN rate
79
-- below row is written for completion, but doesn't impact rows
810
WHEN rateuom = 'mg/kg/min' THEN rate * 1000.0

mimic-iv/concepts/medication/norepinephrine_equivalent_dose.sql

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
-- This query calculates norepinephrine equivalent dose for vasopressors.
22
-- Based on "Vasopressor dose equivalence: A scoping review and
33
-- suggested formula" by Goradia et al. 2020.
4+
5+
-- The relevant table makes the following equivalences:
6+
-- Norepinephrine - 1:1 - comparison dose of 0.1 ug/kg/min
7+
-- Epinephrine - 1:1 [0.7, 1.4] - 0.1 ug/kg/min
8+
-- Dopamine - 1:100 [75.2, 144.4] - 10 ug/kg/min
9+
-- Metaraminol - 1:8 [8.3] - 0.8 ug/kg/min
10+
-- Phenylephrine - 1:10 [1.1, 16.3] - 1 ug/kg/min
11+
-- Vasopressin - 1:0.4 [0.3, 0.4] - 0.04 units/min
12+
-- Angiotensin II - 1:0.1 [0.07, 0.13] - 0.01 ug/kg/min
13+
414
SELECT stay_id, starttime, endtime
515
-- calculate the dose
16+
-- all sources are in mcg/kg/min,
17+
-- except vasopressin which is in units/hour
618
, ROUND(CAST(
719
COALESCE(norepinephrine, 0)
820
+ COALESCE(epinephrine, 0)
921
+ COALESCE(phenylephrine / 10, 0)
1022
+ COALESCE(dopamine / 100, 0)
1123
-- + metaraminol/8 -- metaraminol not used in BIDMC
12-
+ COALESCE(vasopressin * 2.5/60, 0)
24+
+ COALESCE(vasopressin * 2.5 / 60, 0)
1325
-- angiotensin_ii*10 -- angiotensin ii rarely used, though
1426
-- it could be included due to norepinephrine sparing effects
1527
AS NUMERIC), 4) AS norepinephrine_equivalent_dose

mimic-iv/concepts/medication/phenylephrine.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-- This query extracts dose+durations of phenylephrine administration
2+
-- Local hospital dosage guidance: 0.5 mcg/kg/min (low) - 5 mcg/kg/min (high)
23
SELECT
34
stay_id, linkorderid
45
-- one row in mcg/min, the rest in mcg/kg/min

mimic-iv/concepts/medication/vasoactive_agent.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ WITH tm AS (
8282
-- left join to raw data tables to combine doses
8383
SELECT t.stay_id, t.starttime, t.endtime
8484
-- inopressors/vasopressors
85-
, dop.vaso_rate AS dopamine
86-
, epi.vaso_rate AS epinephrine
87-
, nor.vaso_rate AS norepinephrine
88-
, phe.vaso_rate AS phenylephrine
89-
, vas.vaso_rate AS vasopressin
85+
, dop.vaso_rate AS dopamine -- mcg/kg/min
86+
, epi.vaso_rate AS epinephrine -- mcg/kg/min
87+
, nor.vaso_rate AS norepinephrine -- mcg/kg/min
88+
, phe.vaso_rate AS phenylephrine -- mcg/kg/min
89+
, vas.vaso_rate AS vasopressin -- units/hour
9090
-- inodialators
91-
, dob.vaso_rate AS dobutamine
92-
, mil.vaso_rate AS milrinone
91+
, dob.vaso_rate AS dobutamine -- mcg/kg/min
92+
, mil.vaso_rate AS milrinone -- mcg/kg/min
9393
-- isoproterenol is used in CCU/CVICU but not in metavision
9494
-- other drugs not included here but (rarely) used in the BIDMC:
9595
-- angiotensin II, methylene blue

mimic-iv/concepts/medication/vasopressin.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
-- This query extracts dose+durations of vasopressin administration
2+
-- Local hospital dosage guidance: 1.2 units/hour (low) - 2.4 units/hour (high)
23
SELECT
34
stay_id, linkorderid
45
-- three rows in units/min, rest in units/hour
56
-- the three rows in units/min look reasonable and
67
-- fit with the patient course
8+
9+
-- convert all rows to units/hour
710
, CASE WHEN rateuom = 'units/min' THEN rate * 60.0
811
ELSE rate END AS vaso_rate
912
, amount AS vaso_amount

0 commit comments

Comments
 (0)