Conecta demografía y ruta CaCu a persistencia configurada
This commit is contained in:
+17
-13
@@ -18,20 +18,13 @@ from datetime import date
|
||||
from flask import Blueprint, Response, jsonify, request
|
||||
from webapi.follow_up.listing import PaginaFuera, PedidoInvalido, seguimiento_de
|
||||
from webapi.follow_up.screening import detalle_de
|
||||
from sqlmodel import Session
|
||||
from sqlmodel import Session, select
|
||||
from webapi.orchestration.tables.cacu import TABLAS
|
||||
|
||||
FECHA = re.compile(r"\d{4}-\d{2}-\d{2}")
|
||||
RUTA_ID = re.compile(r"[0-9a-f]{64}")
|
||||
|
||||
|
||||
def _rutas_sinteticas(sesion: Session) -> bool:
|
||||
"""DEV no acredita autorización por paciente. Limitar los dos contratos al fixture local."""
|
||||
if os.environ.get("DEV_REVISION") != "cacu-dev-sintetico":
|
||||
return False
|
||||
url = sesion.get_bind().url
|
||||
return url.drivername == "sqlite" and url.database == "/workspace/entorno-dev/datos-sinteticos/cacu.db"
|
||||
|
||||
|
||||
def in_dev() -> bool:
|
||||
"""Obsoleta: las rutas por paciente ya no dependen de `DEV_REVISION` y nada la llama. Se quitará."""
|
||||
warnings.warn("in_dev() está obsoleta: las rutas por paciente se registran siempre", DeprecationWarning, stacklevel=2)
|
||||
@@ -50,8 +43,6 @@ def follow_up_blueprint(get_session: Callable[[], Session]) -> Blueprint:
|
||||
return jsonify({"error": str(error)}), 400
|
||||
sesion = get_session()
|
||||
try:
|
||||
if pedido.get("incluir_ruta") and not _rutas_sinteticas(sesion):
|
||||
return jsonify({"error": "Ruta de tamizaje no disponible"}), 404
|
||||
cuerpo = seguimiento_de(sesion, **pedido)
|
||||
except PedidoInvalido as error:
|
||||
return jsonify({"error": str(error)}), 400
|
||||
@@ -61,6 +52,21 @@ def follow_up_blueprint(get_session: Callable[[], Session]) -> Blueprint:
|
||||
sesion.close()
|
||||
return Response(json.dumps(cuerpo, ensure_ascii=False), mimetype="application/json")
|
||||
|
||||
@blueprint.get("/seguimiento/pacientes/<int:pac_id>/demografia")
|
||||
def get_demografia(pac_id: int):
|
||||
no_disponible = {"error": "Información demográfica no disponible"}
|
||||
if pac_id > 2**63 - 1:
|
||||
return jsonify(no_disponible), 404
|
||||
sesion = get_session()
|
||||
try:
|
||||
fila = sesion.execute(select(TABLAS.Persona.fecha_nacimiento).where(TABLAS.Persona.pac_id == pac_id)).first()
|
||||
if fila is None:
|
||||
return jsonify(no_disponible), 404
|
||||
nacimiento = fila[0]
|
||||
return jsonify({"pac_id": str(pac_id), "fecha_nacimiento": nacimiento.isoformat() if nacimiento is not None else None})
|
||||
finally:
|
||||
sesion.close()
|
||||
|
||||
@blueprint.get("/seguimiento/rutas/<int:pac_id>/<ruta_id>")
|
||||
def get_ruta(pac_id: int, ruta_id: str):
|
||||
no_disponible = {"error": "Ruta de tamizaje no disponible"}
|
||||
@@ -68,8 +74,6 @@ def follow_up_blueprint(get_session: Callable[[], Session]) -> Blueprint:
|
||||
return jsonify(no_disponible), 404
|
||||
sesion = get_session()
|
||||
try:
|
||||
if not _rutas_sinteticas(sesion):
|
||||
return jsonify(no_disponible), 404
|
||||
texto = request.args.get("corte", "")
|
||||
try:
|
||||
if not FECHA.fullmatch(texto):
|
||||
|
||||
Reference in New Issue
Block a user