diff --git a/modules/turnero/api/llamar_turno.php b/modules/turnero/api/llamar_turno.php
index b0d8722..5ea6bf9 100644
--- a/modules/turnero/api/llamar_turno.php
+++ b/modules/turnero/api/llamar_turno.php
@@ -17,6 +17,7 @@ $datos = inputJson();
$area = $datos['area'] ?? '';
$lugarId = isset($datos['lugar_id']) ? (int) $datos['lugar_id'] : null;
$deskId = isset($datos['desk_id']) ? (int) $datos['desk_id'] : null;
+$turnoId = isset($datos['turno_id']) ? (int) $datos['turno_id'] : null; // llamar uno específico
// ── Validación ────────────────────────────────────────────────
if (!in_array($area, ['recepcion', 'lugar'], true)) {
@@ -59,11 +60,26 @@ try {
} else {
// Cola de un Lugar específico: turnos 'en_espera_lugar' asignados a ese lugar
- $turno = siguienteTurnoEnCola('en_espera_lugar', $lugarId);
-
- if (!$turno) {
- $pdo->rollBack();
- jsonOk(['turno' => null], 'Cola del lugar vacía');
+ if ($turnoId) {
+ // Llamar uno específico por id
+ $stmt = $pdo->prepare(
+ 'SELECT t.*, 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.id = ? AND t.estado = "en_espera_lugar"'
+ );
+ $stmt->execute([$turnoId]);
+ $turno = $stmt->fetch(PDO::FETCH_ASSOC);
+ if (!$turno) {
+ $pdo->rollBack();
+ jsonError('El turno no está en espera o no existe.', 404);
+ }
+ } else {
+ $turno = siguienteTurnoEnCola('en_espera_lugar', $lugarId);
+ if (!$turno) {
+ $pdo->rollBack();
+ jsonOk(['turno' => null], 'Cola del lugar vacía');
+ }
}
$stmt = $pdo->prepare(
diff --git a/modules/turnero/views/lugar.php b/modules/turnero/views/lugar.php
index c92e76f..689bfbb 100644
--- a/modules/turnero/views/lugar.php
+++ b/modules/turnero/views/lugar.php
@@ -413,17 +413,29 @@ function renderCola(snap) {
return;
}
lista.innerHTML = espera.map(t => `
-
+
${t.prioridad_codigo}
${escHtml(t.codigo)}
${escHtml(t.paciente_nombre || 'Paciente')}
+
`).join('');
}
// ── Llamar siguiente ──────────────────────────────────────────
async function llamarSiguiente() {
+ await _llamar({});
+}
+
+async function llamarTurnoEspecifico(turnoId) {
+ if (turnoActivo?.id === turnoId) return; // ya está abierto
+ await _llamar({ turno_id: turnoId });
+}
+
+async function _llamar(extra) {
if (!lugarId) { alert('Primero seleccione un lugar.'); return; }
const btn = document.getElementById('btn-llamar');
btn.disabled = true;
@@ -431,15 +443,11 @@ async function llamarSiguiente() {
const res = await fetch(API + 'llamar_turno.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ area: 'lugar', lugar_id: lugarId }),
+ body: JSON.stringify({ area: 'lugar', lugar_id: lugarId, ...extra }),
});
const json = await res.json();
if (!json.ok) { alert('Error: ' + json.error); return; }
-
- if (!json.turno) {
- alert('Cola del lugar vacía.');
- return;
- }
+ if (!json.turno) { alert('Cola del lugar vacía.'); return; }
await abrirFicha(json.turno);
cargarCola();
} catch (err) {
@@ -494,11 +502,11 @@ async function cargarFichaSolicitud(turnoId) {
document.getElementById('bloque-pac-info').style.display = '';
document.getElementById('bloque-pac-sin').classList.add('d-none');
document.getElementById('pac-nombre').textContent =
- (pac.full_name || (pac.nombre||'') + ' ' + (pac.apellido||'')).trim() || '—';
+ pac.nombre_completo || pac.full_name || '—';
document.getElementById('pac-doc').textContent =
- (pac.tipo_documento||'') + ' ' + (pac.documento||'') || '—';
+ ((pac.tipo_documento||'') + ' ' + (pac.numero_documento||pac.documento||'')).trim() || '—';
document.getElementById('pac-fec').textContent = pac.fecha_nacimiento || '—';
- document.getElementById('pac-cel').textContent = pac.celular || pac.telefono || '—';
+ document.getElementById('pac-cel').textContent = pac.telefono || pac.celular || '—';
} else {
document.getElementById('bloque-pac-info').style.display = 'none';
document.getElementById('bloque-pac-sin').classList.remove('d-none');
@@ -569,10 +577,10 @@ function renderConsentimientos(lista) {
// WA / Ver: según estado
const btnWa = ya
- ? (c.token ? `
` : '')
+ ` : '')
: `