Skip to content

Commit 5e05342

Browse files
authored
Merge pull request #1468 from schu/schu/update-mimic-iv-concepts-postgres
concepts_postgres: updates (on top of `mimiciv_v2.2_updates`)
2 parents 4b28df1 + 03107d4 commit 5e05342

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

mimic-iv/concepts/convert_bigquery_to_postgres.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ echo "\echo 'The scripts drop views before creating them, and these notices indi
2929
echo "\echo '==='" >> $TARGET_PATH/postgres-make-concepts.sql
3030
echo "\echo ''" >> $TARGET_PATH/postgres-make-concepts.sql
3131

32+
echo >> $TARGET_PATH/postgres-make-concepts.sql
33+
echo "-- Set the search_path, i.e. the location at which we generate tables." >> $TARGET_PATH/postgres-make-concepts.sql
34+
echo "-- postgres looks at schemas sequentially, so this will generate tables on the mimiciv_derived schema" >> $TARGET_PATH/postgres-make-concepts.sql
35+
echo >> $TARGET_PATH/postgres-make-concepts.sql
36+
echo "-- NOTE: many scripts *require* you to use mimic_derived as the schema for outputting concepts" >> $TARGET_PATH/postgres-make-concepts.sql
37+
echo "-- change the search path at your peril!" >> $TARGET_PATH/postgres-make-concepts.sql
38+
echo "SET search_path TO mimiciv_derived, mimiciv_hosp, mimiciv_icu, mimiciv_ed;" >> $TARGET_PATH/postgres-make-concepts.sql
39+
3240
# reporting to stdout the folder being run
3341
echo -n "Dependencies:"
3442

mimic-iv/concepts_postgres/firstday/first_day_gcs.sql

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,25 @@ DROP TABLE IF EXISTS first_day_gcs; CREATE TABLE first_day_gcs AS
1515
WITH gcs_final AS
1616
(
1717
SELECT
18-
gcs.*
18+
ie.subject_id, ie.stay_id
19+
, g.gcs
20+
, g.gcs_motor
21+
, g.gcs_verbal
22+
, g.gcs_eyes
23+
, g.gcs_unable
1924
-- This sorts the data by GCS
2025
-- rn = 1 is the the lowest total GCS value
2126
, ROW_NUMBER () OVER
2227
(
23-
PARTITION BY gcs.stay_id
24-
ORDER BY gcs.GCS
28+
PARTITION BY g.stay_id
29+
ORDER BY g.GCS
2530
) as gcs_seq
26-
FROM mimiciv_derived.gcs gcs
31+
FROM mimiciv_icu.icustays ie
32+
-- Only get data for the first 24 hours
33+
LEFT JOIN mimiciv_derived.gcs g
34+
ON ie.stay_id = g.stay_id
35+
AND g.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR)
36+
AND g.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
2737
)
2838
SELECT
2939
ie.subject_id

mimic-iv/concepts_postgres/postgres-functions.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-- ???(column) -> PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY column) (not sure how to do median in BQ)
44

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

88
CREATE OR REPLACE FUNCTION REGEXP_EXTRACT(str TEXT, pattern TEXT) RETURNS TEXT AS $$
99
BEGIN

mimic-iv/concepts_postgres/postgres-make-concepts.sql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

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

1616
-- dependencies
1717
\i demographics/icustay_times.sql
@@ -32,7 +32,6 @@ SET search_path TO mimiciv_derived, mimiciv_core, mimiciv_hosp, mimiciv_icu, mim
3232
\i measurement/coagulation.sql
3333
\i measurement/complete_blood_count.sql
3434
\i measurement/creatinine_baseline.sql
35-
\i measurement/differential_detailed.sql
3635
\i measurement/enzyme.sql
3736
\i measurement/gcs.sql
3837
\i measurement/height.sql
@@ -65,8 +64,8 @@ SET search_path TO mimiciv_derived, mimiciv_core, mimiciv_hosp, mimiciv_icu, mim
6564
\i treatment/ventilation.sql
6665

6766
-- firstday
68-
\i firstday/first_day_bg.sql
6967
\i firstday/first_day_bg_art.sql
68+
\i firstday/first_day_bg.sql
7069
\i firstday/first_day_gcs.sql
7170
\i firstday/first_day_height.sql
7271
\i firstday/first_day_lab.sql

mimic-iv/concepts_postgres/sepsis/suspicion_of_infection.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ WITH ab_tbl AS
2929
, CAST(MAX(chartdate) AS DATE) AS chartdate
3030
, MAX(charttime) AS charttime
3131
, MAX(spec_type_desc) AS spec_type_desc
32-
, max(case when org_name is not null and org_name != '' then 1 else 0 end) as PositiveCulture
32+
-- identify negative cultures as NULL organism or a specific itemid saying "NEGATIVE"
33+
, MAX(
34+
CASE WHEN org_name IS NOT NULL
35+
AND org_itemid != 90856
36+
AND org_name != ''
37+
THEN 1 ELSE 0
38+
END) as PositiveCulture
3339
from mimiciv_hosp.microbiologyevents
3440
group by micro_specimen_id
3541
)

0 commit comments

Comments
 (0)