forked from arnepeine/ventai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vent_parameters.sql
31 lines (25 loc) · 1.02 KB
/
vent_parameters.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
DROP MATERIALIZED VIEW IF EXISTS ventparameters;
CREATE MATERIALIZED VIEW ventparameters AS
with ce as (
select
ce.icustay_id, ce.subject_id, ce.hadm_id, ce.charttime
, (case when itemid in (60,437,505,506,686,220339,224700) THEN valuenum else null end) as PEEP -- PEEP
, (case when itemid in (639, 654, 681, 682, 683, 684,224685,224684,224686) THEN valuenum else null end) as tidal_volume -- tidal volume
, (case when itemid in (543) THEN valuenum else null end) as plateau_pressure -- PlateauPressure
FROM mimiciii.chartevents ce
WHERE ce.value is not null
-- exclude rows marked as error
AND ce.error IS DISTINCT FROM 1
AND ce.itemid in
(60,437,505,506,686,220339,224700, -- PEEP
639, 654, 681, 682, 683, 684,224685,224684,224686, -- tidal volume
543 -- PlateauPressure
)
)
SELECT icustay_id, subject_id, hadm_id, charttime,
avg(PEEP) as PEEP,
avg(tidal_volume) as tidal_volume,
avg(plateau_pressure) as plateau_pressure
FROM ce
GROUP BY icustay_id, subject_id,hadm_id, charttime
ORDER BY icustay_id, charttime