-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c88c390
commit e923d62
Showing
7 changed files
with
145 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters