up
This commit is contained in:
@@ -12,33 +12,86 @@ requireMethod('GET');
|
||||
$pdo = db();
|
||||
$sesionId = obtenerOCrearSesionHoy();
|
||||
|
||||
// ── 1. TODOS los turnos activos en Recepción ─────────────────
|
||||
// Puede haber varios simultáneos (un escritorio por operador).
|
||||
$stmtRec = $pdo->prepare(
|
||||
"SELECT t.id,
|
||||
t.codigo,
|
||||
t.numero,
|
||||
t.estado,
|
||||
t.paciente_nombre,
|
||||
t.llamado_recepcion_at AS llamado_at,
|
||||
t.atendido_recepcion_por,
|
||||
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.sesion_id = ?
|
||||
AND t.estado = 'en_recepcion'
|
||||
ORDER BY t.llamado_recepcion_at DESC"
|
||||
// ── 1. Escritorios de Recepción activos + su turno en_recepcion ─
|
||||
// Cada escritorio puede tener un turno distinto (varios recepcionistas).
|
||||
$stmtDesks = $pdo->query(
|
||||
"SELECT id, nombre, sort_order
|
||||
FROM turnero_lugares
|
||||
WHERE activo = 1 AND tipo = 'recepcion'
|
||||
ORDER BY sort_order ASC"
|
||||
);
|
||||
$stmtRec->execute([$sesionId]);
|
||||
$activosRecepcion = $stmtRec->fetchAll(PDO::FETCH_ASSOC);
|
||||
$escritoriosRec = $stmtDesks->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// ── 2. Lugares activos con su turno en servicio ───────────────
|
||||
$activosRecepcion = [];
|
||||
foreach ($escritoriosRec as $desk) {
|
||||
// El turno activo de este escritorio: el más reciente asociado a él
|
||||
$stmtT = $pdo->prepare(
|
||||
"SELECT t.id,
|
||||
t.codigo,
|
||||
t.numero,
|
||||
t.estado,
|
||||
t.paciente_nombre,
|
||||
t.llamado_recepcion_at AS llamado_at,
|
||||
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.sesion_id = ?
|
||||
AND t.estado = 'en_recepcion'
|
||||
AND (t.recepcion_desk_id = ? OR t.recepcion_desk_id IS NULL)
|
||||
ORDER BY t.llamado_recepcion_at DESC
|
||||
LIMIT 1"
|
||||
);
|
||||
$stmtT->execute([$sesionId, (int)$desk['id']]);
|
||||
$turno = $stmtT->fetch(PDO::FETCH_ASSOC) ?: null;
|
||||
|
||||
$activosRecepcion[] = [
|
||||
'desk_id' => (int)$desk['id'],
|
||||
'desk_nombre'=> $desk['nombre'],
|
||||
'sort_order' => (int)$desk['sort_order'],
|
||||
'turno' => $turno,
|
||||
];
|
||||
}
|
||||
|
||||
// Si no hay escritorios configurados, mostrar todos en_recepcion sin desk
|
||||
if (empty($escritoriosRec)) {
|
||||
$stmtRec = $pdo->prepare(
|
||||
"SELECT t.id,
|
||||
t.codigo,
|
||||
t.numero,
|
||||
t.estado,
|
||||
t.paciente_nombre,
|
||||
t.llamado_recepcion_at AS llamado_at,
|
||||
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.sesion_id = ?
|
||||
AND t.estado = 'en_recepcion'
|
||||
ORDER BY t.llamado_recepcion_at DESC"
|
||||
);
|
||||
$stmtRec->execute([$sesionId]);
|
||||
foreach ($stmtRec->fetchAll(PDO::FETCH_ASSOC) as $i => $t) {
|
||||
$activosRecepcion[] = [
|
||||
'desk_id' => 0,
|
||||
'desk_nombre'=> 'Recepción ' . ($i + 1),
|
||||
'sort_order' => $i,
|
||||
'turno' => $t,
|
||||
];
|
||||
}
|
||||
// Si no hay ninguno activo, mostrar un panel vacío
|
||||
if (empty($activosRecepcion)) {
|
||||
$activosRecepcion[] = ['desk_id' => 0, 'desk_nombre' => 'Recepción', 'sort_order' => 0, 'turno' => null];
|
||||
}
|
||||
}
|
||||
|
||||
// ── 2. Estaciones de Muestras activas + su turno ─────────────
|
||||
$stmtLugares = $pdo->query(
|
||||
"SELECT id, nombre, sort_order
|
||||
FROM turnero_lugares
|
||||
WHERE activo = 1
|
||||
WHERE activo = 1 AND (tipo = 'muestras' OR tipo IS NULL)
|
||||
ORDER BY sort_order ASC"
|
||||
);
|
||||
$lugares = $stmtLugares->fetchAll(PDO::FETCH_ASSOC);
|
||||
@@ -122,8 +175,8 @@ $stats = $stmtStats->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
jsonOk([
|
||||
'sesion_id' => $sesionId,
|
||||
'activos_recepcion'=> $activosRecepcion, // array — todos los en_recepcion
|
||||
'lugares' => $lugaresActivos,
|
||||
'activos_recepcion'=> $activosRecepcion, // array de desks con su turno
|
||||
'lugares' => $lugaresActivos, // array de estaciones de muestras
|
||||
'cola' => $cola,
|
||||
'stats' => $stats,
|
||||
'timestamp' => date('c'),
|
||||
|
||||
Reference in New Issue
Block a user