Skip to content

Commit 5e49424

Browse files
author
Alistair Johnson
committed
add post-loop generation of tables which have dependencies
1 parent bd5077a commit 5e49424

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
@@ -86,7 +86,7 @@ do
8686

8787
# skip first_day_sofa as it depends on other firstday queries, we'll generate it later
8888
# we also skipped tables generated in the "Dependencies" loop above.
89-
if [[ "${tbl}" == "first_day_sofa" ]] || [[ "${tbl}" == "icustay_times" ]] || [[ "${tbl}" == "weight_durations" ]] || [[ "${tbl}" == "urine_output" ]] || [[ "${tbl}" == "kdigo_uo" ]]; then
89+
if [[ "${tbl}" == "first_day_sofa" ]] || [[ "${tbl}" == "icustay_times" ]] || [[ "${tbl}" == "weight_durations" ]] || [[ "${tbl}" == "urine_output" ]] || [[ "${tbl}" == "kdigo_uo" ]] || [[ "${tbl}" == "sepsis3" ]]; then
9090
continue
9191
fi
9292
echo -n " ${tbl} .."
@@ -103,9 +103,23 @@ done
103103
# finally generate first_day_sofa which depends on concepts in firstday folder
104104
echo "" >> postgres/postgres-make-concepts.sql
105105
echo "-- final tables dependent on previous concepts" >> postgres/postgres-make-concepts.sql
106-
d=firstday
107-
tbl=first_day_sofa
108-
echo "-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY." > "postgres/${d}/${tbl}.sql"
109-
echo "DROP TABLE IF EXISTS ${tbl}; CREATE TABLE ${tbl} AS " >> "postgres/${d}/${tbl}.sql"
110-
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_SCHEMA}" | sed -r -e "${REGEX_INTERVAL}" | sed -r -e "${REGEX_SECONDS}" | perl -0777 -pe "${PERL_REGEX_ROUND}" >> "postgres/${d}/${tbl}.sql"
111-
echo "\i ${d}/${tbl}.sql" >> postgres/postgres-make-concepts.sql
106+
107+
for dir_and_table in firstday.first_day_sofa sepsis.sepsis3
108+
do
109+
d=`echo ${dir_and_table} | cut -d. -f1`
110+
tbl=`echo ${dir_and_table} | cut -d. -f2`
111+
112+
# make the sub-folder for postgres if it does not exist
113+
mkdir -p "postgres/${d}"
114+
115+
# convert the bigquery script to psql and output it to the appropriate subfolder
116+
echo -n " ${d}.${tbl} .."
117+
echo "-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY." > "postgres/${d}/${tbl}.sql"
118+
echo "DROP TABLE IF EXISTS ${tbl}; CREATE TABLE ${tbl} AS " >> "postgres/${d}/${tbl}.sql"
119+
120+
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_SCHEMA}" | sed -r -e "${REGEX_INTERVAL}" | sed -r -e "${REGEX_SECONDS}" >> "postgres/${d}/${tbl}.sql"
121+
122+
# write out a call to this script in the make concepts file
123+
echo "\i ${d}/${tbl}.sql" >> postgres/postgres-make-concepts.sql
124+
done
125+
echo " done!"

0 commit comments

Comments
 (0)