-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapache_new
More file actions
17 lines (13 loc) · 1.93 KB
/
apache_new
File metadata and controls
17 lines (13 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def in_range(l,u,v): return l<=v<=u
def calculate_single_scores(v,s):
r={"abp":[[160,300,4],[130,159,3],[110,129,2],[70,109,0],[50,69,2],[0,49,4]],"temperature":[[41,50,4],[39,40.9,3],[38.5,38.9,1],[36,38.9,0],[34,35.9,1],[32,33.9,2],[30,31.9,3],[19,29.9,4]],"heart_bpm":[[180,300,4],[140,179,3],[110,139,2],[70,109,0],[55,69,2],[40,45,4],[0,49,4]],"respiratory_rate":[[50,100,4],[35,49,3],[25,34,2],[12,24,0],[10,11,1],[6,9,2],[0,5,4]],"oxygenation":[[500,1000,4],[350,499,3],[200,349,2],[70,200,0],[61,70,1],[55,60,3],[0,55,4]],"ph":[[7.7,9.0,4],[7.6,7.69,3],[7.5,7.59,1],[7.33,7.49,0],[7.25,7.32,2],[7.15,7.24,3],[5,7.15,4]],"sodium":[[180,300,4],[160,179,3],[155,159,2],[150,154,1],[130,149,0],[120,129,2],[111,119,3],[50,110,4]],"potassium":[[7,9,4],[6,6.9,3],[5.5,5.9,2],[3.5,5.4,0],[3,3.4,1],[2.5,2.9,2],[2.5,2,4]],"hematocrit":[[60,100,4],[50,59.9,2],[46,49.9,1],[30,45.9,0],[20,29.9,2],[0,20,4]],"wbc":[[40,100,4],[20,39.9,2],[15,19.9,1],[3,14.9,0],[1,2.9,2],[0,1,4]],"age":[[18,44,0],[45,54,2],[55,64,3],[65,74,5],[75,120,6]]}
return next(int(i[2]) for i in r[s] if in_range(i[0],i[1],v))
def calculate_apache2_physiology(*args):
s=list(reversed(["abp","temperature","heart_bpm","respiratory_rate","oxygenation","ph","sodium","potassium","hematocrit","wbc","age"]))
return sum(calculate_single_scores(a,b) for a,b in zip(args,s))
def chronic_health_score(v): return {"RO NSCD":0,"RO SCD":2,"EO NSCD":0,"EO SCD":5,"NO NSCD":0,"NO SCD":5}[v]
def calculate_apache2_final(abp,temp,heart_bpm,resp_rate,oxy,ph,na,k,hema,wbc,age,scd,aki,cr,gcs):
p=calculate_apache2_physiology(abp,temp,heart_bpm,resp_rate,oxy,ph,na,k,hema,wbc,age)+chronic_health_score(scd)
r=([[3.5,30,8],[2,3.4,6],[1.5,1.9,4],[0.6,1.4,0],[0,0.6,4]] if aki else [[3.5,30,4],[2,3.4,3],[1.5,1.9,2],[0.6,1.4,0],[0,0.6,2]])
return p+next(i[2] for i in r if in_range(i[0],i[1],cr))+15-gcs
print(calculate_apache2_final(60,37,90,20,300,7.7,190,7,50,22,44,"NO NSCD",1,7,15)) #28