Recurrence figures for a patient; governance trains scenarios with external data; lifelines in the lock

This commit is contained in:
rockdrigo
2026-11-21 13:34:56 -06:00
parent a53179aa2e
commit 2c4bfa5691
6 changed files with 153 additions and 6 deletions
+34
View File
@@ -127,3 +127,37 @@ def model_analysis_blueprint(domain: str, scenario: str) -> Blueprint:
return jsonify({"modelo": {"nombre": f"{domain}-{scenario}", "version": str(version)}, "curvas": record})
return blueprint
def recurrence_blueprint() -> Blueprint:
"""CaMa's recurrence figures for a patient, to register with `url_prefix="/cama"`: `GET /modelo/recurrencia?paciente=<pac_id>`
answers the figures (METABRIC's and SCAN-B's) of the clinical scenarios her covariates meet, from the recurrence version in
production. The scenarios are the external cohorts' analyses; she is placed in them by her own age, tumor size, grade and
receptors, from the data ingested so far."""
blueprint = Blueprint("model_analysis_cama_recurrence", __name__)
@blueprint.get("/modelo/recurrencia")
def recurrence():
import pandas as pd
from models.cama.recurrence import patient
from models.io.registry import registry
paciente = request.args.get("paciente", "")
if not paciente.isdigit():
return jsonify({"error": "Falta la paciente."}), 422
try:
resolved = registry.resolve("cama", "recurrence")
_, content = registry.artifact("cama", "recurrence", resolved.version, "analisis/recurrencia.json")
_, _, labelled, _ = _live_context("cama", "survival")
except LookupError as error:
return jsonify({"error": f"sin recurrencia: {error}"}), 404
rows = labelled[labelled["pac_id"] == int(paciente)]
if rows.empty:
return jsonify({"error": "La paciente no está en la cohorte del modelo."}), 422
record = json.loads(content)
found = patient.matching(record["escenarios"], patient.covariates_of(rows.iloc[0]))
return jsonify({"modelo": {"nombre": "cama-recurrence", "version": str(resolved.version)}, "horizontes": record["horizons_months"],
"escenarios": found})
return blueprint