A domain maps its own studies to FHIR; TEA's served resources pass the validator

This commit is contained in:
Roberto Treviño
2026-12-06 04:00:35 -06:00
parent 4ce3a165ad
commit 0f1c59a35f
2 changed files with 17 additions and 1 deletions
+12 -1
View File
@@ -16,7 +16,7 @@ from datetime import date
from pathlib import Path
import pytest
from fhir_checks import pages
from fhir_checks import pages, served, validate
from sqlalchemy import inspect
from test_conectar import ok, wait_for
@@ -276,3 +276,14 @@ def test_tea_from_the_hospital_to_indicators(api, platform, tmp_path):
shown = ok(api.get(f"/tea/eegs/{one['id']}"))
assert shown["valid"] and shown["metrics"] and all(m["value"] is not None
for m in shown["metrics"]) # fmt: skip
# Every resource TEA serves passes the HL7 validator: her ADOS-2 (CSS and classification
# from its items) and her EEG's report with its checks and metrics among them.
children = [one["person_id"], *(e["person_id"] for e in listed if not e["valid"])][:5]
resources = served(api, "/tea/fhir", PERIODS, children)
entries = [e["resource"] for b in resources for e in b.get("entry", [])]
codes = {(r["resourceType"], r["code"]["coding"][0]["code"]) for r in entries if "code" in r}
assert {("Observation", "ados2"), ("DiagnosticReport", "eeg")} <= codes
errors, warnings = validate(resources, tmp_path)
print(f"HL7 validator: {len(warnings)} warnings")
assert errors == []
+5
View File
@@ -310,7 +310,12 @@ def _studies(domain: Domain, persons: list[str], at: str) -> list[Resource]:
by `at`: its DiagnosticReport (or Encounter) and Observations, in date order."""
found: list[Resource] = []
report_facts = _clinical(domain).REPORT_FACTS
own = getattr(part(domain, "fhir"), "STUDIES", {}) # studies the domain maps itself
for study in catalog.of_domain(domain.value):
if study in own:
found += own[study](lambda kind: reads.rows(domain.value, kind, persons=persons,
cutoff=at)) # fmt: skip
continue
spec = catalog.studies()[study]
facts = {}
if kind := report_facts.get(study):