Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daily fluid balance implementation #1714

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions mimic-iv/concepts_postgres/measurement/daily_fluid_balance.sql
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;
19 changes: 19 additions & 0 deletions mimic-iv/concepts_postgres/measurement/daily_fluid_in.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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
WHERE amountuom = 'ml'
)
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 mimic-iv/concepts_postgres/measurement/daily_fluid_out.sql
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;
Loading