Skip to content

Commit

Permalink
add neuroblock to eICU
Browse files Browse the repository at this point in the history
  • Loading branch information
alistairewj committed Aug 24, 2018
1 parent c88c390 commit e923d62
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 24 deletions.
35 changes: 32 additions & 3 deletions eicu/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
See eicu-sepsis-prompt for queries to get pivoted tables.
See eicu-northwell for ventilation queries.
Run pivot queries:

```sql
\i ../eicu-code/concepts/pivoted/pivoted-bg.sql
\i ../eicu-code/concepts/pivoted/pivoted-infusion.sql
\i ../eicu-code/concepts/pivoted/pivoted-lab.sql
\i ../eicu-code/concepts/pivoted/pivoted-med.sql
\i ../eicu-code/concepts/pivoted/pivoted-o2.sql
\i ../eicu-code/concepts/pivoted/pivoted-score.sql
\i ../eicu-code/concepts/pivoted/pivoted-treatment-vasopressor.sql
\i ../eicu-code/concepts/pivoted/pivoted-uo.sql
\i ../eicu-code/concepts/pivoted/pivoted-vital-other.sql
\i ../eicu-code/concepts/pivoted/pivoted-vital.sql
\i ../eicu-code/concepts/neuroblock.sql
```

Run ventilation queries:

```sql
\cd ../eicu-northwell/vent
\i pivoted-vent-rc.sql
\i pivoted-vent-nc.sql
\i load-labels-od.sql
\i load-labels-vm.sql
\cd ../ventduration
\i vent-events.sql
\i ventilation-durations.sql
\cd ../../mechanical-power/eicu
```

Above generates the needed `ventevents` and `ventdurations` tables.

Afterwards, run:

