up
This commit is contained in:
@@ -210,6 +210,7 @@ function siguienteTurnoEnCola(string $estado, ?int $lugarId = null): ?array
|
|||||||
AND t.lugar_destino_id = ?
|
AND t.lugar_destino_id = ?
|
||||||
ORDER BY p.orden_peso ASC, t.creado_at ASC
|
ORDER BY p.orden_peso ASC, t.creado_at ASC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
|
FOR UPDATE
|
||||||
';
|
';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute([$estado, $lugarId]);
|
$stmt->execute([$estado, $lugarId]);
|
||||||
@@ -221,6 +222,7 @@ function siguienteTurnoEnCola(string $estado, ?int $lugarId = null): ?array
|
|||||||
WHERE t.estado = ?
|
WHERE t.estado = ?
|
||||||
ORDER BY p.orden_peso ASC, t.creado_at ASC
|
ORDER BY p.orden_peso ASC, t.creado_at ASC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
|
FOR UPDATE
|
||||||
';
|
';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute([$estado]);
|
$stmt->execute([$estado]);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ if ($nuevoEstado === '') jsonError('nuevo_estado es requerido.');
|
|||||||
// Mapa de transiciones válidas [estado_actual => [estados_destino_permitidos]]
|
// Mapa de transiciones válidas [estado_actual => [estados_destino_permitidos]]
|
||||||
const TRANSICIONES = [
|
const TRANSICIONES = [
|
||||||
'espera' => ['en_recepcion', 'ausente', 'cancelado'],
|
'espera' => ['en_recepcion', 'ausente', 'cancelado'],
|
||||||
'en_recepcion' => ['en_espera_lugar', 'ausente', 'cancelado'],
|
'en_recepcion' => ['en_espera_lugar', 'espera', 'ausente', 'cancelado'],
|
||||||
'en_espera_lugar' => ['en_servicio', 'ausente', 'cancelado'],
|
'en_espera_lugar' => ['en_servicio', 'ausente', 'cancelado'],
|
||||||
'en_servicio' => ['finalizado', 'ausente', 'cancelado', 'en_espera_lugar'],
|
'en_servicio' => ['finalizado', 'ausente', 'cancelado', 'en_espera_lugar'],
|
||||||
];
|
];
|
||||||
@@ -139,6 +139,13 @@ try {
|
|||||||
$binds[] = adminId();
|
$binds[] = adminId();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'espera':
|
||||||
|
// Soltar: liberar el turno para que otro escritorio lo llame
|
||||||
|
$sets[] = 'recepcion_desk_id = NULL';
|
||||||
|
$sets[] = 'inicio_recepcion_at = NULL';
|
||||||
|
$sets[] = 'atendido_recepcion_por = NULL';
|
||||||
|
break;
|
||||||
|
|
||||||
case 'ausente':
|
case 'ausente':
|
||||||
case 'cancelado':
|
case 'cancelado':
|
||||||
// Sin timestamps adicionales; simplemente cambio de estado
|
// Sin timestamps adicionales; simplemente cambio de estado
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ $stmt = $pdo->prepare(
|
|||||||
t.numero,
|
t.numero,
|
||||||
t.estado,
|
t.estado,
|
||||||
t.paciente_nombre,
|
t.paciente_nombre,
|
||||||
|
t.recepcion_desk_id,
|
||||||
t.creado_at,
|
t.creado_at,
|
||||||
t.llamado_recepcion_at,
|
t.llamado_recepcion_at,
|
||||||
t.llamado_lugar_at,
|
t.llamado_lugar_at,
|
||||||
|
|||||||
@@ -300,10 +300,14 @@ require_once __DIR__ . '/../../../shared/components/sidebar.php';
|
|||||||
justify-content:center;font-size:1.6rem;font-weight:900;color:#fff;background:#3b82f6">
|
justify-content:center;font-size:1.6rem;font-weight:900;color:#fff;background:#3b82f6">
|
||||||
—
|
—
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="flex-grow-1">
|
||||||
<div class="h4 mb-0 fw-bold" id="ficha-codigo">—</div>
|
<div class="h4 mb-0 fw-bold" id="ficha-codigo">—</div>
|
||||||
<div class="text-muted small" id="ficha-prio-nombre">—</div>
|
<div class="text-muted small" id="ficha-prio-nombre">—</div>
|
||||||
</div>
|
</div>
|
||||||
|
<button class="btn btn-outline-primary btn-sm" onclick="rellamarActivo()"
|
||||||
|
title="Volver a llamar este turno (suena en pantalla)">
|
||||||
|
<i class="fas fa-bell"></i> Re-llamar
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ── Sección 1: Paciente ── -->
|
<!-- ── Sección 1: Paciente ── -->
|
||||||
@@ -428,6 +432,9 @@ require_once __DIR__ . '/../../../shared/components/sidebar.php';
|
|||||||
<button class="btn btn-warning d-none" id="btn-enviar-consent" onclick="enviarConsentimientos()">
|
<button class="btn btn-warning d-none" id="btn-enviar-consent" onclick="enviarConsentimientos()">
|
||||||
<i class="fas fa-paper-plane me-1"></i>Enviar consentimientos
|
<i class="fas fa-paper-plane me-1"></i>Enviar consentimientos
|
||||||
</button>
|
</button>
|
||||||
|
<button class="btn btn-outline-secondary" id="btn-soltar" onclick="soltarTurno()" title="Liberar turno para que otro escritorio lo llame">
|
||||||
|
<i class="fas fa-undo-alt me-1"></i>Soltar
|
||||||
|
</button>
|
||||||
<button class="btn btn-secondary ms-auto" onclick="marcarAusente()">
|
<button class="btn btn-secondary ms-auto" onclick="marcarAusente()">
|
||||||
<i class="fas fa-user-slash me-1"></i>Ausente
|
<i class="fas fa-user-slash me-1"></i>Ausente
|
||||||
</button>
|
</button>
|
||||||
@@ -489,7 +496,7 @@ async function cargarCola() {
|
|||||||
function renderCola(snap) {
|
function renderCola(snap) {
|
||||||
const lista = document.getElementById('cola-items');
|
const lista = document.getElementById('cola-items');
|
||||||
const todos = snap.cola || [];
|
const todos = snap.cola || [];
|
||||||
const espera = todos.filter(t => t.estado === 'espera' || t.estado === 'en_recepcion');
|
const espera = todos.filter(t => t.estado === 'espera');
|
||||||
const badge = document.getElementById('badge-count');
|
const badge = document.getElementById('badge-count');
|
||||||
badge.textContent = espera.length;
|
badge.textContent = espera.length;
|
||||||
|
|
||||||
@@ -594,6 +601,19 @@ async function llamarTurnoEspecifico(turnoId, estadoActual) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Re-llamar desde la ficha ────────────────────────────────
|
||||||
|
async function rellamarActivo() {
|
||||||
|
if (!turnoActivo) return;
|
||||||
|
mostrarLlamando(turnoActivo.codigo);
|
||||||
|
try {
|
||||||
|
await fetch(API + 'rellamar.php', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ turno_id: turnoActivo.id, desk_id: DESK_ID }),
|
||||||
|
});
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Abrir ficha ───────────────────────────────────────────────
|
// ── Abrir ficha ───────────────────────────────────────────────
|
||||||
function abrirFicha(turno) {
|
function abrirFicha(turno) {
|
||||||
turnoActivo = turno;
|
turnoActivo = turno;
|
||||||
@@ -948,6 +968,26 @@ async function marcarAusente() {
|
|||||||
cargarCola();
|
cargarCola();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Soltar turno ──────────────────────────────────────────────
|
||||||
|
async function soltarTurno() {
|
||||||
|
if (!turnoActivo) return;
|
||||||
|
if (!confirm(`¿Soltar turno ${turnoActivo.codigo}? Otro escritorio podrá llamarlo.`)) return;
|
||||||
|
|
||||||
|
await fetch(API + 'cambiar_estado.php', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ turno_id: turnoActivo.id, nuevo_estado: 'espera' }),
|
||||||
|
});
|
||||||
|
|
||||||
|
turnoActivo = null;
|
||||||
|
solicitudActiva = null;
|
||||||
|
document.getElementById('ficha-turno').classList.add('d-none');
|
||||||
|
document.getElementById('ficha-placeholder').classList.remove('d-none');
|
||||||
|
document.getElementById('badge-turno-activo').classList.add('d-none');
|
||||||
|
mostrarToast('Turno liberado', 'success');
|
||||||
|
cargarCola();
|
||||||
|
}
|
||||||
|
|
||||||
// ── Helpers ───────────────────────────────────────────────────
|
// ── Helpers ───────────────────────────────────────────────────
|
||||||
function resetCheckboxes() {
|
function resetCheckboxes() {
|
||||||
document.querySelectorAll('.exam-chk').forEach(c => c.checked = false);
|
document.querySelectorAll('.exam-chk').forEach(c => c.checked = false);
|
||||||
|
|||||||
Reference in New Issue
Block a user