Skip to content

Commit f66606f

Browse files
committed
move table check code into an array, add tables to it
1 parent 5eb083e commit f66606f

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

mimic-iv/concepts/convert_bigquery_to_postgres.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,19 @@ echo " done!"
6464
# (2) output to the postgres subfolder
6565
# (3) add a line to the postgres-make-concepts.sql script to generate this table
6666

67-
# order of the folders is important for a few tables here:
68-
# * scores (sofa et al) depend on labs, icustay_hourly
69-
# * sepsis depends on score (sofa.sql in particular)
70-
# * organfailure depends on measurement and firstday
67+
# we control the order by skipping tables listed in the below var
68+
DIR_AND_TABLES_TO_SKIP='demographics.icustay_times demographics.weight_durations measurement.urine_output organfailure.kdigo_uo organfailure.kdigo_stages firstday.first_day_sofa sepsis.sepsis3 medication.vasoactive_agent medication.norepinephrine_equivalent_dose'
69+
70+
# create an array to store tables for which the order of generation matters
71+
# i.e. these tables cannot be generated in alphabetical order, as done in the later loop
72+
TABLES_TO_SKIP=()
73+
for dir_and_table in $DIR_AND_TABLES_TO_SKIP;
74+
do
75+
tbl=`echo ${dir_and_table} | cut -d. -f2`
76+
TABLES_TO_SKIP+=($tbl)
77+
done
78+
79+
echo $TABLES_TO_SKIP
7180
# the order *only* matters during the conversion step because our loop is
7281
# inserting table build commands into the postgres-make-concepts.sql file
7382
for d in demographics measurement comorbidity medication treatment firstday organfailure score sepsis;
@@ -93,17 +102,22 @@ do
93102
echo "DROP TABLE IF EXISTS ${tbl}; CREATE TABLE ${tbl} AS " >> "postgres/${d}/${tbl}.sql"
94103
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}" >> "postgres/${d}/${fn}"
95104

96-
echo "\i ${d}/${fn}" >> postgres/postgres-make-concepts.sql
105+
if [[ ! " ${TABLES_TO_SKIP[*]} " =~ " ${tbl} " ]]; then
106+
# this table is *not* in our skip array
107+
# therefore, we print it out to the make concepts script
108+
echo "\i ${d}/${fn}" >> postgres/postgres-make-concepts.sql
109+
fi
97110
fi
98111
done
99112
echo " done!"
100113
done
101114

102115
# finally generate first_day_sofa which depends on concepts in firstday folder
103116
echo "" >> postgres/postgres-make-concepts.sql
104-
echo "-- final tables dependent on previous concepts" >> postgres/postgres-make-concepts.sql
117+
echo "-- final tables which were dependent on one or more prior tables" >> postgres/postgres-make-concepts.sql
105118

106-
for dir_and_table in firstday.first_day_sofa sepsis.sepsis3
119+
echo -n "final:"
120+
for dir_and_table in $DIR_AND_TABLES_TO_SKIP
107121
do
108122
d=`echo ${dir_and_table} | cut -d. -f1`
109123
tbl=`echo ${dir_and_table} | cut -d. -f2`

0 commit comments

Comments
 (0)