TEA follow-up: Patient search with TEA filters and $eeg-summary
Use _patient_rows and shared Query declarations for follow-up selection. Validate filters with an empty row before reading candidates, and use doseq for repeated values in paging links. Keep operation routes out of the metadata scan for read and search interactions. Use _follow_up_gate to compare the 29 captured queries by normalized record number, scalar counts and metrics.
This commit is contained in:
@@ -8,6 +8,7 @@ The hospital (2 GB) is kept outside git; its path is TEA_HOSPITAL (default
|
||||
~/isssteleon-data), and its hash is the manifest's.
|
||||
"""
|
||||
|
||||
import gzip
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
@@ -16,6 +17,7 @@ import time
|
||||
from collections import defaultdict
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
from urllib.parse import parse_qsl
|
||||
|
||||
import dagster as dg
|
||||
import pytest
|
||||
@@ -332,12 +334,80 @@ def _association_gate(api, platform):
|
||||
assert ref == pytest.approx(row["rap_probabilidad_referencia"], abs=1e-4), key
|
||||
|
||||
|
||||
def _follow_up_gate(api, platform):
|
||||
with gzip.open(REFERENCE / "follow_up.json.gz", "rt") as file:
|
||||
reference = json.load(file)
|
||||
persons = {
|
||||
int(number.removeprefix("N")): person
|
||||
for person, number in platform.query(
|
||||
"select distinct person_id, record_number from bronze.staged__identity"
|
||||
)
|
||||
}
|
||||
params_map = {
|
||||
"etapa": "tea-step", "status": "follow-up-status", "resultado-eeg": "tea-eeg-result",
|
||||
"modelo": "tea-model", "grupo-edad": "tea-age-group", "sexo": "tea-sex",
|
||||
"mchat": "tea-mchat", "css": "tea-css",
|
||||
} # fmt: skip
|
||||
values = {
|
||||
**CODES, "NEUROPEDIATRIA": "neurology", "anormal": "abnormal",
|
||||
"sin-eeg-valido": "no_valid_eeg",
|
||||
"si": "yes",
|
||||
} # fmt: skip
|
||||
counts = {
|
||||
"con_eeg_valido": "valid", "sin_eeg_valido": "not_valid",
|
||||
"normales": "normal", "anormales": "abnormal",
|
||||
} # fmt: skip
|
||||
for query, expected in reference.items():
|
||||
params = []
|
||||
for name, value in parse_qsl(query):
|
||||
if name == "date":
|
||||
dates = {"ge": "follow-up-start", "le": "follow-up-cutoff"}
|
||||
params.append((dates[value[:2]], value[2:]))
|
||||
else:
|
||||
params.append((params_map[name], values.get(value, value)))
|
||||
resources = [entry["resource"] for entry in expected["episodes"]["body"].get("entry", [])]
|
||||
patients = {
|
||||
f"Patient/{r['id']}": persons[int(next(
|
||||
identifier["value"].removeprefix("N-") for identifier in r["identifier"]
|
||||
if identifier["system"].endswith("/expediente")
|
||||
))]
|
||||
for r in resources if r["resourceType"] == "Patient"
|
||||
} # fmt: skip
|
||||
children = {
|
||||
patients[r["patient"]["reference"]]
|
||||
for r in resources if r["resourceType"] == "EpisodeOfCare"
|
||||
} # fmt: skip
|
||||
bundles = pages(api, "/tea/fhir/Patient", params)
|
||||
assert {entry["resource"]["id"] for bundle in bundles
|
||||
for entry in bundle.get("entry", [])} == children, query # fmt: skip
|
||||
|
||||
parameters = {}
|
||||
alterations = {}
|
||||
for parameter in expected["summary"]["body"]["parameter"]:
|
||||
name = parameter["name"]
|
||||
if name == "por_alteracion":
|
||||
parts = {p["name"]: p for p in parameter["part"]}
|
||||
metric = METRICS[parts["alteracion"]["valueCode"].upper()]
|
||||
alterations[metric] = parts["pacientes"]["valueInteger"]
|
||||
else:
|
||||
parameters[counts[name]] = parameter["valueInteger"]
|
||||
found = ok(api.get("/tea/fhir/Patient/$eeg-summary", params=params))
|
||||
assert found["resourceType"] == "Parameters", query
|
||||
assert {p["name"]: p["valueInteger"] for p in found["parameter"]
|
||||
if p["name"] != "by_alteration"} == parameters, query # fmt: skip
|
||||
assert {
|
||||
p["part"][0]["valueCode"]: p["part"][1]["valueInteger"]
|
||||
for p in found["parameter"] if p["name"] == "by_alteration"
|
||||
} == alterations, query # fmt: skip
|
||||
|
||||
|
||||
def test_tea_from_the_hospital_to_indicators(api, scored_hospital, monkeypatch):
|
||||
_association_gate(api, scored_hospital)
|
||||
|
||||
# Indicators, from the platform's own EEG verdicts and, for M30, the alterations the
|
||||
# promoted curves found (as the current platform's were captured: curves trained).
|
||||
indicators(api)
|
||||
_follow_up_gate(api, scored_hospital)
|
||||
|
||||
# The EEG pages: every study with its verdict, and a valid one's metrics with their scores.
|
||||
listed = ok(api.get("/tea/eegs"))
|
||||
|
||||
Reference in New Issue
Block a user