eICU Collaborative Research Database

Notebook 2: Demographics and severity of illness in a single patient

The aim of this notebook is to introduce high level admission details relating to a single patient stay, using the following tables:

  • patient
  • admissiondx
  • apacheapsvar
  • apachepredvar
  • apachepatientresult

Before starting, you will need to copy the eicu demo database file ('eicu_demo.sqlite3') to the data directory.

Documentation on the eICU Collaborative Research Database can be found at: http://eicu-crd.mit.edu/.

1. Getting set up


In [ ]:
# Import libraries
import pandas as pd
import matplotlib.pyplot as plt
import psycopg2
import os

In [ ]:
# Plot settings
%matplotlib inline
plt.style.use('ggplot')
fontsize = 20 # size for x and y ticks
plt.rcParams['legend.fontsize'] = fontsize
plt.rcParams.update({'font.size': fontsize})

In [ ]:
# Connect to the database - which is assumed to be in the current directory
fn = 'eicu_demo.sqlite3'
con = sqlite3.connect(fn)
cur = con.cursor()

2. Display a list of tables


In [ ]:
query = \
"""
SELECT type, name
FROM sqlite_master 
WHERE type='table'
ORDER BY name;
"""

list_of_tables = pd.read_sql_query(query,con)

In [ ]:
list_of_tables

3. Selecting a single patient stay

3.1. The patient table

The patient table includes general information about the patient admissions (for example, demographics, admission and discharge details). See: http://eicu-crd.mit.edu/eicutables/patient/

Questions

Use your knowledge from the previous notebook and the online documentation (http://eicu-crd.mit.edu/) to answer the following questions:

  • Which column in the patient table is distinct for each stay in the ICU (similar to icustay_id in MIMIC-III)?
  • Which column is unique for each patient (similar to subject_id in MIMIC-III)?

In [ ]:
# select a single ICU stay
patientunitstayid = 141296

In [ ]:
# query to load data from the patient table
query = \
"""
SELECT *
FROM patient
WHERE patientunitstayid = {}
""".format(patientunitstayid)

print(query)

In [ ]:
# run the query and assign the output to a variable
patient = pd.read_sql_query(query,con)
patient.head()

In [ ]:
# display a complete list of columns
patient.columns

In [ ]:
# select a limited number of columns to view
columns = ['uniquepid','patientunitstayid','gender','age','unitdischargestatus']
patient[columns]

Questions

  • What year was the patient admitted to the ICU? Which year was he or she discharged?
  • What was the status of the patient upon discharge from the unit?

3.2. The admissiondx table

The admissiondx table contains the primary diagnosis for admission to the ICU according to the APACHE scoring criteria. For more detail, see: http://eicu-crd.mit.edu/eicutables/admissiondx/


In [ ]:
# query to load data from the patient table
query = \
"""
SELECT *
FROM admissiondx
WHERE patientunitstayid = {}
""".format(patientunitstayid)

print(query)

In [ ]:
# run the query and assign the output to a variable
admissiondx = pd.read_sql_query(query,con)
admissiondx.head()

In [ ]:
admissiondx.columns

Questions

  • What was the primary reason for admission?
  • How soon after admission to the ICU was the diagnoses recorded in eCareManager?

3.3. The apacheapsvar table

The apacheapsvar table contains the variables used to calculate the Acute Physiology Score (APS) III for patients. APS-III is an established method of summarizing patient severity of illness on admission to the ICU.

The score is part of the Acute Physiology Age Chronic Health Evaluation (APACHE) system of equations for predicting outcomes for ICU patients. See: http://eicu-crd.mit.edu/eicutables/apacheApsVar/


In [ ]:
# query to load data from the patient table
query = \
"""
SELECT *
FROM apacheapsvar
WHERE patientunitstayid = {}
""".format(patientunitstayid)

print(query)

In [ ]:
# run the query and assign the output to a variable
apacheapsvar = pd.read_sql_query(query,con)
apacheapsvar.head()

In [ ]:
apacheapsvar.columns

Questions

  • What was the 'worst' heart rate recorded for the patient during the scoring period?
  • Was the patient oriented and able to converse normally on the day of admission? (hint: the verbal element refers to the Glasgow Coma Scale).

3.4. The apachepredvar table

The apachepredvar table provides variables underlying the APACHE predictions. Acute Physiology Age Chronic Health Evaluation (APACHE) consists of a groups of equations used for predicting outcomes in critically ill patients. See: http://eicu-crd.mit.edu/eicutables/apachePredVar/


In [ ]:
# query to load data from the patient table
query = \
"""
SELECT *
FROM apachepredvar
WHERE patientunitstayid = {}
""".format(patientunitstayid)

print(query)

In [ ]:
# run the query and assign the output to a variable
apachepredvar = pd.read_sql_query(query,con)
apachepredvar.head()

In [ ]:
apachepredvar.columns

In [ ]:
apachepredvar.ventday1

Questions

  • Was the patient ventilated during (APACHE) day 1 of their stay?
  • Did the patient have diabetes?

3.5. The apachepatientresult table

The apachepatientresult table provides predictions made by the APACHE score (versions IV and IVa), including probability of mortality, length of stay, and ventilation days. See: http://eicu-crd.mit.edu/eicutables/apachePatientResult/


In [ ]:
# query to load data from the patient table
query = \
"""
SELECT *
FROM apachepatientresult
WHERE patientunitstayid = {}
""".format(patientunitstayid)

print(query)

In [ ]:
# run the query and assign the output to a variable
apachepatientresult = pd.read_sql_query(query,con)
apachepatientresult.head()

In [ ]:
apachepatientresult.columns

Questions

  • What versions of the APACHE score are computed?
  • How many days during the stay was the patient ventilated?
  • How long was the patient predicted to stay in hospital?
  • Was this prediction close to the truth?