From 461d651805035b67171e8f1d1df1a031233218b3 Mon Sep 17 00:00:00 2001 From: rockdrigo Date: Fri, 13 Nov 2026 17:03:23 -0600 Subject: [PATCH] TEA FHIR: an episode's _include brings its ADOS-2 observation --- tests/test_fhir_tea.py | 7 +++++-- webapi/fhir/__init__.py | 12 ++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/test_fhir_tea.py b/tests/test_fhir_tea.py index 61533db..59bf569 100644 --- a/tests/test_fhir_tea.py +++ b/tests/test_fhir_tea.py @@ -167,8 +167,9 @@ def test_the_follow_up_filters(client, query, n): def test_includes_bring_the_patient_its_steps_and_its_study_eeg(client): """Pins down: `_include` adds each child's Patient (birth date to the month), CarePlan with its steps, M-CHAT, - confirmed diagnosis and study EEG as a DiagnosticReport with its quality observations; no metric observation while - the alterations are hidden. Fails if an included resource drops out or the alterations leak.""" + ADOS-2 (the list shows its CSS and module), confirmed diagnosis and study EEG as a DiagnosticReport with its quality + observations; no metric observation while the alterations are hidden. Fails if an included resource drops out or + the alterations leak.""" body = get(client, "/tea/fhir/EpisodeOfCare?date=le2025-12-31&status=finished&_include=*") included = resources(body, mode="include") kinds = {r["resourceType"] for r in included} @@ -177,6 +178,8 @@ def test_includes_bring_the_patient_its_steps_and_its_study_eeg(client): reports = [r for r in included if r["resourceType"] == "DiagnosticReport"] assert {r["conclusionCode"][0]["coding"][0]["code"] for r in reports} == {"BUENO"} assert all(len(r["result"]) == 5 for r in reports) + ados2 = [r for r in included if r["resourceType"] == "Observation" and r["code"]["coding"][0]["code"] == "ados2"] + assert ados2 and all(any(c["code"]["coding"][0]["code"] == "ados2.css" for c in r["component"]) for r in ados2) def test_the_alteration_filter_waits_for_the_validation(client, monkeypatch): diff --git a/webapi/fhir/__init__.py b/webapi/fhir/__init__.py index eaeb72f..63b750f 100644 --- a/webapi/fhir/__init__.py +++ b/webapi/fhir/__init__.py @@ -342,13 +342,17 @@ def tea_outcome(status: int, code: str, error: Exception): def _included(tea, queries, e, simulated: bool) -> list[dict]: - """What an episode's search includes: its patient, its steps, its M-CHAT, its diagnosis and its study EEG.""" + """What an episode's search includes: its patient, its steps, its M-CHAT, its ADOS-2, its diagnosis and its study + EEG.""" from sqlalchemy import select - persons = tea._rows(queries, select(tea.PERSONS).where(tea.PERSONS.c.pac_id == e.child["pac_id"])) - resources = [tea.patient(e.child["pac_id"], persons[0]["fecha_nacimiento"] if persons else None, simulated), + pac_id = e.child["pac_id"] + persons = tea._rows(queries, select(tea.PERSONS).where(tea.PERSONS.c.pac_id == pac_id)) + ados2 = tea.ados2_observation(tea._rows(queries, select(tea.ADOS2).where(tea.ADOS2.c.pac_id == pac_id)), + e.pseudonym, simulated) + resources = [tea.patient(pac_id, persons[0]["fecha_nacimiento"] if persons else None, simulated), tea.care_plan(e, simulated)] - resources += [r for r in (tea.mchat_observation(e, simulated), tea.condition(e, simulated)) if r] + resources += [r for r in (tea.mchat_observation(e, simulated), ados2, tea.condition(e, simulated)) if r] if (eeg := e.study_eeg()) is not None: resources += tea.eeg_resources(eeg, e.pseudonym, e.metrics, [], simulated) return resources