TEA: an answer as of a knowledge cut-off reads each child's version known then, and the measures waiting for a validation stay hidden outside FHIR too

This commit is contained in:
2026-11-12 19:47:19 -06:00
parent a0407e41d6
commit 0f9433949f
6 changed files with 93 additions and 26 deletions
+19 -4
View File
@@ -10,6 +10,7 @@ durations (`webapi.durations`; without `corte_evento`, the day of the last load)
import json
from collections.abc import Callable
from datetime import date, datetime, timezone
from functools import lru_cache
from pathlib import Path
from core.indicadores.tipos import FechaHoraUTC
@@ -24,28 +25,42 @@ LOADS = table("carga", column("inicio", FechaHoraUTC))
def definitions_of(project: str, manifest: Path) -> dict:
"""Every measure the manifest defines for the domain, by its id (the end of its url)."""
"""Every measure the manifest defines for the domain, by its id (the end of its url). A measure that waits for
a validation (`meta.requiere_validacion`) is left out until it's given."""
return {i: d for i, d in _defined(project, manifest).items() if not _awaits_validation(d)}
@lru_cache
def _defined(project: str, manifest: Path) -> dict:
every = {**measure_definitions(manifest), **composition_definitions(manifest), **duration_definitions(manifest)}
return {d.measure_id: d for d in every.values() if d.url.startswith(f"{project}/")}
def _awaits_validation(definition) -> bool:
"""TEA's EEG alterations, the one validation so far, stay hidden until the domain expert validates them."""
if not definition.meta.get("requiere_validacion"):
return False
from webapi.fhir.tea import alterations_validated
return not alterations_validated()
def kpis_blueprint(project: str, repositories, manifest: Path, *,
now: Callable[[], datetime] = lambda: datetime.now(timezone.utc)) -> Blueprint:
"""The blueprint of a domain, to register with `url_prefix="/<domain>"`. `repositories` is the domain's
`persistance.<domain>` module."""
blueprint = Blueprint(f"{project}_kpis", __name__)
definitions = definitions_of(project, manifest)
@blueprint.get("/indicadores")
def list_kpis():
"""The measures answered on request: id, url, version and scoring."""
return jsonify([{"id": i, "url": d.url, "version": d.version, "scoring": scoring_of(d)}
for i, d in sorted(definitions.items())])
for i, d in sorted(definitions_of(project, manifest).items())])
@blueprint.get("/indicadores/<measure_id>")
def get_kpi(measure_id: str):
"""A measure's periods as a FHIR Bundle of MeasureReports, computed on request and kept in the history."""
definition = definitions.get(measure_id)
definition = definitions_of(project, manifest).get(measure_id)
if definition is None:
return jsonify({"error": f"no hay un indicador {measure_id!r} calculado bajo pedido"}), 404
try: