diff --git a/modules/turnero/views/recepcion.php b/modules/turnero/views/recepcion.php index e4363b6..d2148d2 100644 --- a/modules/turnero/views/recepcion.php +++ b/modules/turnero/views/recepcion.php @@ -116,6 +116,10 @@ try { $desk = $desksRecepcion[0]; $deskId = (int)$desk['id']; } + + $prioridades = $pdo->query( + "SELECT codigo, nombre, color FROM turnero_prioridades WHERE activo=1 ORDER BY orden_peso" + )->fetchAll(PDO::FETCH_ASSOC); } catch (\Throwable $e) { $lugares = []; $examenesAgrupados = []; @@ -123,6 +127,7 @@ try { $desk = null; $lugarRecepcion = null; $lugarMuestras = null; + $prioridades = []; } $deskNombre = $desk['nombre'] ?? null; // null = vista genérica @@ -425,6 +430,42 @@ $SIDEBAR_ICON = 'fas fa-ticket-alt'; require_once __DIR__ . '/../../../shared/components/sidebar.php'; ?> + + + 1): ?> - +
+ + +
@@ -1242,6 +1288,48 @@ function renderCola(snap) { }).join(''); } +// ── Nuevo turno desde recepción ─────────────────────────────── +let _modalNuevoTurno; +function abrirModalNuevoTurno() { + if (!_modalNuevoTurno) _modalNuevoTurno = new bootstrap.Modal(document.getElementById('modalNuevoTurno')); + document.getElementById('mnt-doc').value = ''; + document.getElementById('mnt-msg').className = 'small mt-2 d-none'; + document.getElementById('mnt-btn-crear').disabled = false; + // Pre-fill doc si hay turno activo + const doc = turnoActivo?.paciente_nombre; + if (doc) document.getElementById('mnt-doc').value = doc; + _modalNuevoTurno.show(); +} +async function crearNuevoTurno() { + const btn = document.getElementById('mnt-btn-crear'); + const msg = document.getElementById('mnt-msg'); + const prio = document.getElementById('mnt-prio').value; + const doc = document.getElementById('mnt-doc').value.trim(); + btn.disabled = true; + msg.className = 'small mt-2 d-none'; + try { + const r = await fetch(API + 'create_turno.php', { + method: 'POST', + headers: {'Content-Type':'application/json'}, + body: JSON.stringify({ prioridad_codigo: prio, paciente_nombre: doc || undefined }), + }); + const j = await r.json(); + if (j.ok) { + msg.className = 'small mt-2 text-success'; + msg.textContent = `Turno ${j.turno.codigo} creado`; + setTimeout(() => _modalNuevoTurno.hide(), 1200); + } else { + msg.className = 'small mt-2 text-danger'; + msg.textContent = j.error || 'Error al crear turno'; + btn.disabled = false; + } + } catch { + msg.className = 'small mt-2 text-danger'; + msg.textContent = 'Error de conexión'; + btn.disabled = false; + } +} + // ── Llamar siguiente ────────────────────────────────────────── async function llamarSiguiente() { const btn = document.getElementById('btn-llamar');