CaMa: individual risk and population curves served, and the cycle estimates with any scenario in production

webapi/fhir/risk.py builds a patient's RiskAssessment for CaCu and CaMa; GET /cama/modelo/curvas serves the production
version's survival curves; the cycle's estimator is generic by scenario; silver persona carries the date of death for CaMa;
the import schema accepts it; the CaMa risk batches can be confirmed and voided.
This commit is contained in:
rockdrigo
2026-11-21 02:07:34 -06:00
parent 26f2b35338
commit e2ecaa027c
17 changed files with 446 additions and 85 deletions
+10 -7
View File
@@ -9,7 +9,7 @@ individual risk.
GET CodeSystem, CodeSystem/<id>, ValueSet/<id> the project's code systems
GET EpisodeOfCare, EpisodeOfCare/$resumen-eeg TEA's follow-up list and its EEG summary (DEV only)
GET Patient/<pseudonym>/$resumen-tea TEA's patient summary (DEV only)
GET RiskAssessment?subject=Patient/<pac_id> CaCu's individual risk, the current batch (DEV only)
GET RiskAssessment?subject=Patient/<pac_id> CaCu's and CaMa's individual risk, the current batch (DEV only)
Every question of a measure takes `corte_evento` and `corte_conocimiento` as in `webapi.kpis`. Errors are
`OperationOutcome`s. Patient data are served only in DEV, on simulated data, each resource tagged `simulado`.
@@ -28,6 +28,7 @@ from webapi.fhir.terminology import code_systems, metric_value_set
from webapi.kpis import ANSWERS, _date, _datetime, _last_load, definitions_of, scoring_of
from webapi.metrics import Question, UndecidedRule
RISK_DOMAINS = ("cacu", "cama") # the domains whose patients' individual risk is served as a RiskAssessment
TEA_SEARCH = ("status", "date", "etapa", "fecha-etapa", "grupo-edad", "mchat", "css", "resultado-eeg", "alteracion")
@@ -38,7 +39,7 @@ def fhir_blueprint(project: str, repositories, manifest: Path, *, with_patients:
blueprint = Blueprint(f"{project}_fhir", __name__)
titles = labels(manifest)
patients = with_patients and project == "tea"
risks = with_patients and project == "cacu"
risks = with_patients and project in RISK_DOMAINS
def definitions() -> dict:
"""The domain's measures by their FHIR id; `definition()` also takes the dbt id."""
@@ -176,13 +177,15 @@ def fhir_blueprint(project: str, repositories, manifest: Path, *, with_patients:
if patients:
_patient_routes(blueprint, repositories, now)
if risks:
_risk_routes(blueprint, repositories)
_risk_routes(blueprint, repositories, project)
return blueprint
def _risk_routes(blueprint: Blueprint, repositories) -> None:
"""CaCu's individual risk: `RiskAssessment` searched by `subject` (DEV only, simulated data)."""
from webapi.fhir import cacu
def _risk_routes(blueprint: Blueprint, repositories, project: str) -> None:
"""A patient's individual risk: `RiskAssessment` searched by `subject` (DEV only, simulated data)."""
from importlib import import_module
domain = import_module(f"webapi.fhir.{project}")
@blueprint.get("/RiskAssessment")
def risk_assessments():
@@ -196,7 +199,7 @@ def _risk_routes(blueprint: Blueprint, repositories) -> None:
return outcome(400, "invalid", str(error))
pac_id = int(reference)
risk = repositories.cohort_repository.current_risk(pac_id)
found = [] if risk is None else [cacu.risk_assessment(pac_id, risk, simulated_data())]
found = [] if risk is None else [domain.risk_assessment(pac_id, risk, simulated_data())]
return fhir(searchset([entry(r) for r in found[offset:offset + count]], len(found), count, offset))