Skip to content

Commit

Permalink
Merge pull request #1468 from schu/schu/update-mimic-iv-concepts-post…
Browse files Browse the repository at this point in the history
…gres

concepts_postgres: updates (on top of `mimiciv_v2.2_updates`)
  • Loading branch information
alistairewj authored Jan 15, 2023
2 parents 4b28df1 + 03107d4 commit 5e05342
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
8 changes: 8 additions & 0 deletions mimic-iv/concepts/convert_bigquery_to_postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ echo "\echo 'The scripts drop views before creating them, and these notices indi
echo "\echo '==='" >> $TARGET_PATH/postgres-make-concepts.sql
echo "\echo ''" >> $TARGET_PATH/postgres-make-concepts.sql

echo >> $TARGET_PATH/postgres-make-concepts.sql
echo "-- Set the search_path, i.e. the location at which we generate tables." >> $TARGET_PATH/postgres-make-concepts.sql
echo "-- postgres looks at schemas sequentially, so this will generate tables on the mimiciv_derived schema" >> $TARGET_PATH/postgres-make-concepts.sql
echo >> $TARGET_PATH/postgres-make-concepts.sql
echo "-- NOTE: many scripts *require* you to use mimic_derived as the schema for outputting concepts" >> $TARGET_PATH/postgres-make-concepts.sql
echo "-- change the search path at your peril!" >> $TARGET_PATH/postgres-make-concepts.sql
echo "SET search_path TO mimiciv_derived, mimiciv_hosp, mimiciv_icu, mimiciv_ed;" >> $TARGET_PATH/postgres-make-concepts.sql

# reporting to stdout the folder being run
echo -n "Dependencies:"

Expand Down
18 changes: 14 additions & 4 deletions mimic-iv/concepts_postgres/firstday/first_day_gcs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@ DROP TABLE IF EXISTS first_day_gcs; CREATE TABLE first_day_gcs AS
WITH gcs_final AS
(
SELECT
gcs.*
ie.subject_id, ie.stay_id
, g.gcs
, g.gcs_motor
, g.gcs_verbal
, g.gcs_eyes
, g.gcs_unable
-- This sorts the data by GCS
-- rn = 1 is the the lowest total GCS value
, ROW_NUMBER () OVER
(
PARTITION BY gcs.stay_id
ORDER BY gcs.GCS
PARTITION BY g.stay_id
ORDER BY g.GCS
) as gcs_seq
FROM mimiciv_derived.gcs gcs
FROM mimiciv_icu.icustays ie
-- Only get data for the first 24 hours
LEFT JOIN mimiciv_derived.gcs g
ON ie.stay_id = g.stay_id
AND g.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR)
AND g.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
)
SELECT
ie.subject_id
Expand Down
2 changes: 1 addition & 1 deletion mimic-iv/concepts_postgres/postgres-functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- ???(column) -> PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY column) (not sure how to do median in BQ)

-- Set the search_path so all functions are generated on the mimiciv_derived schema
SET search_path TO mimiciv_derived, mimiciv_core, mimiciv_hosp, mimiciv_icu, mimiciv_ed;
SET search_path TO mimiciv_derived, mimiciv_hosp, mimiciv_icu, mimiciv_ed;

CREATE OR REPLACE FUNCTION REGEXP_EXTRACT(str TEXT, pattern TEXT) RETURNS TEXT AS $$
BEGIN
Expand Down
5 changes: 2 additions & 3 deletions mimic-iv/concepts_postgres/postgres-make-concepts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

-- NOTE: many scripts *require* you to use mimic_derived as the schema for outputting concepts
-- change the search path at your peril!
SET search_path TO mimiciv_derived, mimiciv_core, mimiciv_hosp, mimiciv_icu, mimiciv_ed;
SET search_path TO mimiciv_derived, mimiciv_hosp, mimiciv_icu, mimiciv_ed;

-- dependencies
\i demographics/icustay_times.sql
Expand All @@ -32,7 +32,6 @@ SET search_path TO mimiciv_derived, mimiciv_core, mimiciv_hosp, mimiciv_icu, mim
\i measurement/coagulation.sql
\i measurement/complete_blood_count.sql
\i measurement/creatinine_baseline.sql
\i measurement/differential_detailed.sql
\i measurement/enzyme.sql
\i measurement/gcs.sql
\i measurement/height.sql
Expand Down Expand Up @@ -65,8 +64,8 @@ SET search_path TO mimiciv_derived, mimiciv_core, mimiciv_hosp, mimiciv_icu, mim
\i treatment/ventilation.sql

-- firstday
\i firstday/first_day_bg.sql
\i firstday/first_day_bg_art.sql
\i firstday/first_day_bg.sql
\i firstday/first_day_gcs.sql
\i firstday/first_day_height.sql
\i firstday/first_day_lab.sql
Expand Down
8 changes: 7 additions & 1 deletion mimic-iv/concepts_postgres/sepsis/suspicion_of_infection.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ WITH ab_tbl AS
, CAST(MAX(chartdate) AS DATE) AS chartdate
, MAX(charttime) AS charttime
, MAX(spec_type_desc) AS spec_type_desc
, max(case when org_name is not null and org_name != '' then 1 else 0 end) as PositiveCulture
-- identify negative cultures as NULL organism or a specific itemid saying "NEGATIVE"
, MAX(
CASE WHEN org_name IS NOT NULL
AND org_itemid != 90856
AND org_name != ''
THEN 1 ELSE 0
END) as PositiveCulture
from mimiciv_hosp.microbiologyevents
group by micro_specimen_id
)
Expand Down

0 comments on commit 5e05342

Please # to comment.