feat: store and display per-patient sync detail in historial

- Add detalle_json column to sync_wa_log via migration
- guardar_sync_log() now stores doc, nombre, action, examenes count per patient
- Historial table shows "Ver N" button that expands a row with patient list,
  action badge (Nuevo/Actualizado/Omitido) and exam count per patient

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-17 09:33:46 -05:00
co-authored by Claude Sonnet 4.6
parent 29b6aa4016
commit e044f21e3e
3 changed files with 61 additions and 15 deletions
+17 -4
View File
@@ -14,22 +14,34 @@ from app.database import get_connection
def guardar_sync_log(
resultado: dict,
user_id: int,
user_id,
origen: str = "manual",
modo: str = "insertar",
) -> None:
detalle_raw = resultado.get("detalle", [])
errores_det = None
errores = [d for d in resultado.get("detalle", []) if not d.get("ok")]
errores = [d for d in detalle_raw if not d.get("ok")]
if errores:
errores_det = json.dumps(
[{"doc": e["doc"], "nombre": e["nombre"], "msg": e["message"]} for e in errores],
ensure_ascii=False,
)
detalle_json = None
if detalle_raw:
detalle_json = json.dumps(
[{"doc": d["doc"], "nombre": d["nombre"], "action": d.get("action", ""),
"examenes": d.get("examenes_guardados", 0)}
for d in detalle_raw],
ensure_ascii=False,
)
conn = get_connection()
conn.execute(
"""INSERT INTO sync_wa_log
(user_id, origen, modo, total, created, skipped, updated, errores, errores_det)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)""",
(user_id, origen, modo, total, created, skipped, updated, errores, errores_det, detalle_json)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
(
user_id,
origen,
@@ -40,6 +52,7 @@ def guardar_sync_log(
resultado.get("updated", 0),
resultado.get("errores", 0),
errores_det,
detalle_json,
),
)
conn.commit()