From 7e0c6039b86c488f0068ff8e320a106a780196f9 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Fri, 26 Jun 2026 19:44:46 -0500 Subject: [PATCH] Fix profesionalRemisionante con slash y mejora display resultado test-rda MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - json_generator: limpia DOCIDMEDICO a solo dígitos (eg "9410/86" → "941086") para que TNS acepte el código - test_rda.html: resultado con syntax highlight en JSON enviado y respuesta TNS, mejor legibilidad del error TNS, botones Resp.TNS y JSON env. con íconos Co-Authored-By: Claude Sonnet 4.6 --- app/services/json_generator.py | 5 +- app/templates/test_rda.html | 89 +++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 29 deletions(-) diff --git a/app/services/json_generator.py b/app/services/json_generator.py index aabd831..12d1e14 100644 --- a/app/services/json_generator.py +++ b/app/services/json_generator.py @@ -117,7 +117,10 @@ def generar_rda_paciente(rows: list, default_profesional: str = "", default_espe row.get("FECHA_REPORTADO") if str(row.get("FECHA_REPORTADO") or "")[:4] != "1900" else h.get("FECHA_RECEPCION") ) - cedula_medico = str(row.get("DOCIDMEDICO") or "").strip() + # TNS solo acepta dígitos en profesionalRemisionante; limpiar "9410/86" → "941086" + import re as _re + _doc = str(row.get("DOCIDMEDICO") or "").strip() + cedula_medico = _re.sub(r"[^0-9]", "", _doc) detalle_pedido.append({ "codigoMaterial": str(row.get("COD_EXAMEN") or "").strip(), "codigoBodega": "00", diff --git a/app/templates/test_rda.html b/app/templates/test_rda.html index fc0697a..57ec4da 100644 --- a/app/templates/test_rda.html +++ b/app/templates/test_rda.html @@ -309,46 +309,61 @@ async function enviarRDA() { if (p.tipo === 'tercero') { html += `
- ${icon} + ${icon}
-

Tercero: ${p.codigo} — ${p.nombre}

-

${p.mensaje}

+

Tercero: ${p.codigo} — ${esc(p.nombre || '')}

+

${esc(p.mensaje || '')}

`; } else { - // Marcar fila como enviada marcarFila(p.idrecepcion, p.ok); + const uid = 'j' + p.idrecepcion + '_' + Math.random().toString(36).slice(2); + const uid2 = 'r' + p.idrecepcion + '_' + Math.random().toString(36).slice(2); + + let respHtml = '(sin respuesta)'; + try { + const obj = JSON.parse(p.respuesta_tns || '{}'); + respHtml = syntaxHL(obj); + } catch(e) { respHtml = esc(p.respuesta_tns || ''); } + + let jsonHtml = '{}'; + try { jsonHtml = syntaxHL(p.json_enviado || {}); } catch(e) {} + + const msgClass = p.ok + ? 'border-green-300 bg-green-100 text-green-900' + : 'border-red-300 bg-red-100 text-red-900'; - const jsonStr = JSON.stringify(p.json_enviado || {}, null, 2); - const uid = 'json_' + p.idrecepcion + '_' + Date.now(); - const uid2 = 'resp_' + p.idrecepcion + '_' + Date.now(); - let respTns = ''; - try { respTns = JSON.stringify(JSON.parse(p.respuesta_tns || '{}'), null, 2); } catch(e) { respTns = p.respuesta_tns || ''; } html += ` -
-
- ${icon} +
+
+ ${icon}
-

- IDRECEPCION ${p.idrecepcion} - · Factura ${p.factura} - · Contrato ${p.contrato} - HTTP ${p.status || '?'} -

-

Exámenes: ${(p.examenes || []).join(', ')}

-
- ${p.mensaje || '(sin mensaje de TNS)'} +
+ IDRECEPCION ${p.idrecepcion} + · + Factura ${esc(String(p.factura||''))} + · + Contrato ${esc(String(p.contrato||''))} + HTTP ${p.status||'?'} +
+

Exámenes: ${esc((p.examenes||[]).join(', '))}

+
+ ${esc(p.mensaje || '(sin mensaje de TNS)')}
-
- - +
+ +
-
`; } }); @@ -356,5 +371,23 @@ async function enviarRDA() { } cargarCandidatos(true); + +function esc(s) { + return String(s).replace(/&/g,'&').replace(//g,'>').replace(/"/g,'"'); +} + +function togglePre(id) { + document.getElementById(id).classList.toggle('hidden'); +} + +function syntaxHL(obj) { + let json = JSON.stringify(obj, null, 2); + json = json.replace(/&/g,'&').replace(//g,'>'); + return json + .replace(/("(?:[^"\\]|\\.)*")(?=\s*:)/g,'$1') + .replace(/:(\s*)("(?:[^"\\]|\\.)*")/g,': $1$2') + .replace(/:(\s*)(\d+(?:\.\d+)?)/g,': $1$2') + .replace(/:(\s*)(null|true|false)/g,': $1$2'); +} {% endblock %}