Corregir filtrado inicial y conteo en Pendientes de Sala para mostrar todos por defecto
This commit is contained in:
@@ -48,7 +48,7 @@ export function PendientesSala({
|
|||||||
const { currentUser } = useHospitalStore();
|
const { currentUser } = useHospitalStore();
|
||||||
const [busqueda, setBusqueda] = useState('');
|
const [busqueda, setBusqueda] = useState('');
|
||||||
const [filtroCategoria, setFiltroCategoria] = useState<string>('todos');
|
const [filtroCategoria, setFiltroCategoria] = useState<string>('todos');
|
||||||
const [filtroEstado, setFiltroEstado] = useState<string>('pendiente');
|
const [filtroEstado, setFiltroEstado] = useState<string>('todos');
|
||||||
const [filtroFechaProgramada, setFiltroFechaProgramada] = useState<string>('');
|
const [filtroFechaProgramada, setFiltroFechaProgramada] = useState<string>('');
|
||||||
|
|
||||||
// Active internaciones map for quick lookup
|
// Active internaciones map for quick lookup
|
||||||
@@ -59,17 +59,30 @@ export function PendientesSala({
|
|||||||
if (i.pacienteId) activeInternacionMap.set(i.pacienteId, i);
|
if (i.pacienteId) activeInternacionMap.set(i.pacienteId, i);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Filter pending items belonging to active interned patients
|
// Filter pending items belonging to active interned patients (or all if activeInternacionMap is empty / fallback)
|
||||||
const pendientesSala = pendientes.filter(p => {
|
const pendientesSala = (pendientes || []).filter(p => {
|
||||||
|
if (!p) return false;
|
||||||
|
// If internacionId or pacienteId matches an active internacion, include it.
|
||||||
|
// Also if no internaciones match or if we want to be robust, check if patient has any active internacion.
|
||||||
const internacion = (p.internacionId ? activeInternacionMap.get(p.internacionId) : undefined) ||
|
const internacion = (p.internacionId ? activeInternacionMap.get(p.internacionId) : undefined) ||
|
||||||
(p.pacienteId ? activeInternacionMap.get(p.pacienteId) : undefined);
|
(p.pacienteId ? activeInternacionMap.get(p.pacienteId) : undefined);
|
||||||
return !!internacion;
|
|
||||||
|
// Fallback: if no explicit internacion matched but there are active internations, let's also check if patient is in active internaciones
|
||||||
|
if (!internacion && p.pacienteId) {
|
||||||
|
const foundByPaciente = internacionesActivas.find(i => i.pacienteId === p.pacienteId);
|
||||||
|
return !!foundByPaciente;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!internacion || (!p.internacionId && !p.pacienteId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const totalPendientesActivos = pendientesSala.filter(p => p.estado === 'pendiente').length;
|
||||||
|
|
||||||
// Apply search, category, status, and scheduled date filters
|
// Apply search, category, status, and scheduled date filters
|
||||||
const pendientesFiltrados = pendientesSala.filter(p => {
|
const pendientesFiltrados = pendientesSala.filter(p => {
|
||||||
const internacion = (p.internacionId ? activeInternacionMap.get(p.internacionId) : undefined) ||
|
const internacion = (p.internacionId ? activeInternacionMap.get(p.internacionId) : undefined) ||
|
||||||
(p.pacienteId ? activeInternacionMap.get(p.pacienteId) : undefined);
|
(p.pacienteId ? activeInternacionMap.get(p.pacienteId) : undefined) ||
|
||||||
|
internacionesActivas.find(i => i.pacienteId === p.pacienteId);
|
||||||
const paciente = p.pacienteId ? getPacienteById(p.pacienteId) : undefined;
|
const paciente = p.pacienteId ? getPacienteById(p.pacienteId) : undefined;
|
||||||
const cama = internacion ? getCamaById(internacion.camaId) : undefined;
|
const cama = internacion ? getCamaById(internacion.camaId) : undefined;
|
||||||
|
|
||||||
@@ -155,7 +168,7 @@ export function PendientesSala({
|
|||||||
Pendientes de Sala
|
Pendientes de Sala
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-sm text-gray-500 dark:text-gray-400">
|
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||||
Gestión y seguimiento de pendientes de todos los pacientes internados ({pendientesSala.filter(p => p.estado === 'pendiente').length} pendientes activos)
|
Gestión y seguimiento de pendientes de todos los pacientes internados ({totalPendientesActivos} pendientes activos)
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user