Actualizar lógica de contabilización de camas Fuera de Área según sala
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import { getNombreProfesional } from '@/lib/utils';
|
||||
import { getNombreProfesional, isCamaFueraDeArea } from '@/lib/utils';
|
||||
import type {
|
||||
Paciente,
|
||||
Cama,
|
||||
@@ -1211,11 +1211,11 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P
|
||||
}, [state.cultivos]);
|
||||
|
||||
const getEstadisticas = useCallback(() => {
|
||||
const fueraDeAreaList = state.camas.filter(c => c.areaId === 'Fuera de Area');
|
||||
const camasActivas = state.camas.filter(c => c.areaId !== 'Fuera de Area');
|
||||
const camaPrincipal = state.camas.filter(c => c.areaId !== 'Fuera de Area');
|
||||
const camaOcupadas = state.camas.filter(c => c.estado === 'Ocupada' && c.areaId !== 'Fuera de Area').length;
|
||||
const camasDisponibles = state.camas.filter(c => c.estado === 'Disponible' && c.areaId !== 'Fuera de Area').length;
|
||||
const fueraDeAreaList = state.camas.filter(c => isCamaFueraDeArea(c, state.areas));
|
||||
const camasActivas = state.camas.filter(c => !isCamaFueraDeArea(c, state.areas));
|
||||
const camaPrincipal = state.camas.filter(c => !isCamaFueraDeArea(c, state.areas));
|
||||
const camaOcupadas = state.camas.filter(c => c.estado === 'Ocupada' && !isCamaFueraDeArea(c, state.areas)).length;
|
||||
const camasDisponibles = state.camas.filter(c => c.estado === 'Disponible' && !isCamaFueraDeArea(c, state.areas)).length;
|
||||
const camasMantenimiento = state.camas.filter(c => c.estado === 'Reparacion').length;
|
||||
const internacionesActivas = state.internaciones.filter(i => i.activa).length;
|
||||
const totalPacientes = state.pacientes.length;
|
||||
|
||||
@@ -37,3 +37,40 @@ export function calcularEdad(fechaNacimiento?: string): string | number {
|
||||
}
|
||||
return edad;
|
||||
}
|
||||
|
||||
export function isCamaFueraDeArea(
|
||||
cama: { numero: string; areaId?: string },
|
||||
areas?: { id: string; nombre: string }[]
|
||||
): boolean {
|
||||
if (cama.areaId === 'Fuera de Area') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (areas && cama.areaId) {
|
||||
const area = areas.find(a => (a.nombre || '').toLowerCase().trim() === 'fuera de area');
|
||||
if (area && cama.areaId === area.id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const numero = cama.numero;
|
||||
if (!numero) return false;
|
||||
const parts = numero.trim().split('-');
|
||||
if (parts.length === 0) return false;
|
||||
const salaStr = parts[0].trim();
|
||||
const salaNum = parseInt(salaStr, 10);
|
||||
if (isNaN(salaNum)) return false;
|
||||
|
||||
// Formato 3XX que sean impares
|
||||
if (salaNum >= 300 && salaNum < 400 && salaNum % 2 !== 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Todas las 4XX (sean pares o impares)
|
||||
if (salaNum >= 400 && salaNum < 500) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Bed, CheckCircle2, Clock, Wrench, User, Plus, Trash, Edit2, Save, X } f
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { formatDateDDMMYYYY, getNombreProfesional } from '@/lib/utils';
|
||||
import { formatDateDDMMYYYY, getNombreProfesional, isCamaFueraDeArea } from '@/lib/utils';
|
||||
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
@@ -187,10 +187,10 @@ export function MapaCamas({
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge variant="outline" className="bg-green-50 text-green-700 dark:bg-green-900 dark:text-green-300 dark:border-green-700">
|
||||
{camas.filter(c => c.estado === 'Disponible').length} Disponibles
|
||||
{camas.filter(c => c.estado === 'Disponible' && !isCamaFueraDeArea(c, areas)).length} Disponibles
|
||||
</Badge>
|
||||
<Badge variant="outline" className="bg-red-50 text-red-700 dark:bg-red-900 dark:text-red-300 dark:border-red-700">
|
||||
{camas.filter(c => c.estado === 'Ocupada').length} Ocupadas
|
||||
{camas.filter(c => c.estado === 'Ocupada' && !isCamaFueraDeArea(c, areas)).length} Ocupadas
|
||||
</Badge>
|
||||
<div className="ml-4 flex items-center gap-2 flex-wrap sm:flex-nowrap">
|
||||
<Button variant="outline" onClick={() => {
|
||||
|
||||
Reference in New Issue
Block a user