diff --git a/src/sections/Internaciones.tsx b/src/sections/Internaciones.tsx index e6f6797..38c8ae4 100644 --- a/src/sections/Internaciones.tsx +++ b/src/sections/Internaciones.tsx @@ -137,6 +137,14 @@ export function Internaciones({ } }; + const sortedCamas = sortCamas(camas); + + const getCamaIndex = (camaId?: string) => { + if (!camaId) return 999999; + const index = sortedCamas.findIndex(c => c.id === camaId); + return index !== -1 ? index : 999999; + }; + const internacionesFiltradas = internaciones.filter(i => { const paciente = getPacienteById(i.pacienteId); const cumpleBusqueda = !busqueda || @@ -151,15 +159,20 @@ export function Internaciones({ (filtroEstado === 'finalizadas' && !i.activa); return cumpleBusqueda && cumpleEstado; - }).sort((a, b) => new Date(b.fechaIngresoClinica || '').getTime() - new Date(a.fechaIngresoClinica || '').getTime()); + }).sort((a, b) => { + const indexA = getCamaIndex(a.camaId); + const indexB = getCamaIndex(b.camaId); + if (indexA !== indexB) { + return indexA - indexB; + } + return new Date(b.fechaIngresoClinica || '').getTime() - new Date(a.fechaIngresoClinica || '').getTime(); + }); const pacientesSinInternar = pacientes.filter(p => { const internacionActiva = internaciones.find(i => i.pacienteId === p.id && i.activa); return !internacionActiva; }); - const sortedCamas = sortCamas(camas); - const getGrupoName = (grupoId?: string) => grupos.find(a => a.id === grupoId)?.nombre; const calcularEdad = (fechaNacimiento?: string) => {