diff --git a/modules/turnero/api/get_bandeja.php b/modules/turnero/api/get_bandeja.php index 66c5756..3136213 100644 --- a/modules/turnero/api/get_bandeja.php +++ b/modules/turnero/api/get_bandeja.php @@ -91,6 +91,17 @@ if (isset($_GET['turno_id'])) { } // ── LISTA ───────────────────────────────────────────────────── +$desde = $_GET['desde'] ?? null; +$hasta = $_GET['hasta'] ?? null; + +if ($desde && $hasta) { + $whereClause = "DATE(t.inicio_lugar_at) BETWEEN ? AND ?"; + $params = [$desde, $hasta]; +} else { + $whereClause = "t.sesion_id = ?"; + $params = [$sesionId]; +} + $stmt = $pdo->prepare(" SELECT t.id, t.codigo, t.paciente_nombre, t.estado, t.inicio_lugar_at, t.fin_lugar_at, t.bandeja_visto_at, @@ -107,24 +118,17 @@ $stmt = $pdo->prepare(" LEFT JOIN turnero_examen_items tei ON tei.solicitud_id = ts.id LEFT JOIN exam_tipos et ON et.id = tei.exam_tipo_id LEFT JOIN turnero_comentarios tc ON tc.turno_id = t.id - WHERE t.sesion_id = ? AND t.inicio_lugar_at IS NOT NULL + WHERE $whereClause AND t.inicio_lugar_at IS NOT NULL GROUP BY t.id ORDER BY ts.numero_orden ASC "); -$stmt->execute([$sesionId]); +$stmt->execute($params); $todos = $stmt->fetchAll(PDO::FETCH_ASSOC); $pendientes = array_values(array_filter($todos, fn($t) => $t['bandeja_visto_at'] === null)); $vistos = array_values(array_filter($todos, fn($t) => $t['bandeja_visto_at'] !== null)); -$stmtMp = $pdo->prepare(" - SELECT COUNT(*) FROM turnero_muestras tm - JOIN turnero_solicitudes ts ON ts.id = tm.solicitud_id - JOIN turnero_turnos t ON t.id = ts.turno_id - WHERE t.sesion_id = ? AND tm.estado = 'pendiente' -"); -$stmtMp->execute([$sesionId]); -$muestrasPendientes = (int)$stmtMp->fetchColumn(); +$muestrasPendientes = array_sum(array_column($todos, 'muestras_pendientes')); jsonOk([ 'pendientes' => $pendientes, diff --git a/modules/turnero/views/bandeja.php b/modules/turnero/views/bandeja.php index eec0bc6..8e7a984 100644 --- a/modules/turnero/views/bandeja.php +++ b/modules/turnero/views/bandeja.php @@ -352,11 +352,13 @@ Layout::open('Bandeja del día', 'fas fa-layer-group');
- Bandeja del día + Bandeja Por revisar: — Vistos: — Muestras pend.: — + + +
Cargando...
@@ -436,7 +438,10 @@ async function _bndRefrescarLista() { spin.style.transform = 'rotate(360deg)'; setTimeout(()=>{ spin.style.transition=''; spin.style.transform=''; }, 400); - const res = await fetch(BND_API).then(r=>r.json()).catch(()=>null); + const desde = document.getElementById('bnd-desde')?.value || ''; + const hasta = document.getElementById('bnd-hasta')?.value || ''; + const qs = (desde && hasta) ? `?desde=${desde}&hasta=${hasta}` : ''; + const res = await fetch(BND_API + qs).then(r=>r.json()).catch(()=>null); if (!res?.ok) return; _bndAllData = res; @@ -453,7 +458,7 @@ function _bndFiltrar() { const q = (document.getElementById('bnd-filtro')?.value || '').toLowerCase().trim(); const st = document.getElementById('bnd-filtro-estado')?.value || ''; const match = t => - (!q || (t.paciente_nombre || '').toLowerCase().includes(q) || (t.examenes_txt || '').toLowerCase().includes(q)) && + (!q || (t.paciente_nombre || '').toLowerCase().includes(q) || (t.examenes_txt || '').toLowerCase().includes(q) || String(t.numero_orden || '').includes(q) || (t.codigo || '').toLowerCase().includes(q)) && (!st || (st === 'muestras_pendientes' ? +t.muestras_pendientes > 0 : t.estado === st)); _renderLista(