feat: enrich sync log with exams, diagnosis, EPS and valor per patient
- scheduler.py: after sync_todos(), inject diagnostico, nit_empresa, valor_total and examenes_det (cups/nombre/precio) into each detalle entry - whatsapp_sync.py: guardar_sync_log stores full enriched fields in detalle_json - envios_erp.html: expanded row shows per-patient card with Dx, EPS, valor and a CUPS/examen/precio table — scrollable, max-h-96 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
e044f21e3e
commit
cd63683869
@@ -167,6 +167,21 @@ async def sync_recientes(ventana_min: int = 2) -> dict:
|
||||
resultado = await sync_todos(recientes, ingest_url, wa_key, timeout,
|
||||
modo="upsert", examenes_map=examenes_map)
|
||||
|
||||
# Enriquecer detalle con exámenes, diagnóstico, empresa y valor para el log
|
||||
for entry in resultado.get("detalle", []):
|
||||
doc = entry.get("doc", "")
|
||||
exams = examenes_map.get(doc, [])
|
||||
if exams:
|
||||
first = exams[0]
|
||||
entry["diagnostico_cod"] = first.get("diagnostico_cod", "")
|
||||
entry["diagnostico_nombre"] = first.get("diagnostico_nombre", "")
|
||||
entry["nit_empresa"] = first.get("nit_empresa", "")
|
||||
entry["valor_total"] = first.get("valor_total")
|
||||
entry["examenes_det"] = [
|
||||
{"cups": e.get("cups", ""), "nombre": e.get("nombre", ""), "precio": e.get("precio")}
|
||||
for e in exams
|
||||
]
|
||||
|
||||
if resultado["total"] > 0:
|
||||
guardar_sync_log(resultado, None, origen="scheduler", modo="upsert")
|
||||
|
||||
|
||||
@@ -31,9 +31,17 @@ def guardar_sync_log(
|
||||
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],
|
||||
[{
|
||||
"doc": d["doc"],
|
||||
"nombre": d["nombre"],
|
||||
"action": d.get("action", ""),
|
||||
"examenes_cnt": d.get("examenes_guardados", 0),
|
||||
"diagnostico_cod": d.get("diagnostico_cod", ""),
|
||||
"diagnostico_nombre": d.get("diagnostico_nombre", ""),
|
||||
"nit_empresa": d.get("nit_empresa", ""),
|
||||
"valor_total": d.get("valor_total"),
|
||||
"examenes_det": d.get("examenes_det", []),
|
||||
} for d in detalle_raw],
|
||||
ensure_ascii=False,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user