-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implementation of fluid balance
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
mimic-iv/concepts_postgres/measurement/daily_fluid_balance.sql
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,16 @@ | ||
DROP TABLE IF EXISTS | ||
mimiciv_derived.daily_fluid_balance | ||
CASCADE; | ||
|
||
CREATE TABLE | ||
mimiciv_derived.daily_fluid_balance AS | ||
SELECT | ||
i.stay_id, | ||
i.infusion_date, | ||
( | ||
i.total_daily_amount - COALESCE(o.total_output, 0) | ||
) as net_balance | ||
FROM | ||
mimiciv_derived.daily_fluid_in AS i | ||
LEFT JOIN mimiciv_derived.daily_fluid_out AS o ON i.stay_id = o.stay_id | ||
AND i.infusion_date = o.day; |
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,18 @@ | ||
DROP TABLE IF EXISTS mimiciv_derived.daily_fluid_in | ||
CASCADE; | ||
CREATE TABLE mimiciv_derived.daily_fluid_in AS | ||
WITH RECURSIVE infusion_days AS | ||
( | ||
SELECT stay_id, | ||
CAST(starttime AS DATE) AS infusion_date, | ||
CASE | ||
WHEN CAST(starttime AS DATE) = CAST(endtime AS DATE) THEN amount | ||
ELSE amount / EXTRACT(EPOCH FROM (endtime - starttime)) / 3600 * (24 - EXTRACT(HOUR FROM starttime)) | ||
END AS daily_amount, | ||
endtime | ||
FROM mimiciv_icu.inputevents | ||
) | ||
SELECT stay_id, infusion_date, SUM(daily_amount) AS total_daily_amount | ||
FROM infusion_days | ||
GROUP BY stay_id, infusion_date | ||
ORDER BY stay_id, infusion_date; |
14 changes: 14 additions & 0 deletions
14
mimic-iv/concepts_postgres/measurement/daily_fluid_out.sql
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,14 @@ | ||
DROP TABLE IF EXISTS mimiciv_derived.daily_fluid_out; | ||
CREATE TABLE mimiciv_derived.daily_fluid_out AS | ||
SELECT | ||
stay_id, | ||
DATE(charttime) as day, | ||
SUM(value) as total_output | ||
FROM | ||
mimiciv_icu.outputevents | ||
GROUP BY | ||
stay_id, | ||
day | ||
ORDER BY | ||
stay_id, | ||
day; |