T6: TEA follow-up carries the case state beside the route stage

listed() gives each row case = confirmed | not_confirmed | in_process from
the confirmed / not-confirmed dates against the cut-off; a date after the
cut-off does not count. Filter tea-case, Patient extension tea-case and its
code system follow the tea-step / tea-age-group pattern; those two
extensions were not declared and now are. Tests: the three outcomes around
the cut-off, the filter, and the Patient extension.
This commit is contained in:
2026-12-01 01:10:35 -06:00
parent 95069151a8
commit 2d7a77f1cf
4 changed files with 68 additions and 5 deletions
+12 -1
View File
@@ -48,6 +48,10 @@ CODE_SYSTEMS: dict[str, tuple[str, dict[str, str]]] = {
"cancer": "Diagnóstico confirmado", "pending_biopsy": "Pendiente de biopsia",
"biopsy_no_result": "Biopsia sin resultado", "benign_biopsy": "Biopsia benigna",
}),
"tea-case": ("Estado del caso", {
"confirmed": "Diagnóstico confirmado", "in_process": "En proceso",
"not_confirmed": "Sin TEA",
}),
"follow-up-priority": ("Prioridad de seguimiento", {
"high": "Alta", "medium": "Media", "low": "Baja",
}),
@@ -125,6 +129,9 @@ EXTENSIONS: dict[str, tuple[str | None, list[str]]] = {
"period-type": ("code", ["Measure"]),
"follow-up-status": ("Coding", ["Patient"]),
"follow-up-priority": ("Coding", ["Patient"]),
"tea-step": ("code", ["Patient"]),
"tea-age-group": ("code", ["Patient"]),
"tea-case": ("code", ["Patient"]),
"report-date": ("date", ["DiagnosticReport"]),
"days-to-diagnosis": ("integer", ["DiagnosticReport"]),
"eeg-duration-min": ("decimal", ["DiagnosticReport"]),
@@ -212,7 +219,11 @@ def patient(row: dict, status_system: str | None = None) -> Patient:
priority = coding("follow-up-priority", row["priority"])
found["extension"].append(ext("follow-up-priority", "Coding", priority))
if status_system == "tea-follow-up-status":
for field, name in (("step", "tea-step"), ("age_group", "tea-age-group")):
for field, name in (
("step", "tea-step"),
("age_group", "tea-age-group"),
("case", "tea-case"),
):
if row.get(field) is not None:
found.setdefault("extension", []).append(ext(name, "code", row[field]))
if row.get("names"):
+10
View File
@@ -14,6 +14,7 @@ REPORT_FACTS = {}
FILTERS = {
"tea-step": ("token", "step", ("eeg", "neurology", "psychology", "mchat_only")),
"tea-case": ("token", "case", ("confirmed", "in_process", "not_confirmed")),
"tea-eeg-result": ("token", "eeg_result", ("abnormal", "normal", "no_valid_eeg", "not_scored")),
"tea-model": ("token", "eeg_scored", ("yes", "no")),
"tea-age-group": ("token", "age_group", ("16-23", "24-29", "30-36", "no_data")),
@@ -30,6 +31,14 @@ def listed(rows: list[dict], start: date, cutoff: date) -> list[dict]:
begins, ends = as_day(row["start_date"]), as_day(row["end_date"])
if begins > cutoff or (ends is not None and ends < start):
continue
confirmed = as_day(row.get("confirmed_date"))
not_confirmed = as_day(row.get("not_confirmed_date"))
if confirmed is not None and confirmed <= cutoff:
case = "confirmed"
elif not_confirmed is not None and not_confirmed <= cutoff:
case = "not_confirmed"
else:
case = "in_process"
css, classification = None, None
if evaluated := as_day(row.get("ados2_date")):
evaluation = {item: row.get(f"ados2_{item}") for item in tea.ADOS2_ITEMS}
@@ -40,6 +49,7 @@ def listed(rows: list[dict], start: date, cutoff: date) -> list[dict]:
**row,
"priority": None,
"recent": row["step_date"],
"case": case,
"css": css,
"classification": classification,
}
+17 -2
View File
@@ -4,7 +4,7 @@ import pytest
from core import fhir, fhir_in, tea
from core.pipeline import RECORD
from core.tea import ados2_items
from core.tea import ados2_items, follow_up
from core.tea import fhir as tea_fhir
DAY = date(2025, 1, 1)
@@ -194,12 +194,27 @@ def test_association_risk_headline(altered):
@pytest.mark.parametrize("status_system", ["tea-follow-up-status", "cacu-follow-up-status", None])
def test_patient_tea_follow_up_fields(status_system):
row = {"person_id": "child", "step": "mchat_only", "age_group": "16-23"}
(row,) = follow_up.listed(
[
{
"person_id": "child",
"start_date": DAY,
"end_date": None,
"step_date": DAY,
"step": "mchat_only",
"age_group": "16-23",
"confirmed_date": DAY,
}
],
DAY,
DAY,
)
patient = fhir.patient(row, status_system).model_dump(mode="json", exclude_none=True)
if status_system == "tea-follow-up-status":
extensions = _extensions(patient)
assert extensions["tea-step"]["valueCode"] == "mchat_only"
assert extensions["tea-age-group"]["valueCode"] == "16-23"
assert extensions["tea-case"]["valueCode"] == "confirmed"
else:
assert "extension" not in patient
assert fhir.patient({"person_id": "child"}, status_system).extension is None
+29 -2
View File
@@ -41,21 +41,46 @@ def test_listed():
**finished,
"priority": None,
"recent": start,
"case": "in_process",
"css": 1,
"classification": "non_spectrum",
}
assert found[2] == {**row, "priority": None, "recent": start, "css": None,
assert found[2] == {**row, "priority": None, "recent": start, "case": "in_process", "css": None,
"classification": None} # fmt: skip
assert fu.status(row, cutoff) == "active"
assert fu.status({}, cutoff) is None
assert fu.ordered(found, "-recent", {}, None) is found
@pytest.mark.parametrize(
("confirmed_date", "not_confirmed_date", "expected"),
[
("2026-12-31", "2026-12-30", "confirmed"),
("2027-01-01", "2026-12-31", "not_confirmed"),
(None, "2027-01-01", "in_process"),
],
)
def test_case_at_cutoff(confirmed_date, not_confirmed_date, expected):
start, cutoff = date(2026, 1, 1), date(2026, 12, 31)
row = {
"person_id": "child",
"start_date": start,
"end_date": None,
"step_date": start,
"confirmed_date": confirmed_date,
"not_confirmed_date": not_confirmed_date,
}
(listed,) = fu.listed([row], start, cutoff)
assert listed["case"] == expected
@pytest.mark.parametrize(
("name", "values", "row", "expected"),
[
("tea-step", ["psychology,eeg"], {"step": "eeg"}, True),
("tea-step", ["psychology"], {"step": "eeg"}, False),
("tea-case", ["confirmed,not_confirmed"], {"case": "not_confirmed"}, True),
("tea-case", ["in_process"], {"case": "confirmed"}, False),
("tea-eeg-result", ["not_scored"], {"eeg_result": "not_scored"}, True),
("tea-model", ["yes"], {"eeg_scored": True}, True),
("tea-model", ["no"], {"eeg_scored": False}, True),
@@ -76,7 +101,9 @@ def test_matches(name, values, row, expected):
assert fu.matches(row, {name: values}) is expected
@pytest.mark.parametrize("params", [{"tea-step": ["eeg,unknown"]}, {"tea-css": ["gt4"]}])
@pytest.mark.parametrize(
"params", [{"tea-step": ["eeg,unknown"]}, {"tea-case": ["unknown"]}, {"tea-css": ["gt4"]}]
)
def test_invalid_value(params):
with pytest.raises(ValueError):
fu.matches({}, {"tea-sex": ["female"], **params})