broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    u = Fraction(str(x['urea']))
    high_urea = u > 7 if x['urea_unit'] == 'mmol/L' else u > 19
    s = sum([bool(x['confusion']), high_urea, x['rr'] > 30, x['sbp'] < 90 or x['dbp'] <= 60, x['age'] >= 65])
    disp = 'OUTPATIENT' if s <= 1 else 'SHORT_STAY' if s == 2 else 'INPATIENT'
    return {'score': s, 'disposition': disp, 'icu_review': s >= 4}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 31},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '11', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '21', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.1', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 66, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 41},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 81},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 71},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 32},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '12', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '22', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.2', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 67, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 42},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 82},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 72},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 33},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '13', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '23', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.3', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 68, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 43},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 83},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 73},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 34},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '14', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '24', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.4', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 69, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 44},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 84},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 74},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 35},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '15', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '25', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 70, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 45},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 85},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 75},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})]]
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):
    u = Fraction(str(x['urea']))
    high_urea = u > 7 if x['urea_unit'] == 'mmol/L' else u > 19
    s = sum([bool(x['confusion']), high_urea, x['rr'] >= 30 and x['age'] < 65, x['sbp'] < 90 or x['dbp'] <= 60, x['age'] >= 65])
    disp = 'OUTPATIENT' if s <= 1 else 'SHORT_STAY' if s == 2 else 'INPATIENT'
    return {'score': s, 'disposition': disp, 'icu_review': s >= 4}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 31},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '11', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '21', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.1', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 66, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 41},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 81},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 71},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 32},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '12', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '22', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.2', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 67, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 42},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 82},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 72},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 33},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '13', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '23', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.3', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 68, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 43},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 83},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 73},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 34},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '14', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '24', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.4', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 69, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 44},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 84},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 74},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 35},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '15', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '25', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 70, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 45},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 85},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 75},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})]]
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 respiratory rate of exactly 30 is not counted.

Input {confusion, urea, urea_unit ("mmol/L" or "mg/dL" as BUN), rr, sbp, dbp, age}. Toy criteria: confusion; urea > 7 mmol/L or BUN > 19 mg/dL; rr >= 30; sbp < 90 or dbp <= 60; age >= 65. Disposition: 0-1 OUTPATIENT, 2 SHORT_STAY, >=3 INPATIENT; icu_review when score >= 4. Return {score, disposition, icu_review}.

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):
    u = Fraction(str(x['urea']))
    high_urea = u > 7 if x['urea_unit'] == 'mmol/L' else u > 19
    s = sum([bool(x['confusion']), high_urea, x['rr'] >= 30, x['sbp'] < 90 or x['dbp'] <= 60, x['age'] >= 65])
    disp = 'OUTPATIENT' if s < 1 else 'SHORT_STAY' if s == 2 else 'INPATIENT'
    return {'score': s, 'disposition': disp, 'icu_review': s >= 4}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 31},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '11', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '21', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.1', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 66, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 41},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 81},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 71},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 32},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '12', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '22', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.2', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 67, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 42},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 82},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 72},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 33},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '13', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '23', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.3', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 68, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 43},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 83},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 73},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 34},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '14', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '24', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.4', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 69, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 44},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 84},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 74},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 35},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '15', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '25', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 70, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 45},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 85},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 75},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})]]
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):
    u = Fraction(str(x['urea']))
    high_urea = u > 7 if x['urea_unit'] == 'mmol/L' else u > 19
    s = sum([bool(x['confusion']), high_urea, x['rr'] >= 30, x['sbp'] < 90 or x['dbp'] <= 60, x['age'] >= 65])
    disp = 'OUTPATIENT' if s <= 1 and not x['confusion'] else 'SHORT_STAY' if s == 2 else 'INPATIENT'
    return {'score': s, 'disposition': disp, 'icu_review': s >= 4}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 31},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '11', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '21', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.1', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 66, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 41},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 81},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 71},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 32},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '12', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '22', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.2', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 67, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 42},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 82},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 72},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 33},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '13', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '23', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.3', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 68, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 43},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 83},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 73},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 34},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '14', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '24', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.4', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 69, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 44},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 84},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 74},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 35},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '15', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '25', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 70, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 45},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 85},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 75},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})]]
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 one criterion is sent to a short stay.

