Automation preview: show RDA per patient on click

Preview now returns all patients with their grouped receptions.
Clicking a patient row expands/collapses their RDA list showing
factura, fecha, exam count, diagnosis, and total value.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-25 19:49:21 -05:00
co-authored by Claude Sonnet 4.6
parent 7dc8f37c36
commit dbaf49b30e
2 changed files with 55 additions and 12 deletions
+18 -2
View File
@@ -107,13 +107,30 @@ async def preview_automation(
grupos = agrupar_por_recepcion(rows_rda)
total_examenes = sum(len(v) for v in grupos.values())
# Agrupar RDA por COD_PACIENTE
rda_por_pac = {}
for id_rec, filas in grupos.items():
cod = str(filas[0].get("COD_PACIENTE", ""))
if cod not in rda_por_pac:
rda_por_pac[cod] = []
rda_por_pac[cod].append({
"id_recepcion": id_rec,
"factura": f"{str(filas[0].get('PREFIJO', '')).strip()}-{filas[0].get('NUM_FACTURA', '')}",
"fecha": str(filas[0].get("FECHA_RECEPCION", ""))[:10],
"examenes": len(filas),
"valor": float(filas[0].get("VALORTOTAL") or 0),
"diag": str(filas[0].get("DIAG_PPAL") or ""),
})
pacientes_preview = [
{
"codigo": str(p.get("CODIGO", "")),
"doc": str(p.get("DOCIDENT", "")),
"nombre": f"{p.get('NOMBRES', '')} {p.get('APELLIDOS', '')}".strip(),
"tipo": str(p.get("TIPOIDENT", "")),
"rda": rda_por_pac.get(str(p.get("CODIGO", "")), []),
}
for p in rows_pac[:10]
for p in rows_pac
]
return JSONResponse({
@@ -123,7 +140,6 @@ async def preview_automation(
"recepciones": len(grupos),
"examenes": total_examenes,
"pacientes_preview": pacientes_preview,
"hay_mas": len(rows_pac) > 10,
})