MIT-LCP / mimic-code

MIMIC Code Repository: Code shared by the research community for the MIMIC family of databases
https://mimic.mit.edu
MIT License
2.43k stars 1.5k forks source link

Question about the firstday sql and postgresql code, About the 6 hours. #1565

Open ljz756245026 opened 1 year ago

ljz756245026 commented 1 year ago

Prerequisites

Description

Description of the issue, including:

I tried to get the firstday vitalsign from MIMIC-IV data. And I saw the official sql and postgresql code. I found that both sql and postgresql code use a 6 Hours.

mimic-code/mimic-iv/concepts/firstday/first_day_vitalsign.sql

mimic-code/mimic-iv/concepts_postgres/firstday/first_day_vitalsign.sql

I see the code like follows:

-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
DROP TABLE IF EXISTS first_day_vitalsign; CREATE TABLE first_day_vitalsign AS
-- This query pivots vital signs and aggregates them
-- for the first 24 hours of a patient's stay.
SELECT
    ie.subject_id
    , ie.stay_id
    , MIN(heart_rate) AS heart_rate_min
    , MAX(heart_rate) AS heart_rate_max
    , AVG(heart_rate) AS heart_rate_mean
    , MIN(sbp) AS sbp_min
    , MAX(sbp) AS sbp_max
    , AVG(sbp) AS sbp_mean
    , MIN(dbp) AS dbp_min
    , MAX(dbp) AS dbp_max
    , AVG(dbp) AS dbp_mean
    , MIN(mbp) AS mbp_min
    , MAX(mbp) AS mbp_max
    , AVG(mbp) AS mbp_mean
    , MIN(resp_rate) AS resp_rate_min
    , MAX(resp_rate) AS resp_rate_max
    , AVG(resp_rate) AS resp_rate_mean
    , MIN(temperature) AS temperature_min
    , MAX(temperature) AS temperature_max
    , AVG(temperature) AS temperature_mean
    , MIN(spo2) AS spo2_min
    , MAX(spo2) AS spo2_max
    , AVG(spo2) AS spo2_mean
    , MIN(glucose) AS glucose_min
    , MAX(glucose) AS glucose_max
    , AVG(glucose) AS glucose_mean
FROM mimiciv_icu.icustays ie
LEFT JOIN mimiciv_derived.vitalsign ce
    ON ie.stay_id = ce.stay_id
        AND ce.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR)
        AND ce.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
GROUP BY ie.subject_id, ie.stay_id;

I do not understand why there is a 6 Hour. Can we write it as follows?

-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS first_day_vitalsign; CREATE TABLE first_day_vitalsign AS -- This query pivots vital signs and aggregates them -- for the first 24 hours of a patient's stay. SELECT ie.subject_id , ie.stay_id , MIN(heart_rate) AS heart_rate_min , MAX(heart_rate) AS heart_rate_max , AVG(heart_rate) AS heart_rate_mean , MIN(sbp) AS sbp_min , MAX(sbp) AS sbp_max , AVG(sbp) AS sbp_mean , MIN(dbp) AS dbp_min , MAX(dbp) AS dbp_max , AVG(dbp) AS dbp_mean , MIN(mbp) AS mbp_min , MAX(mbp) AS mbp_max , AVG(mbp) AS mbp_mean , MIN(resp_rate) AS resp_rate_min , MAX(resp_rate) AS resp_rate_max , AVG(resp_rate) AS resp_rate_mean , MIN(temperature) AS temperature_min , MAX(temperature) AS temperature_max , AVG(temperature) AS temperature_mean , MIN(spo2) AS spo2_min , MAX(spo2) AS spo2_max , AVG(spo2) AS spo2_mean , MIN(glucose) AS glucose_min , MAX(glucose) AS glucose_max , AVG(glucose) AS glucose_mean FROM mimiciv_icu.icustays ie LEFT JOIN mimiciv_derived.vitalsign ce ON ie.stay_id = ce.stay_id AND ce.charttime >= ie.intime AND ce.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) GROUP BY ie.subject_id, ie.stay_id;

mlbernauer commented 1 year ago

I suspect the 6hr buffer is used to ensure that events occurring in the ICU prior to official ICU admission are captured. I.e. to address any sort of administrative lag between when the patient was physically moved to the ICU and when the admission was documented.

alistairewj commented 1 year ago

Yes, absolutely that is your choice. I look 6 hours before ICU admission as the admission time is administrative. For labs, there may be ED labs occurring just before ICU admission, and I wanted to include those in the query. For vital signs, they may have been connected to the monitor just before admission, and I wanted to capture that as well. For consistency I chose 6 hours across all the queries. You could do exactly intime, but I'd just caution that none of those in times are exactly when the patient physically entered the ICU. You can compare it to the time of the first heart rate measurement to see what I mean.

ljz756245026 commented 1 year ago

Thank you for your quick reply. I want to know that whether there is a paper or some medical sources to support the use of 6 hours.

alistairewj commented 1 year ago

You'd be lucky to get that kind of detail in a paper! One of the main contributors to challenges in reproducibility.

Best approach would be to create a histogram of the time between intime and charttime for various common measurements you're interested in, and see what comes out. There isn't much justification for the exact 6 hour number, it was just intuition. Could very well be improved!

ljz756245026 commented 1 year ago

You'd be lucky to get that kind of detail in a paper! One of the main contributors to challenges in reproducibility.

Best approach would be to create a histogram of the time between intime and charttime for various common measurements you're interested in, and see what comes out. There isn't much justification for the exact 6 hour number, it was just intuition. Could very well be improved!

I will appreciate it if you could tell me which paper contains such detail. Thank you!

alistairewj commented 1 year ago

Sorry I wasn't clear. I don't know of any paper which justifies the use of 6 hours.