e2ecaa027c
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.
36 lines
1.6 KiB
Python
36 lines
1.6 KiB
Python
"""What a model's production version found about its cohort: `GET /<domain>/modelo/curvas`.
|
|
|
|
The population results a training run publishes (`analisis/curvas.json`, `models.cama.survival.population`): the cohort's
|
|
survival curves and the model's survival at each horizon with its intervals, for the dashboard to draw. They describe the
|
|
cohort, not any patient. The answer names the version they come from, and carries `simulado: true` in DEV, where the
|
|
data are simulated. 404 while the scenario has no version in production, or its version has no such record.
|
|
"""
|
|
|
|
import json
|
|
|
|
from flask import Blueprint, jsonify
|
|
|
|
from webapi.fhir.common import simulated_data
|
|
|
|
|
|
def model_analysis_blueprint(domain: str, scenario: str) -> Blueprint:
|
|
"""The blueprint of one scenario, to register with `url_prefix="/<domain>"`."""
|
|
blueprint = Blueprint(f"model_analysis_{domain}_{scenario}", __name__)
|
|
|
|
@blueprint.get("/modelo/curvas")
|
|
def curves():
|
|
"""The curves and points of the scenario's production version."""
|
|
from models.io.registry import registry
|
|
|
|
try:
|
|
resolved = registry.resolve(domain, scenario)
|
|
_, content = registry.artifact(domain, scenario, resolved.version, "analisis/curvas.json")
|
|
except LookupError as error:
|
|
return jsonify({"error": f"sin curvas: {error}"}), 404
|
|
return jsonify({"simulado": simulated_data(),
|
|
"modelo": {"nombre": f"{domain}-{scenario}", "version": str(resolved.version),
|
|
"mlflow_run_id": resolved.run_id},
|
|
"curvas": json.loads(content)})
|
|
|
|
return blueprint
|