This commit is contained in:
Lizandro Guarnizo
2026-06-16 13:35:03 -05:00
parent 1b9c8efaad
commit fc14360e2e
2 changed files with 48 additions and 22 deletions
+23 -12
View File
@@ -66,23 +66,34 @@ if ($area === 'recepcion') {
);
$stmt->execute($bindsCola);
} else {
// Lugar: cola compartida (grupo) solo en_espera_lugar
// Lugar: cola = en_espera_lugar del grupo + en_servicio en ESTA estación
$grupoIds = lugarIdsDeGrupo($lugarId);
$inLugares = implode(',', array_map('intval', $grupoIds));
$cols = "t.id, t.codigo, t.numero, t.estado, t.paciente_nombre,
t.recepcion_desk_id, t.creado_at, t.llamado_recepcion_at, t.llamado_lugar_at,
p.codigo AS prioridad_codigo, p.nombre AS prioridad_nombre,
p.color AS prioridad_color, p.orden_peso";
$stmt = $pdo->prepare(
"SELECT t.id, t.codigo, t.numero, t.estado, t.paciente_nombre,
t.recepcion_desk_id, t.creado_at, t.llamado_recepcion_at, t.llamado_lugar_at,
p.codigo AS prioridad_codigo, p.nombre AS prioridad_nombre,
p.color AS prioridad_color, p.orden_peso
FROM turnero_turnos t
JOIN turnero_prioridades p ON p.id = t.prioridad_id
WHERE t.sesion_id = ?
AND t.estado = 'en_espera_lugar'
AND t.lugar_destino_id IN ($inLugares)
ORDER BY p.orden_peso ASC, t.creado_at ASC"
"SELECT * FROM (
(SELECT $cols
FROM turnero_turnos t
JOIN turnero_prioridades p ON p.id = t.prioridad_id
WHERE t.sesion_id = ?
AND t.estado = 'en_espera_lugar'
AND t.lugar_destino_id IN ($inLugares))
UNION ALL
(SELECT $cols
FROM turnero_turnos t
JOIN turnero_prioridades p ON p.id = t.prioridad_id
WHERE t.sesion_id = ?
AND t.estado = 'en_servicio'
AND t.lugar_destino_id = ?)
) AS cola_union
ORDER BY orden_peso ASC, creado_at ASC"
);
$stmt->execute([$sesionId]);
$stmt->execute([$sesionId, $sesionId, $lugarId]);
}
$cola = $stmt->fetchAll(PDO::FETCH_ASSOC);