From 648a0a1910a671463069b7f9af56fff58d141cda Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Fri, 10 Jul 2026 20:47:58 -0500 Subject: [PATCH] feat: preview muestra lista de pre-servicios con JSON expandible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Agrega preservicios_preview al endpoint /preview con el JSON generado por cada RCXC/SC - Muestra sección naranja debajo de pacientes con factura, fecha, paciente y exámenes - Clic en cada fila despliega el JSON completo que se enviará a TNS Co-Authored-By: Claude Sonnet 4.6 --- app/routes/automation.py | 25 +++++++++++++++++++++++++ app/templates/automation.html | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/app/routes/automation.py b/app/routes/automation.py index 7c83b3d..6c3f008 100644 --- a/app/routes/automation.py +++ b/app/routes/automation.py @@ -208,6 +208,30 @@ async def preview_automation( grupos_ps = {k: v for k, v in grupos_ps_all.items() if str(v[0].get("CODCONTRATO") or "").strip() not in excluded} + contrato_map = load_contrato_map() + prof_def = configs.get("profesional_defecto", "") + esp_def = configs.get("especialidad_defecto", "") + remis_def = configs.get("remisionante_defecto", "00") + prefijo_def = configs.get("prefijo_defecto", "00") + + preservicios_preview = [] + for id_ps, grupo_rows in grupos_ps.items(): + ps_prefijo = str(grupo_rows[0].get("PS_PREFIJO") or "SC").strip() + ps_numero = str(grupo_rows[0].get("PS_NUMERO") or "").strip() + rda_json = generar_rda_paciente( + grupo_rows, prof_def, esp_def, remis_def, prefijo_def, + numero_override=ps_numero, + contrato_map=contrato_map, + prefijo_override=ps_prefijo, + ) + preservicios_preview.append({ + "factura": f"{ps_prefijo}-{ps_numero.zfill(5)}", + "paciente": str(grupo_rows[0].get("COD_PACIENTE", "")), + "fecha": str(grupo_rows[0].get("FECHA_RECEPCION", ""))[:10], + "examenes": len(grupo_rows), + "json": rda_json, + }) + # Agrupar RDA por COD_PACIENTE rda_por_pac = {} for id_rec, filas in grupos.items(): @@ -245,6 +269,7 @@ async def preview_automation( "excluidos": excluidos_count, "preservicios": len(grupos_ps), "pacientes_preview": pacientes_preview, + "preservicios_preview": preservicios_preview, }) diff --git a/app/templates/automation.html b/app/templates/automation.html index 0c1b0af..a0c9647 100644 --- a/app/templates/automation.html +++ b/app/templates/automation.html @@ -71,6 +71,10 @@

Pacientes — clic para ver sus recepciones:

+ @@ -206,6 +210,26 @@ async function previewAutomation() { document.getElementById('cnt-preservicios').textContent = data.preservicios || 0; document.getElementById('preview-fecha').textContent = data.fecha; + const psTable = document.getElementById('preview-ps-table'); + const psSection = document.getElementById('preservicios-section'); + if (data.preservicios_preview && data.preservicios_preview.length > 0) { + psTable.innerHTML = data.preservicios_preview.map((ps, i) => ` +
+
+ + ${ps.factura} + ${ps.fecha} + Pac. ${ps.paciente} + ${ps.examenes} examen(es) +
+ +
`).join(''); + psSection.classList.remove('hidden'); + } else { + psSection.classList.add('hidden'); + } + const table = document.getElementById('preview-table'); if (data.pacientes === 0) { table.innerHTML = '
No hay pacientes para esta fecha
'; @@ -340,6 +364,14 @@ function toggleRda(id, row) { if (chev) chev.style.transform = hidden ? 'rotate(90deg)' : ''; } +function togglePs(id, row) { + const div = document.getElementById(id); + const chev = row.querySelector('[id^="pschev-"]'); + const hidden = div.classList.contains('hidden'); + div.classList.toggle('hidden', !hidden); + if (chev) chev.style.transform = hidden ? 'rotate(90deg)' : ''; +} + function renderBadge(id, enviados, errores) { const el = document.getElementById(id); if (errores === 0) {