Files
ISSSTELEON/Core/core/tea/ados2.py
T
2026-11-26 07:06:53 -06:00

49 lines
2.1 KiB
Python

"""ADOS-2 scoring (pure): the calibrated severity score (CSS) and classification of one
evaluation from its items (core.tea). The total is the sum of the items given, a 3 counting
as 2; an evaluation without items in either domain is not scored."""
from datetime import date
from core import tea
TODDLER_BANDS = {True: (10, 16), False: (8, 14)} # 20 months or younger: (mild, severe) totals
def algorithm(row: dict) -> str | None:
"""Module 1's algorithm, from the items its report prints."""
if row.get("module") != "module_1":
return None
printed = any(row.get(i) is not None for i in tea.FEW_TO_NO_WORDS_ITEMS)
return "few_to_no_words" if printed else "some_words"
def total(row: dict) -> int | None:
def domain(items: list[str]) -> list[int]:
return [min(int(row[i]), 2) for i in items if row.get(i) is not None]
social = domain(tea.SOCIAL_AFFECT_ITEMS)
restricted = domain(tea.RESTRICTED_REPETITIVE_ITEMS)
return sum(social) + sum(restricted) if social and restricted else None
def score(row: dict, birth: date | None) -> tuple[int | None, str | None]:
"""(CSS, classification); (None, None) when it can't be scored."""
found, module = total(row), row.get("module")
if found is None or module is None:
return None, None
months = (row["evaluation_date"] - birth).days / tea.DAYS_PER_MONTH if birth else None
if module == "toddler":
mild, severe = TODDLER_BANDS[months is not None and months <= 20]
band = "severe_concern" if found >= severe else (
"mild_to_moderate_concern" if found >= mild else "non_spectrum") # fmt: skip
return None, band
under_five = months is not None and months < 60
keys = [(module, algorithm(row), under_five), (module, algorithm(row), None),
(module, None, under_five), (module, None, None)] # fmt: skip
cuts = next((tea.ADOS2_CSS[k] for k in keys if k in tea.ADOS2_CSS), None)
if cuts is None:
return None, None
css = 1 + sum(c <= found for c in cuts)
label = next(n for n, below in tea.ADOS2_CLASSIFICATION if below is None or css < below)
return css, label