```sql
\i vent-durations.sql
\i hospitals-with-vent-data.sql
\i cohort.sql
\i demographics.sql
Expand All @@ -15,6 +43,7 @@ Afterwards, run:
\i during-vent/meds-daily.sql
\i during-vent/vitals-daily.sql
\i during-vent/vent-daily.sql
\i during-vent/neuroblock-daily.sql
-- other queries
\i sofa.sql
\i oasis.sql
Expand Down
4 changes: 2 additions & 2 deletions eicu/cohort.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ with pt as
, pt.uniquepid
, pt.hospitalid
, hospitaladmitoffset
, hospitaladmityear, hospitaldischargeyear
, hospitaldischargeyear
, case when pt.age = '' then null
else REPLACE(age, '>','')
end::INT as age
Expand All @@ -32,7 +32,7 @@ with pt as
(
PARTITION BY uniquepid
ORDER BY
hospitaladmityear, hospitaldischargeyear
hospitaldischargeyear
, age
, patienthealthsystemstayid -- this is temporally random but deterministic
, hospitaladmitoffset
Expand Down
8 changes: 7 additions & 1 deletion eicu/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ select
, med.vasopressin_day1
, med.milrinone_day1) as vasopressor_day1

-- only trustworthy for some hospitals, see analysis folder
, nb.neuroblock_day1
, nb.neuroblock_day2

-- VENT DATA
, v.meanairwaypressure_min_day1
, v.peakpressure_min_day1
Expand Down Expand Up @@ -272,4 +276,6 @@ left join mp_oasis oa
left join mp_charlson ch
on pt.patientunitstayid = ch.patientunitstayid
left join mp_codestatus cs
on pt.patientunitstayid = cs.patientunitstayid;
on pt.patientunitstayid = cs.patientunitstayid
left join mp_neuroblock nb
on pt.patientunitstayid = nb.patientunitstayid;
47 changes: 47 additions & 0 deletions eicu/debug/check-hospital-has-neuroblock-doc.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-- This query subselects hospitals with sufficient ventilation data
-- It cross-checks with APACHE IVa to ensure reliable recording
-- DROP TABLE IF EXISTS mp_hospitals_with_vent_data CASCADE;
-- CREATE TABLE mp_hospitals_with_vent_data AS
with has_vent as
(
select
distinct p.patientunitstayid
FROM vent_unpivot_rc p
-- only include settings before 24 hours
WHERE p.chartoffset <= 24*60
AND p.peakpressure IS NOT NULL
)
, pt_in_hosp as
(
select pt.hospitalid
, sum(neuroblock_day1) as num_neurblock
, sum(case when v.patientunitstayid is not null then 1 else 0 end) as num_vent
, sum(case when v.patientunitstayid is not null and neuroblock_day1 = 1 then 1 else 0 end) as num_vent_and_nb
, count(pt.patientunitstayid) as num_pat_total
from patient pt
inner join mp_neuroblock nb
on pt.patientunitstayid = nb.patientunitstayid
left join has_vent v
on pt.patientunitstayid = v.patientunitstayid
group by pt.hospitalid
)
, hosp_in_cohort as
(
select distinct hospitalid
from mp_cohort
where exclusion_no_peak_pressure = 0
)
select
h.*
, ROUND(100.0*num_vent::NUMERIC/num_pat_total,2) as frac_vent
, ROUND(100.0*num_neurblock::NUMERIC/num_pat_total,2) as frac_nb
, ROUND(100.0*num_vent_and_nb::NUMERIC/num_pat_total,2) as frac_vent_and_nb
, ROUND(100.0*num_vent_and_nb::NUMERIC/num_vent,2) as frac_vent_with_nb
, case when co.hospitalid is not null then 1 else 0 end as hospital_included
from pt_in_hosp h
LEFT JOIN hosp_in_cohort co
ON h.hospitalid = co.hospitalid
-- at least 10 patients in the hospital
WHERE num_pat_total >= 10
AND co.hospitalid is not null
ORDER BY frac_nb DESC;
36 changes: 36 additions & 0 deletions eicu/during-vent/neuroblock-daily.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
DROP TABLE IF EXISTS public.mp_neuroblock CASCADE;
CREATE TABLE public.mp_neuroblock as
-- day 1
with vw1 as
(
select p.patientunitstayid
, 1 as neuroblock
from neuroblock p
INNER JOIN mp_cohort co
ON p.patientunitstayid = co.patientunitstayid
and p.chartoffset > co.startoffset + (-1*60)
and p.chartoffset <= co.startoffset + (24*60)
group by p.patientunitstayid
)
-- day 2
, vw2 as
(
select p.patientunitstayid
, 1 as neuroblock
from neuroblock p
INNER JOIN mp_cohort co
ON p.patientunitstayid = co.patientunitstayid
and p.chartoffset > co.startoffset + (24*60)
and p.chartoffset <= co.startoffset + (48*60)
group by p.patientunitstayid
)
select
pat.patientunitstayid
, COALESCE(vw1.neuroblock,0) as neuroblock_day1
, COALESCE(vw2.neuroblock,0) as neuroblock_day2
from patient pat
left join vw1
on pat.patientunitstayid = vw1.patientunitstayid
left join vw2
on pat.patientunitstayid = vw2.patientunitstayid
order by pat.patientunitstayid;
26 changes: 14 additions & 12 deletions eicu/during-vent/vitals-daily.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ with vw1 as
select p.patientunitstayid
, min(heartrate) as heartrate_min
, max(heartrate) as heartrate_max
, min(coalesce(map,ibp_mean,nibp_mean)) as map_min
, max(coalesce(map,ibp_mean,nibp_mean)) as map_max
, min(coalesce(ibp_mean,nibp_mean)) as map_min
, max(coalesce(ibp_mean,nibp_mean)) as map_max
, min(temperature) as temperature_min
, max(temperature) as temperature_max
, min(o2saturation) as spo2_min
, max(o2saturation) as spo2_max
, min(spo2) as spo2_min
, max(spo2) as spo2_max
from pivoted_vital p
INNER JOIN mp_cohort co
ON p.patientunitstayid = co.patientunitstayid
and p.chartoffset > co.startoffset + (-1*60)
and p.chartoffset <= co.startoffset + (24*60)
WHERE heartrate IS NOT NULL
OR map IS NOT NULL
OR ibp_mean IS NOT NULL
OR nibp_mean IS NOT NULL
OR temperature IS NOT NULL
OR o2saturation IS NOT NULL
OR spo2 IS NOT NULL
group by p.patientunitstayid
)
-- day 2
Expand All @@ -29,21 +30,22 @@ with vw1 as
select p.patientunitstayid
, min(heartrate) as heartrate_min
, max(heartrate) as heartrate_max
, min(coalesce(map,ibp_mean,nibp_mean)) as map_min
, max(coalesce(map,ibp_mean,nibp_mean)) as map_max
, min(coalesce(ibp_mean,nibp_mean)) as map_min
, max(coalesce(ibp_mean,nibp_mean)) as map_max
, min(temperature) as temperature_min
, max(temperature) as temperature_max
, min(o2saturation) as spo2_min
, max(o2saturation) as spo2_max
, min(spo2) as spo2_min
, max(spo2) as spo2_max
from pivoted_vital p
INNER JOIN mp_cohort co
ON p.patientunitstayid = co.patientunitstayid
and p.chartoffset > co.startoffset + (24*60)
and p.chartoffset <= co.startoffset + (48*60)
WHERE heartrate IS NOT NULL
OR map IS NOT NULL
OR ibp_mean IS NOT NULL
OR nibp_mean IS NOT NULL
OR temperature IS NOT NULL
OR o2saturation IS NOT NULL
OR spo2 IS NOT NULL
group by p.patientunitstayid
)
select
Expand Down
13 changes: 7 additions & 6 deletions eicu/sofa.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,22 @@ with la as
select p.patientunitstayid
, min(heartrate) as heartrate_min_day1
, max(heartrate) as heartrate_max_day1
, min(coalesce(map,ibp_mean,nibp_mean)) as map_min_day1
, max(coalesce(map,ibp_mean,nibp_mean)) as map_max_day1
, min(coalesce(ibp_mean,nibp_mean)) as map_min_day1
, max(coalesce(ibp_mean,nibp_mean)) as map_max_day1
, min(temperature) as temperature_min_day1
, max(temperature) as temperature_max_day1
, min(o2saturation) as spo2_min_day1
, max(o2saturation) as spo2_max_day1
, min(spo2) as spo2_min_day1
, max(spo2) as spo2_max_day1
from pivoted_vital p
INNER JOIN mp_cohort co
ON p.patientunitstayid = co.patientunitstayid
and p.chartoffset > co.admitoffset + (-1*60)
and p.chartoffset <= co.admitoffset + (24*60)
WHERE heartrate IS NOT NULL
OR map IS NOT NULL
OR ibp_mean IS NOT NULL
OR nibp_mean IS NOT NULL
OR temperature IS NOT NULL
OR o2saturation IS NOT NULL
OR spo2 IS NOT NULL
group by p.patientunitstayid
)
-- calculate SOFA
Expand Down

0 comments on commit e923d62

Please sign in to comment.