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:
+18
-1
@@ -14,9 +14,12 @@
|
||||
decimal or a range, not both).
|
||||
|
||||
What the number is, from the model's scenario (`[estimand]` of its `model.toml`), goes in the extension `estimando`:
|
||||
one `valueString` per key (`quantity`, `description`, `outcome`, `index_date`, `horizons_unit`, `interval`), and its
|
||||
one `valueString` per key (`quantity`, `description`, `outcome`, `index_date`, `horizons_unit`), and its
|
||||
`quantity` as `method.text`. A model whose scenario can't be read has neither.
|
||||
|
||||
A current model of an outcome that didn't score the patient gives a `RiskAssessment` with no `prediction` and the
|
||||
extension `sin-estimacion` (`not_scored`), so her record can tell "no model" from "not estimated for her".
|
||||
|
||||
Not yet: `basis` (the observations the model used) and `mitigation`. Each domain gives its outcomes' codes and labels
|
||||
(`webapi.fhir.cacu`, `webapi.fhir.cama`).
|
||||
"""
|
||||
@@ -30,6 +33,9 @@ OUTCOME = f"{CODE_SYSTEM}/desenlace"
|
||||
MODEL = f"{CODE_SYSTEM}/modelo"
|
||||
INTERVAL = f"{STRUCTURE}/intervalo-confianza"
|
||||
ESTIMAND = f"{STRUCTURE}/estimando"
|
||||
NOT_SCORED = f"{STRUCTURE}/sin-estimacion"
|
||||
NOT_SCORED_TEXT = ("el modelo vigente de este desenlace no estima a la paciente: queda fuera de su población (su "
|
||||
"índice o sus reglas) o su combinación de resultados no estuvo en su entrenamiento")
|
||||
DAYS_PER_YEAR = 365.25
|
||||
|
||||
|
||||
@@ -75,8 +81,19 @@ def risk_assessment(pac_id: int, risk, simulated: bool, outcomes: dict[str, str]
|
||||
"method": {"coding": [{**coding(MODEL, risk.modelo_nombre), "version": str(risk.modelo_version)}]},
|
||||
"prediction": [_prediction(h, outcome, risk.fecha_indice) for h in risk.horizontes],
|
||||
}
|
||||
if not risk.horizontes: # a current model of the outcome that didn't score her (`not_scored`)
|
||||
del resource["prediction"]
|
||||
if found := estimand(risk.modelo_nombre):
|
||||
resource["method"]["text"] = found.get("quantity", "")
|
||||
resource["extension"] = [{"url": ESTIMAND, "extension": [{"url": k, "valueString": v}
|
||||
for k, v in found.items()]}]
|
||||
return tagged(resource, simulated)
|
||||
|
||||
|
||||
def not_scored(resource: dict, desenlace: str | None) -> dict:
|
||||
"""A `RiskAssessment` of a model that didn't score the patient (a batch with no horizons of hers), marked with
|
||||
the extension `sin-estimacion`: its outcome (`desenlace`, since there is no prediction to carry it) and why it
|
||||
may be so (`motivo`)."""
|
||||
resource.setdefault("extension", []).append({"url": NOT_SCORED, "extension": [
|
||||
{"url": "desenlace", "valueCode": desenlace or ""}, {"url": "motivo", "valueString": NOT_SCORED_TEXT}]})
|
||||
return resource
|
||||
|
||||
Reference in New Issue
Block a user