11#! /bin/bash
22# This script generates the concepts in the BigQuery table mimic_derived.
3- export TARGET_DATASET=mimic_derived
3+ export TARGET_DATASET=mimiciv_derived
44
55# specify bigquery query command options
66# note: max_rows=1 *displays* only one row, but all rows are inserted into the destination table
77BQ_OPTIONS=' --quiet --headless --max_rows=0 --use_legacy_sql=False --replace'
88
9+ # generate a few tables first as the desired order isn't alphabetical
10+ for table_path in demographics/icustay_times;
11+ do
12+ table=` echo $table_path | rev | cut -d/ -f1 | rev`
13+ echo " Generating ${TARGET_DATASET} .${table} "
14+ bq query ${BQ_OPTIONS} --destination_table=${TARGET_DATASET} .${table} < ${table_path} .sql
15+ done
16+
917# generate tables in subfolders
1018# order is important for a few tables here:
1119# * firstday should go last
1220# * sepsis depends on score (sofa.sql in particular)
1321# * organfailure depends on measurement
14- for d in comorbidity demographics measurement medication organfailure treatment score sepsis firstday ;
22+ for d in demographics comorbidity measurement medication organfailure treatment firstday score sepsis;
1523do
1624 for fn in ` ls $d ` ;
1725 do
2028 # table name is file name minus extension
2129 tbl=` echo $fn | rev | cut -d. -f2- | rev`
2230
23- # skip certain tables where order matters - generated at the end of the script
31+ # skip certain tables where order matters
2432 skip=0
25- for skip_table in first_day_sofa kdigo_stages vasoactive_agent norepinephrine_eqivalent_dose
33+ for skip_table in meld icustay_times first_day_sofa kdigo_stages vasoactive_agent norepinephrine_eqivalent_dose
2634 do
2735 if [[ " ${tbl} " == " ${skip_table} " ]]; then
2836 skip=1
4250
4351echo " Now generating tables which were skipped due to depending on other tables."
4452# generate tables after the above, and in a specific order to ensure dependencies are met
45- for table_path in firstday/first_day_sofa organfailure/kdigo_stages medication/vasoactive_agent medication/norepinephrine_equivalent_dose;
53+ for table_path in firstday/first_day_sofa organfailure/kdigo_stages organfailure/meld medication/vasoactive_agent medication/norepinephrine_equivalent_dose;
4654do
4755 table=` echo $table_path | rev | cut -d/ -f1 | rev`
4856
4957 echo " Generating ${TARGET_DATASET} .${table} "
5058 bq query ${BQ_OPTIONS} --destination_table=${TARGET_DATASET} .${table} < ${table_path} .sql
51- done
59+ done
0 commit comments