feat: auto-load RIPS exams when patient is selected in recepcion

When a patient with a cedula is selected, the system queries RIPS
Manager for exams registered in the last 5 minutes. A green banner
shows the count with a "Cargar" button that pre-fills TomSelect.
Unmapped exam codes shown as a warning. Banner clears on deselect/reset.

- config.php: RIPS_MANAGER_URL constant from env var
- api/lab/get_examenes_rips.php: proxy + codigo_legacy mapper
- recepcion.php: banner HTML + consultarExamenesRips/cargarExamenesRips JS

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-09 14:05:39 -05:00
co-authored by Claude Sonnet 4.6
parent bffa38e9c0
commit d0a42dba33
3 changed files with 147 additions and 0 deletions
+62
View File
@@ -625,6 +625,24 @@ document.addEventListener('DOMContentLoaded', function() {
</select>
</div>
<!-- Banner RIPS: exámenes detectados automáticamente -->
<div id="banner-rips" class="d-none mt-1 mb-1 p-2 rounded d-flex align-items-center justify-content-between gap-2"
style="background:#f0fdf4;border:1px solid #86efac;font-size:.82rem">
<div>
<i class="fas fa-flask text-success me-1"></i>
<span id="banner-rips-txt" class="fw-semibold"></span>
<span id="banner-rips-warn" class="d-none text-warning ms-2"></span>
</div>
<div class="d-flex gap-1 flex-shrink-0">
<button class="btn btn-success btn-sm py-0 px-2" onclick="cargarExamenesRips()">
<i class="fas fa-check me-1"></i>Cargar
</button>
<button class="btn btn-outline-secondary btn-sm py-0 px-2" onclick="descartarRips()">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<!-- ── Sección 3: Exámenes ── -->
<div class="ficha-section">
<h6><i class="fas fa-vial me-1"></i>Exámenes solicitados</h6>
@@ -1437,6 +1455,48 @@ function seleccionarPaciente(pac) {
// Precargar en background (usuario decide si abre)
_historialPacienteCargado = false;
_historialPacienteId = pac.id;
// Consultar exámenes recientes en RIPS (últimos 5 min)
const cedula = (pac.numero_documento || pac.documento || '').toString().trim();
if (cedula) consultarExamenesRips(cedula);
}
// ── Exámenes desde RIPS ───────────────────────────────────────
let _ripsData = null;
async function consultarExamenesRips(cedula) {
_ripsData = null;
document.getElementById('banner-rips').classList.add('d-none');
if (!cedula) return;
try {
const r = await fetch(`${BASE_WA}api/lab/get_examenes_rips.php?cedula=${encodeURIComponent(cedula)}`);
const d = await r.json();
if (!d.ok || !d.encontrados?.length) return;
_ripsData = d;
const hora = d.hora ? ' (' + String(d.hora).slice(0, 5) + ')' : '';
document.getElementById('banner-rips-txt').textContent =
`${d.encontrados.length} examen(es) de RIPS${hora} — ¿Cargar?`;
const warn = document.getElementById('banner-rips-warn');
if (d.no_mapeados?.length) {
warn.textContent = `⚠ Sin mapeo: ${d.no_mapeados.join(', ')}`;
warn.classList.remove('d-none');
} else {
warn.classList.add('d-none');
}
document.getElementById('banner-rips').classList.remove('d-none');
} catch (_) {}
}
function cargarExamenesRips() {
if (!_ripsData?.encontrados?.length || !examTS) return;
_ripsData.encontrados.forEach(e => examTS.addItem(String(e.exam_tipo_id), true));
recalcularPrecios();
descartarRips();
}
function descartarRips() {
_ripsData = null;
document.getElementById('banner-rips').classList.add('d-none');
}
function togglePagoCombinado() {
@@ -1463,6 +1523,7 @@ function resetPagoCombinado() {
function desvincularPaciente() {
pacienteActivo = null;
_historialPacienteId = null;
descartarRips();
_historialPacienteCargado = false;
document.getElementById('bloque-pac-no-vinculado').classList.remove('d-none');
document.getElementById('bloque-pac-seleccionado').classList.add('d-none');
@@ -2037,6 +2098,7 @@ function resetCheckboxes() {
if (examTS) { examTS.clear(); examTS.enable(); }
document.getElementById('wrap-examenes').classList.remove('disabled');
document.getElementById('bloque-medico').style.display = '';
descartarRips();
document.getElementById('sel-pago').value = '';
document.getElementById('inp-total').value = '';
document.getElementById('inp-obs').value = '';