-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
46 lines (37 loc) · 1.56 KB
/
analysis.py
File metadata and controls
46 lines (37 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# analysis.py
def calculate_risk_score(current_record):
"""
AI-driven Risk Scoring (2026 Standard)
Evaluates physiological stress by correlating multiple vitals.
"""
score = 0
# 1. Oxygen Saturation (SpO2) - Critical Indicator
if current_record['spo2'] < 90: score += 50
elif current_record['spo2'] < 95: score += 20
# 2. Heart Rate (BPM) vs. Stability
if current_record['bpm'] > 120 or current_record['bpm'] < 50: score += 30
elif current_record['bpm'] > 100 or current_record['bpm'] < 60: score += 15
# 3. Heart Rate Variability (HRV) - Autonomic Stress
# 2026 Research: SDNN below 50ms indicates high risk
if current_record['hrv'] < 50: score += 20
elif current_record['hrv'] < 100: score += 10
# 4. Respiratory Rate (RR)
if current_record['rr'] > 25 or current_record['rr'] < 10: score += 15
# Final Percentage (Capped at 100)
risk_percent = min(score, 100)
# Determine Severity Label
if risk_percent >= 75:
level = "CRITICAL"
elif risk_percent >= 40:
level = "WARNING"
else:
level = "STABLE"
return {
"score": risk_percent,
"level": level,
"recommendation": get_recommendation(level)
}
def get_recommendation(level):
if level == "CRITICAL": return "Immediate medical intervention required. Notify ER."
if level == "WARNING": return "Condition deteriorating. Increase monitoring frequency."
return "Patient is stable. Continue routine monitoring."