492 lines
20 KiB
PHP
492 lines
20 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Pantalla de Turnos</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
|
|
<style>
|
|
/* ── Base ─────────────────────────────────────────── */
|
|
*, *::before, *::after { box-sizing: border-box; }
|
|
html, body {
|
|
margin: 0; padding: 0;
|
|
height: 100%; width: 100%;
|
|
overflow: hidden;
|
|
background: #0a0f1e;
|
|
color: #f0f4ff;
|
|
font-family: 'Segoe UI', system-ui, sans-serif;
|
|
}
|
|
|
|
/* ── Layout ───────────────────────────────────────── */
|
|
.display-grid {
|
|
display: grid;
|
|
grid-template-rows: auto 1fr auto;
|
|
height: 100vh;
|
|
gap: 0;
|
|
}
|
|
.display-header {
|
|
display: flex; align-items: center; justify-content: space-between;
|
|
padding: .75rem 2rem;
|
|
background: #0f172a;
|
|
border-bottom: 1px solid #1e293b;
|
|
flex-shrink: 0;
|
|
}
|
|
.display-header .titulo {
|
|
font-size: clamp(1rem, 2.5vw, 1.5rem);
|
|
font-weight: 700; color: #94a3b8;
|
|
display: flex; align-items: center; gap: .6rem;
|
|
}
|
|
.display-header .reloj {
|
|
font-size: clamp(1.2rem, 3vw, 1.8rem);
|
|
font-weight: 800; color: #e2e8f0;
|
|
font-variant-numeric: tabular-nums;
|
|
}
|
|
.display-header .estado-chip {
|
|
font-size: .8rem; padding: .25rem .75rem; border-radius: 20px;
|
|
font-weight: 700;
|
|
}
|
|
.estado-chip.conectado { background: #14532d; color: #86efac; }
|
|
.estado-chip.conectando { background: #422006; color: #fdba74; }
|
|
.estado-chip.error { background: #450a0a; color: #fca5a5; }
|
|
|
|
/* ── Panel central ────────────────────────────────── */
|
|
.display-body {
|
|
display: grid;
|
|
grid-template-columns: 1fr 340px;
|
|
height: 100%;
|
|
overflow: hidden;
|
|
}
|
|
@media (max-width: 768px) {
|
|
.display-body { grid-template-columns: 1fr; }
|
|
.cola-panel { display: none !important; }
|
|
}
|
|
|
|
/* ── Turno activo ─────────────────────────────────── */
|
|
.turno-activo {
|
|
display: flex; flex-direction: column;
|
|
align-items: center; justify-content: center;
|
|
padding: 2rem; position: relative;
|
|
overflow: hidden;
|
|
background: radial-gradient(ellipse at center, #111827 0%, #0a0f1e 70%);
|
|
}
|
|
.turno-activo .etiqueta {
|
|
font-size: clamp(.9rem, 2vw, 1.2rem);
|
|
color: #64748b; font-weight: 600;
|
|
text-transform: uppercase; letter-spacing: 3px;
|
|
margin-bottom: .5rem;
|
|
}
|
|
.turno-activo .codigo-grande {
|
|
font-size: clamp(5rem, 22vw, 16rem);
|
|
font-weight: 900; line-height: 1;
|
|
letter-spacing: -4px;
|
|
transition: color .4s;
|
|
}
|
|
.turno-activo .nombre-pac {
|
|
font-size: clamp(1rem, 3vw, 2rem);
|
|
font-weight: 600; color: #cbd5e1;
|
|
margin-top: .5rem; text-align: center;
|
|
}
|
|
.turno-activo .prio-badge {
|
|
display: inline-flex; align-items: center; gap: .5rem;
|
|
padding: .4rem 1.2rem; border-radius: 30px;
|
|
font-size: clamp(.8rem, 1.8vw, 1.15rem); font-weight: 700;
|
|
margin-top: 1rem;
|
|
}
|
|
.turno-activo .sin-turno {
|
|
font-size: clamp(1.5rem, 4vw, 3rem);
|
|
color: #334155; text-align: center;
|
|
}
|
|
|
|
/* Anillo de animación al llamar turno */
|
|
@keyframes ping-ring {
|
|
0% { transform: scale(.8); opacity: .9; }
|
|
100% { transform: scale(2.5); opacity: 0; }
|
|
}
|
|
.ring-anim {
|
|
position: absolute; inset: 0;
|
|
display: flex; align-items: center; justify-content: center;
|
|
pointer-events: none; z-index: 0;
|
|
}
|
|
.ring-anim::before {
|
|
content: '';
|
|
width: 35vmin; height: 35vmin;
|
|
border-radius: 50%;
|
|
background: transparent;
|
|
border: 4px solid currentColor;
|
|
opacity: 0;
|
|
}
|
|
.ring-anim.animar::before {
|
|
animation: ping-ring .7s ease-out 1;
|
|
}
|
|
.turno-activo > *:not(.ring-anim) { position: relative; z-index: 1; }
|
|
|
|
/* ── Panel de cola ────────────────────────────────── */
|
|
.cola-panel {
|
|
background: #0f172a;
|
|
border-left: 1px solid #1e293b;
|
|
display: flex; flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
.cola-panel-header {
|
|
padding: 1rem 1.2rem .6rem;
|
|
font-size: .85rem; font-weight: 700;
|
|
color: #64748b; text-transform: uppercase; letter-spacing: 2px;
|
|
border-bottom: 1px solid #1e293b;
|
|
flex-shrink: 0;
|
|
}
|
|
.cola-lista {
|
|
flex: 1; overflow-y: auto;
|
|
padding: .5rem;
|
|
scrollbar-width: thin; scrollbar-color: #1e293b transparent;
|
|
}
|
|
.cola-item {
|
|
display: flex; align-items: center; gap: .75rem;
|
|
padding: .6rem .8rem; border-radius: 10px;
|
|
margin-bottom: .35rem;
|
|
background: #1e293b;
|
|
transition: background .2s;
|
|
}
|
|
.cola-item:first-child { background: #1e3a5f; }
|
|
.cola-item .cod-badge {
|
|
font-size: 1.2rem; font-weight: 900;
|
|
min-width: 52px; text-align: center;
|
|
padding: .2rem .4rem; border-radius: 8px;
|
|
}
|
|
.cola-item .pac-info { flex: 1; min-width: 0; }
|
|
.cola-item .pac-nombre {
|
|
font-size: .85rem; color: #e2e8f0; font-weight: 600;
|
|
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
|
}
|
|
.cola-item .pac-hora { font-size: .72rem; color: #475569; }
|
|
.cola-vacia { color: #334155; text-align: center; padding: 3rem 1rem; font-size: .95rem; }
|
|
|
|
/* ── Stats (footer) ──────────────────────────────── */
|
|
.display-footer {
|
|
display: flex; justify-content: center; gap: 2.5rem; flex-wrap: wrap;
|
|
padding: .65rem 2rem;
|
|
background: #0f172a;
|
|
border-top: 1px solid #1e293b;
|
|
flex-shrink: 0;
|
|
}
|
|
.stat-item { text-align: center; }
|
|
.stat-item .val { font-size: 1.3rem; font-weight: 800; color: #e2e8f0; }
|
|
.stat-item .lbl { font-size: .7rem; color: #64748b; text-transform: uppercase; letter-spacing: 1px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="display-grid">
|
|
|
|
<!-- ── Cabecera ─────────────────────────────────────── -->
|
|
<header class="display-header">
|
|
<div class="titulo">
|
|
<i class="fas fa-ticket-alt"></i>
|
|
<span id="lbl-area">Sistema de Turnos</span>
|
|
</div>
|
|
<span id="chip-estado" class="estado-chip conectando">
|
|
<i class="fas fa-circle-notch fa-spin me-1"></i>Conectando…
|
|
</span>
|
|
<button id="btn-activar-sonido" onclick="activarSonido()" title="Toca para activar el sonido del turnero"
|
|
style="background:rgba(59,130,246,0.15);border:1px solid rgba(59,130,246,0.4);color:#93c5fd;
|
|
border-radius:8px;padding:6px 14px;font-size:.82rem;cursor:pointer;
|
|
display:flex;align-items:center;gap:6px;white-space:nowrap">
|
|
<i class="fas fa-volume-mute"></i> Activar sonido
|
|
</button>
|
|
<div class="reloj" id="reloj">--:--:--</div>
|
|
</header>
|
|
|
|
<!-- ── Cuerpo ────────────────────────────────────────── -->
|
|
<div class="display-body">
|
|
|
|
<!-- Turno activo -->
|
|
<div class="turno-activo" id="zona-activo">
|
|
<div class="ring-anim" id="ring" style="color:#3b82f6"></div>
|
|
<div class="etiqueta">Turno en atención</div>
|
|
<div class="codigo-grande" id="codigo-activo" style="color:#3b82f6">—</div>
|
|
<div class="nombre-pac" id="nombre-activo"></div>
|
|
<div class="prio-badge" id="prio-activo" style="background:#1e293b;color:#94a3b8">
|
|
<i class="fas fa-ticket-alt"></i> Esperando turno
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Lista de cola -->
|
|
<div class="cola-panel">
|
|
<div class="cola-panel-header">
|
|
<i class="fas fa-list-ol me-1"></i>EN ESPERA
|
|
</div>
|
|
<div class="cola-lista" id="cola-lista">
|
|
<div class="cola-vacia">
|
|
<i class="fas fa-hourglass-start fa-2x mb-2 d-block"></i>
|
|
Cola vacía
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- ── Footer stats ──────────────────────────────────── -->
|
|
<footer class="display-footer">
|
|
<div class="stat-item">
|
|
<div class="val" id="stat-espera">—</div>
|
|
<div class="lbl">En espera</div>
|
|
</div>
|
|
<div class="stat-item">
|
|
<div class="val" id="stat-atendidos">—</div>
|
|
<div class="lbl">Atendidos hoy</div>
|
|
</div>
|
|
<div class="stat-item">
|
|
<div class="val" id="stat-total">—</div>
|
|
<div class="lbl">Total del día</div>
|
|
</div>
|
|
<div class="stat-item">
|
|
<div class="val" id="stat-tiempo">—</div>
|
|
<div class="lbl">Tiempo prom.</div>
|
|
</div>
|
|
</footer>
|
|
</div>
|
|
|
|
<script>
|
|
// ── Configuración desde URL ───────────────────────────────────
|
|
const params = new URLSearchParams(location.search);
|
|
const area = params.get('display') || 'recepcion';
|
|
const lugarId = params.get('lugar_id') || '';
|
|
const BASE_API = '<?= BASE_URL ?>modules/turnero/api/';
|
|
|
|
// Etiqueta de área
|
|
document.getElementById('lbl-area').textContent =
|
|
area === 'lugar' && lugarId ? `Lugar #${lugarId} — Turnos` : 'Recepción — Turnos';
|
|
|
|
// ── Reloj ─────────────────────────────────────────────────────
|
|
function actualizarReloj() {
|
|
document.getElementById('reloj').textContent =
|
|
new Date().toLocaleTimeString('es-CO', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
}
|
|
actualizarReloj();
|
|
setInterval(actualizarReloj, 1000);
|
|
|
|
// ── Audio ─────────────────────────────────────────────────────
|
|
let audioCtx = null;
|
|
let sonidoActivo = false;
|
|
|
|
function activarSonido() {
|
|
try {
|
|
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
|
// Beep silencioso para desbloquear el contexto en el mismo gesto
|
|
const g = audioCtx.createGain();
|
|
g.gain.setValueAtTime(0.001, audioCtx.currentTime);
|
|
const o = audioCtx.createOscillator();
|
|
o.connect(g); g.connect(audioCtx.destination);
|
|
o.start(); o.stop(audioCtx.currentTime + 0.05);
|
|
} catch (_) {}
|
|
sonidoActivo = true;
|
|
const btn = document.getElementById('btn-activar-sonido');
|
|
if (btn) {
|
|
btn.innerHTML = '<i class="fas fa-volume-up"></i> Sonido ON';
|
|
btn.style.background = 'rgba(34,197,94,0.2)';
|
|
btn.style.borderColor = 'rgba(34,197,94,0.5)';
|
|
btn.style.color = '#86efac';
|
|
btn.onclick = null;
|
|
btn.style.cursor = 'default';
|
|
// Reproducir beep de prueba al activar
|
|
setTimeout(playBeep, 100);
|
|
}
|
|
}
|
|
|
|
// Desbloquear también si el usuario toca/clica cualquier parte de la pantalla
|
|
document.addEventListener('click', () => { if (!sonidoActivo) activarSonido(); }, { once: true });
|
|
document.addEventListener('touchstart', () => { if (!sonidoActivo) activarSonido(); }, { once: true });
|
|
|
|
function playBeep() {
|
|
if (sonidoActivo && audioCtx) {
|
|
try {
|
|
const osc = audioCtx.createOscillator();
|
|
const gain = audioCtx.createGain();
|
|
osc.type = 'sine';
|
|
osc.connect(gain);
|
|
gain.connect(audioCtx.destination);
|
|
osc.frequency.setValueAtTime(880, audioCtx.currentTime);
|
|
osc.frequency.setValueAtTime(1100, audioCtx.currentTime + 0.1);
|
|
osc.frequency.setValueAtTime(880, audioCtx.currentTime + 0.2);
|
|
gain.gain.setValueAtTime(0.35, audioCtx.currentTime);
|
|
gain.gain.exponentialRampToValueAtTime(0.0001, audioCtx.currentTime + 0.65);
|
|
osc.start(audioCtx.currentTime);
|
|
osc.stop(audioCtx.currentTime + 0.65);
|
|
} catch (_) {}
|
|
}
|
|
}
|
|
|
|
function anunciarTurno(codigo, nombre) {
|
|
// 1. Beep electrónico
|
|
playBeep();
|
|
// 2. Voz sintética — funciona sin interacción previa en la mayoría de navegadores
|
|
if ('speechSynthesis' in window) {
|
|
// Esperar a que el beep termine antes de hablar
|
|
setTimeout(() => {
|
|
window.speechSynthesis.cancel();
|
|
const letras = codigo.split('').join(' '); // "A 0 1" para mejor pronunciación
|
|
let texto = `Turno ${letras}.`;
|
|
if (nombre) texto += ` ${nombre}, por favor pase a recepción.`;
|
|
const utt = new SpeechSynthesisUtterance(texto);
|
|
utt.lang = 'es-CO';
|
|
utt.rate = 0.88;
|
|
utt.pitch = 1.05;
|
|
utt.volume = 1;
|
|
window.speechSynthesis.speak(utt);
|
|
}, 700);
|
|
}
|
|
}
|
|
|
|
// ── Estado previo ─────────────────────────────────────────────
|
|
let lastCodigoActivo = null;
|
|
|
|
// ── Render ────────────────────────────────────────────────────
|
|
function renderSnapshot(snap) {
|
|
const activo = snap.activo;
|
|
const cola = snap.cola || [];
|
|
const stats = snap.stats || {};
|
|
|
|
// Turno activo
|
|
const elCodigo = document.getElementById('codigo-activo');
|
|
const elNombre = document.getElementById('nombre-activo');
|
|
const elPrio = document.getElementById('prio-activo');
|
|
const elRing = document.getElementById('ring');
|
|
|
|
if (activo) {
|
|
const color = activo.prioridad_color || '#3b82f6';
|
|
|
|
// ¿Cambió el turno? → animar + sonido
|
|
if (activo.codigo !== lastCodigoActivo) {
|
|
anunciarTurno(activo.codigo, activo.paciente_nombre || '');
|
|
elRing.style.color = color;
|
|
elRing.classList.remove('animar');
|
|
// Forzar reflow para reiniciar animación
|
|
void elRing.offsetWidth;
|
|
elRing.classList.add('animar');
|
|
lastCodigoActivo = activo.codigo;
|
|
}
|
|
|
|
elCodigo.textContent = activo.codigo;
|
|
elCodigo.style.color = color;
|
|
elNombre.textContent = activo.paciente_nombre || '';
|
|
elPrio.style.background = color + '33'; // 20% opacity
|
|
elPrio.style.color = color;
|
|
elPrio.innerHTML = `<i class="fas fa-ticket-alt"></i> ${activo.prioridad_codigo} — ${activo.prioridad_nombre}`;
|
|
} else {
|
|
elCodigo.textContent = '—';
|
|
elCodigo.style.color = '#334155';
|
|
elNombre.textContent = '';
|
|
elPrio.style.background = '#1e293b';
|
|
elPrio.style.color = '#94a3b8';
|
|
elPrio.innerHTML = '<i class="fas fa-ticket-alt"></i> Esperando turno';
|
|
lastCodigoActivo = null;
|
|
}
|
|
|
|
// Lista de cola (excluir el activo si está ahí)
|
|
const colaEspera = cola.filter(t =>
|
|
t.estado === 'espera' || t.estado === 'en_espera_lugar'
|
|
);
|
|
const elLista = document.getElementById('cola-lista');
|
|
|
|
if (colaEspera.length === 0) {
|
|
elLista.innerHTML = `
|
|
<div class="cola-vacia">
|
|
<i class="fas fa-hourglass-start fa-2x mb-2 d-block"></i>
|
|
Cola vacía
|
|
</div>`;
|
|
} else {
|
|
elLista.innerHTML = colaEspera.map((t, idx) => {
|
|
const hora = t.creado_at ? new Date(t.creado_at).toLocaleTimeString('es-CO',
|
|
{ hour: '2-digit', minute: '2-digit' }) : '';
|
|
return `
|
|
<div class="cola-item">
|
|
<span class="cod-badge" style="background:${t.prioridad_color}22;color:${t.prioridad_color}">${t.codigo}</span>
|
|
<div class="pac-info">
|
|
<div class="pac-nombre">${escHtml(t.paciente_nombre || 'Paciente')}</div>
|
|
<div class="pac-hora">${t.prioridad_nombre} • ${hora}</div>
|
|
</div>
|
|
${idx === 0 ? '<i class="fas fa-arrow-right" style="color:#3b82f6;font-size:.8rem"></i>' : ''}
|
|
</div>`;
|
|
}).join('');
|
|
}
|
|
|
|
// Stats
|
|
const enEspera = parseInt(stats.en_espera || 0) + parseInt(stats.en_espera_lugar || 0);
|
|
document.getElementById('stat-espera').textContent = enEspera;
|
|
document.getElementById('stat-atendidos').textContent = stats.finalizados || 0;
|
|
document.getElementById('stat-total').textContent = stats.total || 0;
|
|
document.getElementById('stat-tiempo').textContent = stats.tiempo_promedio_atencion
|
|
? stats.tiempo_promedio_atencion.substring(0, 5) : '—';
|
|
}
|
|
|
|
function escHtml(str) {
|
|
const d = document.createElement('div');
|
|
d.appendChild(document.createTextNode(str));
|
|
return d.innerHTML;
|
|
}
|
|
|
|
// ── Carga/polling ─────────────────────────────────────────────
|
|
let pollTimer = null;
|
|
|
|
async function cargarSnapshot() {
|
|
const url = new URL(BASE_API + 'get_cola.php', location.href);
|
|
url.searchParams.set('area', area);
|
|
if (lugarId) url.searchParams.set('lugar_id', lugarId);
|
|
|
|
try {
|
|
const res = await fetch(url.toString(), { cache: 'no-store' });
|
|
const json = await res.json();
|
|
if (json.ok) renderSnapshot(json);
|
|
} catch (_) {}
|
|
}
|
|
|
|
// Arrancar polling cada 4 s (funciona aunque SSE falle por proxy)
|
|
function iniciarPolling() {
|
|
cargarSnapshot();
|
|
pollTimer = setInterval(cargarSnapshot, 4000);
|
|
}
|
|
|
|
// ── SSE ───────────────────────────────────────────────────────
|
|
const chipEstado = document.getElementById('chip-estado');
|
|
let esSource = null;
|
|
let reconnectDelay = 2000;
|
|
let sseViva = false;
|
|
|
|
function conectarSSE() {
|
|
const sseUrl = new URL(BASE_API + 'sse_turno.php', location.href);
|
|
sseUrl.searchParams.set('area', area);
|
|
if (lugarId) sseUrl.searchParams.set('lugar_id', lugarId);
|
|
|
|
esSource = new EventSource(sseUrl.toString());
|
|
|
|
esSource.addEventListener('open', () => {
|
|
reconnectDelay = 2000;
|
|
sseViva = true;
|
|
chipEstado.className = 'estado-chip conectado';
|
|
chipEstado.innerHTML = '<i class="fas fa-circle me-1" style="font-size:.5rem"></i>En vivo';
|
|
});
|
|
|
|
esSource.addEventListener('cola_update', (e) => {
|
|
try {
|
|
const snap = JSON.parse(e.data);
|
|
renderSnapshot(snap);
|
|
} catch (_) {}
|
|
});
|
|
|
|
esSource.addEventListener('error', () => {
|
|
sseViva = false;
|
|
chipEstado.className = 'estado-chip error';
|
|
chipEstado.innerHTML = '<i class="fas fa-exclamation-circle me-1"></i>Reconectando…';
|
|
esSource.close();
|
|
setTimeout(conectarSSE, reconnectDelay);
|
|
reconnectDelay = Math.min(reconnectDelay * 2, 30000);
|
|
});
|
|
}
|
|
|
|
// ── Inicio ────────────────────────────────────────────────────
|
|
iniciarPolling();
|
|
conectarSSE();
|
|
</script>
|
|
</body>
|
|
</html>
|