Skip to content

Instantly share code, notes, and snippets.

@docsteveharris
Created June 15, 2017 13:04
Show Gist options
  • Save docsteveharris/9d99a0ee431fd5fa17c1289e46f5bfb6 to your computer and use it in GitHub Desktop.
Save docsteveharris/9d99a0ee431fd5fa17c1289e46f5bfb6 to your computer and use it in GitHub Desktop.
skeleton for working out ICNARC acute physiology score
-
fname: icnarc_score
sqltype: tinyint
varlab: ICNARC acute physiology score
derived: True
derived_missing_ok: True
primaryfields:
- hrate
- bpsys
- temperature
- rrate
- pao2
- abgfio2
- rxfio2
- ph
- urea
- creatinine
- sodium
- urine_vol
- urine_period
- v_timestamp
- wcc
- gcst
code:
python: |
# CHANGED: 2013-02-08 - since rxfio2 is now an integer code
rxfio2_dict = {0:'r', 1:'w', 2:'v', 3:'b', 4:'c', 5:'n', 6:'p', 7:'o'}
if rxfio2 in rxfio2_dict:
rxfio2 = rxfio2_dict[rxfio2]
else:
rxfio2 = ''
# derive intermediate vars uvol24 and pf
if urine_period is not None and v_timestamp is not None and urine_vol is not None:
if urine_period in [1, 2, 3]:
uvol24 = urine_vol / {1:1,2:6, 3:12}[urine_period] * 24
elif urine_period == 4 and v_timestamp.hour != 0:
uvol24 = urine_vol / v_timestamp.hour * 24
else:
uvol24 = None
if (pao2 is not None) and (abgfio2 is not None):
# ensure that one var is float else get integer division in python 2.x
pf = round(float(pao2) * 7.6 / abgfio2 * 100)
else:
pf = None
i = 0
# heart rate
if hrate is None:
pass
elif hrate <= 39:
i += 14
elif hrate >= 140:
i += 3
elif hrate >= 120:
i += 2
elif hrate >= 110:
i += 1
# systolic bp
if bpsys is None:
pass
elif bpsys <= 49:
i += 15
elif bpsys <=59:
i += 9
elif bpsys <=69:
i += 6
elif bpsys <= 79:
i += 4
elif bpsys <= 99:
i += 2
elif bpsys >= 220:
i += 16
elif bpsys >= 180:
i += 7
# temperature
if temperature is None:
pass
elif temperature <= 33.9:
i += 12
elif temperature <= 35.9:
i += 7
elif temperature <= 38.4:
i += 1
elif temperature >= 41:
i += 5
# respiratory rate
if rrate is None:
pass
elif rrate <= 5:
i += 1
elif rrate >= 25:
i += 5
elif rrate >= 14:
i += 2
elif rrate >= 12:
i += 1
# p:f ratio
if pf is None:
pass
elif pf <= 99 and rxfio2 not in list('cnp'):
i += 6
elif pf <= 199 and rxfio2 not in list('cnp'):
i += 3
elif pf <= 99 and rxfio2 in list('cnp'):
i += 8
elif pf <= 199 and rxfio2 in list('cnp'):
i += 5
elif pf >= 200 and rxfio2 in list('cnp'):
i += 3
# pH
if ph is None:
pass
elif ph <= 7.14:
i += 4
elif ph <= 7.24:
i += 2
elif ph >= 7.5:
i += 4
elif ph >= 7.33:
i += 1
# urea
if urea is None:
pass
elif urea >= 14.4:
i += 5
elif urea >= 7.2:
i += 3
elif urea >= 6.2:
i += 1
# creatinine
if creatinine is None:
pass
elif creatinine > 1.5 * 88.4:
i += 4
elif creatinine > 0.6 * 88.4:
i += 2
# sodium
if sodium is None:
pass
elif sodium <= 129:
i += 4
elif sodium >= 160:
i += 8
elif sodium >= 155:
i += 7
elif sodium >= 150:
i += 4
# urine volume
if uvol24 is None:
pass
elif uvol24 <= 399:
i += 7
elif uvol24 <= 599:
i += 6
elif uvol24 <= 899:
i += 5
elif uvol24 <= 1499:
i += 3
elif uvol24 <= 1999:
i += 1
# white cell count
if wcc is None:
pass
elif wcc <= 0.9:
i += 6
elif wcc <= 2.9:
i += 3
elif wcc >= 40:
i += 4
elif wcc >= 15:
i += 2
# gcs
if gcst is None:
pass
elif gcst <= 3:
i += 11
elif gcst <=4:
i += 9
elif gcst <= 5:
i += 6
elif gcst <= 6:
i += 4
elif gcst <= 13:
i += 2
elif gcst <= 14:
i += 1
derived_var = i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment