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

Notes from years away from admissions #1750

Open
1 task done
sarahfpoole opened this issue May 14, 2024 · 0 comments
Open
1 task done

Notes from years away from admissions #1750

sarahfpoole opened this issue May 14, 2024 · 0 comments

Comments

@sarahfpoole
Copy link

Prerequisites

Description

Description of the issue, including:

  • what you have tried
  • references to similar issues
  • queries demonstrating your question (if applicable)

I have been working to associate notes with specific admissions. I expect to see some notes available days / weeks outside of the admissions recorded in the 'admissions' table, but I actually see 1000s of notes that are at least 100 days from any recorded admission. I have done some spot checking on about 10 of the rows identified using the below query, and have confirmed that the admissions recorded are far from the CHARTTIME recorded in the note. Could you help me to understand these notes? I see a mix of nursing notes, physician notes, radiology notes, and a handful of others.

WITH
  notes AS (
  SELECT
    ROW_ID,
    SUBJECT_ID,
    CHARTTIME,
    TEXT,
    CATEGORY,
    DESCRIPTION
  FROM
    `physionet-data.mimiciii_notes.noteevents`),
  admissions AS (
  SELECT
    SUBJECT_ID,
    ADMITTIME,
    DISCHTIME,
    EDREGTIME,
    EDOUTTIME,
    ADMISSION_TYPE,
    ADMISSION_LOCATION,
    DISCHARGE_LOCATION
  FROM
    `physionet-data.mimiciii_clinical.admissions`),
  joined AS (
  SELECT
    *
  FROM
    notes
  LEFT JOIN (
    SELECT
      *
    FROM
      admissions)
  USING
    (SUBJECT_ID)),
  inpatient_label AS (
  SELECT
    *,
    CHARTTIME >= ADMITTIME
    AND CHARTTIME <= DISCHTIME AS inpatient_note,
    ABS(DATETIME_DIFF(CHARTTIME, DISCHTIME, DAY)) AS days_from_discharge,
    ABS(DATETIME_DIFF(CHARTTIME, ADMITTIME, DAY)) AS days_from_admit
  FROM
    joined),
  summary AS (
  SELECT
    SUBJECT_ID,
    ROW_ID,
    CHARTTIME,
    CATEGORY,
    DESCRIPTION,
    MAX(inpatient_note) AS any_inpatient_encounter,
    MIN(days_from_discharge) AS min_time_to_discharge,
    MIN(days_from_admit) AS min_time_to_admit
  FROM
    inpatient_label
  WHERE
    CHARTTIME IS NOT NULL
  GROUP BY
    1,
    2,
    3,
    4,
    5)
SELECT
  *
FROM
  summary
WHERE
  NOT any_inpatient_encounter
  AND min_time_to_discharge > 100
  AND min_time_to_admit > 100
ORDER BY
  min_time_to_discharge DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant