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/.
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()
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
patient
tableThe patient
table includes general information about the patient admissions (for example, demographics, admission and discharge details). See: http://eicu-crd.mit.edu/eicutables/patient/
Use your knowledge from the previous notebook and the online documentation (http://eicu-crd.mit.edu/) to answer the following questions:
patient
table is distinct for each stay in the ICU (similar to icustay_id
in MIMIC-III)?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]
admissiondx
tableThe 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
apacheapsvar
tableThe 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
apachepredvar
tableThe 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
apachepatientresult
tableThe 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