47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
"""Patient follow-up for the configured breast cohort."""
|
|
|
|
import calendar
|
|
from datetime import date, timedelta
|
|
|
|
from flask import Blueprint, jsonify, request
|
|
|
|
from webapi.cama_analysis import SelectionError, selection_response
|
|
|
|
|
|
def _desde(corte, meses):
|
|
indice = corte.year * 12 + corte.month - 1 - meses
|
|
anio, mes = divmod(indice, 12)
|
|
if anio < 1:
|
|
raise ValueError("la ventana excede el rango de fechas admitido")
|
|
anterior = date(anio, mes + 1, min(corte.day, calendar.monthrange(anio, mes + 1)[1]))
|
|
return anterior + timedelta(days=1)
|
|
|
|
|
|
def blueprint_seguimiento_cama():
|
|
blueprint = Blueprint("cama_seguimiento", __name__)
|
|
|
|
@blueprint.after_request
|
|
def no_cache(response):
|
|
response.headers["Cache-Control"] = "no-store"
|
|
return response
|
|
|
|
def respond(mode, patient=None):
|
|
try:
|
|
return selection_response(request.args, mode, patient)
|
|
except SelectionError as error:
|
|
return jsonify(error=error.message), error.status
|
|
|
|
@blueprint.get("/seguimiento")
|
|
def seguimiento():
|
|
return respond('list')
|
|
|
|
@blueprint.get("/seguimiento/exportacion")
|
|
def exportacion():
|
|
return respond('export')
|
|
|
|
@blueprint.get("/pacientes/<pac_id>")
|
|
def paciente(pac_id):
|
|
return respond('patient', pac_id)
|
|
|
|
return blueprint
|