From 6950e5aaedadee843f373df1be649cab45646833 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 23 Jul 2026 12:17:10 -0500 Subject: [PATCH] =?UTF-8?q?tmp:=20debug=20script=20exploraci=C3=B3n=20mues?= =?UTF-8?q?tras=20pendientes=20Firebird?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debug_muestras.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 debug_muestras.py diff --git a/debug_muestras.py b/debug_muestras.py new file mode 100644 index 0000000..ffd986c --- /dev/null +++ b/debug_muestras.py @@ -0,0 +1,70 @@ +""" +Explora tablas de toma de muestras pendientes en Firebird. +Uso: python debug_muestras.py +""" +from app.database import get_connection +from app.services.firebird_service import get_firebird_from_config + +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: + print("Error Firebird:", msg) + exit(1) + +# 1. Buscar tablas que suenen a muestras/toma +print("=== Tablas con nombres relacionados a muestras ===") +_, _, tablas = fb.execute_query(""" + SELECT TRIM(rdb$relation_name) AS tabla + FROM rdb$relations + WHERE rdb$system_flag = 0 + AND (UPPER(rdb$relation_name) LIKE '%MUESTRA%' + OR UPPER(rdb$relation_name) LIKE '%TOMA%' + OR UPPER(rdb$relation_name) LIKE '%PENDIENTE%' + OR UPPER(rdb$relation_name) LIKE '%EXAMEN%' + OR UPPER(rdb$relation_name) LIKE '%RESULTADO%' + OR UPPER(rdb$relation_name) LIKE '%RELACION%' + OR UPPER(rdb$relation_name) LIKE '%ORDEN%') + ORDER BY 1 +""", None) +for t in (tablas or []): + print(" ", t["TABLA"]) + +# 2. Ver columnas de RELACION (exámenes por recepción) +print("\n=== Columnas de RELACION ===") +_, _, cols = fb.execute_query(""" + SELECT TRIM(rdb$field_name) AS campo + FROM rdb$relation_fields + WHERE rdb$relation_name = 'RELACION' + ORDER BY rdb$field_position +""", None) +for c in (cols or []): + print(" ", c["CAMPO"]) + +# 3. Ver si hay campo de estado/pendiente en RELACION +print("\n=== Muestra de RELACION (primeras 3 filas) ===") +_, _, sample = fb.execute_query("SELECT FIRST 3 * FROM RELACION", None) +for r in (sample or []): + print(" ", dict(r)) + +# 4. Si existe TOMA_MUESTRA o similar, ver su estructura +for tabla in ["TOMA_MUESTRA", "MUESTRAS", "TOMA", "MUESTRA"]: + ok_t, _, _ = fb.execute_query(f"SELECT FIRST 1 * FROM {tabla}", None) + if ok_t: + print(f"\n=== Tabla {tabla} existe — columnas ===") + _, _, tcols = fb.execute_query(f""" + SELECT TRIM(rdb$field_name) AS campo + FROM rdb$relation_fields + WHERE rdb$relation_name = '{tabla}' + ORDER BY rdb$field_position + """, None) + for c in (tcols or []): + print(" ", c["CAMPO"]) + _, _, trows = fb.execute_query(f"SELECT FIRST 3 * FROM {tabla}", None) + for r in (trows or []): + print(" ", dict(r)) + +fb.disconnect() +print("\nFin.")