integration layer; merge work on indicators from forks with existing ingestion pipeline

This commit is contained in:
Roberto Treviño Cervantes
2026-10-23 00:00:13 -06:00
parent c1444e2b8d
commit 043f7635f4
80 changed files with 7766 additions and 38 deletions
+21 -5
View File
@@ -1,14 +1,18 @@
from flask import Blueprint, jsonify
from flask import Blueprint, jsonify, request
from models.cacu import CaCuModel
from models.prediction import ApplicabilityRejected, PredictionService
from persistance.cacu import paciente_repository
from persistance.db import get_cacu_session
from webapi.indicadores import registrar_indicadores
cacu_bp = Blueprint("cacu", __name__)
registrar_indicadores(cacu_bp, "cacu", get_cacu_session)
@cacu_bp.get("/pacientes/<int:pac_id>")
def get_paciente(pac_id: int):
"""Example read route — proves WebApi resolves Persistance's repository API."""
"""Read one CaCu patient by primary key."""
paciente = paciente_repository.get(pac_id)
if paciente is None:
return jsonify({"error": "not found"}), 404
@@ -17,9 +21,21 @@ def get_paciente(pac_id: int):
@cacu_bp.post("/predict")
def predict():
"""Example predict route — proves WebApi resolves the models package."""
model = CaCuModel()
"""Predict and record the result against the active `ModelVersion` (MLD-4/MLD-5).
Returns 501 while `CaCuModel.predict` is not implemented."""
body = request.get_json(silent=True) or {}
service = PredictionService(CaCuModel(), domain="cacu", scenario=body.get("scenario", "tamizaje"))
try:
return jsonify({"prediction": model.predict(data=None)})
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())