Skip to content

Commit

Permalink
fix errors due to order of make
Browse files Browse the repository at this point in the history
  • Loading branch information
alistairewj committed Jul 11, 2022
1 parent 8ed4060 commit dfe0b37
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions mimic-iv/concepts/make_concepts.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
#!/bin/bash
# This script generates the concepts in the BigQuery table mimic_derived.
export TARGET_DATASET=mimic_derived
export TARGET_DATASET=mimiciv_derived

# specify bigquery query command options
# note: max_rows=1 *displays* only one row, but all rows are inserted into the destination table
BQ_OPTIONS='--quiet --headless --max_rows=0 --use_legacy_sql=False --replace'

# generate a few tables first as the desired order isn't alphabetical
for table_path in demographics/icustay_times;
do
table=`echo $table_path | rev | cut -d/ -f1 | rev`
echo "Generating ${TARGET_DATASET}.${table}"
bq query ${BQ_OPTIONS} --destination_table=${TARGET_DATASET}.${table} < ${table_path}.sql
done

# generate tables in subfolders
# order is important for a few tables here:
# * firstday should go last
# * sepsis depends on score (sofa.sql in particular)
# * organfailure depends on measurement
for d in comorbidity demographics measurement medication organfailure treatment score sepsis firstday;
for d in demographics comorbidity measurement medication organfailure treatment firstday score sepsis;
do
for fn in `ls $d`;
do
Expand All @@ -20,9 +28,9 @@ do
# table name is file name minus extension
tbl=`echo $fn | rev | cut -d. -f2- | rev`

# skip certain tables where order matters - generated at the end of the script
# skip certain tables where order matters
skip=0
for skip_table in first_day_sofa kdigo_stages vasoactive_agent norepinephrine_eqivalent_dose
for skip_table in meld icustay_times first_day_sofa kdigo_stages vasoactive_agent norepinephrine_eqivalent_dose
do
if [[ "${tbl}" == "${skip_table}" ]]; then
skip=1
Expand All @@ -42,10 +50,10 @@ done

echo "Now generating tables which were skipped due to depending on other tables."
# generate tables after the above, and in a specific order to ensure dependencies are met
for table_path in firstday/first_day_sofa organfailure/kdigo_stages medication/vasoactive_agent medication/norepinephrine_equivalent_dose;
for table_path in firstday/first_day_sofa organfailure/kdigo_stages organfailure/meld medication/vasoactive_agent medication/norepinephrine_equivalent_dose;
do
table=`echo $table_path | rev | cut -d/ -f1 | rev`

echo "Generating ${TARGET_DATASET}.${table}"
bq query ${BQ_OPTIONS} --destination_table=${TARGET_DATASET}.${table} < ${table_path}.sql
done
done

0 comments on commit dfe0b37

Please sign in to comment.