0
点赞
收藏
分享

微信扫一扫

MIMIC数据库官方SQL查询标注(续)

金穗_ec4b 2022-01-27 阅读 53

说明:
'SOFA’的意思是序贯器官衰竭评分表。
本SQL的目的就是查出计算Sepsis3的相关的资料。
展示了MIMIC查询的一种策略,即在官方SQL的基础上进一步进行查询,本SQL是在SOFA.sql查询和suspicion_of_infection.sql查询结果上的基础上进行的查询。
多条记录变为一条记录的另一种方式。rownumber()over的用法。
在这里插入图片描述


-- Creates a table with "onset" time of Sepsis-3 in the ICU.目的:Sepsis-3形成的时间
-- That is, the **earliest time** at which a patient had SOFA >= 2 and suspicion of infection.
-- As many variables used in SOFA are only collected in the ICU, this query can only
-- define sepsis-3 onset within the ICU.仅限于ICU患者

-- extract rows with SOFA >= 2
-- implicitly this assumes baseline SOFA was 0 before ICU admission.
WITH sofa AS--临时表,是从一个叫做mimic_derived的模块的sofa表格中获取的,算是二次获取
(
  SELECT stay_id
    , starttime, endtime
    , respiration_24hours as respiration--呼吸
    , coagulation_24hours as coagulation--血小板
    , liver_24hours as liver--肝
    , cardiovascular_24hours as cardiovascular--心
    , cns_24hours as cns--神经
    , renal_24hours as renal--肾脏
    , sofa_24hours as sofa_score
  FROM `physionet-data.mimic_derived.sofa`
  WHERE sofa_24hours >= 2
)
, s1 as
(
  SELECT
    soi.subject_id
    , soi.stay_id
    -- suspicion columns
    , soi.ab_id
    , soi.antibiotic
    , soi.antibiotic_time
    , soi.culture_time
    , soi.suspected_infection
    , soi.suspected_infection_time
    , soi.specimen
    , soi.positive_culture
    -- sofa columns
    , starttime, endtime
    , respiration, coagulation, liver, cardiovascular, cns, renal
    , sofa_score
    -- All rows have an associated suspicion of infection event
    -- Therefore, Sepsis-3 is defined as SOFA >= 2.
    -- Implicitly, the baseline SOFA score is assumed to be zero, as we do not know
    -- if the patient has preexisting (acute or chronic) organ dysfunction
    -- before the onset of infection.
    , sofa_score >= 2 and suspected_infection = 1 as sepsis3
    -- subselect to the earliest suspicion/antibiotic/SOFA row
    , ROW_NUMBER() OVER--实现分组功能
    (
        PARTITION BY soi.stay_id--ICU的id,分组的根据, 有多条记录,分组为1,2,3,后面只取了=1的记录
        ORDER BY suspected_infection_time, antibiotic_time, culture_time, endtime--排序
    ) AS rn_sus
  FROM `physionet-data.mimic_derived.suspicion_of_infection` as soi
  INNER JOIN sofa
    ON soi.stay_id = sofa.stay_id
    AND sofa.endtime >= DATETIME_SUB(soi.suspected_infection_time, INTERVAL '48' HOUR)
    AND sofa.endtime <= DATETIME_ADD(soi.suspected_infection_time, INTERVAL '24' HOUR)
  -- only include in-ICU rows
  WHERE soi.stay_id is not null
)
--以下是主查询
SELECT
subject_id, stay_id
-- note: there may be more than one antibiotic given at this time
, antibiotic_time
-- culture times may be dates, rather than times
, culture_time
, suspected_infection_time
-- endtime is latest time at which the SOFA score is valid
, endtime as sofa_time
, sofa_score
, respiration, coagulation, liver, cardiovascular, cns, renal
, sepsis3
FROM s1
WHERE rn_sus = 1--

举报

相关推荐

0 条评论