Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
from fastapi import APIRouter, Request, Depends
|
|
from fastapi.responses import JSONResponse
|
|
from app.database import get_connection
|
|
from app.auth import get_current_user
|
|
from app.services.firebird_service import get_firebird_from_config
|
|
|
|
router = APIRouter(prefix="/debug-fb", tags=["debug"])
|
|
|
|
|
|
@router.get("/cups")
|
|
async def find_cups(request: Request, user: dict = Depends(get_current_user)):
|
|
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})
|
|
|
|
results = {}
|
|
|
|
# Columnas de RELACION_HIMS
|
|
ok1, err1, rows1 = fb.execute_query(
|
|
"SELECT TRIM(f.RDB$FIELD_NAME) AS c FROM RDB$RELATION_FIELDS f "
|
|
"WHERE TRIM(f.RDB$RELATION_NAME)='RELACION_HIMS' ORDER BY f.RDB$FIELD_POSITION"
|
|
)
|
|
results["columnas_relacion_hims"] = [r["c"] for r in rows1] if ok1 else f"error: {err1}"
|
|
|
|
# Muestra de RELACION_HIMS con CUPS_REF no vacío
|
|
ok2, err2, rows2 = fb.execute_query(
|
|
"SELECT FIRST 3 rh.* FROM RELACION_HIMS rh "
|
|
"WHERE rh.CUPS_REF IS NOT NULL AND TRIM(rh.CUPS_REF) <> ''"
|
|
)
|
|
results["relacion_hims_con_cups"] = list(rows2) if (ok2 and rows2) else f"sin datos o error: {err2}"
|
|
|
|
# Ver si RELACION_HIMS se conecta con RELACION (buscar campo IDRECEPCION o COD_EXAMEN)
|
|
ok3, err3, rows3 = fb.execute_query("SELECT FIRST 1 rh.* FROM RELACION_HIMS rh")
|
|
results["relacion_hims_primera_fila"] = rows3[0] if (ok3 and rows3) else f"error: {err3}"
|
|
|
|
fb.disconnect()
|
|
return JSONResponse(results)
|