Antes solo aparecían pacientes con inicio_lugar_at IS NOT NULL (ya llamados).
Ahora incluye estado IN ('en_espera_lugar','en_servicio') para mostrar
pacientes enviados a ginecología/pediatría antes de ser llamados.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* GET get_especialidades.php?ids[]=20&ids[]=21
|
|
* Devuelve pacientes esperando en lugares de especialidad (ginecología, pediatría).
|
|
* "Esperando" = inicio_lugar_at IS NOT NULL AND fin_lugar_at IS NULL
|
|
*/
|
|
require_once __DIR__ . '/_helpers.php';
|
|
requireTurnero();
|
|
requireMethod('GET');
|
|
|
|
$pdo = db();
|
|
|
|
$ids = array_filter(array_map('intval', (array)($_GET['ids'] ?? [])));
|
|
if (!$ids) jsonOk(['grupos' => []]);
|
|
|
|
$sesionId = (int)($pdo->query(
|
|
"SELECT id FROM turnero_sesiones ORDER BY id DESC LIMIT 1"
|
|
)->fetchColumn() ?: 0);
|
|
|
|
if (!$sesionId) jsonOk(['grupos' => []]);
|
|
|
|
$in = implode(',', $ids);
|
|
$lugares = $pdo->query(
|
|
"SELECT id, nombre FROM turnero_lugares WHERE id IN ($in) AND activo=1 ORDER BY sort_order"
|
|
)->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$grupos = [];
|
|
foreach ($lugares as $l) {
|
|
$lid = (int)$l['id'];
|
|
$stmt = $pdo->prepare("
|
|
SELECT t.id, t.paciente_nombre, t.inicio_lugar_at, ts.numero_orden
|
|
FROM turnero_turnos t
|
|
JOIN turnero_solicitudes ts ON ts.turno_id = t.id
|
|
WHERE t.sesion_id = ? AND t.lugar_destino_id = ?
|
|
AND t.estado IN ('en_espera_lugar','en_servicio') AND t.fin_lugar_at IS NULL
|
|
ORDER BY ts.numero_orden ASC
|
|
");
|
|
$stmt->execute([$sesionId, $lid]);
|
|
$grupos[] = [
|
|
'lugar_id' => $lid,
|
|
'lugar_nombre' => $l['nombre'],
|
|
'pacientes' => $stmt->fetchAll(PDO::FETCH_ASSOC),
|
|
];
|
|
}
|
|
|
|
jsonOk(['grupos' => $grupos]);
|