diff --git a/modules/turnero/views/display_global.php b/modules/turnero/views/display_global.php index c888903..25fdd86 100644 --- a/modules/turnero/views/display_global.php +++ b/modules/turnero/views/display_global.php @@ -590,9 +590,10 @@ function showAnnouncement({ codigo, destino, paciente, color }) { } /* ── State ── */ -let lastSeenKeys = new Set(); -let llamados = []; -let _firstLoad = true; +let lastSeenKeys = new Set(); +let announcedCalls = new Set(); // dedup por id+llamado_at, evita anunciar mismo turno desde varios escritorios +let llamados = []; +let _firstLoad = true; function renderSnapshot(snap) { const codEl = document.getElementById('codigo-activo'); @@ -614,14 +615,15 @@ function renderSnapshot(snap) { const currentKeys = new Set(); let anuncioNuevo = false; allTurnos.forEach(t => { - const key = t.codigo + '|' + t.destino + '|' + (t.llamado_at || ''); + const key = t.codigo + '|' + t.destino + '|' + (t.llamado_at || ''); + // Clave única por evento de llamada (id+llamado_at), independiente del escritorio + const callKey = (t.id || t.codigo) + '|' + (t.llamado_at || ''); currentKeys.add(key); if (!lastSeenKeys.has(key)) { const c = t.prioridad_color || ''; - // Solo decir el nombre en voz si el paciente está registrado en lab_pacientes const nomVoz = t.paciente_id ? t.paciente_nombre : null; - // En primera carga silenciar todos; el más reciente se anuncia abajo - if (!_firstLoad) { + if (!_firstLoad && !announcedCalls.has(callKey)) { + announcedCalls.add(callKey); queueAnnouncement({ _key: key, codigo: t.codigo, destino: t.destino, paciente: nomVoz, color: c }); } llamados.unshift({ codigo: t.codigo, destino: t.destino, paciente: t.paciente_nombre, color: c }); @@ -635,10 +637,12 @@ function renderSnapshot(snap) { _firstLoad = false; const sorted = allTurnos.slice().sort((a, b) => new Date(b.llamado_at || 0) - new Date(a.llamado_at || 0)); if (sorted.length > 0) { - const t = sorted[0]; - const c = t.prioridad_color || ''; - const key = t.codigo + '|' + t.destino + '|' + (t.llamado_at || ''); - const nomVoz = t.paciente_id ? t.paciente_nombre : null; + const t = sorted[0]; + const c = t.prioridad_color || ''; + const key = t.codigo + '|' + t.destino + '|' + (t.llamado_at || ''); + const callKey = (t.id || t.codigo) + '|' + (t.llamado_at || ''); + const nomVoz = t.paciente_id ? t.paciente_nombre : null; + announcedCalls.add(callKey); queueAnnouncement({ _key: key, codigo: t.codigo, destino: t.destino, paciente: nomVoz, color: c }); } }