Skip to content

Commit 9928c9b

Browse files
committed
fix: gcs now correctly filtered to first 24hr of icu stay
1 parent 8047c9d commit 9928c9b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

mimic-iv/concepts/firstday/first_day_gcs.sql

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@
1313
WITH gcs_final AS
1414
(
1515
SELECT
16-
gcs.*
16+
ie.subject_id, ie.stay_id
17+
, g.gcs
18+
, g.gcs_motor
19+
, g.gcs_verbal
20+
, g.gcs_eyes
21+
, g.gcs_unable
1722
-- This sorts the data by GCS
1823
-- rn = 1 is the the lowest total GCS value
1924
, ROW_NUMBER () OVER
2025
(
21-
PARTITION BY gcs.stay_id
22-
ORDER BY gcs.GCS
26+
PARTITION BY g.stay_id
27+
ORDER BY g.GCS
2328
) as gcs_seq
24-
FROM `physionet-data.mimiciv_derived.gcs` gcs
29+
FROM `physionet-data.mimiciv_icu.icustays` ie
30+
-- Only get data for the first 24 hours
31+
LEFT JOIN `physionet-data.mimiciv_derived.gcs` g
32+
ON ie.stay_id = g.stay_id
33+
AND g.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR)
34+
AND g.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
2535
)
2636
SELECT
2737
ie.subject_id

0 commit comments

Comments
 (0)