From 9400416f712b33344c0f029673396a66d8fdab8b Mon Sep 17 00:00:00 2001 From: alberto Date: Tue, 1 Dec 2026 03:55:35 -0600 Subject: [PATCH] T8/T9: Patient carries tea-eeg-result; the _id search keeps the TEA follow-up row; submodules --- Core/core/fhir.py | 6 ++++++ WebApi | 2 +- WebApp | 2 +- tests/test_core_tea_fhir.py | 39 +++++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/Core/core/fhir.py b/Core/core/fhir.py index 545691a..8c63ce7 100644 --- a/Core/core/fhir.py +++ b/Core/core/fhir.py @@ -52,6 +52,10 @@ CODE_SYSTEMS: dict[str, tuple[str, dict[str, str]]] = { "confirmed": "Diagnóstico confirmado", "in_process": "En proceso", "not_confirmed": "Sin TEA", }), + "tea-eeg-result": ("Resultado del EEG", { + "abnormal": "Anormal", "normal": "Normal", + "no_valid_eeg": "Sin EEG válido", "not_scored": "Sin analizar", + }), "follow-up-priority": ("Prioridad de seguimiento", { "high": "Alta", "medium": "Media", "low": "Baja", }), @@ -132,6 +136,7 @@ EXTENSIONS: dict[str, tuple[str | None, list[str]]] = { "tea-step": ("code", ["Patient"]), "tea-age-group": ("code", ["Patient"]), "tea-case": ("code", ["Patient"]), + "tea-eeg-result": ("code", ["Patient"]), "report-date": ("date", ["DiagnosticReport"]), "days-to-diagnosis": ("integer", ["DiagnosticReport"]), "eeg-duration-min": ("decimal", ["DiagnosticReport"]), @@ -223,6 +228,7 @@ def patient(row: dict, status_system: str | None = None) -> Patient: ("step", "tea-step"), ("age_group", "tea-age-group"), ("case", "tea-case"), + ("eeg_result", "tea-eeg-result"), ): if row.get(field) is not None: found.setdefault("extension", []).append(ext(name, "code", row[field])) diff --git a/WebApi b/WebApi index 6c1d098..b61a486 160000 --- a/WebApi +++ b/WebApi @@ -1 +1 @@ -Subproject commit 6c1d098619b08b127936abe3d433062803abe20f +Subproject commit b61a4863d18702aac114372bbf3a75aedca6dc64 diff --git a/WebApp b/WebApp index 48e6c9f..fcb3634 160000 --- a/WebApp +++ b/WebApp @@ -1 +1 @@ -Subproject commit 48e6c9f390342384c760592f1a2d810b8059f23d +Subproject commit fcb3634fa9ca9da88a1af95c8834bf6a02a8471e diff --git a/tests/test_core_tea_fhir.py b/tests/test_core_tea_fhir.py index 592411b..4b27a6e 100644 --- a/tests/test_core_tea_fhir.py +++ b/tests/test_core_tea_fhir.py @@ -1,11 +1,14 @@ from datetime import date import pytest +from fastapi import Request from core import fhir, fhir_in, tea +from core.domains import Domain from core.pipeline import RECORD from core.tea import ados2_items, follow_up from core.tea import fhir as tea_fhir +from webapi.fhir import _patient_rows DAY = date(2025, 1, 1) EEG = {"person_id": "child", "edf": "0123456789abcdef", "study_date": DAY} @@ -204,6 +207,7 @@ def test_patient_tea_follow_up_fields(status_system): "step": "mchat_only", "age_group": "16-23", "confirmed_date": DAY, + "eeg_result": "no_valid_eeg", } ], DAY, @@ -215,11 +219,46 @@ def test_patient_tea_follow_up_fields(status_system): assert extensions["tea-step"]["valueCode"] == "mchat_only" assert extensions["tea-age-group"]["valueCode"] == "16-23" assert extensions["tea-case"]["valueCode"] == "confirmed" + assert extensions["tea-eeg-result"]["valueCode"] == "no_valid_eeg" else: assert "extension" not in patient assert fhir.patient({"person_id": "child"}, status_system).extension is None +def test_focused_patient_search_uses_the_tea_follow_up_cohort(fresh_platform): + with fresh_platform.begin() as connection: + connection.exec_driver_sql("create table silver.person (person_id, birth_date, sex)") + connection.exec_driver_sql( + "insert into silver.person (person_id) values ('child'), ('other'), ('outside')" + ) + connection.exec_driver_sql("create table silver.death (person_id, death_date)") + connection.exec_driver_sql( + "create table gold.tea_follow_up " + "(person_id, status, step, age_group, start_date, end_date, step_date, eeg_result)" + ) + connection.exec_driver_sql( + "insert into gold.tea_follow_up values " + "('child', 'finished', 'eeg', '16-23', '2023-01-01', '2023-02-01', " + "'2023-02-01', 'normal'), " + "('other', 'active', 'mchat_only', '24-29', '2024-11-01', null, " + "'2024-11-01', 'no_valid_eeg')" + ) + + def listed_rows(patient_id=None): + request = Request({"type": "http", "query_string": b""}) + rows, listed, _ = _patient_rows( + request, Domain.TEA, follow_up, DAY, None, date.min, DAY, None, _id=patient_id + ) + assert listed + return rows + + listed = listed_rows() + assert len(listed) == 2 + (focused,) = listed_rows("child") + assert focused == next(row for row in listed if row["person_id"] == "child") + assert listed_rows("outside") == [] + + def test_fhir_in_joins_encounter_results_and_subject_by_full_url(): patient = { "resourceType": "Patient",