Skip to content

Commit 958fcd5

Browse files
committed
refactor so skipped tables are later generated in one loop
1 parent 9caae33 commit 958fcd5

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

mimic-iv/concepts/make_concepts.sh

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,32 @@ do
1616
# table name is file name minus extension
1717
tbl=`echo $fn | rev | cut -d. -f2- | rev`
1818

19-
# skip first_day_sofa as it depends on other firstday queries
20-
if [[ "${tbl}" == "first_day_sofa" ]]; then
21-
continue
22-
# kdigo_stages needs to be run after creat/uo
23-
elif [[ "${tbl}" == "kdigo_stages" ]]; then
24-
continue
25-
# vasoactive tables also need to be run last
26-
elif [[ "${tbl}" == "vasoactive_agent" ]]; then
27-
continue
28-
elif [[ "${tbl}" == "norepinephrine_equivalent_dose" ]]; then
29-
continue
19+
# skip certain tables where order matters - generated at the end of the script
20+
skip=0
21+
for skip_table in first_day_sofa kdigo_stages vasoactive_agent norepinephrine_eqivalent_dose
22+
do
23+
if [[ "${tbl}" == "${skip_table}" ]]; then
24+
skip=1
25+
break
26+
fi
27+
done;
28+
if [[ "${skip}" == "1" ]]; then
29+
continue
3030
fi
31+
32+
# not skipping - so generate the table on bigquery
3133
echo "Generating ${TARGET_DATASET}.${tbl}"
32-
bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.${tbl} < ${d}/${fn}
34+
echo bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.${tbl} < ${d}/${fn}
3335
fi
3436
done
3537
done
3638

37-
# generate first_day_sofa table last
38-
echo "Generating ${TARGET_DATASET}.first_day_sofa"
39-
bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.first_day_sofa < firstday/first_day_sofa.sql
40-
41-
# generate first_day_sofa table last
42-
echo "Generating ${TARGET_DATASET}.kdigo_stages"
43-
bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.kdigo_stages < organfailure/kdigo_stages.sql
39+
echo "Now generating tables which were skipped due to depending on other tables."
40+
# generate tables after the above, and in a specific order to ensure dependencies are met
41+
for table_path in firstday/first_day_sofa organfailure/kdigo_stages medication/vasoactive_agent medication/norepinephrine_equivalent_dose;
42+
do
43+
table=`echo $table_path | rev | cut -d/ -f1 | rev`
4444

45-
# generate vasoactive tables - first agent table, then NED table
46-
echo "Generating ${TARGET_DATASET}.vasoactive_agent"
47-
bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.vasoactive_agent < medication/vasoactive_agent.sql
48-
echo "Generating ${TARGET_DATASET}.norepinephrine_equivalent_dose"
49-
bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.norepinephrine_equivalent_dose < medication/norepinephrine_equivalent_dose.sql
45+
echo "Generating ${TARGET_DATASET}.${table}"
46+
bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.${table} < ${table_path}.sql
47+
done

0 commit comments

Comments
 (0)