Merge origin/rebuild into parity/T1-merge (WebApi)

- main.py: both routers sets (execution, preview from tea/parity; sources, users from
  rebuild).
- runs.py: tea/parity's cancel, history and execution config; rebuild's /terminate is the
  same action and is not kept twice.
- eeg.py: tea/parity's (the record reads per-child FHIR resources, not rebuild's EEG
  detail with zones and relation).
- fhir.py: tea/parity's patient rows with TEA filters, plus rebuild's name/identifier
  search applied to whatever rows the request selects.
- models.py: tea/parity's endpoints; /models/{domain} returns rebuild's name + title.
- tests: P7 deletions kept (test_cacu, test_cama, test_conectar, test_synthea*, test_tea);
  test_webapp keeps tea/parity's runner, now with the first administrator (sign-in).
This commit is contained in:
2026-11-30 23:56:11 -06:00
12 changed files with 925 additions and 36 deletions
+39 -5
View File
@@ -3,6 +3,7 @@ uses, paging, and a CapabilityStatement built from these routes themselves. Reso
built by Core's mappers from the rows Persistance reads; nothing is computed here beyond
counting a few thousand rows (measures) and ordering the follow-up list."""
import unicodedata
from collections import defaultdict
from datetime import date, datetime
from typing import Annotated, Any
@@ -184,6 +185,25 @@ def _with_identity(domain: Domain, rows: list[dict]) -> list[dict]:
] # fmt: skip
def _folded(text: str) -> str:
return "".join(c for c in unicodedata.normalize("NFKD", text.casefold())
if not unicodedata.combining(c)) # fmt: skip
def _matches(row: dict, name: str | None, identifier: str | None) -> bool:
if name:
words = _folded(name).split()
if not any(all(any(w.startswith(q) for w in _folded(n).split()) for q in words)
for n in row["names"]): # fmt: skip
return False
if identifier:
system, _, value = identifier.rpartition("|")
if not any((not system or s == system) and v.casefold() == value.strip().casefold()
for s, v in row["identifiers"]): # fmt: skip
return False
return True
@router.get(
"/Patient",
responses=_OK,
@@ -202,6 +222,12 @@ def search_patient(
start: date | None = _START,
cutoff: date | None = _CUTOFF,
status: str | None = _STATUS,
name: str | None = Query(
None, description="each word starts a word of her name (case and accents ignored)"
),
identifier: str | None = Query(
None, description="[system|]value: a CURP or record number (case ignored)"
),
sort: str = Query("-recent", alias="_sort", description="-recent or -risk-<outcome>"),
horizon: float | None = Query(None, alias="risk-horizon", description="years"),
revinclude: list[str] = Query([], alias="_revinclude", description=f"any of {REVINCLUDES}"),
@@ -219,6 +245,10 @@ def search_patient(
)
except ValueError as exc:
return outcome(422, str(exc))
if name or identifier:
found = {r["person_id"] for r in _with_identity(domain, rows)
if _matches(r, name, identifier)} # fmt: skip
rows = [r for r in rows if r["person_id"] in found]
persons = [r["person_id"] for r in rows]
risks: dict[str, list[dict]] = {}
if domain != Domain.TEA and (listed and sort != "-recent" or
@@ -464,7 +494,7 @@ def search_condition(request: Request, domain: Domain,
subject: str | None = Query(None, description=SUBJECT),
_count: int | None = Query(None),
_offset: int = Query(0)) -> Response: # fmt: skip
"""What clinical notes diagnosed."""
"""What clinical notes diagnosed (CaMa: and each recurrence)."""
def build(rows):
return [f.condition(r) for r in rows]
@@ -477,10 +507,11 @@ def search_procedure(request: Request, domain: Domain,
subject: str | None = Query(None, description=SUBJECT),
_count: int | None = Query(None),
_offset: int = Query(0)) -> Response: # fmt: skip
"""The procedures the domain's timeline infers (CaCu: colposcopies and treatments)."""
"""The procedures the domain's timeline infers (CaCu: colposcopies and treatments;
CaMa: each treatment, by its kind)."""
def build(rows):
return [f.procedure(r) for r in rows]
return [f.procedure(r, domain.value) for r in rows]
return _clinical_search("procedure", build, request, domain, subject, _count, _offset)
@@ -546,8 +577,9 @@ def search_measure_report(
raise HTTPException(422, f"reporting-period: {e}") from e
rows = measure_reads.rows(domain.value, found.rows, **found.params)
reports = []
for text, period in _sliced(asked, count, offset):
result = m.evaluate(found, rows, period, as_of, event_cutoff)
page = _sliced(asked, count, offset)
results = m.evaluate_periods(found, rows, [p for _, p in page], as_of, event_cutoff)
for (text, period), result in zip(page, results, strict=True):
report = m.report(found, period, result, as_of)
report.id = f"{f.measure_id(found.id)}-{text.lower()}"
reports.append(report)
@@ -652,4 +684,6 @@ _STANDARD = {
"subject": "reference",
"measure": "reference",
"follow-up-start": "date",
"name": "string",
"identifier": "token",
}