Files
rips_manager/app/templates/test_rda.html
T
Lizandro GuarnizoandClaude Sonnet 4.6 c64a68ec6f Add test-rda page, fix prefijo/remisionante/especialidad for TNS RDA sends
- New /test-rda route: list Firebird candidates with valid contract/factura,
  send individual RDA with auto tercero creation and full result display
- json_generator: use prefijo_tns_default config instead of Firebird PREFIJO,
  add profesionalRemisionante from DOCIDMEDICO or remisionante_default config
- All queries: add DOCIDMEDICO column from MEDICO JOIN
- automation/transaccion: add remisionante_default and prefijo_tns_default params
- config: add remisionante_default (00) and prefijo_tns_default (00) keys
- automation SQL: filter NUM_FACTURA > 0 to skip unbilled records
- config.html: add UI fields for new config keys

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 18:57:54 -05:00

218 lines
9.5 KiB
HTML

{% extends "base.html" %}
{% block title %}Prueba RDA{% endblock %}
{% block header %}Prueba RDA Individual{% endblock %}
{% block content %}
<div class="max-w-6xl space-y-6">
<!-- Filtros y candidatos -->
<div class="bg-white rounded-xl shadow-sm border border-gray-200">
<div class="px-6 py-4 border-b border-gray-200 flex items-center justify-between">
<h3 class="font-semibold text-gray-800"><i class="fas fa-list mr-2 text-blue-500"></i>Candidatos disponibles</h3>
<div class="flex gap-2 items-center">
<input id="filtro-contrato" type="text" placeholder="Contrato (ej: 011)"
class="px-3 py-1.5 border border-gray-300 rounded-lg text-sm w-32">
<input id="filtro-factura" type="text" placeholder="Factura (ej: 3990)"
class="px-3 py-1.5 border border-gray-300 rounded-lg text-sm w-36">
<button onclick="cargarCandidatos()"
class="px-4 py-1.5 bg-blue-600 text-white rounded-lg text-sm hover:bg-blue-700">
<i class="fas fa-search mr-1"></i> Buscar
</button>
</div>
</div>
<div class="p-4">
<div id="cargando-candidatos" class="hidden text-center py-6 text-gray-400">
<i class="fas fa-spinner fa-spin text-2xl"></i>
<p class="mt-2 text-sm">Consultando Firebird...</p>
</div>
<div id="tabla-candidatos" class="hidden">
<table class="w-full text-sm">
<thead>
<tr class="text-left text-xs text-gray-500 uppercase border-b">
<th class="pb-2 pr-3">IDRECEPCION</th>
<th class="pb-2 pr-3">Factura</th>
<th class="pb-2 pr-3">Fecha</th>
<th class="pb-2 pr-3">Paciente</th>
<th class="pb-2 pr-3">Contrato</th>
<th class="pb-2 pr-3">Exámenes</th>
<th class="pb-2"></th>
</tr>
</thead>
<tbody id="tbody-candidatos" class="divide-y divide-gray-100"></tbody>
</table>
</div>
<p id="sin-candidatos" class="hidden text-center py-6 text-gray-400 text-sm">No se encontraron registros con los filtros aplicados.</p>
</div>
</div>
<!-- Envío manual -->
<div class="bg-white rounded-xl shadow-sm border border-gray-200">
<div class="px-6 py-4 border-b border-gray-200">
<h3 class="font-semibold text-gray-800"><i class="fas fa-paper-plane mr-2 text-green-500"></i>Enviar RDA</h3>
</div>
<div class="p-6">
<div class="flex gap-3 items-end">
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Tipo</label>
<select id="modo" class="px-3 py-2 border border-gray-300 rounded-lg text-sm">
<option value="idrecepcion">IDRECEPCION</option>
<option value="factura">Factura</option>
</select>
</div>
<div class="flex-1 max-w-xs">
<label class="block text-xs font-medium text-gray-600 mb-1">Número</label>
<input id="valor" type="text" placeholder="ej: 314863"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500">
</div>
<button onclick="enviarRDA()"
class="px-5 py-2 bg-green-600 text-white rounded-lg text-sm hover:bg-green-700 font-medium">
<i class="fas fa-paper-plane mr-1"></i> Enviar
</button>
</div>
</div>
</div>
<!-- Resultado -->
<div id="resultado-box" class="hidden bg-white rounded-xl shadow-sm border border-gray-200">
<div class="px-6 py-4 border-b border-gray-200 flex items-center justify-between">
<h3 class="font-semibold text-gray-800"><i class="fas fa-chart-bar mr-2 text-purple-500"></i>Resultado</h3>
<div id="resumen-badges" class="flex gap-2"></div>
</div>
<div id="resultado-contenido" class="p-6 space-y-3"></div>
</div>
</div>
<script>
async function cargarCandidatos() {
const contrato = document.getElementById('filtro-contrato').value.trim();
const factura = document.getElementById('filtro-factura').value.trim();
document.getElementById('cargando-candidatos').classList.remove('hidden');
document.getElementById('tabla-candidatos').classList.add('hidden');
document.getElementById('sin-candidatos').classList.add('hidden');
const params = new URLSearchParams();
if (contrato) params.append('contrato', contrato);
if (factura) params.append('factura', factura);
const resp = await fetch('/test-rda/candidatos?' + params.toString());
const data = await resp.json();
document.getElementById('cargando-candidatos').classList.add('hidden');
if (data.error) {
document.getElementById('sin-candidatos').textContent = 'Error: ' + data.error;
document.getElementById('sin-candidatos').classList.remove('hidden');
return;
}
const candidatos = data.candidatos || [];
if (!candidatos.length) {
document.getElementById('sin-candidatos').classList.remove('hidden');
return;
}
const tbody = document.getElementById('tbody-candidatos');
tbody.innerHTML = '';
candidatos.forEach(c => {
const tr = document.createElement('tr');
tr.className = 'hover:bg-gray-50';
tr.innerHTML = `
<td class="py-2 pr-3 font-mono text-blue-700 font-medium">${c.idrecepcion}</td>
<td class="py-2 pr-3 font-mono">${c.factura}</td>
<td class="py-2 pr-3 text-gray-500">${c.fecha}</td>
<td class="py-2 pr-3 text-gray-600">${c.paciente}</td>
<td class="py-2 pr-3">
<span class="px-2 py-0.5 bg-blue-50 text-blue-700 rounded text-xs font-mono">${c.contrato}</span>
</td>
<td class="py-2 pr-3 text-gray-500 text-xs max-w-xs truncate" title="${c.examenes}">${c.examenes} <span class="text-gray-400">(${c.total})</span></td>
<td class="py-2">
<button onclick="enviarDesde(${c.idrecepcion})"
class="px-3 py-1 bg-green-100 text-green-700 rounded text-xs hover:bg-green-200 font-medium">
<i class="fas fa-paper-plane mr-1"></i>Enviar
</button>
</td>
`;
tbody.appendChild(tr);
});
document.getElementById('tabla-candidatos').classList.remove('hidden');
}
function enviarDesde(idrecepcion) {
document.getElementById('modo').value = 'idrecepcion';
document.getElementById('valor').value = idrecepcion;
enviarRDA();
}
async function enviarRDA() {
const modo = document.getElementById('modo').value;
const valor = document.getElementById('valor').value.trim();
if (!valor) { alert('Ingresa un número'); return; }
const box = document.getElementById('resultado-box');
const contenido = document.getElementById('resultado-contenido');
const badges = document.getElementById('resumen-badges');
box.classList.remove('hidden');
contenido.innerHTML = '<div class="text-center py-8 text-gray-400"><i class="fas fa-spinner fa-spin text-3xl"></i><p class="mt-2">Enviando...</p></div>';
badges.innerHTML = '';
const fd = new FormData();
fd.append('modo', modo);
fd.append('valor', valor);
const resp = await fetch('/test-rda/enviar', { method: 'POST', body: fd });
const data = await resp.json();
if (data.error) {
contenido.innerHTML = `<div class="p-4 bg-red-50 border border-red-200 rounded-lg text-red-700 text-sm"><i class="fas fa-times-circle mr-2"></i>${data.error}</div>`;
return;
}
const res = data.resumen || {};
badges.innerHTML = `
<span class="px-2 py-1 bg-green-100 text-green-700 rounded text-xs font-medium">${res.rda_exitosos} exitosos</span>
<span class="px-2 py-1 bg-red-100 text-red-700 rounded text-xs font-medium">${res.rda_errores} errores</span>
<span class="px-2 py-1 bg-gray-100 text-gray-600 rounded text-xs">${res.pacientes_procesados} pacientes</span>
`;
let html = '';
(data.pasos || []).forEach(p => {
const icon = p.ok ? '✅' : '❌';
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 class="text-lg">${icon}</span>
<div class="flex-1 min-w-0">
<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 mt-0.5">${p.mensaje}</p>
</div>
</div>`;
} else {
const jsonStr = JSON.stringify(p.json_enviado || {}, null, 2);
const uid = 'json_' + p.idrecepcion;
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">${icon}</span>
<div class="flex-1">
<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>
</p>
<p class="text-xs text-gray-500 mt-0.5">Exámenes: ${(p.examenes || []).join(', ')}</p>
<p class="text-sm mt-1 ${p.ok ? 'text-green-700' : 'text-red-700'} font-medium">${p.mensaje}</p>
</div>
<button onclick="document.getElementById('${uid}').classList.toggle('hidden')"
class="text-xs text-gray-400 hover:text-gray-600 shrink-0">JSON</button>
</div>
<pre id="${uid}" class="hidden mx-3 mb-3 p-3 bg-gray-900 text-green-300 rounded text-xs overflow-x-auto">${jsonStr.replace(/</g,'&lt;')}</pre>
</div>`;
}
});
contenido.innerHTML = html;
}
// Cargar candidatos al abrir la página
cargarCandidatos();
</script>
{% endblock %}