From bc5fc36a5d7b669120177292bb41704ee2a35bc1 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 1 Jul 2026 12:30:12 -0500 Subject: [PATCH] debug: explore RELACION_HIMS table for CUPS_REF field Co-Authored-By: Claude Sonnet 4.6 --- app/routes/debug_fb.py | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/app/routes/debug_fb.py b/app/routes/debug_fb.py index c8e6d8e..2a087ee 100644 --- a/app/routes/debug_fb.py +++ b/app/routes/debug_fb.py @@ -19,36 +19,23 @@ async def find_cups(request: Request, user: dict = Depends(get_current_user)): results = {} - # Columnas de ITEM via sistema + # 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)='ITEM' ORDER BY f.RDB$FIELD_POSITION" + "WHERE TRIM(f.RDB$RELATION_NAME)='RELACION_HIMS' ORDER BY f.RDB$FIELD_POSITION" ) - cols_item = [r["c"] for r in rows1] if ok1 else [] - results["columnas_item"] = cols_item if cols_item else f"error: {err1}" + results["columnas_relacion_hims"] = [r["c"] for r in rows1] if ok1 else f"error: {err1}" - # Probar cada posible campo clave contra COD_EXAMEN de RELACION - candidatos = ["COD_ITEM", "CODITEM", "CODIGO", "COD", "ID", "CODARTICULO", "ARTICULO"] - joins_ok = {} - for campo in candidatos: - if campo not in cols_item: - continue - ok2, _, rows2 = fb.execute_query( - f"SELECT FIRST 3 rel.COD_EXAMEN, i.CUPS_DETALLE " - f"FROM RELACION rel " - f"LEFT JOIN ITEM i ON TRIM(i.{campo}) = TRIM(rel.COD_EXAMEN) " - f"WHERE i.CUPS_DETALLE IS NOT NULL AND TRIM(i.CUPS_DETALLE)<>'' " - ) - if ok2 and rows2: - joins_ok[campo] = rows2 - break - else: - joins_ok[campo] = "sin resultados" - results["join_pruebas"] = joins_ok + # 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}" - # Primera fila de ITEM sin JOIN - ok3, err3, rows3 = fb.execute_query("SELECT FIRST 1 i.* FROM ITEM i") - results["item_primera_fila"] = rows3[0] if (ok3 and rows3) else f"error: {err3}" + # 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)