From eaa8a23af62647a027df0abb8f3896ea14628dba Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 16 Jun 2026 14:51:46 -0500 Subject: [PATCH] UP --- modules/turnero/api/get_display_global.php | 2 +- modules/turnero/views/display_global.php | 53 +++--- modules/turnero/views/lugar.php | 187 ++++++++++++--------- 3 files changed, 141 insertions(+), 101 deletions(-) diff --git a/modules/turnero/api/get_display_global.php b/modules/turnero/api/get_display_global.php index b5d8b4c..89bf58d 100644 --- a/modules/turnero/api/get_display_global.php +++ b/modules/turnero/api/get_display_global.php @@ -115,7 +115,7 @@ foreach ($lugares as $lugar) { FROM turnero_turnos t JOIN turnero_prioridades p ON p.id = t.prioridad_id WHERE t.sesion_id = ? - AND t.estado IN ('en_espera_lugar', 'en_servicio') + AND t.estado = 'en_servicio' AND t.lugar_destino_id = ? ORDER BY t.llamado_lugar_at DESC LIMIT 1" diff --git a/modules/turnero/views/display_global.php b/modules/turnero/views/display_global.php index faaf1a4..3c8f86b 100644 --- a/modules/turnero/views/display_global.php +++ b/modules/turnero/views/display_global.php @@ -566,7 +566,7 @@ function showAnnouncement({ codigo, destino, paciente, color }) { } /* ── State ── */ -let lastTurnoKey = null; +let lastSeenKeys = new Set(); // clave por turno+destino+llamado_at let llamados = []; function renderSnapshot(snap) { @@ -576,48 +576,53 @@ function renderSnapshot(snap) { const lblEl = document.getElementById('lugar-label'); const ringEl = document.getElementById('pulse-ring'); - const turnos = []; - + // Recopilar TODOS los turnos activos: recepción + lugares + const allTurnos = []; (snap.activos_recepcion || []).forEach(d => { - if (d.turno) turnos.push({ ...d.turno, destino: d.desk_nombre, tipo: 'rec' }); + if (d.turno) allTurnos.push({ ...d.turno, destino: d.desk_nombre }); }); (snap.lugares || []).forEach(l => { - if (l.turno) turnos.push({ ...l.turno, destino: l.lugar_nombre, tipo: 'mue' }); + if (l.turno) allTurnos.push({ ...l.turno, destino: l.lugar_nombre }); }); - if (turnos.length > 0) { - const t = turnos[0]; + // Detectar turno nuevo en CUALQUIER estación y anunciar + const currentKeys = new Set(); + let anuncioNuevo = false; + allTurnos.forEach(t => { + const key = t.codigo + '|' + t.destino + '|' + (t.llamado_at || ''); + currentKeys.add(key); + if (!lastSeenKeys.has(key)) { + const c = t.prioridad_color || ''; + queueAnnouncement({ _key: key, codigo: t.codigo, destino: t.destino, paciente: t.paciente_nombre, color: c }); + llamados.unshift({ codigo: t.codigo, destino: t.destino, paciente: t.paciente_nombre, color: c }); + if (llamados.length > 30) llamados.pop(); + anuncioNuevo = true; + } + }); + lastSeenKeys = currentKeys; + if (anuncioNuevo) renderLlamados(); + + // zona-activo: mostrar el turno llamado más recientemente + const sorted = allTurnos.slice().sort((a, b) => { + return new Date(b.llamado_at || 0) - new Date(a.llamado_at || 0); + }); + + if (sorted.length > 0) { + const t = sorted[0]; codEl.textContent = t.codigo; lugEl.textContent = t.destino; pacEl.textContent = t.paciente_nombre || ''; lblEl.textContent = 'Llamado a'; ringEl.classList.add('active'); - const c = t.prioridad_color || ''; codEl.style.color = c; document.getElementById('zona-activo').style.setProperty('--brand', c); - - const key = t.codigo + '|' + t.destino + '|' + (t.llamado_at || ''); - if (key !== lastTurnoKey) { - queueAnnouncement({ - _key: key, - codigo: t.codigo, - destino: t.destino, - paciente: t.paciente_nombre, - color: c - }); - lastTurnoKey = key; - llamados.unshift({ codigo: t.codigo, destino: t.destino, paciente: t.paciente_nombre, color: c }); - if (llamados.length > 30) llamados.pop(); - renderLlamados(); - } } else { codEl.textContent = '—'; lugEl.textContent = '—'; pacEl.textContent = ''; lblEl.textContent = 'Llamado a'; codEl.style.color = ''; - lastTurnoKey = null; ringEl.classList.remove('active'); } diff --git a/modules/turnero/views/lugar.php b/modules/turnero/views/lugar.php index f9ceff9..d509f53 100644 --- a/modules/turnero/views/lugar.php +++ b/modules/turnero/views/lugar.php @@ -176,6 +176,29 @@ $adminNombre = $_SESSION['admin_user']['full_name'] ?? $_SESSION['admin_user'][' } .selector-lugar-box h2 { font-size: 1.4rem; font-weight: 700; margin-bottom: 1.5rem; } + /* ── Toast ── */ + .rec-toast { + position: fixed; bottom: 2rem; right: 2rem; z-index: 9999; + display: flex; align-items: center; gap: .7rem; + padding: .8rem 1.2rem; border-radius: 12px; + background: #fff; border: 1px solid #e2e8f0; + box-shadow: 0 8px 30px rgba(0,0,0,.12); + font-size: .9rem; font-weight: 500; + transform: translateY(120%); opacity: 0; + transition: transform .3s ease, opacity .3s ease; + pointer-events: none; + } + .rec-toast.show { transform: translateY(0); opacity: 1; } + .rec-toast.success { border-left: 4px solid #22c55e; } + .rec-toast.info { border-left: 4px solid #3b82f6; } + .rec-toast.warn { border-left: 4px solid #f59e0b; } + .rec-toast.error { border-left: 4px solid #ef4444; } + .rec-toast .ico { font-size: 1.2rem; } + .rec-toast.success .ico { color: #22c55e; } + .rec-toast.info .ico { color: #3b82f6; } + .rec-toast.warn .ico { color: #f59e0b; } + .rec-toast.error .ico { color: #ef4444; } + /* ── Indicador de bloqueo ── */ .bloqueo-banner { background: #fef2f2; border: 1px solid #fca5a5; border-radius: 10px; @@ -313,8 +336,8 @@ require_once __DIR__ . '/../../../shared/components/sidebar.php';
-