Input {confusion, urea, urea_unit ("mmol/L" or "mg/dL" as BUN), rr, sbp, dbp, age}. Toy criteria: confusion; urea > 7 mmol/L or BUN > 19 mg/dL; rr >= 30; sbp < 90 or dbp <= 60; age >= 65. Disposition: 0-1 OUTPATIENT, 2 SHORT_STAY, >=3 INPATIENT; icu_review when score >= 4. Return {score, disposition, icu_review}.

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):
    u = Fraction(str(x['urea']))
    high_urea = u > 7 if x['urea_unit'] == 'mmol/L' else u > 19
    s = sum([bool(x['confusion']), high_urea, x['rr'] >= 30, x['sbp'] < 90 or x['dbp'] <= 60, x['age'] >= 65])
    disp = 'OUTPATIENT' if s <= 1 else 'SHORT_STAY' if s == 2 else 'INPATIENT'
    return {'score': s, 'disposition': disp, 'icu_review': s > 4}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 31},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '11', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '21', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.1', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 66, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 41},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 81},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 71},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 32},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '12', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '22', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.2', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 67, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 42},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 82},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 72},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 33},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '13', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '23', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.3', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 68, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 43},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 83},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 73},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 34},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '14', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '24', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.4', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 69, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 44},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 84},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 74},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 35},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '15', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '25', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 70, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 45},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 85},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 75},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})]]
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):
    u = Fraction(str(x['urea']))
    high_urea = u > 7 if x['urea_unit'] == 'mmol/L' else u > 19
    s = sum([bool(x['confusion']), high_urea, x['rr'] >= 30, x['sbp'] < 90 or x['dbp'] <= 60, x['age'] >= 65])
    disp = 'OUTPATIENT' if s <= 1 else 'SHORT_STAY' if s == 2 else 'INPATIENT'
    return {'score': s, 'disposition': disp, 'icu_review': s >= 3}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 31},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '11', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '21', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.1', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 66, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 41},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 81},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 71},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 32},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '12', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '22', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.2', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 67, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 42},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 82},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 72},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 33},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '13', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '23', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.3', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 68, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 43},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 83},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 73},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 34},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '14', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '24', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.4', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 60, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 69, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 64},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 44},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 84},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 74},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})],
 [('healthy control',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 35},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL below threshold',
   {'confusion': False, 'urea': '15', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 70},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('BUN in mg/dL above threshold',
   {'confusion': False, 'urea': '25', 'urea_unit': 'mg/dL', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('urea in mmol/L above threshold',
   {'confusion': False, 'urea': '7.5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 66},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('low diastolic only',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 110, 'dbp': 59, 'age': 50},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('systolic exactly 90',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 90, 'dbp': 70, 'age': 50},
   {'score': 0, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('respiratory rate exactly 30',
   {'confusion': False, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 30, 'sbp': 120, 'dbp': 75, 'age': 65},
   {'score': 2, 'disposition': 'SHORT_STAY', 'icu_review': False}),
  ('single criterion outpatient with confusion',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 20, 'sbp': 120, 'dbp': 75, 'age': 45},
   {'score': 1, 'disposition': 'OUTPATIENT', 'icu_review': False}),
  ('three criteria inpatient',
   {'confusion': True, 'urea': '5', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 85},
   {'score': 3, 'disposition': 'INPATIENT', 'icu_review': False}),
  ('four criteria review',
   {'confusion': True, 'urea': '9', 'urea_unit': 'mmol/L', 'rr': 32, 'sbp': 120, 'dbp': 75, 'age': 75},
   {'score': 4, 'disposition': 'INPATIENT', 'icu_review': True})]]
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 score of 4 is not flagged for intensive review.

Input {confusion, urea, urea_unit ("mmol/L" or "mg/dL" as BUN), rr, sbp, dbp, age}. Toy criteria: confusion; urea > 7 mmol/L or BUN > 19 mg/dL; rr >= 30; sbp < 90 or dbp <= 60; age >= 65. Disposition: 0-1 OUTPATIENT, 2 SHORT_STAY, >=3 INPATIENT; icu_review when score >= 4. Return {score, disposition, icu_review}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    m = x['age_months']
    bands = [(12, 100, 160, 30, 50), (48, 90, 150, 24, 40), (144, 70, 120, 18, 30), (10 ** 6, 60, 100, 12, 20)]
    for lim, hlo, hhi, rlo, rhi in bands:
        if m <= lim:
            break
    dh = max(hlo - x['hr'], x['hr'] - hhi, 0)
    dr = max(rlo - x['rr'], x['rr'] - rhi, 0)
    crt = x['crt_s']
    card = 2 if dh > 20 or crt >= 4 else 1 if dh > 0 or crt == 3 else 0
    o2 = x['o2_lpm']
    resp = 2 if dr > 10 or o2 >= 4 else 1 if dr > 0 or o2 > 0 else 0
    beh = {'playing': 0, 'sleeping': 0, 'irritable': 1, 'lethargic': 3}[x['behavior']]
    total = card + resp + beh
    return {'score': total, 'escalate': total >= 5 or beh == 3}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('school-age control',
   {'age_months': 60, 'hr': 91, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 151, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 84, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 81, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 81, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 52, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 126, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 92, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 152, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 83, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 82, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 82, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 53, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 127, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 93, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 26, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 153, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 82, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 83, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 83, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 54, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 128, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 94, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 154, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 81, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 84, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 84, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 55, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 129, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 95, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 155, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 80, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 85, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 85, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 56, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 130, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})]]
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

N = 1
observations = []
def solve(x):
    m = x['age_months']
    bands = [(12, 100, 160, 30, 50), (48, 90, 150, 24, 40), (144, 70, 120, 18, 30), (10 ** 6, 60, 100, 12, 20)]
    for lim, hlo, hhi, rlo, rhi in bands:
        if m < lim and m > 0:
            break
    dh = max(hlo - x['hr'], x['hr'] - hhi, 0)
    dr = max(rlo - x['rr'], x['rr'] - rhi, 0)
    crt = x['crt_s']
    card = 2 if dh > 20 or crt >= 4 else 1 if dh > 0 or crt == 3 else 0
    o2 = x['o2_lpm']
    resp = 2 if dr > 10 or o2 >= 4 else 1 if dr > 0 or o2 > 0 else 0
    beh = {'playing': 0, 'sleeping': 0, 'irritable': 1, 'lethargic': 3}[x['behavior']]
    total = card + resp + beh
    return {'score': total, 'escalate': total >= 5 or beh == 3}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('school-age control',
   {'age_months': 60, 'hr': 91, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 151, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 84, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 81, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 81, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 52, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 126, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 92, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 152, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 83, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 82, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 82, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 53, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 127, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 93, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 26, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 153, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 82, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 83, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 83, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 54, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 128, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 94, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 154, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 81, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 84, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 84, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 55, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 129, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 95, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 155, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 80, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 85, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 85, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 56, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 130, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})]]
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 child on their first birthday is scored against infant ranges.

Input {age_months, hr, rr, behavior, crt_s, o2_lpm}. Toy normal ranges by age: < 12 months HR 100-160 RR 30-50; 12-47 HR 90-150 RR 24-40; 48-143 HR 70-120 RR 18-30; >= 144 HR 60-100 RR 12-20. Deviation = distance outside the range (0 inside). Cardiovascular: 2 if HR deviation > 20 or refill >= 4 s, 1 if any HR deviation or refill 3 s, else 0. Respiratory: 2 if RR deviation > 10 or oxygen >= 4 L/min, 1 if any RR deviation or any oxygen, else 0. Behaviour: playing/sleeping 0, irritable 1, lethargic 3. escalate when total >= 5 or behaviour scores 3. Return {score, escalate}.

split: open-access