up
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* GET /modules/turnero/api/get_display_global.php
|
||||
* Devuelve el estado GLOBAL del sistema para la pantalla TV unificada.
|
||||
* Retorna: turno activo en Recepción + turno activo en cada Lugar + cola.
|
||||
* No requiere autenticación (acceso público).
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_helpers.php';
|
||||
requireMethod('GET');
|
||||
|
||||
$pdo = db();
|
||||
$sesionId = obtenerOCrearSesionHoy();
|
||||
|
||||
// ── 1. TODOS los turnos activos en Recepción ─────────────────
|
||||
// Puede haber varios simultáneos (un escritorio por operador).
|
||||
$stmtRec = $pdo->prepare(
|
||||
"SELECT t.id,
|
||||
t.codigo,
|
||||
t.numero,
|
||||
t.estado,
|
||||
t.paciente_nombre,
|
||||
t.llamado_recepcion_at AS llamado_at,
|
||||
t.atendido_recepcion_por,
|
||||
p.codigo AS prioridad_codigo,
|
||||
p.nombre AS prioridad_nombre,
|
||||
p.color AS prioridad_color
|
||||
FROM turnero_turnos t
|
||||
JOIN turnero_prioridades p ON p.id = t.prioridad_id
|
||||
WHERE t.sesion_id = ?
|
||||
AND t.estado = 'en_recepcion'
|
||||
ORDER BY t.llamado_recepcion_at DESC"
|
||||
);
|
||||
$stmtRec->execute([$sesionId]);
|
||||
$activosRecepcion = $stmtRec->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// ── 2. Lugares activos con su turno en servicio ───────────────
|
||||
$stmtLugares = $pdo->query(
|
||||
"SELECT id, nombre, sort_order
|
||||
FROM turnero_lugares
|
||||
WHERE activo = 1
|
||||
ORDER BY sort_order ASC"
|
||||
);
|
||||
$lugares = $stmtLugares->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$lugaresActivos = [];
|
||||
foreach ($lugares as $lugar) {
|
||||
$stmtActivo = $pdo->prepare(
|
||||
"SELECT t.id,
|
||||
t.codigo,
|
||||
t.numero,
|
||||
t.estado,
|
||||
t.paciente_nombre,
|
||||
t.llamado_lugar_at AS llamado_at,
|
||||
p.codigo AS prioridad_codigo,
|
||||
p.nombre AS prioridad_nombre,
|
||||
p.color AS prioridad_color
|
||||
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.lugar_destino_id = ?
|
||||
ORDER BY t.llamado_lugar_at DESC
|
||||
LIMIT 1"
|
||||
);
|
||||
$stmtActivo->execute([$sesionId, (int)$lugar['id']]);
|
||||
$turnoActivo = $stmtActivo->fetch(PDO::FETCH_ASSOC) ?: null;
|
||||
|
||||
$lugaresActivos[] = [
|
||||
'lugar_id' => (int)$lugar['id'],
|
||||
'lugar_nombre'=> $lugar['nombre'],
|
||||
'sort_order' => (int)$lugar['sort_order'],
|
||||
'turno' => $turnoActivo,
|
||||
];
|
||||
}
|
||||
|
||||
// ── 3. Cola en espera (pendientes por llamar) ─────────────────
|
||||
$stmtCola = $pdo->prepare(
|
||||
"SELECT t.id,
|
||||
t.codigo,
|
||||
t.numero,
|
||||
t.estado,
|
||||
t.paciente_nombre,
|
||||
t.creado_at,
|
||||
p.codigo AS prioridad_codigo,
|
||||
p.nombre AS prioridad_nombre,
|
||||
p.color AS prioridad_color,
|
||||
p.orden_peso
|
||||
FROM turnero_turnos t
|
||||
JOIN turnero_prioridades p ON p.id = t.prioridad_id
|
||||
WHERE t.sesion_id = ?
|
||||
AND t.estado = 'espera'
|
||||
ORDER BY p.orden_peso ASC, t.creado_at ASC"
|
||||
);
|
||||
$stmtCola->execute([$sesionId]);
|
||||
$cola = $stmtCola->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// ── 4. Estadísticas ───────────────────────────────────────────
|
||||
$stmtStats = $pdo->prepare(
|
||||
"SELECT
|
||||
COUNT(*) AS total,
|
||||
SUM(estado = 'espera') AS en_espera,
|
||||
SUM(estado = 'en_recepcion') AS en_recepcion,
|
||||
SUM(estado = 'en_espera_lugar') AS en_espera_lugar,
|
||||
SUM(estado = 'en_servicio') AS en_servicio,
|
||||
SUM(estado IN ('en_recepcion','en_espera_lugar',
|
||||
'en_servicio')) AS en_atencion,
|
||||
SUM(estado = 'finalizado') AS finalizados,
|
||||
SUM(estado IN ('ausente','cancelado')) AS no_atendidos,
|
||||
SEC_TO_TIME(
|
||||
AVG(
|
||||
CASE WHEN fin_lugar_at IS NOT NULL AND creado_at IS NOT NULL
|
||||
THEN TIMESTAMPDIFF(SECOND, creado_at, fin_lugar_at)
|
||||
ELSE NULL END
|
||||
)
|
||||
) AS tiempo_promedio_atencion
|
||||
FROM turnero_turnos
|
||||
WHERE sesion_id = ?"
|
||||
);
|
||||
$stmtStats->execute([$sesionId]);
|
||||
$stats = $stmtStats->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
jsonOk([
|
||||
'sesion_id' => $sesionId,
|
||||
'activos_recepcion'=> $activosRecepcion, // array — todos los en_recepcion
|
||||
'lugares' => $lugaresActivos,
|
||||
'cola' => $cola,
|
||||
'stats' => $stats,
|
||||
'timestamp' => date('c'),
|
||||
]);
|
||||
@@ -18,6 +18,7 @@ return [
|
||||
['name' => 'Recepción', 'icon' => 'fas fa-concierge-bell', 'route' => '/erp.php?m=turnero&v=recepcion'],
|
||||
['name' => 'Configuración', 'icon' => 'fas fa-sliders-h', 'route' => '/erp.php?m=turnero&v=configuracion'],
|
||||
['name' => 'Kiosko', 'icon' => 'fas fa-desktop', 'route' => '/erp.php?m=turnero&v=kiosko'],
|
||||
['name' => 'Pantalla TV', 'icon' => 'fas fa-tv', 'route' => '/erp.php?m=turnero&v=display'],
|
||||
['name' => 'Pantalla TV', 'icon' => 'fas fa-tv', 'route' => '/erp.php?m=turnero&v=display'],
|
||||
['name' => 'Pantalla TV Global', 'icon' => 'fas fa-th-large', 'route' => '/erp.php?m=turnero&v=display_global'],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -117,11 +117,13 @@ $_labColor = preg_match('/^#[0-9a-fA-F]{3,8}$/', $_dispCfg['doc_color'] ?? '')
|
||||
padding: 2rem; position: relative;
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
transition: background .5s;
|
||||
}
|
||||
/* Franja decorativa de color en el borde izquierdo */
|
||||
.turno-activo::before {
|
||||
content: ''; position: absolute; left: 0; top: 0; bottom: 0;
|
||||
width: 8px; background: var(--brand);
|
||||
width: 10px; background: var(--prio-color, var(--brand));
|
||||
transition: background .5s;
|
||||
}
|
||||
.turno-activo .etiqueta {
|
||||
font-size: clamp(.8rem, 1.8vw, 1.1rem);
|
||||
@@ -133,7 +135,7 @@ $_labColor = preg_match('/^#[0-9a-fA-F]{3,8}$/', $_dispCfg['doc_color'] ?? '')
|
||||
font-size: clamp(5rem, 20vw, 15rem);
|
||||
font-weight: 900; line-height: 1;
|
||||
letter-spacing: -4px;
|
||||
color: var(--brand);
|
||||
color: var(--prio-color, var(--brand));
|
||||
transition: color .4s;
|
||||
}
|
||||
.turno-activo .nombre-pac {
|
||||
@@ -147,6 +149,7 @@ $_labColor = preg_match('/^#[0-9a-fA-F]{3,8}$/', $_dispCfg['doc_color'] ?? '')
|
||||
font-size: clamp(.8rem, 1.6vw, 1.1rem); font-weight: 700;
|
||||
margin-top: 1rem;
|
||||
background: var(--brand-light); color: var(--brand-dark);
|
||||
transition: background .4s, color .4s;
|
||||
}
|
||||
.turno-activo .sin-turno {
|
||||
font-size: clamp(1.2rem, 3vw, 2.2rem);
|
||||
@@ -164,7 +167,7 @@ $_labColor = preg_match('/^#[0-9a-fA-F]{3,8}$/', $_dispCfg['doc_color'] ?? '')
|
||||
}
|
||||
.ring-anim::before {
|
||||
content: ''; width: 35vmin; height: 35vmin; border-radius: 50%;
|
||||
background: transparent; border: 5px solid var(--brand); opacity: 0;
|
||||
background: transparent; border: 5px solid var(--prio-color, var(--brand)); opacity: 0;
|
||||
}
|
||||
.ring-anim.animar::before { animation: ping-ring .75s ease-out 1; }
|
||||
.turno-activo > *:not(.ring-anim) { position: relative; z-index: 1; }
|
||||
@@ -449,15 +452,21 @@ function renderSnapshot(snap) {
|
||||
lastCodigoActivo = activo.codigo;
|
||||
}
|
||||
|
||||
elCodigo.textContent = activo.codigo;
|
||||
elCodigo.style.color = activo.prioridad_color
|
||||
? shadeColor(activo.prioridad_color, -30)
|
||||
: 'var(--brand-dark)';
|
||||
elNombre.textContent = activo.paciente_nombre || '';
|
||||
elPrio.style.background = (activo.prioridad_color || '#1565c0') + '22';
|
||||
elPrio.style.color = activo.prioridad_color || '#1565c0';
|
||||
const prioColor = activo.prioridad_color || '#1565c0';
|
||||
const zona = document.getElementById('zona-activo');
|
||||
zona.style.setProperty('--prio-color', prioColor);
|
||||
zona.style.background = prioColor + '12'; // fondo muy suave con color de prioridad
|
||||
|
||||
elCodigo.textContent = activo.codigo;
|
||||
elCodigo.style.color = '';
|
||||
elNombre.textContent = activo.paciente_nombre || '';
|
||||
elPrio.style.background = prioColor + '22';
|
||||
elPrio.style.color = prioColor;
|
||||
elPrio.innerHTML = `<i class="fas fa-ticket-alt"></i> ${activo.prioridad_codigo} — ${activo.prioridad_nombre}`;
|
||||
} else {
|
||||
const zona = document.getElementById('zona-activo');
|
||||
zona.style.removeProperty('--prio-color');
|
||||
zona.style.background = '#fff';
|
||||
elCodigo.textContent = '—';
|
||||
elCodigo.style.color = '#cbd5e1';
|
||||
elNombre.textContent = '';
|
||||
|
||||
@@ -0,0 +1,551 @@
|
||||
<?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')"
|
||||
)->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';
|
||||
?>
|
||||
<!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; }
|
||||
html, body {
|
||||
margin: 0; padding: 0;
|
||||
height: 100%; width: 100%;
|
||||
overflow: hidden;
|
||||
background: #f0f4f8;
|
||||
font-family: 'Segoe UI', system-ui, sans-serif;
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
:root {
|
||||
--brand: <?= $_labColor ?>;
|
||||
--brand-dark: color-mix(in srgb, <?= $_labColor ?> 70%, #000);
|
||||
--brand-light: color-mix(in srgb, <?= $_labColor ?> 15%, #fff);
|
||||
}
|
||||
|
||||
/* ── Layout principal ──────────────────────────────── */
|
||||
.pg-grid {
|
||||
display: grid;
|
||||
grid-template-rows: auto 1fr auto auto;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
/* ── Header ─────────────────────────────────────────── */
|
||||
.pg-header {
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
padding: .6rem 2rem;
|
||||
background: var(--brand);
|
||||
gap: 1rem; flex-shrink: 0;
|
||||
}
|
||||
.header-brand {
|
||||
display: flex; align-items: center; gap: .8rem;
|
||||
flex: 1; min-width: 0;
|
||||
}
|
||||
.header-brand img.logo {
|
||||
height: 44px; max-width: 120px; object-fit: contain;
|
||||
background: rgba(255,255,255,.12); border-radius: 8px; padding: 4px 6px;
|
||||
}
|
||||
.header-brand .lab-nombre {
|
||||
font-size: clamp(.9rem, 2vw, 1.3rem);
|
||||
font-weight: 800; color: #fff;
|
||||
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||||
}
|
||||
.header-brand .lab-sub {
|
||||
font-size: .7rem; color: rgba(255,255,255,.65);
|
||||
font-weight: 500; text-transform: uppercase; letter-spacing: 1.5px;
|
||||
display: block; margin-top: 1px;
|
||||
}
|
||||
.header-right {
|
||||
display: flex; align-items: center; gap: .75rem; flex-shrink: 0;
|
||||
}
|
||||
.reloj {
|
||||
font-size: clamp(1rem, 2.2vw, 1.45rem);
|
||||
font-weight: 800; color: #fff;
|
||||
font-variant-numeric: tabular-nums;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.btn-sonido {
|
||||
background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3);
|
||||
color: #fff; border-radius: 8px; padding: 5px 12px;
|
||||
font-size: .78rem; cursor: pointer;
|
||||
}
|
||||
|
||||
/* ── Cuerpo: paneles de área ─────────────────────── */
|
||||
.pg-body {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr; /* recepción | lugares */
|
||||
gap: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Panel genérico de área */
|
||||
.area-panel {
|
||||
display: flex; flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Encabezado del área */
|
||||
.area-header {
|
||||
padding: .55rem 1.2rem;
|
||||
font-size: clamp(.7rem, 1.4vw, .9rem);
|
||||
font-weight: 800; text-transform: uppercase; letter-spacing: 2px;
|
||||
color: #fff; display: flex; align-items: center; gap: .5rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.area-header.recepcion { background: #1e40af; }
|
||||
.area-header.muestras { background: #15803d; }
|
||||
|
||||
/* Turno activo dentro del área */
|
||||
.area-turno {
|
||||
flex: 1; display: flex; flex-direction: column;
|
||||
align-items: center; justify-content: center;
|
||||
padding: 1.5rem 1rem;
|
||||
position: relative; overflow: hidden;
|
||||
background: #fff;
|
||||
transition: background .5s;
|
||||
}
|
||||
.area-turno::before {
|
||||
content: ''; position: absolute; top: 0; left: 0; right: 0; height: 6px;
|
||||
background: var(--prio-color, var(--brand));
|
||||
transition: background .5s;
|
||||
}
|
||||
.area-turno .lbl-destino {
|
||||
font-size: clamp(.65rem, 1.3vw, .85rem);
|
||||
color: #94a3b8; font-weight: 700;
|
||||
text-transform: uppercase; letter-spacing: 3px;
|
||||
margin-bottom: .15rem;
|
||||
}
|
||||
.area-turno .codigo-num {
|
||||
font-size: clamp(4rem, 16vw, 12rem);
|
||||
font-weight: 900; line-height: 1; letter-spacing: -3px;
|
||||
color: var(--prio-color, var(--brand));
|
||||
transition: color .4s;
|
||||
}
|
||||
.area-turno .pac-nombre {
|
||||
font-size: clamp(.9rem, 2.2vw, 1.5rem);
|
||||
font-weight: 700; color: #334155;
|
||||
margin-top: .3rem; text-align: center;
|
||||
}
|
||||
.area-turno .prio-chip {
|
||||
display: inline-flex; align-items: center; gap: .4rem;
|
||||
padding: .35rem 1.1rem; border-radius: 30px;
|
||||
font-size: clamp(.7rem, 1.3vw, .95rem); font-weight: 700;
|
||||
margin-top: .75rem;
|
||||
transition: background .4s, color .4s;
|
||||
}
|
||||
.area-turno .sin-turno {
|
||||
font-size: clamp(1rem, 2.5vw, 1.8rem);
|
||||
color: #cbd5e1; text-align: center;
|
||||
}
|
||||
|
||||
/* Anillo */
|
||||
@keyframes ping-ring {
|
||||
0% { transform: scale(.8); opacity: .7; }
|
||||
100% { transform: scale(2.6); opacity: 0; }
|
||||
}
|
||||
.ring {
|
||||
position: absolute; inset: 0;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
pointer-events: none; z-index: 0;
|
||||
}
|
||||
.ring::before {
|
||||
content: ''; width: 30vmin; height: 30vmin; border-radius: 50%;
|
||||
background: transparent;
|
||||
border: 5px solid var(--prio-color, var(--brand)); opacity: 0;
|
||||
}
|
||||
.ring.animar::before { animation: ping-ring .75s ease-out 1; }
|
||||
.area-turno > *:not(.ring) { position: relative; z-index: 1; }
|
||||
|
||||
/* Divisor entre áreas */
|
||||
.area-divider {
|
||||
width: 3px; background: #e2e8f0; flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Sub-paneles múltiples cuando hay varios lugares */
|
||||
.lugares-grid {
|
||||
display: grid;
|
||||
grid-template-rows: repeat(auto-fill, 1fr);
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
.lugar-sub {
|
||||
display: flex; flex-direction: column;
|
||||
border-bottom: 2px solid #e2e8f0;
|
||||
}
|
||||
.lugar-sub:last-child { border-bottom: none; }
|
||||
.lugar-sub .area-header { background: #166534; }
|
||||
.lugar-sub .area-turno .codigo-num {
|
||||
font-size: clamp(2.5rem, 10vw, 7rem);
|
||||
}
|
||||
|
||||
/* ── Cola en espera ──────────────────────────────── */
|
||||
.pg-cola {
|
||||
background: #f8fafc;
|
||||
border-top: 2px solid #e2e8f0;
|
||||
padding: .4rem .8rem;
|
||||
display: flex; align-items: center; gap: .6rem;
|
||||
overflow-x: auto; flex-shrink: 0;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
.pg-cola::-webkit-scrollbar { display: none; }
|
||||
.cola-lbl {
|
||||
font-size: .7rem; font-weight: 800; text-transform: uppercase;
|
||||
letter-spacing: 1.5px; color: var(--brand); white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.cola-chip {
|
||||
display: inline-flex; align-items: center; gap: .3rem;
|
||||
padding: .25rem .7rem; border-radius: 99px;
|
||||
font-size: .78rem; font-weight: 700;
|
||||
background: #fff; border: 1.5px solid;
|
||||
white-space: nowrap; flex-shrink: 0;
|
||||
}
|
||||
.cola-vacia-msg {
|
||||
font-size: .78rem; color: #94a3b8;
|
||||
}
|
||||
|
||||
/* ── Footer stats ─────────────────────────────────── */
|
||||
.pg-footer {
|
||||
display: flex; justify-content: center; align-items: center;
|
||||
gap: 2rem; flex-wrap: wrap;
|
||||
padding: .4rem 2rem;
|
||||
background: var(--brand);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.stat-item { text-align: center; }
|
||||
.stat-item .val { font-size: 1.15rem; font-weight: 800; color: #fff; }
|
||||
.stat-item .lbl { font-size: .6rem; color: rgba(255,255,255,.65); text-transform: uppercase; letter-spacing: 1px; }
|
||||
.stat-sep { width: 1px; height: 26px; background: rgba(255,255,255,.2); }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="pg-grid">
|
||||
|
||||
<!-- Header -->
|
||||
<header class="pg-header">
|
||||
<div class="header-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="header-right">
|
||||
<button class="btn-sonido" id="btn-sonido" onclick="activarSonido()">
|
||||
<i class="fas fa-volume-mute"></i> Sonido
|
||||
</button>
|
||||
<div class="reloj" id="reloj">--:--:--</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Cuerpo: Recepción | Muestras -->
|
||||
<div class="pg-body" id="pg-body">
|
||||
|
||||
<!-- Panel Recepción -->
|
||||
<div class="area-panel" id="panel-recepcion">
|
||||
<div class="area-header recepcion">
|
||||
<i class="fas fa-door-open"></i> Recepción
|
||||
</div>
|
||||
<div class="area-turno" id="turno-recepcion">
|
||||
<div class="ring" id="ring-recepcion"></div>
|
||||
<div class="lbl-destino">Pase a Recepción</div>
|
||||
<div class="codigo-num" id="cod-recepcion">—</div>
|
||||
<div class="pac-nombre" id="pac-recepcion"></div>
|
||||
<div class="prio-chip" id="chip-recepcion">
|
||||
<i class="fas fa-hourglass-half"></i> En espera
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Divisor -->
|
||||
<div class="area-divider"></div>
|
||||
|
||||
<!-- Panel Muestras (múltiples lugares) -->
|
||||
<div class="area-panel">
|
||||
<div class="area-header muestras">
|
||||
<i class="fas fa-vials"></i> Toma de Muestras
|
||||
</div>
|
||||
<div class="lugares-grid" id="lugares-grid">
|
||||
<!-- Se genera en JS -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Cola en espera -->
|
||||
<div class="pg-cola" id="pg-cola">
|
||||
<span class="cola-lbl"><i class="fas fa-list-ol me-1"></i>EN ESPERA</span>
|
||||
<span class="cola-vacia-msg" id="cola-vacia">Cola vacía</span>
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<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 hoy</div>
|
||||
</div>
|
||||
<div class="stat-sep"></div>
|
||||
<div class="stat-item">
|
||||
<div class="val" id="st-total">—</div>
|
||||
<div class="lbl">Total del día</div>
|
||||
</div>
|
||||
<div class="stat-sep"></div>
|
||||
<div class="stat-item">
|
||||
<div class="val" id="st-tiempo">—</div>
|
||||
<div class="lbl">Tiempo prom.</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const BASE_API = '<?= BASE_URL ?>modules/turnero/api/';
|
||||
|
||||
// ── 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, 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.style.background = 'rgba(34,197,94,.25)';
|
||||
btn.style.borderColor = 'rgba(34,197,94,.5)';
|
||||
btn.onclick = null; btn.style.cursor = 'default';
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Estado previo ──────────────────────────────────────────────
|
||||
let lastCodRecepcion = null;
|
||||
const lastCodLugar = {}; // { lugar_id: codigo }
|
||||
|
||||
// ── Escape HTML ────────────────────────────────────────────────
|
||||
function esc(str) {
|
||||
const d = document.createElement('div');
|
||||
d.appendChild(document.createTextNode(str));
|
||||
return d.innerHTML;
|
||||
}
|
||||
|
||||
// ── Aplicar color de prioridad a un panel ─────────────────────
|
||||
function aplicarColor(panelEl, ringEl, chipEl, color) {
|
||||
panelEl.style.setProperty('--prio-color', color);
|
||||
panelEl.style.background = color + '12';
|
||||
chipEl.style.background = color + '22';
|
||||
chipEl.style.color = color;
|
||||
if (ringEl) ringEl.style.setProperty('--prio-color', color);
|
||||
}
|
||||
function limpiarColor(panelEl, ringEl, chipEl) {
|
||||
panelEl.style.removeProperty('--prio-color');
|
||||
panelEl.style.background = '#fff';
|
||||
chipEl.style.background = '#f1f5f9';
|
||||
chipEl.style.color = '#94a3b8';
|
||||
if (ringEl) ringEl.style.removeProperty('--prio-color');
|
||||
}
|
||||
|
||||
// ── Render snapshot global ─────────────────────────────────────
|
||||
function renderSnapshot(snap) {
|
||||
// ── Recepción ───────────────────────────────────────────
|
||||
const rec = snap.activo_recepcion;
|
||||
const panelRec = document.getElementById('turno-recepcion');
|
||||
const ringRec = document.getElementById('ring-recepcion');
|
||||
const codRec = document.getElementById('cod-recepcion');
|
||||
const pacRec = document.getElementById('pac-recepcion');
|
||||
const chipRec = document.getElementById('chip-recepcion');
|
||||
|
||||
if (rec) {
|
||||
const color = rec.prioridad_color || '#1565c0';
|
||||
if (rec.codigo !== lastCodRecepcion) {
|
||||
anunciarTurno(rec.codigo, 'Recepción');
|
||||
ringRec.classList.remove('animar');
|
||||
void ringRec.offsetWidth;
|
||||
ringRec.classList.add('animar');
|
||||
lastCodRecepcion = rec.codigo;
|
||||
}
|
||||
aplicarColor(panelRec, ringRec, chipRec, color);
|
||||
codRec.textContent = rec.codigo;
|
||||
codRec.style.color = '';
|
||||
pacRec.textContent = rec.paciente_nombre || '';
|
||||
chipRec.innerHTML = `<i class="fas fa-ticket-alt"></i> ${esc(rec.prioridad_codigo)} — ${esc(rec.prioridad_nombre)}`;
|
||||
} else {
|
||||
limpiarColor(panelRec, ringRec, chipRec);
|
||||
codRec.textContent = '—';
|
||||
codRec.style.color = '#cbd5e1';
|
||||
pacRec.textContent = '';
|
||||
chipRec.innerHTML = '<i class="fas fa-hourglass-half"></i> En espera';
|
||||
lastCodRecepcion = null;
|
||||
}
|
||||
|
||||
// ── Lugares (muestras) ──────────────────────────────────
|
||||
const lugares = snap.lugares || [];
|
||||
const grid = document.getElementById('lugares-grid');
|
||||
|
||||
// Construir HTML para todos los lugares
|
||||
grid.innerHTML = lugares.map(l => {
|
||||
const t = l.turno;
|
||||
const color = t ? (t.prioridad_color || '#15803d') : null;
|
||||
|
||||
const colorStyle = color ? `style="--prio-color:${color};background:${color}12"` : '';
|
||||
const codStyle = color ? '' : 'style="color:#cbd5e1"';
|
||||
const chipStyle = color
|
||||
? `style="background:${color}22;color:${color}"`
|
||||
: 'style="background:#f1f5f9;color:#94a3b8"';
|
||||
const chipContent = t
|
||||
? `<i class='fas fa-ticket-alt'></i> ${esc(t.prioridad_codigo)} — ${esc(t.prioridad_nombre)}`
|
||||
: `<i class='fas fa-hourglass-half'></i> En espera`;
|
||||
const codText = t ? esc(t.codigo) : '—';
|
||||
const pacText = t ? esc(t.paciente_nombre || '') : '';
|
||||
const ringId = `ring-lugar-${l.lugar_id}`;
|
||||
const panelId = `area-lugar-${l.lugar_id}`;
|
||||
const codId = `cod-lugar-${l.lugar_id}`;
|
||||
const chipId = `chip-lugar-${l.lugar_id}`;
|
||||
|
||||
return `
|
||||
<div class="lugar-sub" id="sub-lugar-${l.lugar_id}">
|
||||
<div class="area-header" style="background:#166534;font-size:.7rem;padding:.35rem 1rem">
|
||||
<i class="fas fa-flask"></i> ${esc(l.lugar_nombre)}
|
||||
</div>
|
||||
<div class="area-turno" id="${panelId}" ${colorStyle}>
|
||||
<div class="ring" id="${ringId}"></div>
|
||||
<div class="lbl-destino">Pase a ${esc(l.lugar_nombre)}</div>
|
||||
<div class="codigo-num" id="${codId}" ${codStyle}>${codText}</div>
|
||||
<div class="pac-nombre">${pacText}</div>
|
||||
<div class="prio-chip" id="${chipId}" ${chipStyle}>${chipContent}</div>
|
||||
</div>
|
||||
</div>`;
|
||||
}).join('');
|
||||
|
||||
// Animaciones/sonido para lugares que cambiaron
|
||||
lugares.forEach(l => {
|
||||
const t = l.turno;
|
||||
if (!t) { lastCodLugar[l.lugar_id] = null; return; }
|
||||
if (t.codigo !== lastCodLugar[l.lugar_id]) {
|
||||
anunciarTurno(t.codigo, l.lugar_nombre);
|
||||
const ring = document.getElementById(`ring-lugar-${l.lugar_id}`);
|
||||
if (ring) {
|
||||
ring.classList.remove('animar');
|
||||
void ring.offsetWidth;
|
||||
ring.classList.add('animar');
|
||||
}
|
||||
lastCodLugar[l.lugar_id] = t.codigo;
|
||||
}
|
||||
});
|
||||
|
||||
// ── Cola en espera ───────────────────────────────────────
|
||||
const cola = snap.cola || [];
|
||||
const pgCola = document.getElementById('pg-cola');
|
||||
const vaciaMg = document.getElementById('cola-vacia');
|
||||
|
||||
// Limpiar chips anteriores (conservar el label y el mensaje)
|
||||
pgCola.querySelectorAll('.cola-chip').forEach(c => c.remove());
|
||||
|
||||
if (cola.length === 0) {
|
||||
if (vaciaMg) vaciaMg.style.display = '';
|
||||
} else {
|
||||
if (vaciaMg) vaciaMg.style.display = 'none';
|
||||
cola.forEach(t => {
|
||||
const chip = document.createElement('span');
|
||||
chip.className = 'cola-chip';
|
||||
chip.style.color = t.prioridad_color || '#1565c0';
|
||||
chip.style.borderColor = t.prioridad_color || '#1565c0';
|
||||
chip.innerHTML = `<span style="width:8px;height:8px;border-radius:50%;background:${t.prioridad_color || '#1565c0'};display:inline-block"></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 cada 4 s ──────────────────────────────────────────
|
||||
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>
|
||||
Reference in New Issue
Block a user