From 4ff2e774f4ee6d7536dfe68c250405d9e48aeae0 Mon Sep 17 00:00:00 2001 From: minkoo Date: Tue, 3 May 2022 17:19:34 +0900 Subject: [PATCH 1/4] change default schema to include public --- mimic_direct_extract.py | 2 +- mimic_querier.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mimic_direct_extract.py b/mimic_direct_extract.py index 9c6a66f..c65e683 100644 --- a/mimic_direct_extract.py +++ b/mimic_direct_extract.py @@ -734,7 +734,7 @@ def plot_variable_histograms(col_names, df): help='Postgres host. Try "/var/run/postgresql/" for Unix domain socket errors.') ap.add_argument('--psql_dbname', type=str, default='mimic', help='Postgres database name.') - ap.add_argument('--psql_schema_name', type=str, default='mimiciii', + ap.add_argument('--psql_schema_name', type=str, default='public,mimiciii', help='Postgres database name.') ap.add_argument('--psql_user', type=str, default=None, help='Postgres user.') diff --git a/mimic_querier.py b/mimic_querier.py index a5c76c6..8150d51 100644 --- a/mimic_querier.py +++ b/mimic_querier.py @@ -25,7 +25,7 @@ def __init__( self, exclusion_criteria_template_vars={}, query_args={}, # passed wholesale to psycopg2.connect - schema_name='mimiciii' + schema_name='public,mimiciii' ): """ A class to facilitate repeated Queries to a MIMIC psql database """ self.exclusion_criteria_template_vars = {} From ca4528fc3d93f9405e115bbadff98d17cb1dd1a1 Mon Sep 17 00:00:00 2001 From: minkoo Date: Tue, 3 May 2022 17:27:02 +0900 Subject: [PATCH 2/4] modify schema as mimic-code has changed to generate all concepts on the public schema. --- SQL_Queries/codes.sql | 2 +- SQL_Queries/debug_statics.sql | 2 +- utils/niv-durations.sql | 2 +- utils/setup_user_env.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SQL_Queries/codes.sql b/SQL_Queries/codes.sql index 4596806..3029101 100644 --- a/SQL_Queries/codes.sql +++ b/SQL_Queries/codes.sql @@ -2,7 +2,7 @@ SELECT i.icustay_id, d.subject_id, d.hadm_id, array_agg(d.icd9_code ORDER BY seq_num ASC) AS icd9_codes FROM mimiciii.diagnoses_icd d - LEFT OUTER JOIN (SELECT ccs_matched_id, icd9_code from mimiciii.ccs_dx) c + LEFT OUTER JOIN (SELECT ccs_matched_id, icd9_code from public.ccs_dx) c ON c.icd9_code = d.icd9_code INNER JOIN icustays i ON i.hadm_id = d.hadm_id AND i.subject_id = d.subject_id diff --git a/SQL_Queries/debug_statics.sql b/SQL_Queries/debug_statics.sql index f1960b4..b68f8f2 100644 --- a/SQL_Queries/debug_statics.sql +++ b/SQL_Queries/debug_statics.sql @@ -1,5 +1,5 @@ \echo "This file is just for debugging" -SET search_path TO mimiciii; +SET search_path TO public,mimiciii; select distinct i.subject_id, i.hadm_id, diff --git a/utils/niv-durations.sql b/utils/niv-durations.sql index 3c69fec..a577be5 100755 --- a/utils/niv-durations.sql +++ b/utils/niv-durations.sql @@ -4,7 +4,7 @@ -- events can then be used for various purposes: calculating the total duration -- of mechanical ventilation, cross-checking values (e.g. PaO2:FiO2 on vent), etc -SET SEARCH_PATH TO 'mimiciii'; +SET SEARCH_PATH TO 'public,mimiciii'; -- The query's logic is roughly: -- 1) The presence of a mechanical ventilation setting starts a new ventilation event diff --git a/utils/setup_user_env.sh b/utils/setup_user_env.sh index 2dfb58a..81f5d6d 100755 --- a/utils/setup_user_env.sh +++ b/utils/setup_user_env.sh @@ -10,7 +10,7 @@ mkdir -p $MIMIC_EXTRACT_OUTPUT_DIR export DBUSER=bnestor export DBNAME=mimic -export SCHEMA=mimiciii +export SCHEMA=public,mimiciii export HOST=mimic export DBSTRING="dbname=$DBNAME options=--search_path=$SCHEMA" alias psql="psql -h $HOST -U $DBUSER " From 10dffa452f0627fcba90b83c61288e700ff44105 Mon Sep 17 00:00:00 2001 From: minkoo Date: Wed, 4 May 2022 09:32:00 +0900 Subject: [PATCH 3/4] Use search path instead of dot notation --- SQL_Queries/codes.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SQL_Queries/codes.sql b/SQL_Queries/codes.sql index 3029101..628c2fa 100644 --- a/SQL_Queries/codes.sql +++ b/SQL_Queries/codes.sql @@ -1,8 +1,9 @@ +SET SEARCH_PATH TO 'public,mimiciii'; SELECT i.icustay_id, d.subject_id, d.hadm_id, array_agg(d.icd9_code ORDER BY seq_num ASC) AS icd9_codes -FROM mimiciii.diagnoses_icd d - LEFT OUTER JOIN (SELECT ccs_matched_id, icd9_code from public.ccs_dx) c +FROM diagnoses_icd d + LEFT OUTER JOIN (SELECT ccs_matched_id, icd9_code from ccs_dx) c ON c.icd9_code = d.icd9_code INNER JOIN icustays i ON i.hadm_id = d.hadm_id AND i.subject_id = d.subject_id From 63585d449116bdfbedbd60f401e683dfcea8a389 Mon Sep 17 00:00:00 2001 From: minkoo Date: Wed, 4 May 2022 10:13:22 +0900 Subject: [PATCH 4/4] fix search path --- SQL_Queries/codes.sql | 2 +- utils/niv-durations.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SQL_Queries/codes.sql b/SQL_Queries/codes.sql index 628c2fa..a3ddaf5 100644 --- a/SQL_Queries/codes.sql +++ b/SQL_Queries/codes.sql @@ -1,4 +1,4 @@ -SET SEARCH_PATH TO 'public,mimiciii'; +SET SEARCH_PATH TO public,mimiciii; SELECT i.icustay_id, d.subject_id, d.hadm_id, array_agg(d.icd9_code ORDER BY seq_num ASC) AS icd9_codes diff --git a/utils/niv-durations.sql b/utils/niv-durations.sql index a577be5..62e6c16 100755 --- a/utils/niv-durations.sql +++ b/utils/niv-durations.sql @@ -4,7 +4,7 @@ -- events can then be used for various purposes: calculating the total duration -- of mechanical ventilation, cross-checking values (e.g. PaO2:FiO2 on vent), etc -SET SEARCH_PATH TO 'public,mimiciii'; +SET SEARCH_PATH TO public,mimiciii; -- The query's logic is roughly: -- 1) The presence of a mechanical ventilation setting starts a new ventilation event