debug: search 903967 across all candidate tables
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
fb81ddf263
commit
b22b47a1e1
+31
-15
@@ -21,23 +21,39 @@ async def find_cups(request: Request, user: dict = Depends(get_current_user)):
|
||||
|
||||
results = {}
|
||||
|
||||
# 1. Buscar todas las tablas que tengan campo con "CUP" en nombre
|
||||
ok0, _, rows0 = fb.execute_query(
|
||||
"SELECT TRIM(f.RDB$RELATION_NAME) AS t, TRIM(f.RDB$FIELD_NAME) AS c "
|
||||
"FROM RDB$RELATION_FIELDS f WHERE f.RDB$FIELD_NAME LIKE '%CUP%' "
|
||||
"AND f.RDB$SYSTEM_FLAG = 0 ORDER BY 1,2"
|
||||
)
|
||||
results["todos_campos_cup"] = list(rows0) if ok0 else []
|
||||
BUSCAR = "903967"
|
||||
|
||||
# 2. Tabla PROTOCOLO - primera fila
|
||||
ok1, err1, rows1 = fb.execute_query("SELECT FIRST 1 p.* FROM PROTOCOLO p")
|
||||
results["protocolo_fila"] = rows1[0] if (ok1 and rows1) else f"error: {err1}"
|
||||
# Tablas y sus campos de texto para buscar
|
||||
tablas_candidatas = [
|
||||
("PROTOCOLO", ["CODIGO", "NOMBRE"]),
|
||||
("ITEM", ["COD_PROTOCOLO", "CUPS_DETALLE", "CODITEMINTERFACE"]),
|
||||
("RELACION", ["COD_EXAMEN"]),
|
||||
("RELACION_HIMS", ["CUPS_REF"]),
|
||||
("ARTICULO", ["CODIGO", "CUPS"]),
|
||||
("SERVICIO", ["CODIGO", "CUPS", "COD_CUPS"]),
|
||||
("PROCEDIMIENTO", ["CODIGO", "CUPS"]),
|
||||
]
|
||||
|
||||
# 3. PROTOCOLO para CH4
|
||||
ok2, err2, rows2 = fb.execute_query(
|
||||
"SELECT FIRST 1 p.* FROM PROTOCOLO p WHERE TRIM(p.CODIGO) = 'CH4'"
|
||||
)
|
||||
results["protocolo_ch4"] = rows2[0] if (ok2 and rows2) else f"error: {err2}"
|
||||
encontrado = {}
|
||||
for tabla, campos in tablas_candidatas:
|
||||
for campo in campos:
|
||||
ok_t, _, rows_t = fb.execute_query(
|
||||
f"SELECT FIRST 3 t.* FROM {tabla} t "
|
||||
f"WHERE TRIM(t.{campo}) = '{BUSCAR}'"
|
||||
)
|
||||
if ok_t and rows_t:
|
||||
encontrado[f"{tabla}.{campo}"] = list(rows_t)
|
||||
|
||||
results["valor_903967_encontrado_en"] = encontrado if encontrado else "no encontrado en tablas comunes"
|
||||
|
||||
# Buscar en campos de tipo char/varchar de PROTOCOLO e ITEM que no conocemos
|
||||
for tabla in ["PROTOCOLO", "ITEM"]:
|
||||
ok_c, _, rows_c = fb.execute_query(
|
||||
f"SELECT TRIM(f.RDB$FIELD_NAME) AS c FROM RDB$RELATION_FIELDS f "
|
||||
f"WHERE TRIM(f.RDB$RELATION_NAME)='{tabla}' ORDER BY f.RDB$FIELD_POSITION"
|
||||
)
|
||||
if ok_c:
|
||||
results[f"columnas_{tabla.lower()}"] = [r["c"] for r in rows_c]
|
||||
|
||||
fb.disconnect()
|
||||
return JSONResponse(results)
|
||||
|
||||
Reference in New Issue
Block a user