"""`/cama/recurrencia`: the scenarios of each cohort, the figure of one and the scenarios a patient meets.""" from flask import Blueprint, jsonify, request from werkzeug.exceptions import BadRequest, NotFound from webapi.cama_recurrence import service cama_recurrence_bp = Blueprint("cama_recurrence", __name__) @cama_recurrence_bp.errorhandler(service.NotAvailable) def _not_available(error): return jsonify({"error": str(error)}), 404 @cama_recurrence_bp.get("/escenarios") def scenarios(): return jsonify(service.scenarios()) @cama_recurrence_bp.get("/figura") def figure(): cohort = request.args.get("cohorte", "").strip() scenario = request.args.get("escenario", "").strip() if not cohort or not scenario: raise BadRequest("faltan los parámetros «cohorte» y «escenario»") try: return jsonify(service.figure(cohort, scenario)) except service.Calculating: return jsonify({"estado": "calculando"}), 202 except KeyError: raise NotFound(f"el modelo no define el escenario «{scenario}» en la cohorte «{cohort}»") except LookupError: raise NotFound(f"el escenario «{scenario}» no tiene recaídas suficientes para dibujarse") @cama_recurrence_bp.get("/pacientes/") def patient(pac_id: int): try: return jsonify(service.patient_scenarios(pac_id)) except KeyError: raise NotFound("la paciente no está en la cohorte")