Skip to content

Instantly share code, notes, and snippets.

@tompollard
Last active August 22, 2018 21:29
Show Gist options
  • Save tompollard/d4c216d0c4ad30481c99 to your computer and use it in GitHub Desktop.
Save tompollard/d4c216d0c4ad30481c99 to your computer and use it in GitHub Desktop.
Compute the Oxford Severity of Illness Score (OASIS)
# The MIT License
# Copyright (c) 2015 Tom Pollard
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
def compute_oasis(pd_dataframe):
"""
Takes Pandas DataFrame as an argument and computes Oxford Acute
Severity of Illness Score (OASIS) (http://oasisicu.com/)
The DataFrame should include only measurements taken over the first 24h
from admission. pd_dataframe should contain the following columns:
'prelos' => Pre-ICU length of stay, hours
'age' => Age of patient, years
'GCS_total' => Total Glasgow Coma Scale for patient
'hrate' => All heart rate measurements
'MAP' => All mean arterial blood pressure measurements
'resp_rate' => All respiratory rate measurements
'temp_c' => All temperature measurements, C
'urine' => Total urine output over 24 h (note, not consecutive measurements)
'ventilated' => Is patient ventilated? (y,n)
'admission_type' => Type of admission (elective, urgent, emergency)
Reference:
Johnson AE, Kramer AA, Clifford GD. A new severity of illness scale
using a subset of Acute Physiology And Chronic Health Evaluation
data elements shows comparable predictive accuracy.
Crit Care Med. 2013 Jul;41(7):1711-8. doi: 10.1097/CCM.0b013e31828a24fe
http://www.ncbi.nlm.nih.gov/pubmed/23660729
"""
# 10 variables
oasis_score, oasis_prelos, oasis_age, oasis_gcs, oasis_hr, oasis_map, oasis_resp, \
oasis_temp, oasis_urine, oasis_vent, oasis_surg = 0,0,0,0,0,0,0,0,0,0,0
# Pre-ICU length of stay, hours
for val in pd_dataframe['prelos']:
if val >= 4.95 and val <= 24.0:
oasis_prelos = np.nanmax([0,oasis_prelos])
elif val > 311.8:
oasis_prelos = np.nanmax([1,oasis_prelos])
elif val > 24.0 and val <= 311.8:
oasis_prelos = np.nanmax([2,oasis_prelos])
elif val >= 0.17 and val < 4.95:
oasis_prelos = np.nanmax([3,oasis_prelos])
elif val < 0.17:
oasis_prelos = np.nanmax([5,oasis_prelos])
else:
oasis_prelos = np.nanmax([np.nan,oasis_prelos])
if pd_dataframe['prelos'].isnull().all():
oasis_prelos = np.nan
# Age, years
for val in pd_dataframe['age']:
if val < 24:
oasis_age = np.nanmax([0,oasis_age])
elif val >= 24 and val <= 53:
oasis_age = np.nanmax([3,oasis_age])
elif val > 53 and val <= 77:
oasis_age = np.nanmax([6,oasis_age])
elif val > 77 and val <= 89:
oasis_age = np.nanmax([9,oasis_age])
elif val > 89:
oasis_age = np.nanmax([7,oasis_age])
else:
oasis_age = np.nanmax([np.nan,oasis_age])
if pd_dataframe['age'].isnull().all():
oasis_age = np.nan
# Glasgow Coma Scale
for val in pd_dataframe['GCS_total']:
if val == 15:
oasis_gcs = np.nanmax([0,oasis_gcs])
elif val == 14:
oasis_gcs = np.nanmax([3,oasis_gcs])
elif val >= 8 and val <= 13:
oasis_gcs = np.nanmax([4,oasis_gcs])
elif val >= 3 and val <= 7:
oasis_gcs = np.nanmax([10,oasis_gcs])
else:
oasis_gcs = np.nanmax([np.nan,oasis_gcs])
if pd_dataframe['GCS_total'].isnull().all():
oasis_gcs = np.nan
# Heart rate
for val in pd_dataframe['hrate']:
if val >= 33 and val <= 88:
oasis_hr = np.nanmax([0,oasis_hr])
elif val > 88 and val <= 106:
oasis_hr = np.nanmax([1,oasis_hr])
elif val > 106 and val <= 125:
oasis_hr = np.nanmax([3,oasis_hr])
elif val < 33:
oasis_hr = np.nanmax([4,oasis_hr])
elif val > 125:
oasis_hr = np.nanmax([6,oasis_hr])
else:
oasis_hr = np.nanmax([np.nan,oasis_hr])
if pd_dataframe['hrate'].isnull().all():
oasis_hr = np.nan
# Mean arterial pressure
for val in pd_dataframe['MAP']:
if val >=61.33 and val <= 143.44:
oasis_map = np.nanmax([0,oasis_map])
elif val >= 51.0 and val < 61.33:
oasis_map = np.nanmax([2,oasis_map])
elif (val >= 20.65 and val < 51.0) or (val > 143.44):
oasis_map = np.nanmax([3,oasis_map])
elif val < 20.65:
oasis_map = np.nanmax([4,oasis_map])
else:
oasis_map = np.nanmax([np.nan,oasis_map])
if pd_dataframe['MAP'].isnull().all():
oasis_map = np.nan
# Respiratory Rate
for val in pd_dataframe['resp_rate']:
if val >=13 and val <= 22:
oasis_resp = np.nanmax([0,oasis_resp])
elif (val >= 6 and val <= 12) or (val >= 23 and val <= 30):
oasis_resp = np.nanmax([1,oasis_resp])
elif val > 30 and val <= 44:
oasis_resp = np.nanmax([6,oasis_resp])
elif val > 44:
oasis_resp = np.nanmax([9,oasis_resp])
elif val < 6:
oasis_resp = np.nanmax([10,oasis_resp])
else:
oasis_resp = np.nanmax([np.nan,oasis_resp])
if pd_dataframe['resp_rate'].isnull().all():
oasis_resp = np.nan
# Temperature, C
for val in pd_dataframe['temp_c']:
if val >= 36.40 and val <= 36.88:
oasis_temp = np.nanmax([0,oasis_temp])
elif (val >= 35.94 and val < 36.40) or (val > 36.88 and val <= 39.88):
oasis_temp = np.nanmax([2,oasis_temp])
elif val < 33.22:
oasis_temp = np.nanmax([3,oasis_temp])
elif val >= 33.22 and val < 35.94:
oasis_temp = np.nanmax([4,oasis_temp])
elif val > 39.88:
oasis_temp = np.nanmax([6,oasis_temp])
else:
oasis_temp = np.nanmax([np.nan,oasis_temp])
if pd_dataframe['temp_c'].isnull().all():
oasis_temp = np.nan
# Urine output, cc/day (total over 24h)
val = np.max(pd_dataframe['urine'])
if val >=2544.0 and val <= 6896.0:
oasis_urine = np.nanmax([0,oasis_urine])
elif val >= 1427.0 and val < 2544.0:
oasis_urine = np.nanmax([1,oasis_urine])
elif val >= 671.0 and val < 1427.0:
oasis_urine = np.nanmax([5,oasis_urine])
elif val > 6896.0:
oasis_urine = np.nanmax([8,oasis_urine])
elif val < 671:
oasis_urine = np.nanmax([10,oasis_urine])
else:
oasis_urine = np.nanmax([np.nan,oasis_urine])
if pd_dataframe['urine'].isnull().all():
oasis_urine = np.nan
# Ventilated y/n
for val in pd_dataframe['ventilated']:
if val == 'n':
oasis_vent = np.nanmax([0,oasis_vent])
elif val == 'y':
oasis_vent = np.nanmax([9,oasis_vent])
else:
oasis_vent = np.nanmax([np.nan,oasis_vent])
if pd_dataframe['ventilated'].isnull().all():
oasis_vent = np.nan
# Elective surgery y/n
for val in pd_dataframe['admission_type']:
if val == 'elective':
oasis_surg = np.nanmax([0,oasis_surg])
elif val in ['urgent','emergency']:
oasis_surg = np.nanmax([6,oasis_surg])
else:
oasis_surg = np.nanmax([np.nan,oasis_surg])
if pd_dataframe['admission_type'].isnull().all():
oasis_surg = np.nan
# Return sum
oasis_score = sum([oasis_prelos, oasis_age, oasis_gcs, oasis_hr, oasis_map, oasis_resp, \
oasis_temp, oasis_urine, oasis_vent, oasis_surg])
return oasis_score
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment