From 8b0bdc6b3015d99fa1ae3c91b8c997d697d9bd20 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 16 Jul 2026 20:54:02 -0500 Subject: [PATCH] =?UTF-8?q?turnero/recepcion:=20bot=C3=B3n=20para=20genera?= =?UTF-8?q?r=20nuevo=20turno=20desde=20recepci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modal con select de prioridad (cargado desde BD) y campo opcional de cédula/nombre. Llama a create_turno.php que ya maneja sesión, duplicados, SSE y notificación WhatsApp. Co-Authored-By: Claude Sonnet 4.6 --- modules/turnero/views/recepcion.php | 94 ++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 3 deletions(-) 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');