Skip to content

Commit

Permalink
fix: bug where norepinephrine is skipped in output to psql
Browse files Browse the repository at this point in the history
was due to a regex match succeeding against similarly named
norepinephrine_equivalent_dose. fix was to change to exact
matching with grep. re-ran to regenerate psql concepts.
fixed #1494
  • Loading branch information
alistairewj committed Mar 23, 2023
1 parent dcb8985 commit 46808bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
14 changes: 8 additions & 6 deletions mimic-iv/concepts/convert_bigquery_to_postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,24 @@ do
tbl="${fn%????}"
echo -n " ${tbl} "

if [[ "$DIR_AND_TABLES_TO_PREBUILD" =~ "$d.$tbl" ]]; then
# check if var2 is in var1
if echo "$DIR_AND_TABLES_TO_PREBUILD" | grep -wq "$d.$tbl"; then
echo -n "(prebuilt!) .."
continue
elif [[ "$DIR_AND_TABLES_TO_SKIP" =~ "$d.$tbl" ]]; then
elif echo "$DIR_AND_TABLES_TO_SKIP" | grep -wq "$d.$tbl"; then
echo -n "(skipping!) .."
continue
else
echo -n ".."
fi

# re-write the script into psql using regex
# the if statement ensures we do not overwrite tables which are already written in psql
if ! [[ "$DIR_AND_TABLES_ALREADY_IN_PSQL" =~ "$d.$tbl" ]]; then
if ! echo "$DIR_AND_TABLES_ALREADY_IN_PSQL" | grep -wq "$d.$tbl"; then
echo "-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY." > "${TARGET_PATH}/${d}/${tbl}.sql"
echo "DROP TABLE IF EXISTS ${tbl}; CREATE TABLE ${tbl} AS" >> "${TARGET_PATH}/${d}/${tbl}.sql"
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}"
echo -n ".."
else
echo -n "(psql!) .."
fi

# add statement to generate this table
Expand All @@ -167,7 +169,7 @@ do

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

Expand Down
4 changes: 3 additions & 1 deletion mimic-iv/concepts_postgres/medication/norepinephrine.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
DROP TABLE IF EXISTS norepinephrine; CREATE TABLE norepinephrine AS
DROP TABLE IF EXISTS norepinephrine; CREATE TABLE norepinephrine AS
-- This query extracts dose+durations of norepinephrine administration
-- Local hospital dosage guidance: 0.03 mcg/kg/min (low), 0.5 mcg/kg/min (high)
SELECT
stay_id, linkorderid
-- two rows in mg/kg/min... rest in mcg/kg/min
-- the rows in mg/kg/min are documented incorrectly
-- all rows converted into mcg/kg/min (equiv to ug/kg/min)
, CASE WHEN rateuom = 'mg/kg/min' AND patientweight = 1 THEN rate
-- below row is written for completion, but doesn't impact rows
WHEN rateuom = 'mg/kg/min' THEN rate * 1000.0
Expand Down
1 change: 1 addition & 0 deletions mimic-iv/concepts_postgres/postgres-make-concepts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ SET search_path TO mimiciv_derived, mimiciv_hosp, mimiciv_icu, mimiciv_ed;
\i medication/epinephrine.sql
\i medication/milrinone.sql
\i medication/neuroblock.sql
\i medication/norepinephrine.sql
\i medication/phenylephrine.sql
\i medication/vasopressin.sql

Expand Down

0 comments on commit 46808bf

Please sign in to comment.