Fix profesionalRemisionante con slash y mejora display resultado test-rda

- 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 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-26 19:44:46 -05:00
co-authored by Claude Sonnet 4.6
parent 7699303a53
commit 7e0c6039b8
2 changed files with 65 additions and 29 deletions
+4 -1
View File
@@ -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",
+61 -28
View File
@@ -309,46 +309,61 @@ async function enviarRDA() {
if (p.tipo === 'tercero') {
html += `
<div class="flex items-start gap-3 p-3 rounded-lg border ${p.ok ? 'border-green-100 bg-green-50' : 'border-red-100 bg-red-50'}">
<span>${icon}</span>
<span class="text-base">${icon}</span>
<div>
<p class="text-sm font-medium text-gray-700">Tercero: <span class="font-mono">${p.codigo}</span> — ${p.nombre}</p>
<p class="text-xs text-gray-500">${p.mensaje}</p>
<p class="text-sm font-medium text-gray-700">Tercero: <span class="font-mono text-blue-700">${p.codigo}</span> — ${esc(p.nombre || '')}</p>
<p class="text-xs mt-0.5 ${p.ok ? 'text-green-700' : 'text-red-700'}">${esc(p.mensaje || '')}</p>
</div>
</div>`;
} 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 += `
<div class="rounded-lg border ${p.ok ? 'border-green-200 bg-green-50' : 'border-red-200 bg-red-50'}">
<div class="flex items-start gap-3 p-3">
<span class="text-lg leading-tight">${icon}</span>
<div class="rounded-lg border ${p.ok ? 'border-green-200 bg-green-50/50' : 'border-red-200 bg-red-50/50'}">
<div class="p-4 flex items-start gap-3">
<span class="text-lg leading-tight shrink-0">${icon}</span>
<div class="flex-1 min-w-0">
<p class="text-sm font-medium text-gray-800">
IDRECEPCION <span class="font-mono text-blue-700">${p.idrecepcion}</span>
· Factura <span class="font-mono">${p.factura}</span>
· Contrato <span class="font-mono text-purple-700">${p.contrato}</span>
<span class="text-gray-400 text-xs ml-1">HTTP ${p.status || '?'}</span>
</p>
<p class="text-xs text-gray-500 mt-0.5">Exámenes: ${(p.examenes || []).join(', ')}</p>
<div class="mt-2 px-3 py-2 rounded-lg border ${p.ok ? 'border-green-300 bg-green-100 text-green-900' : 'border-red-300 bg-red-100 text-red-900'} text-sm font-semibold">
${p.mensaje || '(sin mensaje de TNS)'}
<div class="flex flex-wrap items-center gap-x-3 gap-y-0.5 text-sm">
<span class="font-medium text-gray-800">IDRECEPCION <span class="font-mono text-blue-700">${p.idrecepcion}</span></span>
<span class="text-gray-400">·</span>
<span class="text-gray-600">Factura <span class="font-mono font-medium">${esc(String(p.factura||''))}</span></span>
<span class="text-gray-400">·</span>
<span class="text-gray-600">Contrato <span class="font-mono font-medium text-purple-700">${esc(String(p.contrato||''))}</span></span>
<span class="px-1.5 py-0.5 rounded text-xs font-mono ${p.status >= 400 ? 'bg-red-100 text-red-700' : 'bg-gray-100 text-gray-500'}">HTTP ${p.status||'?'}</span>
</div>
<p class="text-xs text-gray-500 mt-1">Exámenes: <span class="font-mono">${esc((p.examenes||[]).join(', '))}</span></p>
<div class="mt-2 px-3 py-2 rounded-lg border ${msgClass} text-sm font-medium">
${esc(p.mensaje || '(sin mensaje de TNS)')}
</div>
</div>
<div class="flex flex-col gap-1 shrink-0">
<button onclick="document.getElementById('${uid2}').classList.toggle('hidden')"
class="px-2 py-1 text-xs bg-yellow-100 hover:bg-yellow-200 text-yellow-800 rounded">Resp. TNS</button>
<button onclick="document.getElementById('${uid}').classList.toggle('hidden')"
class="px-2 py-1 text-xs bg-gray-100 hover:bg-gray-200 text-gray-600 rounded">JSON env.</button>
<div class="flex flex-col gap-1.5 shrink-0">
<button onclick="togglePre('${uid2}')"
class="px-2.5 py-1 text-xs bg-yellow-100 hover:bg-yellow-200 text-yellow-800 rounded font-medium whitespace-nowrap">
<i class="fas fa-server mr-1"></i>Resp. TNS
</button>
<button onclick="togglePre('${uid}')"
class="px-2.5 py-1 text-xs bg-gray-100 hover:bg-gray-200 text-gray-600 rounded font-medium whitespace-nowrap">
<i class="fas fa-code mr-1"></i>JSON env.
</button>
</div>
</div>
<pre id="${uid2}" class="hidden mx-3 mb-1 p-3 bg-yellow-950 text-yellow-200 rounded text-xs overflow-x-auto whitespace-pre-wrap">${respTns.replace(/</g,'&lt;')}</pre>
<pre id="${uid}" class="hidden mx-3 mb-3 p-3 bg-gray-900 text-green-300 rounded text-xs overflow-x-auto whitespace-pre-wrap">${jsonStr.replace(/</g,'&lt;')}</pre>
<pre id="${uid2}" class="hidden mx-4 mb-1 p-3 bg-amber-950 text-amber-100 rounded-lg text-xs overflow-x-auto whitespace-pre-wrap">${respHtml}</pre>
<pre id="${uid}" class="hidden mx-4 mb-4 p-3 bg-gray-900 text-green-300 rounded-lg text-xs overflow-x-auto whitespace-pre-wrap">${jsonHtml}</pre>
</div>`;
}
});
@@ -356,5 +371,23 @@ async function enviarRDA() {
}
cargarCandidatos(true);
function esc(s) {
return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
}
function togglePre(id) {
document.getElementById(id).classList.toggle('hidden');
}
function syntaxHL(obj) {
let json = JSON.stringify(obj, null, 2);
json = json.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
return json
.replace(/("(?:[^"\\]|\\.)*")(?=\s*:)/g,'<span style="color:#93c5fd">$1</span>')
.replace(/:(\s*)("(?:[^"\\]|\\.)*")/g,': $1<span style="color:#86efac">$2</span>')
.replace(/:(\s*)(\d+(?:\.\d+)?)/g,': $1<span style="color:#fdba74">$2</span>')
.replace(/:(\s*)(null|true|false)/g,': $1<span style="color:#d8b4fe">$2</span>');
}
</script>
{% endblock %}