FHIR: one RiskAssessment per outcome, and one with no prediction for a model that didn't score her

The patient's Bundle holds the current batch of each outcome (`CohortRepository.current_risks`), so a CIN2+ and a
cancer model are both shown. For a patient with some risk, each current model of another outcome that didn't score
her (`current_batches`) gives a RiskAssessment with no prediction and the extension `sin-estimacion` (its outcome and
why it may be so), so the record can tell "no model" from "not estimated for her".
This commit is contained in:
2026-11-22 09:34:49 -06:00
parent f002e24811
commit b63a253b19
3 changed files with 80 additions and 3 deletions
+10 -2
View File
@@ -24,6 +24,7 @@ from werkzeug.exceptions import HTTPException
from webapi.fhir.common import FHIR_VERSION, canonical, entry, fhir, outcome, page, searchset, simulated_data
from webapi.fhir.measures import fhir_id, labels, measure_report, measure_resource, measure_url
from webapi.fhir.risk import not_scored
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
@@ -198,8 +199,15 @@ def _risk_routes(blueprint: Blueprint, repositories, project: str) -> None:
except ValueError as error:
return outcome(400, "invalid", str(error))
pac_id = int(reference)
risk = repositories.cohort_repository.current_risk(pac_id)
found = [] if risk is None else [domain.risk_assessment(pac_id, risk, simulated_data())]
# one RiskAssessment per outcome: the current batch of each (a CIN2+ and a cancer model, say), and, for a
# patient with some risk, one with no prediction for each current model of another outcome that didn't
# score her
risks = repositories.cohort_repository.current_risks(pac_id)
found = [domain.risk_assessment(pac_id, r, simulated_data()) for r in risks]
if risks:
scored = {r.desenlace for r in risks}
found += [not_scored(domain.risk_assessment(pac_id, b, simulated_data()), b.desenlace)
for b in repositories.cohort_repository.current_batches() if b.desenlace not in scored]
return fhir(searchset([entry(r) for r in found[offset:offset + count]], len(found), count, offset))