fix(turnero): llamar_desde_espera actualiza lugar y dispara display
Al llamar un paciente de toma progresiva desde la espera, ahora se actualiza lugar_destino_id al puesto que llama, se pone llamado_lugar_at para que el display anuncie al paciente, y se notifica por SSE. El JS abre la ficha y muestra el toast igual que un llamar normal. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
3d26700e16
commit
8472c916b0
@@ -1,8 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* POST llamar_desde_espera.php
|
||||
* {turno_id} → devuelve el paciente a la cola activa para la siguiente muestra.
|
||||
* SET muestra_espera_at = NULL.
|
||||
* {turno_id, lugar_id} → regresa el paciente a cola, actualiza lugar y dispara display.
|
||||
*/
|
||||
require_once __DIR__ . '/_helpers.php';
|
||||
requireTurnero();
|
||||
@@ -10,10 +9,31 @@ requireMethod('POST');
|
||||
|
||||
$input = inputJson();
|
||||
$turnoId = (int)($input['turno_id'] ?? 0);
|
||||
$lugarId = (int)($input['lugar_id'] ?? 0);
|
||||
if (!$turnoId) jsonError('turno_id requerido');
|
||||
if (!$lugarId) jsonError('lugar_id requerido');
|
||||
|
||||
db()->prepare(
|
||||
"UPDATE turnero_turnos SET muestra_espera_at = NULL WHERE id = ? AND muestra_espera_at IS NOT NULL"
|
||||
)->execute([$turnoId]);
|
||||
$pdo = db();
|
||||
$pdo->prepare(
|
||||
'UPDATE turnero_turnos
|
||||
SET muestra_espera_at = NULL,
|
||||
lugar_destino_id = ?,
|
||||
llamado_lugar_at = NOW(),
|
||||
atendido_lugar_por = ?
|
||||
WHERE id = ? AND muestra_espera_at IS NOT NULL'
|
||||
)->execute([$lugarId, adminId(), $turnoId]);
|
||||
|
||||
jsonOk([], 'Paciente de vuelta en cola');
|
||||
$stmt = $pdo->prepare(
|
||||
'SELECT t.*, p.codigo AS prioridad_codigo, p.nombre AS prioridad_nombre, p.color AS prioridad_color,
|
||||
COALESCE(ts.solo_muestras, 0) AS solo_muestras
|
||||
FROM turnero_turnos t
|
||||
JOIN turnero_prioridades p ON p.id = t.prioridad_id
|
||||
LEFT JOIN turnero_solicitudes ts ON ts.turno_id = t.id
|
||||
WHERE t.id = ?'
|
||||
);
|
||||
$stmt->execute([$turnoId]);
|
||||
$turno = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($turno) notificarSSE((int)$turno['sesion_id']);
|
||||
|
||||
jsonOk(['turno' => $turno], 'Paciente llamado');
|
||||
|
||||
@@ -2589,11 +2589,13 @@ async function _llamarDesdeEspera(turnoId) {
|
||||
try {
|
||||
const res = await fetch(API + 'llamar_desde_espera.php', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ turno_id: turnoId }),
|
||||
body: JSON.stringify({ turno_id: turnoId, lugar_id: lugarId }),
|
||||
});
|
||||
const j = await res.json();
|
||||
if (!j.ok) mostrarError(j.error);
|
||||
else cargarCola();
|
||||
if (!j.ok) { mostrarError(j.error); return; }
|
||||
mostrarLlamando(j.turno.codigo);
|
||||
await abrirFicha(j.turno);
|
||||
cargarCola();
|
||||
} catch (e) { mostrarError(e.message); }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user