turnero: sala de espera entre muestras (toma progresiva)
- DB: columna muestra_espera_at en turnero_turnos - Panel 'Esperando siguiente muestra' en la cola de lugar.php · Muestra pacientes en espera con countdown a siguiente_toma_at · Botón 'Llamar' los devuelve a la cola activa - Botón 'Mandar a espera' en la ficha (visible cuando toma progresiva activa) · Desaparece de la cola principal, queda en sección de espera - get_cola.php: excluye muestra_espera_at IS NOT NULL de cola y activo · Agrega array en_espera_muestra en la respuesta - Nuevas APIs: poner_en_espera_muestra.php, llamar_desde_espera.php Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
e634eb8932
commit
4012ae97be
@@ -83,7 +83,8 @@ if ($area === 'recepcion') {
|
||||
LEFT JOIN turnero_solicitudes s ON s.turno_id = t.id
|
||||
WHERE t.sesion_id = ?
|
||||
AND t.estado = 'en_espera_lugar'
|
||||
AND t.lugar_destino_id IN ($inLugares))
|
||||
AND t.lugar_destino_id IN ($inLugares)
|
||||
AND t.muestra_espera_at IS NULL)
|
||||
UNION ALL
|
||||
(SELECT $cols
|
||||
FROM turnero_turnos t
|
||||
@@ -91,7 +92,8 @@ if ($area === 'recepcion') {
|
||||
LEFT JOIN turnero_solicitudes s ON s.turno_id = t.id
|
||||
WHERE t.sesion_id = ?
|
||||
AND t.estado = 'en_servicio'
|
||||
AND t.lugar_destino_id = ?)
|
||||
AND t.lugar_destino_id = ?
|
||||
AND t.muestra_espera_at IS NULL)
|
||||
) AS cola_union
|
||||
ORDER BY solo_muestras DESC, orden_peso ASC, creado_at ASC"
|
||||
);
|
||||
@@ -126,7 +128,7 @@ if (!empty($cola)) {
|
||||
$campoLlamado = $area === 'recepcion' ? 'llamado_recepcion_at' : 'llamado_lugar_at';
|
||||
$estadoActivo = $area === 'recepcion' ? "'en_recepcion'" : "'en_servicio'";
|
||||
// Activo: para lugar filtrar SOLO por esta estación (ya fue asignada al llamar)
|
||||
$filtroActivo = $area === 'lugar' ? 'AND t.lugar_destino_id = ?' : '';
|
||||
$filtroActivo = $area === 'lugar' ? 'AND t.lugar_destino_id = ? AND t.muestra_espera_at IS NULL' : '';
|
||||
$bindActivo = $area === 'lugar' ? [$sesionId, $lugarId] : [$sesionId];
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
@@ -173,12 +175,33 @@ $stmt = $pdo->prepare(
|
||||
$stmt->execute([$sesionId]);
|
||||
$stats = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
// ── Pacientes en espera entre muestras (toma progresiva) ─────
|
||||
$enEsperaMuestra = [];
|
||||
if ($area === 'lugar') {
|
||||
$stmtEsp = $pdo->prepare("
|
||||
SELECT t.id, t.paciente_nombre, ts.numero_orden, t.muestra_espera_at,
|
||||
(SELECT tc.siguiente_toma_at
|
||||
FROM turnero_consentimientos tc
|
||||
JOIN lab_formularios f ON f.id = tc.formulario_id AND f.es_toma_progresiva = 1
|
||||
WHERE tc.turno_id = t.id AND tc.estado = 'en_progreso'
|
||||
ORDER BY tc.siguiente_toma_at ASC LIMIT 1) AS siguiente_toma_at
|
||||
FROM turnero_turnos t
|
||||
JOIN turnero_solicitudes ts ON ts.turno_id = t.id
|
||||
WHERE t.sesion_id = ? AND t.lugar_destino_id IN ($inLugares)
|
||||
AND t.muestra_espera_at IS NOT NULL AND t.fin_lugar_at IS NULL
|
||||
ORDER BY t.muestra_espera_at ASC
|
||||
");
|
||||
$stmtEsp->execute([$sesionId]);
|
||||
$enEsperaMuestra = $stmtEsp->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
jsonOk([
|
||||
'sesion_id' => $sesionId,
|
||||
'area' => $area,
|
||||
'lugar_id' => $lugarId,
|
||||
'activo' => $activo,
|
||||
'cola' => $cola,
|
||||
'stats' => $stats,
|
||||
'timestamp' => date('c'),
|
||||
'sesion_id' => $sesionId,
|
||||
'area' => $area,
|
||||
'lugar_id' => $lugarId,
|
||||
'activo' => $activo,
|
||||
'cola' => $cola,
|
||||
'en_espera_muestra' => $enEsperaMuestra,
|
||||
'stats' => $stats,
|
||||
'timestamp' => date('c'),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user