diff --git a/tests/test_tea.py b/tests/test_tea.py index 44dd41b..4adb03f 100644 --- a/tests/test_tea.py +++ b/tests/test_tea.py @@ -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 == [] diff --git a/webapi/fhir.py b/webapi/fhir.py index d9fbc67..fffdd30 100644 --- a/webapi/fhir.py +++ b/webapi/fhir.py @@ -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):