add import audit trail, live indicator recompute, reportes endpoints; production hardening

This commit is contained in:
Roberto Treviño Cervantes
2026-10-30 11:19:30 -06:00
parent 168edb30f5
commit 2b2c290f58
74 changed files with 4095 additions and 1782 deletions
+2 -35
View File
@@ -1,40 +1,7 @@
from flask import Blueprint, jsonify, request
from models.prediction import ApplicabilityRejected, PredictionService
from models.tea import TeaModel
from flask import Blueprint
from persistance.db import get_tea_session
from persistance.tea import pacientes_repository
from webapi.indicadores import registrar_indicadores
tea_bp = Blueprint("tea", __name__)
registrar_indicadores(tea_bp, "tea", get_tea_session)
@tea_bp.get("/pacientes/<int:pac_id>")
def get_paciente(pac_id: int):
paciente = pacientes_repository.get(pac_id)
if paciente is None:
return jsonify({"error": "not found"}), 404
return jsonify(paciente.model_dump())
@tea_bp.post("/predict")
def predict():
"""Predict and record the result against the active `ModelVersion` (MLD-4/MLD-5).
Returns 501 while `TeaModel.predict` is not implemented."""
body = request.get_json(silent=True) or {}
service = PredictionService(TeaModel(), domain="tea", scenario=body.get("scenario", "tamizaje"))
try:
prediction = service.predict_and_record(
body.get("data"),
pac_id_hospital=body.get("pac_id_hospital", ""),
episodio_id=body.get("episodio_id"),
)
except NotImplementedError as exc:
return jsonify({"error": str(exc)}), 501
except ApplicabilityRejected as exc:
return jsonify({"error": str(exc)}), 422
except RuntimeError as exc:
return jsonify({"error": str(exc)}), 503
return jsonify(prediction.model_dump())