-
Notifications
You must be signed in to change notification settings - Fork 0
/
10_CRRT.sql
40 lines (38 loc) · 1.22 KB
/
10_CRRT.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
DROP TABLE IF EXISTS `mvte-318912.mv.crrt`;
CREATE TABLE `mvte-318912.mv.crrt` AS
WITH crrt_settings AS
(
SELECT ce.stay_id,
ce.charttime,
MIN(ce.itemid) as itemid,
MIN(ce.value) as value,
MIN(ce.valuenum) as valuenum,
max(
CASE
WHEN ce.itemid IN ( 224144, -- Blood Flow (ml/min)
224191 -- Hourly Patient Fluid Removal
) THEN 1
ELSE 0
END ) AS rrt
FROM `physionet-data.mimiciv_icu.chartevents` ce
WHERE ce.value IS NOT NULL and ce.itemid IN (224144, 224191)
AND ce.valuenum IS NOT NULL AND ce.valuenum >0
GROUP BY stay_id,
charttime,
ce.value,
ce.valuenum )
,hr_table AS
(
SELECT crrt_settings.stay_id,
itemid,
value,
charttime,
rrt,
cast(floor(datetime_diff(charttime, intime, minute) / 60) AS int64 ) AS hr
FROM `physionet-data.mimiciv_icu.icustays` icu
INNER JOIN crrt_settings
ON icu.stay_id = crrt_settings.stay_id )
SELECT distinct stay_id,hr,rrt
FROM hr_table
WHERE hr >=0
ORDER BY stay_id, hr