F7i: A-1 read from the ADOS-2 report; no column fallback
ADOS-2 records without A-1 where the manual needs it (Module 1; Toddler from 21 months) and records whose printed totals differ from their items' totals are held for Revision. The preview shows the same errors.
This commit is contained in:
@@ -5,6 +5,7 @@ import os
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from concurrent.futures import ProcessPoolExecutor
|
from concurrent.futures import ProcessPoolExecutor
|
||||||
|
from datetime import date
|
||||||
from functools import cache
|
from functools import cache
|
||||||
|
|
||||||
import duckdb
|
import duckdb
|
||||||
@@ -20,6 +21,7 @@ from splink.backends.duckdb import DuckDBAPI
|
|||||||
from splink.clustering import cluster_pairwise_predictions_at_threshold
|
from splink.clustering import cluster_pairwise_predictions_at_threshold
|
||||||
|
|
||||||
from core import catalog, concept_map, fhir_in
|
from core import catalog, concept_map, fhir_in
|
||||||
|
from core.measures import as_day
|
||||||
from core.pipeline import (
|
from core.pipeline import (
|
||||||
HELD,
|
HELD,
|
||||||
IDENTIFIERS,
|
IDENTIFIERS,
|
||||||
@@ -43,6 +45,7 @@ from core.pipeline import (
|
|||||||
matches,
|
matches,
|
||||||
validate,
|
validate,
|
||||||
)
|
)
|
||||||
|
from core.tea import ados2
|
||||||
from models.tea.eeg import read
|
from models.tea.eeg import read
|
||||||
from persistance import config_log, files, nodes, silver
|
from persistance import config_log, files, nodes, silver
|
||||||
|
|
||||||
@@ -466,10 +469,23 @@ def run_link(p: str, node: Link):
|
|||||||
return nodes.write(p, f"{node.id}__review", queue)
|
return nodes.write(p, f"{node.id}__review", queue)
|
||||||
|
|
||||||
|
|
||||||
|
def _births(linked) -> dict[str, date]:
|
||||||
|
found: dict[str, date] = {}
|
||||||
|
for row in linked:
|
||||||
|
try:
|
||||||
|
day = as_day(row.get("birth_date"))
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
if day:
|
||||||
|
found[row["person_id"]] = min(day, found.get(row["person_id"], day))
|
||||||
|
return found
|
||||||
|
|
||||||
|
|
||||||
def run_target(p: str, node: Target, kinds: dict[str, str]):
|
def run_target(p: str, node: Target, kinds: dict[str, str]):
|
||||||
link = next(i for i in node.inputs if kinds[i] == "link")
|
link = next(i for i in node.inputs if kinds[i] == "link")
|
||||||
linked = {r[RECORD]: r for r in nodes.rows(p, link)}
|
linked = {r[RECORD]: r for r in nodes.rows(p, link)}
|
||||||
person = {k: r["person_id"] for k, r in linked.items()}
|
person = {k: r["person_id"] for k, r in linked.items()}
|
||||||
|
births = _births(linked.values())
|
||||||
model, study = catalog.model(node.entity), catalog.studies()[node.entity]
|
model, study = catalog.model(node.entity), catalog.studies()[node.entity]
|
||||||
fixed = nodes.corrections()
|
fixed = nodes.corrections()
|
||||||
observations, held_rows = [], []
|
observations, held_rows = [], []
|
||||||
@@ -479,6 +495,8 @@ def run_target(p: str, node: Target, kinds: dict[str, str]):
|
|||||||
values |= {f: v for f, v in fixed.get(row[RECORD], {}).items()
|
values |= {f: v for f, v in fixed.get(row[RECORD], {}).items()
|
||||||
if f in model.model_fields} # fmt: skip
|
if f in model.model_fields} # fmt: skip
|
||||||
held = json.loads(row.get(HELD) or "[]") + validate(node.entity, values)
|
held = json.loads(row.get(HELD) or "[]") + validate(node.entity, values)
|
||||||
|
if node.entity == "ados2":
|
||||||
|
held += ados2.errors(values, births.get(person.get(row[RECORD])))
|
||||||
if row[RECORD] not in person:
|
if row[RECORD] not in person:
|
||||||
held.append("no identity linked to this record")
|
held.append("no identity linked to this record")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -159,6 +159,8 @@ def _report(
|
|||||||
]
|
]
|
||||||
items = {item: _parse(item, row.get(item), "number", warnings) for item in order}
|
items = {item: _parse(item, row.get(item), "number", warnings) for item in order}
|
||||||
css, classification = None, None
|
css, classification = None, None
|
||||||
|
errors = scoring.errors(row | items | {"evaluation_date": evaluation_date}, birth)
|
||||||
|
warnings.extend(errors)
|
||||||
if evaluation_date is None:
|
if evaluation_date is None:
|
||||||
warnings.append("ADOS-2 not scored: no evaluation date")
|
warnings.append("ADOS-2 not scored: no evaluation date")
|
||||||
else:
|
else:
|
||||||
@@ -169,7 +171,7 @@ def _report(
|
|||||||
else:
|
else:
|
||||||
if scored:
|
if scored:
|
||||||
css, classification = scored.css, scored.classification
|
css, classification = scored.css, scored.classification
|
||||||
else:
|
elif not errors:
|
||||||
warnings.append(
|
warnings.append(
|
||||||
"the ADOS-2 score could not be calculated: "
|
"the ADOS-2 score could not be calculated: "
|
||||||
"the report lacks the module or the item scores"
|
"the report lacks the module or the item scores"
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
from datetime import date
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
|
from core.pipeline import HELD, RECORD, Target
|
||||||
|
from core.tea import ados2
|
||||||
|
from core.tea.ados2_items import ITEMS
|
||||||
|
from models.graph import run_target
|
||||||
|
from persistance import nodes, review
|
||||||
|
|
||||||
|
NODE = Target(id="ados2_out", inputs=["reports", "persons"], entity="ados2")
|
||||||
|
KINDS = {"reports": "extract", "persons": "link"}
|
||||||
|
A1_NEEDED = "language_level: A-1 (0 to 4) is needed to score"
|
||||||
|
|
||||||
|
|
||||||
|
def _loaded(module, birth):
|
||||||
|
report = {
|
||||||
|
RECORD: "report",
|
||||||
|
"_index": 0,
|
||||||
|
"evaluation_date": date(2025, 2, 1),
|
||||||
|
"module": module,
|
||||||
|
**{item.field: 1 for item in ITEMS[module]},
|
||||||
|
}
|
||||||
|
nodes.write("tea", "reports", [report])
|
||||||
|
persons = [
|
||||||
|
{RECORD: "report", "person_id": "child", "birth_date": None},
|
||||||
|
{RECORD: "patient", "person_id": "child", "birth_date": birth},
|
||||||
|
]
|
||||||
|
columns = {"birth_date": {"data_type": "text", "nullable": True}}
|
||||||
|
nodes.write("tea", "persons", persons, columns)
|
||||||
|
run_target("tea", NODE, KINDS)
|
||||||
|
|
||||||
|
|
||||||
|
def _held():
|
||||||
|
return [row[HELD] for row in review.held("ados2")]
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_held_record_corrected_with_a1_is_scored(fresh_platform):
|
||||||
|
birth = "2022-08-01"
|
||||||
|
_loaded("module_1", birth)
|
||||||
|
assert _held() == [[A1_NEEDED]]
|
||||||
|
|
||||||
|
nodes.correct("report", "language_level", "3", "reviewer", "ados2")
|
||||||
|
run_target("tea", NODE, KINDS)
|
||||||
|
assert _held() == []
|
||||||
|
with fresh_platform.connect() as con:
|
||||||
|
sql = text("select field, value_num, value_text from bronze.staged__observation")
|
||||||
|
values = {field: num if num is not None else said for field, num, said in con.execute(sql)}
|
||||||
|
scored = ados2.score(values | {"evaluation_date": date(2025, 2, 1)}, date.fromisoformat(birth))
|
||||||
|
assert (scored.column, scored.column_source) == ("few_words", "a1")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"birth, held",
|
||||||
|
[("2023-08-01", []), ("2023-01-01", [[A1_NEEDED]]), (None, [[A1_NEEDED]])],
|
||||||
|
)
|
||||||
|
def test_the_persons_birth_date_says_whether_a_toddler_needs_a1(fresh_platform, birth, held):
|
||||||
|
_loaded("toddler", birth)
|
||||||
|
assert _held() == held
|
||||||
+25
-10
@@ -64,8 +64,7 @@ def test_the_job_deletes_its_files_when_the_study_fails(preview_area):
|
|||||||
assert list(preview_area.iterdir()) == []
|
assert list(preview_area.iterdir()) == []
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("language, css", [(3, 1), (1, 2)])
|
def _preview_report(monkeypatch, *lines):
|
||||||
def test_ados2_preview_reads_language_level_and_scores_its_column(monkeypatch, language, css):
|
|
||||||
node = Extract(
|
node = Extract(
|
||||||
id="ados2",
|
id="ados2",
|
||||||
column="text",
|
column="text",
|
||||||
@@ -76,19 +75,35 @@ def test_ados2_preview_reads_language_level_and_scores_its_column(monkeypatch, l
|
|||||||
"vocalization_directed": r"A-2 (\d)",
|
"vocalization_directed": r"A-2 (\d)",
|
||||||
"intonation": r"A-3 (\d)",
|
"intonation": r"A-3 (\d)",
|
||||||
"stereotyped_language": r"A-5 (\d)",
|
"stereotyped_language": r"A-5 (\d)",
|
||||||
|
"social_affect_total": r"AS (\d+)",
|
||||||
|
"restricted_repetitive_total": r"CRR (\d+)",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
monkeypatch.setattr(
|
text = "\n".join(("Módulo module_1", "A-2 2", "A-3 3", "A-5 3", *lines))
|
||||||
study.graph,
|
monkeypatch.setattr(study.graph, "read_file", lambda _: {"text": text, "error": None})
|
||||||
"read_file",
|
|
||||||
lambda _: {
|
|
||||||
"text": f"Módulo module_1\nA-1 {language}\nA-2 2\nA-3 3\nA-5 3",
|
|
||||||
"error": None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(study.config_log, "get", lambda _: (1, SimpleNamespace(nodes=[node])))
|
monkeypatch.setattr(study.config_log, "get", lambda _: (1, SimpleNamespace(nodes=[node])))
|
||||||
warnings = []
|
warnings = []
|
||||||
result = study._report(b"%PDF", "tea", date(2026, 1, 1), date(2023, 7, 1), warnings)
|
result = study._report(b"%PDF", "tea", date(2026, 1, 1), date(2023, 7, 1), warnings)
|
||||||
|
return result, warnings
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"lines, css, warned",
|
||||||
|
[
|
||||||
|
(("AS 2", "CRR 2"), None, ["language_level: A-1 (0 to 4) is needed to score"]),
|
||||||
|
(("A-1 3", "AS 2", "CRR 2"), 1, []),
|
||||||
|
(("A-1 3", "AS 2", "CRR 3"), 1, ["the printed totals differ from the item scores"]),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_ados2_preview_warns_what_would_hold_the_record(monkeypatch, lines, css, warned):
|
||||||
|
result, warnings = _preview_report(monkeypatch, *lines)
|
||||||
|
assert result.css == css
|
||||||
|
assert warnings == warned
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("language, css", [(3, 1), (1, 2)])
|
||||||
|
def test_ados2_preview_reads_language_level_and_scores_its_column(monkeypatch, language, css):
|
||||||
|
result, warnings = _preview_report(monkeypatch, f"A-1 {language}")
|
||||||
assert result.items["language_level"] == language
|
assert result.items["language_level"] == language
|
||||||
assert next(iter(result.items)) == "language_level"
|
assert next(iter(result.items)) == "language_level"
|
||||||
assert result.titles["language_level"] == "A-1 Nivel general de lenguaje oral no ecolálico"
|
assert result.titles["language_level"] == "A-1 Nivel general de lenguaje oral no ecolálico"
|
||||||
|
|||||||
Reference in New Issue
Block a user