Files
whatsapp/modules/turnero/views/display_global.php
T

474 lines
17 KiB
PHP

<?php
$_dispCfg = [];
try {
$__pdo = Database::getInstance()->getConnection();
$__rows = $__pdo->query(
"SELECT clave, valor FROM lab_config WHERE clave IN ('empresa_nombre','doc_logo_base64','doc_color','turnero_tv_video')"
)->fetchAll(PDO::FETCH_KEY_PAIR);
$_dispCfg = $__rows ?: [];
} catch (\Throwable $_) {}
$_labNombre = htmlspecialchars($_dispCfg['empresa_nombre'] ?? 'Sistema de Turnos');
$_labLogo = $_dispCfg['doc_logo_base64'] ?? '';
$_labColor = preg_match('/^#[0-9a-fA-F]{3,8}$/', $_dispCfg['doc_color'] ?? '') ? $_dispCfg['doc_color'] : '#1565c0';
$_tvVideo = $_dispCfg['turnero_tv_video'] ?? '';
if ($_tvVideo && !preg_match('#^https?://#', $_tvVideo)) { $_tvVideo = ''; }
$_hasVideo = (bool)$_tvVideo;
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pantalla Global 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>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
height: 100%; width: 100%;
overflow: hidden;
background: #0f172a;
font-family: 'Segoe UI', system-ui, sans-serif;
color: #fff;
}
:root {
--brand: <?= $_labColor ?>;
--brand-glow: color-mix(in srgb, <?= $_labColor ?> 70%, transparent);
}
.pg-wrap {
display: grid;
grid-template-rows: auto 1fr auto;
height: 100vh;
overflow: hidden;
}
/* ── Header ── */
.pg-header {
display: flex; align-items: center; gap: 1rem;
padding: .5rem 1.5rem;
background: rgba(15,23,42,.95);
border-bottom: 1px solid rgba(255,255,255,.06);
flex-shrink: 0;
}
.hd-brand { display: flex; align-items: center; gap: .7rem; flex: 1; min-width: 0; }
.hd-brand .logo {
height: 40px; max-width: 100px; object-fit: contain;
background: rgba(255,255,255,.1); border-radius: 6px; padding: 3px 5px;
}
.lab-nombre {
font-size: clamp(.9rem, 1.8vw, 1.2rem);
font-weight: 700; color: #fff;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hd-right { display: flex; align-items: center; gap: .8rem; flex-shrink: 0; }
.reloj {
font-size: clamp(1rem, 2vw, 1.5rem);
font-weight: 700; color: rgba(255,255,255,.7);
font-variant-numeric: tabular-nums; letter-spacing: .5px;
}
.live-dot {
width: 7px; height: 7px; border-radius: 50%;
background: #4ade80; box-shadow: 0 0 8px #4ade80;
animation: pdot 2s ease-in-out infinite;
}
@keyframes pdot { 0%,100%{opacity:1} 50%{opacity:.3} }
/* ── Main body ── */
.pg-body {
display: grid;
grid-template-columns: 1fr;
overflow: hidden;
position: relative;
}
.pg-body.has-video {
grid-template-columns: 1fr;
}
/* ── Turno activo (centro) ── */
.turno-activo {
display: flex; flex-direction: column;
align-items: center; justify-content: center;
text-align: center;
padding: 1rem;
position: relative;
overflow: hidden;
}
.turno-activo .label {
font-size: clamp(.7rem, 1.2vw, .9rem);
font-weight: 700; text-transform: uppercase; letter-spacing: 4px;
color: rgba(255,255,255,.35);
margin-bottom: .2rem;
}
.turno-activo .codigo {
font-size: clamp(5rem, 22vw, 16rem);
font-weight: 900; line-height: 1;
letter-spacing: -4px;
color: var(--brand);
text-shadow: 0 0 60px var(--brand-glow), 0 0 120px var(--brand-glow);
transition: color .3s;
font-variant-numeric: tabular-nums;
}
.turno-activo .lugar-label {
font-size: clamp(1rem, 2.5vw, 1.8rem);
font-weight: 600;
color: rgba(255,255,255,.55);
margin-top: .3rem;
}
.turno-activo .lugar-nombre {
font-size: clamp(1.4rem, 3.5vw, 2.6rem);
font-weight: 800;
color: #fff;
margin-top: .1rem;
}
.turno-activo .pac-nombre {
font-size: clamp(.8rem, 1.6vw, 1.1rem);
color: rgba(255,255,255,.4);
margin-top: .3rem;
}
.turno-activo .sin-turno {
font-size: clamp(1.2rem, 2.5vw, 1.8rem);
color: rgba(255,255,255,.15);
}
/* ── Video reel (esquina inferior derecha) ── */
.reel-wrap {
position: fixed;
bottom: 80px;
right: 24px;
width: 160px;
height: 284px;
border-radius: 16px;
overflow: hidden;
box-shadow: 0 8px 32px rgba(0,0,0,.5);
border: 2px solid rgba(255,255,255,.1);
z-index: 100;
background: #000;
display: none;
}
.reel-wrap.has-video { display: block; }
.reel-wrap video {
width: 100%; height: 100%;
object-fit: cover;
display: block;
}
/* ── Waiting queue ── */
.pg-cola {
background: rgba(15,23,42,.9);
border-top: 1px solid rgba(255,255,255,.06);
padding: .35rem 1rem;
display: flex;
align-items: center;
gap: .5rem;
overflow-x: auto;
flex-shrink: 0;
scrollbar-width: none;
min-height: 44px;
}
.pg-cola::-webkit-scrollbar { display: none; }
.cola-lbl {
font-size: .6rem; font-weight: 700;
text-transform: uppercase; letter-spacing: 1.5px;
color: rgba(255,255,255,.3); white-space: nowrap; flex-shrink: 0;
}
.cola-sep { width: 1px; height: 18px; background: rgba(255,255,255,.08); flex-shrink: 0; }
.cola-chip {
display: inline-flex; align-items: center; gap: .25rem;
padding: .2rem .6rem; border-radius: 99px;
font-size: .72rem; font-weight: 700;
border: 1px solid rgba(255,255,255,.1);
background: rgba(255,255,255,.04);
color: rgba(255,255,255,.6);
white-space: nowrap; flex-shrink: 0;
}
.cola-chip .cdot { width: 5px; height: 5px; border-radius: 50%; display: inline-block; }
.cola-empty { font-size: .65rem; color: rgba(255,255,255,.2); }
/* ── Announcement overlay ── */
#ann-overlay {
position: fixed; inset: 0; z-index: 9999;
display: flex; align-items: center; justify-content: center;
opacity: 0; pointer-events: none; transition: opacity .35s ease;
}
#ann-overlay.visible { opacity: 1; pointer-events: all; }
.ann-bg {
position: absolute; inset: 0;
background: rgba(4,8,20,.94);
backdrop-filter: blur(20px);
}
.ann-card {
position: relative; z-index: 1;
text-align: center;
transform: scale(.85) translateY(20px);
transition: transform .45s cubic-bezier(.34,1.5,.64,1);
}
#ann-overlay.visible .ann-card { transform: scale(1) translateY(0); }
.ann-label {
font-size: clamp(.8rem, 1.5vw, 1rem); font-weight: 700;
text-transform: uppercase; letter-spacing: 4px;
color: rgba(255,255,255,.3); margin-bottom: .2rem;
}
.ann-code {
font-size: clamp(7rem, 22vw, 16rem); font-weight: 900;
line-height: 1; letter-spacing: -6px;
font-variant-numeric: tabular-nums;
color: var(--ac, var(--brand));
text-shadow: 0 0 80px var(--ac, var(--brand))66;
}
.ann-destino {
font-size: clamp(1.5rem, 4vw, 3rem); font-weight: 700;
color: #fff; margin-top: .2rem;
}
.ann-pac {
font-size: clamp(.8rem, 1.5vw, 1.1rem);
color: rgba(255,255,255,.45); margin-top: .3rem;
}
.ann-progress {
width: 200px; height: 3px;
background: rgba(255,255,255,.06);
border-radius: 99px; margin: 1.5rem auto 0; overflow: hidden;
}
.ann-bar {
height: 100%; width: 100%; border-radius: 99px;
background: var(--ac, var(--brand));
box-shadow: 0 0 10px var(--ac, var(--brand));
}
/* ── Mini stat en footer ── */
.pg-footer {
position: fixed;
bottom: 0; left: 0; right: 0;
display: flex; justify-content: center; align-items: center;
gap: 1.5rem;
padding: .25rem 1rem;
background: rgba(15,23,42,.85);
flex-shrink: 0;
z-index: 50;
}
.stat-item { text-align: center; }
.stat-item .val {
font-size: clamp(.7rem, 1.2vw, .85rem);
font-weight: 700; color: rgba(255,255,255,.7);
font-variant-numeric: tabular-nums;
}
.stat-item .lbl {
font-size: .5rem; color: rgba(255,255,255,.25);
text-transform: uppercase; letter-spacing: 1px;
}
.stat-sep { width: 1px; height: 18px; background: rgba(255,255,255,.08); }
@media (min-width: 1200px) {
.reel-wrap { width: 200px; height: 356px; }
}
</style>
</head>
<body>
<div id="ann-overlay">
<div class="ann-bg"></div>
<div class="ann-card">
<div class="ann-label">Pase a</div>
<div class="ann-code" id="ann-code">A01</div>
<div class="ann-destino" id="ann-destino">Recepción 1</div>
<div class="ann-pac" id="ann-pac"></div>
<div class="ann-progress"><div class="ann-bar" id="ann-bar"></div></div>
</div>
</div>
<div class="pg-wrap">
<header class="pg-header">
<div class="hd-brand">
<?php if ($_labLogo): ?>
<img class="logo" src="<?= htmlspecialchars($_labLogo) ?>" alt="Logo">
<?php endif; ?>
<div class="lab-nombre"><?= $_labNombre ?></div>
</div>
<div class="hd-right">
<div class="live-dot"></div>
<div class="reloj" id="reloj">--:--:--</div>
</div>
</header>
<div class="pg-body <?= $_hasVideo ? 'has-video' : '' ?>">
<div class="turno-activo" id="zona-activo">
<div class="label">Siguiente turno</div>
<div class="codigo" id="codigo-activo">—</div>
<div class="lugar-label" id="lugar-label">Llamado a</div>
<div class="lugar-nombre" id="lugar-nombre">—</div>
<div class="pac-nombre" id="pac-nombre"></div>
</div>
</div>
<div class="pg-cola" id="pg-cola">
<span class="cola-lbl">EN ESPERA</span>
<div class="cola-sep"></div>
<span class="cola-empty" id="cola-vacia">Cola vacía</span>
</div>
</div>
<div class="reel-wrap <?= $_hasVideo ? 'has-video' : '' ?>" id="reel-wrap">
<video autoplay muted loop playsinline>
<source src="<?= htmlspecialchars($_tvVideo) ?>">
</video>
</div>
<footer class="pg-footer">
<div class="stat-item"><div class="val" id="st-espera">—</div><div class="lbl">Espera</div></div>
<div class="stat-sep"></div>
<div class="stat-item"><div class="val" id="st-atencion">—</div><div class="lbl">Atención</div></div>
<div class="stat-sep"></div>
<div class="stat-item"><div class="val" id="st-finalizados">—</div><div class="lbl">Atendidos</div></div>
<div class="stat-sep"></div>
<div class="stat-item"><div class="val" id="st-total">—</div><div class="lbl">Total día</div></div>
</footer>
<script>
const BASE_API = '<?= BASE_URL ?>modules/turnero/api/';
function tick() {
const d = new Date();
document.getElementById('reloj').textContent =
String(d.getHours()).padStart(2,'0') + ':' +
String(d.getMinutes()).padStart(2,'0') + ':' +
String(d.getSeconds()).padStart(2,'0');
}
tick(); setInterval(tick, 1000);
/* ── Announcement ── */
const annQueue = [];
let isAnnouncing = false;
function queueAnnouncement(item) {
if (annQueue.some(q => q._key === item._key)) return;
annQueue.push(item);
if (!isAnnouncing) processQueue();
}
function processQueue() {
if (annQueue.length === 0) { isAnnouncing = false; return; }
isAnnouncing = true;
showAnnouncement(annQueue.shift());
}
function showAnnouncement({ codigo, destino, paciente, color }) {
const ov = document.getElementById('ann-overlay');
const cd = document.getElementById('ann-code');
const dst = document.getElementById('ann-destino');
const pac = document.getElementById('ann-pac');
const bar = document.getElementById('ann-bar');
const c = color || '<?= $_labColor ?>';
cd.textContent = codigo;
dst.textContent = destino;
pac.textContent = paciente || '';
ov.style.setProperty('--ac', c);
ov.classList.add('visible');
bar.style.transition = 'none';
bar.style.width = '100%';
requestAnimationFrame(() => requestAnimationFrame(() => {
bar.style.transition = 'width 2s linear';
bar.style.width = '0%';
}));
setTimeout(() => {
ov.classList.remove('visible');
setTimeout(processQueue, 370);
}, 2300);
}
/* ── State ── */
let lastTurnoKey = null;
function renderSnapshot(snap) {
const codEl = document.getElementById('codigo-activo');
const lugEl = document.getElementById('lugar-nombre');
const pacEl = document.getElementById('pac-nombre');
const lblEl = document.getElementById('lugar-label');
const turnos = [];
(snap.activos_recepcion || []).forEach(d => {
if (d.turno) turnos.push({ ...d.turno, destino: d.desk_nombre, tipo: 'rec' });
});
(snap.lugares || []).forEach(l => {
if (l.turno) turnos.push({ ...l.turno, destino: l.lugar_nombre, tipo: 'mue' });
});
if (turnos.length > 0) {
const t = turnos[0];
codEl.textContent = t.codigo;
lugEl.textContent = t.destino;
pacEl.textContent = t.paciente_nombre || '';
lblEl.textContent = 'Llamado a';
const c = t.prioridad_color || '<?= $_labColor ?>';
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;
}
} else {
codEl.textContent = '—';
lugEl.textContent = '—';
pacEl.textContent = '';
lblEl.textContent = 'Llamado a';
codEl.style.color = '<?= $_labColor ?>';
lastTurnoKey = null;
}
// Queue
const cola = snap.cola || [];
const pgCola = document.getElementById('pg-cola');
pgCola.querySelectorAll('.cola-chip').forEach(c => c.remove());
const vaciaMg = document.getElementById('cola-vacia');
if (cola.length === 0) {
vaciaMg.style.display = '';
} else {
vaciaMg.style.display = 'none';
cola.forEach(t => {
const chip = document.createElement('span');
const c = t.prioridad_color || '<?= $_labColor ?>';
chip.className = 'cola-chip';
chip.innerHTML = '<span class="cdot" style="background:' + c + ';box-shadow:0 0 4px ' + c + '88"></span>' + esc(t.codigo);
pgCola.appendChild(chip);
});
}
// Stats
const s = snap.stats || {};
document.getElementById('st-espera').textContent = s.en_espera || 0;
document.getElementById('st-atencion').textContent = s.en_atencion || 0;
document.getElementById('st-finalizados').textContent = s.finalizados || 0;
document.getElementById('st-total').textContent = s.total || 0;
}
function esc(s) {
const d = document.createElement('div');
d.appendChild(document.createTextNode(String(s ?? '')));
return d.innerHTML;
}
async function cargarSnapshot() {
try {
const res = await fetch(BASE_API + 'get_display_global.php', { cache: 'no-store' });
const json = await res.json();
if (json.ok) renderSnapshot(json);
} catch(_) {}
}
cargarSnapshot();
setInterval(cargarSnapshot, 4000);
</script>
</body>
</html>