Cleanup of the TEA parity work: no prose in code, no hacks, everything in its place
1. No prose in code - Remove parity-added Python comments and docstrings across the EEG, FHIR, execution, preview, training and run code and tests. Preserve endpoint descriptions as explicit FastAPI schema metadata. 2. No hacks, no glued code - Read the declared TEA patient filters and training inputs directly and use the same TEA check for exposing and validating reference options. - Give the Dagster GraphQL request one helper. Keep lock backoff and cancellation polling because their timing and error behavior are covered by run tests and they handle different Dagster states. - Use the renamed FHIR report ID helper in the hospital test. Keep TEA_GATE_SLOW local to that test and preserve the test assertions. 3. Everything in its place - Keep endpoint and run handling in WebApi and reuse Core and Persistance for domain rules and reads. Leave tests in the existing testpaths.
This commit is contained in:
+24
-14
@@ -24,6 +24,7 @@ from core.domains import Domain, measures, part
|
||||
from core.follow_up import window_start
|
||||
from core.pipeline import ID_PATTERN
|
||||
from core.tea import fhir as tea_fhir
|
||||
from core.tea.follow_up import FILTERS as TEA_FILTERS
|
||||
from persistance import config_log, readers
|
||||
from persistance import fhir as reads
|
||||
from persistance import measures as measure_reads
|
||||
@@ -115,7 +116,13 @@ _CUTOFF = Query(None, alias="follow-up-cutoff", description="default: the last d
|
||||
_STATUS = Query(None, alias="follow-up-status")
|
||||
|
||||
|
||||
@router.get("/Patient/$eeg-summary", responses=_OK, response_class=Response)
|
||||
@router.get(
|
||||
"/Patient/$eeg-summary",
|
||||
responses=_OK,
|
||||
response_class=Response,
|
||||
description="EEG counts for the follow-up list. Without a window or start, "
|
||||
"use the whole history.",
|
||||
)
|
||||
def eeg_summary(
|
||||
request: Request,
|
||||
domain: Domain,
|
||||
@@ -124,7 +131,6 @@ def eeg_summary(
|
||||
cutoff: date | None = _CUTOFF,
|
||||
status: str | None = _STATUS,
|
||||
) -> Response:
|
||||
"""EEG counts for the follow-up list. Without a window or start, use the whole history."""
|
||||
fu = _clinical(domain)
|
||||
if not hasattr(fu, "summary"):
|
||||
return outcome(404, f"no EEG summary for {domain.value}")
|
||||
@@ -178,7 +184,16 @@ def _with_identity(domain: Domain, rows: list[dict]) -> list[dict]:
|
||||
] # fmt: skip
|
||||
|
||||
|
||||
@router.get("/Patient", responses=_OK, response_class=Response)
|
||||
@router.get(
|
||||
"/Patient",
|
||||
responses=_OK,
|
||||
response_class=Response,
|
||||
description=(
|
||||
"Patients, or the domain's follow-up list selected by window or start.\n\n"
|
||||
"For TEA, a cutoff or a TEA filter also selects the follow-up list. Patients without\n"
|
||||
"follow-up episodes appear only in the plain search."
|
||||
),
|
||||
)
|
||||
def search_patient(
|
||||
request: Request,
|
||||
domain: Domain,
|
||||
@@ -194,11 +209,6 @@ def search_patient(
|
||||
_count: int | None = Query(None),
|
||||
_offset: int = Query(0),
|
||||
) -> Response:
|
||||
"""Patients, or the domain's follow-up list selected by window or start.
|
||||
|
||||
For TEA, a cutoff or a TEA filter also selects the follow-up list. Patients without
|
||||
follow-up episodes appear only in the plain search.
|
||||
"""
|
||||
fu = _clinical(domain)
|
||||
count, offset = _page(_count, _offset)
|
||||
at = _cutoff(domain, cutoff)
|
||||
@@ -242,11 +252,11 @@ def _patient_rows(
|
||||
) -> tuple[list[dict], bool, dict]:
|
||||
filters = {
|
||||
name: request.query_params.getlist(name)
|
||||
for name in getattr(fu, "FILTERS", ())
|
||||
for name in (TEA_FILTERS if domain == Domain.TEA else ())
|
||||
if name in request.query_params
|
||||
}
|
||||
if filters:
|
||||
fu.matches({}, filters) # Validate values even when the selection has no rows.
|
||||
fu.matches({}, filters)
|
||||
listed = (
|
||||
whole_history
|
||||
or start is not None
|
||||
@@ -378,7 +388,6 @@ def _tea_risks(persons: list[str], at: str) -> list[Resource]:
|
||||
groups = defaultdict(list)
|
||||
for row in reads.rows("tea", "association_scores", persons=persons, cutoff=at):
|
||||
group = groups[row["person_id"]]
|
||||
# The earliest scored EEG supplies the one set of predictions for this child.
|
||||
if (
|
||||
not group
|
||||
or row["edf"] == group[0]["edf"]
|
||||
@@ -607,9 +616,10 @@ def metadata(request: Request, domain: Domain) -> Response:
|
||||
if kind == "Patient" and not rest:
|
||||
entry |= {"searchInclude": ["DiagnosticReport:result"],
|
||||
"searchRevInclude": list(_revincludes(domain))} # fmt: skip
|
||||
entry["searchParam"] += [
|
||||
{"name": name, "type": spec[0]} for name, spec in getattr(fu, "FILTERS", {}).items()
|
||||
]
|
||||
if domain == Domain.TEA:
|
||||
entry["searchParam"] += [
|
||||
{"name": name, "type": spec[0]} for name, spec in TEA_FILTERS.items()
|
||||
]
|
||||
entry["interaction"].append({"code": "read" if rest else "search-type"})
|
||||
for param in route.dependant.query_params:
|
||||
name = param.alias
|
||||
|
||||
Reference in New Issue
Block a user