Skip to content

Commit

Permalink
feat: implementation of fluid balance
Browse files Browse the repository at this point in the history
  • Loading branch information
aegis301 committed Feb 24, 2024
1 parent b9ed7a3 commit 27f75b8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
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;
18 changes: 18 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,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 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;

0 comments on commit 27f75b8

Please sign in to comment.