From 37c4124559dd01975d031a3883bf33571ee01b2f Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 16 Jul 2026 21:43:40 -0500 Subject: [PATCH] debug: add /debug-fb/recepcion diagnostic endpoint Shows recent recepciones without filters, CURRENT_DATE from Firebird, and counts with/without NUM_FACTURA filter to diagnose zero-result sync. Co-Authored-By: Claude Sonnet 4.6 --- app/routes/debug_fb.py | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/app/routes/debug_fb.py b/app/routes/debug_fb.py index 3f82c90..52be313 100644 --- a/app/routes/debug_fb.py +++ b/app/routes/debug_fb.py @@ -8,6 +8,58 @@ from app.services.firebird_service import get_firebird_from_config router = APIRouter(prefix="/debug-fb", tags=["debug"]) +@router.get("/recepcion") +async def debug_recepcion(user: dict = Depends(get_current_user)): + """Diagnóstico: qué hay en RECEPCION hoy sin filtros restrictivos.""" + try: + conn = get_connection() + cfg = {r["key"]: r["value"] for r in conn.execute("SELECT * FROM config").fetchall()} + conn.close() + + fb, ok, msg = get_firebird_from_config(cfg) + if not ok: + return JSONResponse({"error": msg}) + + result = {} + + # Últimas 5 recepciones sin ningún filtro + ok1, _, rows1 = fb.execute_query( + "SELECT FIRST 5 r.IDRECEPCION, r.FECHA_RECEPCION, r.HORAINICIORECEPCION, " + "r.NUM_FACTURA, r.COD_PACIENTE " + "FROM RECEPCION r ORDER BY r.IDRECEPCION DESC", None + ) + result["ultimas_5_sin_filtro"] = list(rows1) if ok1 and rows1 else f"error: {rows1}" + + # Fecha actual en Firebird + ok2, _, rows2 = fb.execute_query("SELECT CURRENT_DATE AS FH FROM RDB$DATABASE", None) + result["current_date_firebird"] = rows2[0] if ok2 and rows2 else "error" + + # Cuántas recepciones de hoy (CURRENT_DATE) sin filtro NUM_FACTURA + ok3, _, rows3 = fb.execute_query( + "SELECT COUNT(*) AS CNT FROM RECEPCION r WHERE r.FECHA_RECEPCION = CURRENT_DATE", None + ) + result["hoy_sin_filtro_factura"] = rows3[0] if ok3 and rows3 else "error" + + # Cuántas con NUM_FACTURA > 0 + ok4, _, rows4 = fb.execute_query( + "SELECT COUNT(*) AS CNT FROM RECEPCION r " + "WHERE r.FECHA_RECEPCION = CURRENT_DATE AND r.NUM_FACTURA > 0", None + ) + result["hoy_con_factura"] = rows4[0] if ok4 and rows4 else "error" + + # Distintas fechas recientes en la tabla + ok5, _, rows5 = fb.execute_query( + "SELECT FIRST 5 DISTINCT r.FECHA_RECEPCION FROM RECEPCION r " + "ORDER BY r.FECHA_RECEPCION DESC", None + ) + result["fechas_recientes"] = list(rows5) if ok5 and rows5 else "error" + + fb.disconnect() + return JSONResponse(result) + except Exception: + return JSONResponse({"traceback": traceback.format_exc()}) + + @router.get("/cups") async def find_cups(request: Request, user: dict = Depends(get_current_user)): try: