broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    rr = x['rr']
    s_rr = 3 if rr <= 8 else 1 if rr <= 11 else 0 if rr <= 20 else 2 if rr <= 24 else 3
    sp = x['spo2']
    if x['scale2']:
        if sp <= 83:
            s_sp = 3
        elif sp <= 85:
            s_sp = 2
        elif sp <= 87:
            s_sp = 1
        elif sp <= 92:
            s_sp = 0
        elif sp <= 94:
            s_sp = 1
        elif sp <= 96:
            s_sp = 2
        else:
            s_sp = 3
    else:
        s_sp = 3 if sp <= 91 else 2 if sp <= 93 else 1 if sp <= 95 else 0
    s_o2 = 2 if x['on_o2'] else 0
    t = Fraction(str(x['temp'])) * 10
    s_t = 3 if t <= 350 else 1 if t <= 360 else 0 if t <= 380 else 1 if t <= 390 else 2
    bp = x['sbp']
    s_bp = 3 if bp <= 90 else 2 if bp <= 100 else 1 if bp <= 110 else 0 if bp <= 219 else 3
    hr = x['hr']
    s_hr = 3 if hr <= 40 else 1 if hr <= 50 else 0 if hr <= 90 else 1 if hr <= 110 else 2 if hr <= 130 else 3
    s_c = 0 if x['avpu'] == 'A' else 3
    parts = [s_rr, s_sp, s_o2, s_t, s_bp, s_hr, s_c]
    total = sum(parts)
    if total >= 7:
        risk = 'HIGH'
    elif total >= 5:
        risk = 'MEDIUM'
    elif 3 in parts:
        risk = 'LOW_MEDIUM'
    else:
        risk = 'LOW'
    return {'score': total, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 71, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.1', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 126, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 89, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 81, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 76, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.3', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 96, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 61, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 72, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 127, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 90, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 82, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 77, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.4', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 97, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 62, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 73, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.3', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 128, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 94, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 91, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 83, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 97, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 78, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.5', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 98, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 63, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 74, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.4', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 129, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 92, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 84, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 79, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.6', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 99, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 64, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.5', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 130, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 88, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 85, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 80, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.7', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22,
    'spo2': 97,
    'on_o2': False,
    'scale2': False,
    'temp': '37.0',
    'sbp': 140,
    'hr': 100,
    'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 65, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    rr = x['rr']
    s_rr = 3 if rr <= 8 else 1 if rr <= 11 else 0 if rr <= 20 else 2 if rr <= 24 else 3
    sp = x['spo2']
    if x['scale2']:
        if sp <= 83:
            s_sp = 3
        elif sp <= 85:
            s_sp = 2
        elif sp <= 87:
            s_sp = 1
        elif not x['on_o2']:
            s_sp = 0
        elif sp <= 94:
            s_sp = 1
        elif sp <= 96:
            s_sp = 2
        else:
            s_sp = 3
    else:
        s_sp = 3 if sp <= 91 else 2 if sp <= 93 else 1 if sp <= 95 else 0
    s_o2 = 2 if x['on_o2'] else 0
    t = Fraction(str(x['temp'])) * 10
    s_t = 3 if t <= 350 else 1 if t <= 360 else 0 if t <= 380 else 1 if t <= 390 else 2
    bp = x['sbp']
    s_bp = 3 if bp <= 90 else 2 if bp <= 100 else 1 if bp <= 110 else 0 if bp <= 219 else 3
    hr = x['hr']
    s_hr = 3 if hr <= 40 else 1 if hr <= 50 else 0 if hr <= 90 else 1 if hr <= 110 else 2 if hr <= 130 else 3
    s_c = 0 if x['avpu'] == 'A' else 3
    parts = [s_rr, s_sp, s_o2, s_t, s_bp, s_hr, s_c]
    total = sum(parts)
    if total >= 7:
        risk = 'HIGH'
    elif total >= 5:
        risk = 'MEDIUM'
    elif 3 in parts:
        risk = 'LOW_MEDIUM'
    else:
        risk = 'LOW'
    return {'score': total, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 71, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.1', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 126, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 89, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 81, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 76, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.3', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 96, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 61, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 72, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 127, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 90, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 82, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 77, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.4', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 97, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 62, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 73, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.3', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 128, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 94, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 91, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 83, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 97, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 78, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.5', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 98, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 63, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 74, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.4', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 129, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 92, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 84, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 79, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.6', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 99, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 64, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.5', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 130, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 88, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 85, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 80, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.7', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22,
    'spo2': 97,
    'on_o2': False,
    'scale2': False,
    'temp': '37.0',
    'sbp': 140,
    'hr': 100,
    'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 65, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A hypercapnic-target patient saturating 95% on room air scores 2 points.

Input {rr, spo2, on_o2, scale2, temp (1 dp), sbp, hr, avpu}. Toy points: RR <=8:3, 9-11:1, 12-20:0, 21-24:2, >=25:3. SpO2 scale 1: <=91:3, 92-93:2, 94-95:1, >=96:0. Scale 2: <=83:3, 84-85:2, 86-87:1, 88-92:0, and >=93 scores 0 on air but on oxygen 93-94:1, 95-96:2, >=97:3. Oxygen +2. Temp <=35.0:3, 35.1-36.0:1, 36.1-38.0:0, 38.1-39.0:1, >=39.1:2. SBP <=90:3, 91-100:2, 101-110:1, 111-219:0, >=220:3. HR <=40:3, 41-50:1, 51-90:0, 91-110:1, 111-130:2, >=131:3. AVPU "A" 0, any other (C new confusion, V, P, U) 3. Risk: total >=7 HIGH, >=5 MEDIUM, else LOW_MEDIUM if any single parameter scores 3, else LOW. Return {score, risk}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    rr = x['rr']
    s_rr = 3 if rr <= 8 else 1 if rr <= 11 else 0 if rr <= 20 else 2 if rr <= 24 else 3
    sp = x['spo2']
    if x['scale2']:
        if sp <= 83:
            s_sp = 3
        elif sp <= 85:
            s_sp = 2
        elif sp <= 87:
            s_sp = 1
        elif sp <= 92 or not x['on_o2']:
            s_sp = 0
        elif sp <= 94:
            s_sp = 1
        elif sp <= 96:
            s_sp = 2
        else:
            s_sp = 3
    else:
        s_sp = 3 if sp <= 91 else 2 if sp <= 93 else 1 if sp <= 95 else 0
    s_o2 = 2 if x['on_o2'] and not x['scale2'] else 0
    t = Fraction(str(x['temp'])) * 10
    s_t = 3 if t <= 350 else 1 if t <= 360 else 0 if t <= 380 else 1 if t <= 390 else 2
    bp = x['sbp']
    s_bp = 3 if bp <= 90 else 2 if bp <= 100 else 1 if bp <= 110 else 0 if bp <= 219 else 3
    hr = x['hr']
    s_hr = 3 if hr <= 40 else 1 if hr <= 50 else 0 if hr <= 90 else 1 if hr <= 110 else 2 if hr <= 130 else 3
    s_c = 0 if x['avpu'] == 'A' else 3
    parts = [s_rr, s_sp, s_o2, s_t, s_bp, s_hr, s_c]
    total = sum(parts)
    if total >= 7:
        risk = 'HIGH'
    elif total >= 5:
        risk = 'MEDIUM'
    elif 3 in parts:
        risk = 'LOW_MEDIUM'
    else:
        risk = 'LOW'
    return {'score': total, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 71, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.1', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 126, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 89, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 81, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 76, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.3', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 96, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 61, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 72, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 127, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 90, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 82, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 77, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.4', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 97, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 62, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 73, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.3', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 128, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 94, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 91, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 83, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 97, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 78, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.5', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 98, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 63, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 74, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.4', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 129, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 92, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 84, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 79, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.6', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 99, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 64, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.5', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 130, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 88, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 85, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 80, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.7', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22,
    'spo2': 97,
    'on_o2': False,
    'scale2': False,
    'temp': '37.0',
    'sbp': 140,
    'hr': 100,
    'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 65, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    rr = x['rr']
    s_rr = 3 if rr <= 8 else 1 if rr <= 11 else 0 if rr <= 20 else 2 if rr <= 24 else 3
    sp = x['spo2']
    if x['scale2']:
        if sp <= 83:
            s_sp = 3
        elif sp <= 85:
            s_sp = 2
        elif sp <= 87:
            s_sp = 1
        elif sp <= 92 or not x['on_o2']:
            s_sp = 0
        elif sp <= 94:
            s_sp = 1
        elif sp <= 96:
            s_sp = 2
        else:
            s_sp = 3
    else:
        s_sp = 3 if sp <= 91 else 2 if sp <= 93 else 1 if sp <= 95 else 0
    s_o2 = 2 if x['on_o2'] and sp < 96 else 0
    t = Fraction(str(x['temp'])) * 10
    s_t = 3 if t <= 350 else 1 if t <= 360 else 0 if t <= 380 else 1 if t <= 390 else 2
    bp = x['sbp']
    s_bp = 3 if bp <= 90 else 2 if bp <= 100 else 1 if bp <= 110 else 0 if bp <= 219 else 3
    hr = x['hr']
    s_hr = 3 if hr <= 40 else 1 if hr <= 50 else 0 if hr <= 90 else 1 if hr <= 110 else 2 if hr <= 130 else 3
    s_c = 0 if x['avpu'] == 'A' else 3
    parts = [s_rr, s_sp, s_o2, s_t, s_bp, s_hr, s_c]
    total = sum(parts)
    if total >= 7:
        risk = 'HIGH'
    elif total >= 5:
        risk = 'MEDIUM'
    elif 3 in parts:
        risk = 'LOW_MEDIUM'
    else:
        risk = 'LOW'
    return {'score': total, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 71, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.1', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 126, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 89, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 81, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 76, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.3', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 96, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 61, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 72, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 127, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 90, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 82, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 77, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.4', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 97, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 62, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 73, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.3', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 128, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 94, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 91, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 83, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 97, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 78, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.5', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 98, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 63, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 74, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.4', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 129, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 92, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 84, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 79, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.6', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 99, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 64, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.5', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 130, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 88, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 85, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 80, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.7', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22,
    'spo2': 97,
    'on_o2': False,
    'scale2': False,
    'temp': '37.0',
    'sbp': 140,
    'hr': 100,
    'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 65, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Scale 2 patients on oxygen do not receive the oxygen points.

Input {rr, spo2, on_o2, scale2, temp (1 dp), sbp, hr, avpu}. Toy points: RR <=8:3, 9-11:1, 12-20:0, 21-24:2, >=25:3. SpO2 scale 1: <=91:3, 92-93:2, 94-95:1, >=96:0. Scale 2: <=83:3, 84-85:2, 86-87:1, 88-92:0, and >=93 scores 0 on air but on oxygen 93-94:1, 95-96:2, >=97:3. Oxygen +2. Temp <=35.0:3, 35.1-36.0:1, 36.1-38.0:0, 38.1-39.0:1, >=39.1:2. SBP <=90:3, 91-100:2, 101-110:1, 111-219:0, >=220:3. HR <=40:3, 41-50:1, 51-90:0, 91-110:1, 111-130:2, >=131:3. AVPU "A" 0, any other (C new confusion, V, P, U) 3. Risk: total >=7 HIGH, >=5 MEDIUM, else LOW_MEDIUM if any single parameter scores 3, else LOW. Return {score, risk}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    rr = x['rr']
    s_rr = 3 if rr <= 8 else 1 if rr <= 11 else 0 if rr <= 20 else 2 if rr <= 24 else 3
    sp = x['spo2']
    if x['scale2']:
        if sp <= 83:
            s_sp = 3
        elif sp <= 85:
            s_sp = 2
        elif sp <= 87:
            s_sp = 1
        elif sp <= 92 or not x['on_o2']:
            s_sp = 0
        elif sp <= 94:
            s_sp = 1
        elif sp <= 96:
            s_sp = 2
        else:
            s_sp = 3
    else:
        s_sp = 3 if sp <= 91 else 2 if sp <= 93 else 1 if sp <= 95 else 0
    s_o2 = 2 if x['on_o2'] else 0
    t = Fraction(str(x['temp'])) * 10
    s_t = 3 if t <= 350 else 1 if t < 360 else 0 if t <= 380 else 1 if t <= 390 else 2
    bp = x['sbp']
    s_bp = 3 if bp <= 90 else 2 if bp <= 100 else 1 if bp <= 110 else 0 if bp <= 219 else 3
    hr = x['hr']
    s_hr = 3 if hr <= 40 else 1 if hr <= 50 else 0 if hr <= 90 else 1 if hr <= 110 else 2 if hr <= 130 else 3
    s_c = 0 if x['avpu'] == 'A' else 3
    parts = [s_rr, s_sp, s_o2, s_t, s_bp, s_hr, s_c]
    total = sum(parts)
    if total >= 7:
        risk = 'HIGH'
    elif total >= 5:
        risk = 'MEDIUM'
    elif 3 in parts:
        risk = 'LOW_MEDIUM'
    else:
        risk = 'LOW'
    return {'score': total, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 71, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.1', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 126, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 89, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 81, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 76, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.3', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 96, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 61, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 72, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 127, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 90, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 82, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 77, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.4', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 97, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 62, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 73, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.3', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 128, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 94, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 91, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 83, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 97, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 78, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.5', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 98, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 63, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 74, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.4', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 129, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 92, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 84, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 79, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.6', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 99, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 64, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.5', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 130, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 88, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 85, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 80, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.7', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22,
    'spo2': 97,
    'on_o2': False,
    'scale2': False,
    'temp': '37.0',
    'sbp': 140,
    'hr': 100,
    'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 65, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    rr = x['rr']
    s_rr = 3 if rr <= 8 else 1 if rr <= 11 else 0 if rr <= 20 else 2 if rr <= 24 else 3
    sp = x['spo2']
    if x['scale2']:
        if sp <= 83:
            s_sp = 3
        elif sp <= 85:
            s_sp = 2
        elif sp <= 87:
            s_sp = 1
        elif sp <= 92 or not x['on_o2']:
            s_sp = 0
        elif sp <= 94:
            s_sp = 1
        elif sp <= 96:
            s_sp = 2
        else:
            s_sp = 3
    else:
        s_sp = 3 if sp <= 91 else 2 if sp <= 93 else 1 if sp <= 95 else 0
    s_o2 = 2 if x['on_o2'] else 0
    t = Fraction(str(x['temp'])) * 10
    s_t = 3 if t <= 350 else 1 if math.floor(t / 10) <= 36 else 0 if t <= 380 else 1 if t <= 390 else 2
    bp = x['sbp']
    s_bp = 3 if bp <= 90 else 2 if bp <= 100 else 1 if bp <= 110 else 0 if bp <= 219 else 3
    hr = x['hr']
    s_hr = 3 if hr <= 40 else 1 if hr <= 50 else 0 if hr <= 90 else 1 if hr <= 110 else 2 if hr <= 130 else 3
    s_c = 0 if x['avpu'] == 'A' else 3
    parts = [s_rr, s_sp, s_o2, s_t, s_bp, s_hr, s_c]
    total = sum(parts)
    if total >= 7:
        risk = 'HIGH'
    elif total >= 5:
        risk = 'MEDIUM'
    elif 3 in parts:
        risk = 'LOW_MEDIUM'
    else:
        risk = 'LOW'
    return {'score': total, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 71, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.1', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 126, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 89, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 81, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 76, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.3', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 96, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 61, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 72, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 127, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 90, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 82, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 77, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.4', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 97, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 62, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 73, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.3', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 128, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 94, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 91, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 83, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 97, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 78, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.5', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 98, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 63, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 74, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.4', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 129, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 92, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 84, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 79, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.6', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 99, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 64, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.5', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 130, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 88, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 85, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 80, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.7', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22,
    'spo2': 97,
    'on_o2': False,
    'scale2': False,
    'temp': '37.0',
    'sbp': 140,
    'hr': 100,
    'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 65, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A temperature of exactly 36.0 scores 0 instead of 1.

Input {rr, spo2, on_o2, scale2, temp (1 dp), sbp, hr, avpu}. Toy points: RR <=8:3, 9-11:1, 12-20:0, 21-24:2, >=25:3. SpO2 scale 1: <=91:3, 92-93:2, 94-95:1, >=96:0. Scale 2: <=83:3, 84-85:2, 86-87:1, 88-92:0, and >=93 scores 0 on air but on oxygen 93-94:1, 95-96:2, >=97:3. Oxygen +2. Temp <=35.0:3, 35.1-36.0:1, 36.1-38.0:0, 38.1-39.0:1, >=39.1:2. SBP <=90:3, 91-100:2, 101-110:1, 111-219:0, >=220:3. HR <=40:3, 41-50:1, 51-90:0, 91-110:1, 111-130:2, >=131:3. AVPU "A" 0, any other (C new confusion, V, P, U) 3. Risk: total >=7 HIGH, >=5 MEDIUM, else LOW_MEDIUM if any single parameter scores 3, else LOW. Return {score, risk}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    rr = x['rr']
    s_rr = 3 if rr <= 8 else 1 if rr <= 11 else 0 if rr <= 20 else 2 if rr <= 24 else 3
    sp = x['spo2']
    if x['scale2']:
        if sp <= 83:
            s_sp = 3
        elif sp <= 85:
            s_sp = 2
        elif sp <= 87:
            s_sp = 1
        elif sp <= 92 or not x['on_o2']:
            s_sp = 0
        elif sp <= 94:
            s_sp = 1
        elif sp <= 96:
            s_sp = 2
        else:
            s_sp = 3
    else:
        s_sp = 3 if sp <= 91 else 2 if sp <= 93 else 1 if sp <= 95 else 0
    s_o2 = 2 if x['on_o2'] else 0
    t = Fraction(str(x['temp'])) * 10
    s_t = 3 if t <= 350 else 1 if t <= 360 else 0 if t <= 380 else 1 if t <= 390 else 2
    bp = x['sbp']
    s_bp = 3 if bp <= 90 else 2 if bp <= 100 else 1 if bp <= 110 else 0 if bp <= 219 else 3
    hr = x['hr']
    s_hr = 3 if hr <= 40 else 1 if hr <= 50 else 0 if hr <= 90 else 1 if hr <= 110 else 2 if hr <= 130 else 3
    s_c = 0 if x['avpu'] == 'A' else 3
    parts = [s_rr, s_sp, s_o2, s_t, s_bp, s_hr, s_c]
    total = sum(parts)
    if total >= 7:
        risk = 'HIGH'
    elif total >= 5:
        risk = 'MEDIUM'
    elif total >= 3:
        risk = 'LOW_MEDIUM'
    else:
        risk = 'LOW'
    return {'score': total, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 71, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.1', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 126, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 89, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 81, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 76, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.3', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 96, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 61, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 72, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 127, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 90, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 82, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 77, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.4', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 97, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 62, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 73, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.3', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 128, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 94, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 91, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 83, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 97, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 78, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.5', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 98, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 63, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 74, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.4', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 129, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 92, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 84, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 79, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.6', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 99, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 64, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.5', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 130, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 88, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 85, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 80, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.7', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22,
    'spo2': 97,
    'on_o2': False,
    'scale2': False,
    'temp': '37.0',
    'sbp': 140,
    'hr': 100,
    'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 65, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    rr = x['rr']
    s_rr = 3 if rr <= 8 else 1 if rr <= 11 else 0 if rr <= 20 else 2 if rr <= 24 else 3
    sp = x['spo2']
    if x['scale2']:
        if sp <= 83:
            s_sp = 3
        elif sp <= 85:
            s_sp = 2
        elif sp <= 87:
            s_sp = 1
        elif sp <= 92 or not x['on_o2']:
            s_sp = 0
        elif sp <= 94:
            s_sp = 1
        elif sp <= 96:
            s_sp = 2
        else:
            s_sp = 3
    else:
        s_sp = 3 if sp <= 91 else 2 if sp <= 93 else 1 if sp <= 95 else 0
    s_o2 = 2 if x['on_o2'] else 0
    t = Fraction(str(x['temp'])) * 10
    s_t = 3 if t <= 350 else 1 if t <= 360 else 0 if t <= 380 else 1 if t <= 390 else 2
    bp = x['sbp']
    s_bp = 3 if bp <= 90 else 2 if bp <= 100 else 1 if bp <= 110 else 0 if bp <= 219 else 3
    hr = x['hr']
    s_hr = 3 if hr <= 40 else 1 if hr <= 50 else 0 if hr <= 90 else 1 if hr <= 110 else 2 if hr <= 130 else 3
    s_c = 0 if x['avpu'] == 'A' else 3
    parts = [s_rr, s_sp, s_o2, s_t, s_bp, s_hr, s_c]
    total = sum(parts)
    if total >= 7:
        risk = 'HIGH'
    elif total >= 5:
        risk = 'MEDIUM'
    elif 3 in parts[:-1]:
        risk = 'LOW_MEDIUM'
    else:
        risk = 'LOW'
    return {'score': total, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 71, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.1', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 126, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 89, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 81, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 76, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.3', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 96, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 61, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 72, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 127, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 90, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 82, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 77, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.4', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 97, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 62, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 73, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.3', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 128, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 94, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 91, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 83, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 97, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 78, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.5', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 98, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 63, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 74, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.4', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 129, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 92, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 84, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 79, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.6', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 99, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 64, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.5', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 130, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 88, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 85, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 80, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.7', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22,
    'spo2': 97,
    'on_o2': False,
    'scale2': False,
    'temp': '37.0',
    'sbp': 140,
    'hr': 100,
    'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 65, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A patient with aggregate 3 from two mild abnormalities is flagged as low-medium.

Input {rr, spo2, on_o2, scale2, temp (1 dp), sbp, hr, avpu}. Toy points: RR <=8:3, 9-11:1, 12-20:0, 21-24:2, >=25:3. SpO2 scale 1: <=91:3, 92-93:2, 94-95:1, >=96:0. Scale 2: <=83:3, 84-85:2, 86-87:1, 88-92:0, and >=93 scores 0 on air but on oxygen 93-94:1, 95-96:2, >=97:3. Oxygen +2. Temp <=35.0:3, 35.1-36.0:1, 36.1-38.0:0, 38.1-39.0:1, >=39.1:2. SBP <=90:3, 91-100:2, 101-110:1, 111-219:0, >=220:3. HR <=40:3, 41-50:1, 51-90:0, 91-110:1, 111-130:2, >=131:3. AVPU "A" 0, any other (C new confusion, V, P, U) 3. Risk: total >=7 HIGH, >=5 MEDIUM, else LOW_MEDIUM if any single parameter scores 3, else LOW. Return {score, risk}.

split: open-access