diff --git a/modules/turnero/api/get_resumen_muestras.php b/modules/turnero/api/get_resumen_muestras.php new file mode 100644 index 0000000..c4f522a --- /dev/null +++ b/modules/turnero/api/get_resumen_muestras.php @@ -0,0 +1,51 @@ +prepare( + "SELECT l.id, l.nombre, + t.id AS turno_id, t.codigo, t.paciente_nombre + FROM turnero_lugares l + LEFT JOIN turnero_turnos t + ON t.lugar_destino_id = l.id + AND t.sesion_id = ? + AND t.estado = 'en_servicio' + AND t.muestra_espera_at IS NULL + AND t.fin_lugar_at IS NULL + WHERE l.tipo = 'muestras' AND l.activo = 1 + ORDER BY l.sort_order" +); +$stmt->execute([$sesionId]); +$estaciones = $stmt->fetchAll(PDO::FETCH_ASSOC); + +// Cola global de muestras (en_espera_lugar) +$s = $pdo->prepare( + "SELECT COUNT(*) FROM turnero_turnos + WHERE sesion_id = ? AND estado = 'en_espera_lugar' AND muestra_espera_at IS NULL + AND lugar_destino_id IN (SELECT id FROM turnero_lugares WHERE tipo='muestras' AND activo=1)" +); +$s->execute([$sesionId]); +$enEspera = (int)$s->fetchColumn(); + +// Pacientes entre tomas (espera progresiva) +$s2 = $pdo->prepare( + "SELECT COUNT(*) FROM turnero_turnos + WHERE sesion_id = ? AND muestra_espera_at IS NOT NULL AND fin_lugar_at IS NULL + AND lugar_destino_id IN (SELECT id FROM turnero_lugares WHERE tipo='muestras' AND activo=1)" +); +$s2->execute([$sesionId]); +$enEsperaMuestra = (int)$s2->fetchColumn(); + +jsonOk([ + 'estaciones' => $estaciones, + 'en_espera' => $enEspera, + 'en_espera_muestra' => $enEsperaMuestra, +]); diff --git a/modules/turnero/views/recepcion.php b/modules/turnero/views/recepcion.php index e14b158..4610182 100644 --- a/modules/turnero/views/recepcion.php +++ b/modules/turnero/views/recepcion.php @@ -934,6 +934,14 @@ document.addEventListener('DOMContentLoaded', function() { + + +
+ Muestras: +
+ + +
@@ -1200,6 +1208,8 @@ document.addEventListener('DOMContentLoaded', () => { cargarCola(); pollingColaId = setInterval(cargarCola, 3000); + _cargarResumenMuestras(); + setInterval(_cargarResumenMuestras, 7000); let _pacBusqTimer; const _inpPac = document.getElementById('inp-buscar-pac'); _inpPac.addEventListener('input', () => { @@ -3079,6 +3089,28 @@ async function mpacGuardar() { // ── Toast ──────────────────────────────────────────────────── let toastTimer = null; +async function _cargarResumenMuestras() { + try { + const r = await fetch(API + 'get_resumen_muestras.php'); + const j = await r.json(); + if (!j.ok) return; + const cont = document.getElementById('muestras-estaciones'); + if (!cont) return; + cont.innerHTML = j.estaciones.map(e => { + const libre = !e.turno_id; + return ` + ${escHtml(e.nombre)}: ${libre ? '—' : escHtml(e.codigo)} + `; + }).join(''); + const cb = document.getElementById('muestras-cola-badge'); + cb.textContent = `${j.en_espera} en espera`; + cb.classList.toggle('d-none', j.en_espera === 0); + const pb = document.getElementById('muestras-prog-badge'); + pb.textContent = `${j.en_espera_muestra} prog.`; + pb.classList.toggle('d-none', j.en_espera_muestra === 0); + } catch {} +} + function mostrarToast(msg, type = 'info', duration = 2500) { const el = document.getElementById('rec-toast'); const ico = document.getElementById('toast-ico');