771 lines
34 KiB
PHP
771 lines
34 KiB
PHP
<?php
|
|
// Leer configuración visual del laboratorio
|
|
$_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: #ffffff;
|
|
font-family: 'Segoe UI', system-ui, sans-serif;
|
|
color: #0f172a;
|
|
}
|
|
|
|
:root {
|
|
--brand: <?= $_labColor ?>;
|
|
--brand-dk: color-mix(in srgb, <?= $_labColor ?> 72%, #000);
|
|
--brand-lt: color-mix(in srgb, <?= $_labColor ?> 10%, #fff);
|
|
}
|
|
|
|
/* ─── Wrapper principal ─────────────────────────────────── */
|
|
.pg-wrap {
|
|
display: grid;
|
|
grid-template-rows: auto 1fr auto auto;
|
|
height: 100vh;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* ─── Header ────────────────────────────────────────────── */
|
|
.pg-header {
|
|
display: flex; align-items: center; gap: 1rem;
|
|
padding: .65rem 1.8rem;
|
|
background: var(--brand);
|
|
flex-shrink: 0;
|
|
box-shadow: 0 3px 14px rgba(0,0,0,.2);
|
|
}
|
|
.hd-brand { display: flex; align-items: center; gap: .8rem; flex: 1; min-width: 0; }
|
|
.hd-brand .logo {
|
|
height: 46px; max-width: 120px; object-fit: contain;
|
|
background: rgba(255,255,255,.16); border-radius: 8px; padding: 4px 7px;
|
|
}
|
|
.lab-nombre {
|
|
font-size: clamp(1rem, 2.4vw, 1.55rem);
|
|
font-weight: 800; color: #fff;
|
|
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
|
}
|
|
.lab-sub {
|
|
font-size: .62rem; color: rgba(255,255,255,.65);
|
|
font-weight: 600; text-transform: uppercase; letter-spacing: 1.5px;
|
|
display: block; margin-top: 1px;
|
|
}
|
|
.hd-right { display: flex; align-items: center; gap: .7rem; flex-shrink: 0; }
|
|
.reloj {
|
|
font-size: clamp(1.2rem, 3vw, 2rem);
|
|
font-weight: 800; color: #fff;
|
|
font-variant-numeric: tabular-nums; letter-spacing: 1px;
|
|
}
|
|
.live-dot {
|
|
width: 9px; height: 9px; border-radius: 50%;
|
|
background: #4ade80; box-shadow: 0 0 9px #4ade80;
|
|
animation: pdot 2s ease-in-out infinite; flex-shrink: 0;
|
|
}
|
|
@keyframes pdot { 0%,100%{opacity:1} 50%{opacity:.35} }
|
|
.btn-son {
|
|
background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.28);
|
|
color: rgba(255,255,255,.9); border-radius: 8px; padding: 5px 12px;
|
|
font-size: .7rem; font-weight: 600; cursor: pointer; font-family: inherit;
|
|
transition: background .2s;
|
|
}
|
|
.btn-son.on { background: rgba(74,222,128,.22); border-color: rgba(74,222,128,.45); color: #86efac; }
|
|
.btn-fs {
|
|
background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22);
|
|
color: rgba(255,255,255,.82); border-radius: 8px; padding: 5px 10px;
|
|
font-size: .7rem; cursor: pointer; font-family: inherit;
|
|
}
|
|
|
|
/* ─── Body layout ───────────────────────────────────────── */
|
|
.pg-body {
|
|
display: grid;
|
|
overflow: hidden;
|
|
}
|
|
.pg-body.has-video { grid-template-columns: 1fr 38%; }
|
|
.pg-body.no-video { grid-template-columns: 1fr 1fr; }
|
|
|
|
/* ─── Turnos area (stacked when video) ──────────────────── */
|
|
.turnos-area {
|
|
display: grid;
|
|
overflow: hidden;
|
|
border-right: 3px solid #e8ecf0;
|
|
}
|
|
.pg-body.has-video .turnos-area { grid-template-rows: 1fr 1fr; }
|
|
.pg-body.no-video .turnos-area { grid-template-rows: 1fr; }
|
|
|
|
/* ─── Section panel ─────────────────────────────────────── */
|
|
.section-panel {
|
|
display: flex; flex-direction: column;
|
|
overflow: hidden;
|
|
background: #f8fafc;
|
|
}
|
|
.turnos-area .section-panel + .section-panel {
|
|
border-top: 3px solid #e8ecf0;
|
|
}
|
|
/* no-video: muestras column sits right of turnos-area */
|
|
.mue-panel {
|
|
display: flex; flex-direction: column;
|
|
overflow: hidden;
|
|
background: #f8fafc;
|
|
border-left: 3px solid #e8ecf0;
|
|
}
|
|
|
|
/* Section header */
|
|
.sec-hdr {
|
|
display: flex; align-items: center; gap: .5rem;
|
|
padding: .5rem 1.2rem;
|
|
font-size: .72rem; font-weight: 800;
|
|
text-transform: uppercase; letter-spacing: 2.5px;
|
|
color: #fff; flex-shrink: 0;
|
|
}
|
|
.sec-hdr.rec { background: var(--brand); }
|
|
.sec-hdr.mue { background: var(--brand-dk); }
|
|
|
|
/* ─── Slots container ───────────────────────────────────── */
|
|
.slots-row {
|
|
flex: 1; display: grid;
|
|
grid-auto-flow: column;
|
|
grid-auto-columns: 1fr;
|
|
gap: 10px; padding: 10px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* ─── Single slot card ──────────────────────────────────── */
|
|
.slot {
|
|
background: #fff;
|
|
border-radius: 16px;
|
|
border: 2.5px solid #e2e8f0;
|
|
display: flex; flex-direction: column;
|
|
overflow: hidden;
|
|
box-shadow: 0 2px 8px rgba(0,0,0,.06);
|
|
transition: border-color .45s, box-shadow .45s;
|
|
}
|
|
.slot.lit {
|
|
border-color: var(--pc, var(--brand));
|
|
box-shadow: 0 6px 28px color-mix(in srgb, var(--pc, var(--brand)) 24%, transparent),
|
|
0 2px 8px rgba(0,0,0,.06);
|
|
}
|
|
|
|
/* Slot header bar */
|
|
.slot-hdr {
|
|
display: flex; align-items: center; gap: .45rem;
|
|
padding: .35rem .9rem;
|
|
font-size: .62rem; font-weight: 800;
|
|
text-transform: uppercase; letter-spacing: 2px;
|
|
background: var(--brand-lt); color: var(--brand);
|
|
border-bottom: 2px solid color-mix(in srgb, var(--brand) 18%, transparent);
|
|
flex-shrink: 0;
|
|
transition: background .45s, color .45s, border-color .45s;
|
|
}
|
|
.slot.lit .slot-hdr {
|
|
background: color-mix(in srgb, var(--pc, var(--brand)) 12%, #fff);
|
|
color: var(--pc, var(--brand));
|
|
border-color: color-mix(in srgb, var(--pc, var(--brand)) 30%, transparent);
|
|
}
|
|
|
|
/* Slot body */
|
|
.slot-body {
|
|
flex: 1; display: flex; flex-direction: column;
|
|
align-items: center; justify-content: center;
|
|
padding: .6rem .4rem;
|
|
position: relative; overflow: hidden;
|
|
}
|
|
|
|
/* Ring pop on new turno */
|
|
.ring-pop-el {
|
|
position: absolute; top: 50%; left: 50%;
|
|
width: 10px; height: 10px; border-radius: 50%;
|
|
transform: translate(-50%,-50%);
|
|
pointer-events: none; z-index: 0;
|
|
}
|
|
.ring-pop-el.do-pop { animation: r-pop .85s ease-out forwards; }
|
|
@keyframes r-pop {
|
|
0% { transform:translate(-50%,-50%) scale(1); background:var(--pc,var(--brand)); opacity:.2; }
|
|
100% { transform:translate(-50%,-50%) scale(50); background:var(--pc,var(--brand)); opacity:0; }
|
|
}
|
|
|
|
/* Labels */
|
|
.lbl-dest {
|
|
font-size: clamp(.5rem, .88vw, .68rem);
|
|
font-weight: 700; text-transform: uppercase; letter-spacing: 3px;
|
|
color: #94a3b8; margin-bottom: .05rem;
|
|
z-index: 1; position: relative;
|
|
transition: color .4s;
|
|
}
|
|
.slot-body.lit .lbl-dest { color: var(--pc, var(--brand)); opacity: .75; }
|
|
|
|
/* BIG turno code */
|
|
.big-code {
|
|
font-size: clamp(3rem, 9vw, 10rem);
|
|
font-weight: 900; line-height: 1; letter-spacing: -2px;
|
|
color: #dde3eb;
|
|
font-variant-numeric: tabular-nums;
|
|
z-index: 1; position: relative;
|
|
transition: color .4s;
|
|
}
|
|
.slot-body.lit .big-code { color: var(--pc, var(--brand)); }
|
|
|
|
/* Patient name */
|
|
.pac-name {
|
|
font-size: clamp(.7rem, 1.4vw, 1.15rem);
|
|
font-weight: 700; color: #334155;
|
|
margin-top: .25rem; text-align: center; min-height: 1.2em;
|
|
z-index: 1; position: relative;
|
|
}
|
|
|
|
/* Priority badge */
|
|
.prio-badge {
|
|
display: inline-flex; align-items: center; gap: .3rem;
|
|
padding: .22rem .7rem; border-radius: 99px;
|
|
font-size: clamp(.52rem, .75vw, .68rem); font-weight: 700;
|
|
margin-top: .25rem; border: 1.5px solid #e2e8f0;
|
|
color: #94a3b8; background: #f8fafc;
|
|
transition: all .4s;
|
|
z-index: 1; position: relative;
|
|
}
|
|
.slot-body.lit .prio-badge {
|
|
color: var(--pc, var(--brand));
|
|
border-color: color-mix(in srgb, var(--pc, var(--brand)) 40%, transparent);
|
|
background: color-mix(in srgb, var(--pc, var(--brand)) 8%, #fff);
|
|
}
|
|
|
|
/* ─── Video panel ───────────────────────────────────────── */
|
|
.video-panel {
|
|
display: flex; align-items: center; justify-content: center;
|
|
overflow: hidden;
|
|
background: #f1f5f9;
|
|
border-left: 3px solid #e8ecf0;
|
|
}
|
|
.video-panel video {
|
|
width: 100%; height: 100%;
|
|
object-fit: contain; /* video completo, sin recortar */
|
|
display: block;
|
|
}
|
|
|
|
/* ─── Cola en espera ────────────────────────────────────── */
|
|
.pg-cola {
|
|
background: #fff;
|
|
border-top: 2.5px solid #e8ecf0;
|
|
padding: .45rem 1rem;
|
|
display: flex; align-items: center; gap: .55rem;
|
|
overflow-x: auto; flex-shrink: 0;
|
|
scrollbar-width: none;
|
|
min-height: 38px;
|
|
}
|
|
.pg-cola::-webkit-scrollbar { display: none; }
|
|
.cola-lbl {
|
|
font-size: .64rem; font-weight: 800;
|
|
text-transform: uppercase; letter-spacing: 2px;
|
|
color: var(--brand); white-space: nowrap; flex-shrink: 0;
|
|
}
|
|
.cola-sep { width: 1px; height: 14px; background: #e2e8f0; flex-shrink: 0; }
|
|
.cola-chip {
|
|
display: inline-flex; align-items: center; gap: .3rem;
|
|
padding: .22rem .7rem; border-radius: 99px;
|
|
font-size: .78rem; font-weight: 700;
|
|
background: #fff; border: 1.5px solid;
|
|
white-space: nowrap; flex-shrink: 0;
|
|
}
|
|
.cola-chip .cdot { width: 6px; height: 6px; border-radius: 50%; }
|
|
.cola-empty { font-size: .72rem; color: #94a3b8; }
|
|
|
|
/* ─── Footer stats ──────────────────────────────────────── */
|
|
.pg-footer {
|
|
display: flex; justify-content: center; align-items: center;
|
|
gap: 2.5rem; flex-wrap: wrap;
|
|
padding: .5rem 2rem;
|
|
background: var(--brand);
|
|
flex-shrink: 0;
|
|
}
|
|
.stat-item { text-align: center; }
|
|
.stat-item .val {
|
|
font-size: clamp(.95rem, 2vw, 1.35rem);
|
|
font-weight: 800; color: #fff;
|
|
font-variant-numeric: tabular-nums;
|
|
}
|
|
.stat-item .lbl {
|
|
font-size: .58rem; color: rgba(255,255,255,.65);
|
|
text-transform: uppercase; letter-spacing: 1.5px;
|
|
}
|
|
.stat-sep { width: 1px; height: 24px; background: rgba(255,255,255,.22); }
|
|
|
|
/* ─── 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 .3s ease;
|
|
}
|
|
#ann-overlay.visible { opacity: 1; pointer-events: all; }
|
|
.ann-bg {
|
|
position: absolute; inset: 0;
|
|
background: rgba(4,8,20,.93);
|
|
backdrop-filter: blur(18px);
|
|
transition: background .4s;
|
|
}
|
|
.ann-card {
|
|
position: relative; z-index: 1;
|
|
width: min(600px, 88vw);
|
|
background: rgba(255,255,255,.055);
|
|
border: 1px solid rgba(255,255,255,.12);
|
|
border-radius: 28px; padding: 2.8rem 3.5rem 2.4rem; text-align: center;
|
|
box-shadow: 0 30px 90px rgba(0,0,0,.7), 0 0 70px var(--ac, #1565c0)44;
|
|
transform: scale(.88) translateY(14px);
|
|
transition: transform .4s cubic-bezier(.34,1.5,.64,1);
|
|
}
|
|
#ann-overlay.visible .ann-card { transform: scale(1) translateY(0); }
|
|
.ann-card::before {
|
|
content: ''; position: absolute; left: 0; top: 12%; bottom: 12%;
|
|
width: 4px; border-radius: 0 4px 4px 0;
|
|
background: var(--ac, var(--brand));
|
|
box-shadow: 0 0 28px var(--ac, var(--brand));
|
|
}
|
|
.ann-ring {
|
|
position: absolute; top: 50%; left: 50%;
|
|
width: 10px; height: 10px; border-radius: 50%;
|
|
transform: translate(-50%,-50%); pointer-events: none;
|
|
}
|
|
.ann-ring.pop { animation: ann-pop 1.1s ease-out forwards; }
|
|
@keyframes ann-pop {
|
|
0% { transform:translate(-50%,-50%) scale(1); background:var(--ac,var(--brand)); opacity:.4; }
|
|
100% { transform:translate(-50%,-50%) scale(55); background:var(--ac,var(--brand)); opacity:0; }
|
|
}
|
|
.ann-label {
|
|
font-size: clamp(.7rem, 1.5vw, .92rem); font-weight: 700;
|
|
text-transform: uppercase; letter-spacing: 3.5px;
|
|
color: rgba(255,255,255,.44); margin-bottom: .5rem;
|
|
}
|
|
.ann-code {
|
|
font-size: clamp(5rem, 17vw, 11rem); font-weight: 900;
|
|
line-height: 1; letter-spacing: -4px;
|
|
font-variant-numeric: tabular-nums;
|
|
color: var(--ac, var(--brand));
|
|
text-shadow: 0 0 90px var(--ac, var(--brand))55;
|
|
position: relative; z-index: 1;
|
|
}
|
|
.ann-pac {
|
|
font-size: clamp(.88rem, 2.2vw, 1.3rem); font-weight: 700;
|
|
color: rgba(255,255,255,.72); margin-top: .55rem; min-height: 1.5em;
|
|
}
|
|
.ann-chip {
|
|
display: inline-flex; align-items: center; gap: .35rem;
|
|
padding: .34rem 1.1rem; border-radius: 99px;
|
|
font-size: clamp(.62rem, 1.05vw, .82rem); font-weight: 700;
|
|
margin-top: .7rem; border: 1px solid;
|
|
}
|
|
.ann-progress {
|
|
width: 100%; height: 3px;
|
|
background: rgba(255,255,255,.07);
|
|
border-radius: 99px; margin-top: 1.7rem; overflow: hidden;
|
|
}
|
|
.ann-bar {
|
|
height: 100%; width: 100%; border-radius: 99px;
|
|
background: var(--ac, var(--brand));
|
|
box-shadow: 0 0 12px var(--ac, var(--brand));
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<!-- ══ Announcement overlay ═══════════════════════════════════════ -->
|
|
<div id="ann-overlay">
|
|
<div class="ann-bg" id="ann-bg"></div>
|
|
<div class="ann-card">
|
|
<div class="ann-ring" id="ann-ring"></div>
|
|
<div class="ann-label" id="ann-label">Pase a Recepción</div>
|
|
<div class="ann-code" id="ann-code">A01</div>
|
|
<div class="ann-pac" id="ann-pac"></div>
|
|
<div class="ann-chip" id="ann-chip"></div>
|
|
<div class="ann-progress"><div class="ann-bar" id="ann-bar"></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ══ Main layout ════════════════════════════════════════════════ -->
|
|
<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>
|
|
<div class="lab-nombre"><?= $_labNombre ?></div>
|
|
<span class="lab-sub">Sistema de Turnos — Vista General</span>
|
|
</div>
|
|
</div>
|
|
<div class="hd-right">
|
|
<div class="live-dot" title="En línea"></div>
|
|
<button class="btn-son" id="btn-sonido" onclick="event.stopPropagation();activarSonido()">
|
|
<i class="fas fa-volume-mute"></i> Sonido
|
|
</button>
|
|
<button class="btn-fs" onclick="toggleFullscreen()" title="Pantalla completa">
|
|
<i class="fas fa-expand" id="fs-icon"></i>
|
|
</button>
|
|
<div class="reloj" id="reloj">--:--:--</div>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="pg-body <?= $_hasVideo ? 'has-video' : 'no-video' ?>">
|
|
|
|
<?php if ($_hasVideo): ?>
|
|
<!-- Layout con video: recepción+muestras apiladas (izq) | video (der) -->
|
|
<div class="turnos-area">
|
|
<div class="section-panel">
|
|
<div class="sec-hdr rec"><i class="fas fa-door-open"></i> Recepción</div>
|
|
<div class="slots-row" id="rec-grid"></div>
|
|
</div>
|
|
<div class="section-panel">
|
|
<div class="sec-hdr mue"><i class="fas fa-vials"></i> Toma de Muestras</div>
|
|
<div class="slots-row" id="lugares-grid"></div>
|
|
</div>
|
|
</div>
|
|
<div class="video-panel">
|
|
<video autoplay muted loop playsinline>
|
|
<source src="<?= htmlspecialchars($_tvVideo) ?>">
|
|
</video>
|
|
</div>
|
|
|
|
<?php else: ?>
|
|
<!-- Layout sin video: recepción (izq) | muestras (der) -->
|
|
<div class="turnos-area">
|
|
<div class="section-panel">
|
|
<div class="sec-hdr rec"><i class="fas fa-door-open"></i> Recepción</div>
|
|
<div class="slots-row" id="rec-grid"></div>
|
|
</div>
|
|
</div>
|
|
<div class="mue-panel">
|
|
<div class="sec-hdr mue"><i class="fas fa-vials"></i> Toma de Muestras</div>
|
|
<div class="slots-row" id="lugares-grid"></div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
|
|
<div class="pg-cola" id="pg-cola">
|
|
<span class="cola-lbl"><i class="fas fa-list-ol" style="margin-right:.3rem"></i>EN ESPERA</span>
|
|
<div class="cola-sep"></div>
|
|
<span class="cola-empty" id="cola-vacia">Cola vacía</span>
|
|
</div>
|
|
|
|
<footer class="pg-footer">
|
|
<div class="stat-item"><div class="val" id="st-espera">—</div><div class="lbl">En espera</div></div>
|
|
<div class="stat-sep"></div>
|
|
<div class="stat-item"><div class="val" id="st-atencion">—</div><div class="lbl">En 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>
|
|
<div class="stat-sep"></div>
|
|
<div class="stat-item"><div class="val" id="st-tiempo">—</div><div class="lbl">T. promedio</div></div>
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
const BASE_API = '<?= BASE_URL ?>modules/turnero/api/';
|
|
|
|
/* ── Reloj ──────────────────────────────────────────────────────── */
|
|
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);
|
|
|
|
/* ── Pantalla completa ──────────────────────────────────────────── */
|
|
function toggleFullscreen() {
|
|
if (!document.fullscreenElement) {
|
|
document.documentElement.requestFullscreen().catch(() => {});
|
|
} else {
|
|
document.exitFullscreen().catch(() => {});
|
|
}
|
|
}
|
|
document.addEventListener('fullscreenchange', () => {
|
|
const ico = document.getElementById('fs-icon');
|
|
if (ico) ico.className = document.fullscreenElement ? 'fas fa-compress' : 'fas fa-expand';
|
|
});
|
|
|
|
/* ── Audio ──────────────────────────────────────────────────────── */
|
|
let audioCtx = null, sonidoActivo = false;
|
|
|
|
function activarSonido() {
|
|
try {
|
|
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
|
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-sonido');
|
|
if (btn) {
|
|
btn.innerHTML = '<i class="fas fa-volume-up"></i> Sonido ON';
|
|
btn.classList.add('on');
|
|
setTimeout(playBeep, 100);
|
|
}
|
|
}
|
|
document.addEventListener('click', () => { if (!sonidoActivo) activarSonido(); }, { once: true });
|
|
document.addEventListener('touchstart', () => { if (!sonidoActivo) activarSonido(); }, { once: true });
|
|
|
|
function playBeep() {
|
|
if (!sonidoActivo || !audioCtx) return;
|
|
try {
|
|
const osc = audioCtx.createOscillator();
|
|
const g = audioCtx.createGain();
|
|
osc.type = 'sine';
|
|
osc.connect(g); g.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);
|
|
g.gain.setValueAtTime(0.35, audioCtx.currentTime);
|
|
g.gain.exponentialRampToValueAtTime(0.0001, audioCtx.currentTime + 0.65);
|
|
osc.start(audioCtx.currentTime);
|
|
osc.stop(audioCtx.currentTime + 0.65);
|
|
} catch (_) {}
|
|
}
|
|
|
|
function anunciarTurno(codigo, destino) {
|
|
playBeep();
|
|
if ('speechSynthesis' in window) {
|
|
setTimeout(() => {
|
|
window.speechSynthesis.cancel();
|
|
const letras = codigo.split('').join(' ');
|
|
const utt = new SpeechSynthesisUtterance(`Turno ${letras}, pase a ${destino}`);
|
|
utt.lang = 'es-CO'; utt.rate = 0.85; utt.pitch = 1.05; utt.volume = 1;
|
|
window.speechSynthesis.speak(utt);
|
|
}, 700);
|
|
}
|
|
}
|
|
|
|
/* ── Announcement queue ─────────────────────────────────────────── */
|
|
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, prio_codigo, prio_nombre, color }) {
|
|
const ov = document.getElementById('ann-overlay');
|
|
const bg = document.getElementById('ann-bg');
|
|
const ring = document.getElementById('ann-ring');
|
|
const code = document.getElementById('ann-code');
|
|
const lbl = document.getElementById('ann-label');
|
|
const pac = document.getElementById('ann-pac');
|
|
const chip = document.getElementById('ann-chip');
|
|
const bar = document.getElementById('ann-bar');
|
|
const c = color || '#1565c0';
|
|
|
|
code.textContent = codigo;
|
|
lbl.textContent = 'Pase a ' + destino;
|
|
pac.textContent = paciente || '';
|
|
chip.innerHTML = '<i class="fas fa-ticket-alt"></i> ' + esc(prio_codigo||'') + ' — ' + esc(prio_nombre||'');
|
|
|
|
ov.style.setProperty('--ac', c);
|
|
bg.style.background = 'radial-gradient(ellipse at 50% 45%, ' + c + '2a 0%, rgba(4,8,20,.94) 65%)';
|
|
chip.style.color = c;
|
|
chip.style.borderColor = c + '55';
|
|
chip.style.background = c + '18';
|
|
|
|
ov.classList.add('visible');
|
|
ring.classList.remove('pop');
|
|
void ring.offsetWidth;
|
|
ring.classList.add('pop');
|
|
|
|
bar.style.transition = 'none';
|
|
bar.style.width = '100%';
|
|
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
bar.style.transition = 'width 1.65s linear';
|
|
bar.style.width = '0%';
|
|
}));
|
|
|
|
anunciarTurno(codigo, destino);
|
|
|
|
setTimeout(() => {
|
|
ov.classList.remove('visible');
|
|
setTimeout(processQueue, 370);
|
|
}, 1950);
|
|
}
|
|
|
|
/* ── State ──────────────────────────────────────────────────────── */
|
|
const lastRec = {};
|
|
const lastLugar = {};
|
|
|
|
/* ── Helpers ────────────────────────────────────────────────────── */
|
|
function esc(s) {
|
|
const d = document.createElement('div');
|
|
d.appendChild(document.createTextNode(String(s ?? '')));
|
|
return d.innerHTML;
|
|
}
|
|
|
|
function buildSlot(id, nombre, turno, tipo) {
|
|
const has = !!turno;
|
|
const c = has ? (turno.prioridad_color || '#1565c0') : null;
|
|
const slotCl = has ? 'slot lit' : 'slot';
|
|
const slotSt = c ? ' style="--pc:' + c + '"' : '';
|
|
const bodyCl = has ? 'slot-body lit' : 'slot-body';
|
|
const bodySt = c ? '--pc:' + c + ';' : '';
|
|
const hCls = tipo === 'rec' ? 'slot-hdr rec' : 'slot-hdr mue';
|
|
const icon = tipo === 'rec' ? 'fas fa-concierge-bell' : 'fas fa-flask';
|
|
const cod = has ? esc(turno.codigo) : '—';
|
|
const pac = has ? esc(turno.paciente_nombre || '') : '';
|
|
const chip = has
|
|
? "<i class='fas fa-ticket-alt'></i> " + esc(turno.prioridad_codigo) + ' — ' + esc(turno.prioridad_nombre)
|
|
: "<i class='fas fa-hourglass-half'></i> En espera";
|
|
const chipSt = has && c ? 'style="color:' + c + ';border-color:' + c + '44;background:' + c + '15"' : '';
|
|
return '<div class="' + slotCl + '" id="slot-' + tipo + '-' + id + '"' + slotSt + '>'
|
|
+ '<div class="' + hCls + '"><i class="' + icon + '"></i> ' + esc(nombre) + '</div>'
|
|
+ '<div class="' + bodyCl + '" id="body-' + tipo + '-' + id + '" style="' + bodySt + '">'
|
|
+ '<div class="ring-pop-el" id="ring-' + tipo + '-' + id + '"></div>'
|
|
+ '<div class="lbl-dest">' + esc(nombre) + '</div>'
|
|
+ '<div class="big-code" id="cod-' + tipo + '-' + id + '">' + cod + '</div>'
|
|
+ '<div class="pac-name" id="pac-' + tipo + '-' + id + '">' + pac + '</div>'
|
|
+ '<div class="prio-badge" id="chip-' + tipo + '-' + id + '" ' + chipSt + '>' + chip + '</div>'
|
|
+ '</div></div>';
|
|
}
|
|
|
|
function updateSlot(id, turno, tipo) {
|
|
const slotEl = document.getElementById('slot-' + tipo + '-' + id);
|
|
const body = document.getElementById('body-' + tipo + '-' + id);
|
|
const cod = document.getElementById('cod-' + tipo + '-' + id);
|
|
const pac = document.getElementById('pac-' + tipo + '-' + id);
|
|
const chip = document.getElementById('chip-' + tipo + '-' + id);
|
|
if (!body) return false;
|
|
const c = turno ? (turno.prioridad_color || '#1565c0') : null;
|
|
if (turno) {
|
|
body.className = 'slot-body lit';
|
|
body.style.setProperty('--pc', c);
|
|
if (slotEl) { slotEl.className = 'slot lit'; slotEl.style.setProperty('--pc', c); }
|
|
cod.textContent = turno.codigo;
|
|
pac.textContent = turno.paciente_nombre || '';
|
|
chip.innerHTML = "<i class='fas fa-ticket-alt'></i> " + esc(turno.prioridad_codigo) + ' — ' + esc(turno.prioridad_nombre);
|
|
chip.style.color = c; chip.style.borderColor = c + '44'; chip.style.background = c + '15';
|
|
} else {
|
|
body.className = 'slot-body';
|
|
body.style.removeProperty('--pc');
|
|
if (slotEl) { slotEl.className = 'slot'; slotEl.style.removeProperty('--pc'); }
|
|
cod.textContent = '—';
|
|
pac.textContent = '';
|
|
chip.innerHTML = "<i class='fas fa-hourglass-half'></i> En espera";
|
|
chip.style.color = chip.style.borderColor = chip.style.background = '';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/* ── Render snapshot ────────────────────────────────────────────── */
|
|
function renderSnapshot(snap) {
|
|
const recList = snap.activos_recepcion || [];
|
|
const mueList = snap.lugares || [];
|
|
const recGrid = document.getElementById('rec-grid');
|
|
const mueGrid = document.getElementById('lugares-grid');
|
|
|
|
// Recepción
|
|
const curRecIds = [...recGrid.querySelectorAll('.slot')].map(el => +el.id.replace('slot-rec-',''));
|
|
const newRecIds = recList.map(d => d.desk_id);
|
|
if (curRecIds.length !== newRecIds.length || newRecIds.some(id => !curRecIds.includes(id))) {
|
|
recGrid.innerHTML = recList.map(d => buildSlot(d.desk_id, d.desk_nombre, d.turno, 'rec')).join('');
|
|
} else {
|
|
recList.forEach(d => updateSlot(d.desk_id, d.turno, 'rec'));
|
|
}
|
|
recList.forEach(d => {
|
|
const t = d.turno;
|
|
if (!t) { lastRec[d.desk_id] = null; return; }
|
|
const clave = t.codigo + '|' + (t.llamado_at || '');
|
|
if (clave !== lastRec[d.desk_id]) {
|
|
queueAnnouncement({ _key: 'rec-' + d.desk_id + '-' + clave, codigo: t.codigo, destino: d.desk_nombre, paciente: t.paciente_nombre, prio_codigo: t.prioridad_codigo, prio_nombre: t.prioridad_nombre, color: t.prioridad_color });
|
|
const ring = document.getElementById('ring-rec-' + d.desk_id);
|
|
if (ring) { ring.classList.remove('do-pop'); void ring.offsetWidth; ring.classList.add('do-pop'); }
|
|
lastRec[d.desk_id] = clave;
|
|
}
|
|
});
|
|
|
|
// Muestras
|
|
const curMueIds = [...mueGrid.querySelectorAll('.slot')].map(el => +el.id.replace('slot-mue-',''));
|
|
const newMueIds = mueList.map(l => l.lugar_id);
|
|
if (curMueIds.length !== newMueIds.length || newMueIds.some(id => !curMueIds.includes(id))) {
|
|
mueGrid.innerHTML = mueList.map(l => buildSlot(l.lugar_id, l.lugar_nombre, l.turno, 'mue')).join('');
|
|
} else {
|
|
mueList.forEach(l => updateSlot(l.lugar_id, l.turno, 'mue'));
|
|
}
|
|
mueList.forEach(l => {
|
|
const t = l.turno;
|
|
if (!t) { lastLugar[l.lugar_id] = null; return; }
|
|
const clave = t.codigo + '|' + (t.llamado_at || '');
|
|
if (clave !== lastLugar[l.lugar_id]) {
|
|
queueAnnouncement({ _key: 'mue-' + l.lugar_id + '-' + clave, codigo: t.codigo, destino: l.lugar_nombre, paciente: t.paciente_nombre, prio_codigo: t.prioridad_codigo, prio_nombre: t.prioridad_nombre, color: t.prioridad_color });
|
|
const ring = document.getElementById('ring-mue-' + l.lugar_id);
|
|
if (ring) { ring.classList.remove('do-pop'); void ring.offsetWidth; ring.classList.add('do-pop'); }
|
|
lastLugar[l.lugar_id] = clave;
|
|
}
|
|
});
|
|
|
|
// Cola
|
|
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 || '#1565c0';
|
|
chip.className = 'cola-chip';
|
|
chip.style.color = c; chip.style.borderColor = c + '55'; chip.style.background = c + '12';
|
|
chip.innerHTML = '<span class="cdot" style="background:' + c + ';box-shadow:0 0 5px ' + 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;
|
|
document.getElementById('st-tiempo').textContent = s.tiempo_promedio_atencion
|
|
? s.tiempo_promedio_atencion.substring(0, 5) : '—';
|
|
}
|
|
|
|
/* ── Polling ─────────────────────────────────────────────────────── */
|
|
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>
|