fix: use Firebird PREFIJO as codigoPrefijo; add debug endpoint to find CUPs field
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
ed9fead353
commit
8732db9c1f
@@ -0,0 +1,67 @@
|
||||
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"])
|
||||
|
||||
|
||||
def _cfg():
|
||||
conn = get_connection()
|
||||
c = {r["key"]: r["value"] for r in conn.execute("SELECT * FROM config").fetchall()}
|
||||
conn.close()
|
||||
return c
|
||||
|
||||
|
||||
@router.get("/cups")
|
||||
async def find_cups(request: Request, user: dict = Depends(get_current_user)):
|
||||
cfg = _cfg()
|
||||
fb, ok, msg = get_firebird_from_config(cfg)
|
||||
if not ok:
|
||||
return JSONResponse({"error": msg})
|
||||
|
||||
results = {}
|
||||
|
||||
# 1. Tablas/campos que contengan "CUP" en el nombre
|
||||
ok1, _, rows1 = fb.execute_query("""
|
||||
SELECT DISTINCT TRIM(f.RDB$RELATION_NAME) AS tabla, TRIM(f.RDB$FIELD_NAME) AS campo
|
||||
FROM RDB$RELATION_FIELDS f
|
||||
WHERE f.RDB$FIELD_NAME CONTAINING 'CUP'
|
||||
ORDER BY 1, 2
|
||||
""")
|
||||
results["campos_cup"] = rows1 if ok1 else []
|
||||
|
||||
# 2. Columnas de la tabla ARTICULO
|
||||
ok2, _, rows2 = fb.execute_query("""
|
||||
SELECT TRIM(f.RDB$FIELD_NAME) AS campo
|
||||
FROM RDB$RELATION_FIELDS f
|
||||
WHERE f.RDB$RELATION_NAME = 'ARTICULO'
|
||||
ORDER BY f.RDB$FIELD_POSITION
|
||||
""")
|
||||
results["columnas_articulo"] = [r["campo"] for r in rows2] if ok2 else "no existe"
|
||||
|
||||
# 3. Columnas de la tabla EXAMEN (si existe)
|
||||
ok3, _, rows3 = fb.execute_query("""
|
||||
SELECT TRIM(f.RDB$FIELD_NAME) AS campo
|
||||
FROM RDB$RELATION_FIELDS f
|
||||
WHERE f.RDB$RELATION_NAME = 'EXAMEN'
|
||||
ORDER BY f.RDB$FIELD_POSITION
|
||||
""")
|
||||
results["columnas_examen"] = [r["campo"] for r in rows3] if ok3 else "no existe"
|
||||
|
||||
# 4. Muestra de ARTICULO con el primer examen de RELACION
|
||||
ok4, _, rows4 = fb.execute_query("""
|
||||
SELECT FIRST 1 rel.COD_EXAMEN FROM RELACION rel WHERE rel.COD_EXAMEN IS NOT NULL
|
||||
""")
|
||||
if ok4 and rows4:
|
||||
cod = rows4[0]["COD_EXAMEN"]
|
||||
ok5, _, rows5 = fb.execute_query(
|
||||
"SELECT FIRST 1 a.* FROM ARTICULO a WHERE a.CODIGO = :cod",
|
||||
{"cod": cod}
|
||||
)
|
||||
results["muestra_articulo"] = rows5[0] if (ok5 and rows5) else "sin datos"
|
||||
results["cod_examen_muestra"] = cod
|
||||
|
||||
fb.disconnect()
|
||||
return JSONResponse(results)
|
||||
@@ -197,7 +197,7 @@ def generar_rda_paciente(rows: list, default_profesional: str = "", default_espe
|
||||
vigencia = 30
|
||||
|
||||
result = {
|
||||
"codigoPrefijo": default_prefijo or str(h.get("PREFIJO") or "00").strip(),
|
||||
"codigoPrefijo": str(h.get("PREFIJO") or "").strip() or default_prefijo or "00",
|
||||
"numero": numero_override if numero_override else (
|
||||
str(h.get("NUM_FACTURA") or "").strip() if (h.get("NUM_FACTURA") or 0) != 0 else ""
|
||||
),
|
||||
|
||||
@@ -65,7 +65,7 @@ async def root():
|
||||
return RedirectResponse(url="/dashboard")
|
||||
|
||||
|
||||
from app.routes import auth, dashboard, config, queries, terceros, transaccion, logs, automation, test_rda
|
||||
from app.routes import auth, dashboard, config, queries, terceros, transaccion, logs, automation, test_rda, debug_fb
|
||||
|
||||
app.include_router(auth.router)
|
||||
app.include_router(dashboard.router)
|
||||
@@ -76,6 +76,7 @@ app.include_router(transaccion.router)
|
||||
app.include_router(logs.router)
|
||||
app.include_router(automation.router)
|
||||
app.include_router(test_rda.router)
|
||||
app.include_router(debug_fb.router)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user