Agregar tab de pendientes, categoria procedimiento y fecha/hora programada
This commit is contained in:
@@ -16,6 +16,7 @@ import type {
|
||||
ATB,
|
||||
Indicacion,
|
||||
MovimientoIndicacion,
|
||||
Pendiente,
|
||||
Vista,
|
||||
Usuario
|
||||
} from '@/types';
|
||||
@@ -48,6 +49,7 @@ interface HospitalState {
|
||||
atb: ATB[];
|
||||
indicaciones: Indicacion[];
|
||||
movimientosIndicaciones: MovimientoIndicacion[];
|
||||
pendientes: Pendiente[];
|
||||
vistaActual: Vista;
|
||||
currentInternacionId?: string | null;
|
||||
usuarios: Usuario[];
|
||||
@@ -73,6 +75,7 @@ const defaultState = (): HospitalState => ({
|
||||
vistaActual: 'dashboard',
|
||||
indicaciones: [],
|
||||
movimientosIndicaciones: [],
|
||||
pendientes: [],
|
||||
camas: [],
|
||||
usuarios: [],
|
||||
currentUser: null,
|
||||
@@ -104,6 +107,7 @@ export function useHospitalStore() {
|
||||
atb: body.atb || [],
|
||||
glucemias: body.glucemias || [],
|
||||
movimientosIndicaciones: body.movimientosIndicaciones || [],
|
||||
pendientes: body.pendientes || [],
|
||||
currentInternacionId: storedInternacionId || body.currentInternacionId || null,
|
||||
currentUser,
|
||||
isAuthenticated: !!currentUser,
|
||||
@@ -1293,6 +1297,60 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P
|
||||
.sort((a, b) => new Date(b.fechaToma).getTime() - new Date(a.fechaToma).getTime());
|
||||
}, [state.cultivos]);
|
||||
|
||||
const agregarPendiente = useCallback(async (datos: Omit<Pendiente, 'id'>) => {
|
||||
const nuevoPendiente: Pendiente = {
|
||||
...datos,
|
||||
id: generateUUID(),
|
||||
fechaCreacion: datos.fechaCreacion || new Date().toISOString().split('T')[0],
|
||||
horaCreacion: datos.horaCreacion || new Date().toTimeString().slice(0, 5),
|
||||
estado: datos.estado || 'pendiente',
|
||||
prioridad: datos.prioridad || 'media',
|
||||
};
|
||||
try {
|
||||
await apiCall('POST', '/pendientes', nuevoPendiente);
|
||||
setState(prev => ({
|
||||
...prev,
|
||||
pendientes: [...(prev.pendientes || []), nuevoPendiente],
|
||||
}));
|
||||
return nuevoPendiente.id;
|
||||
} catch (err) {
|
||||
console.error('Error al agregar pendiente:', err);
|
||||
throw err;
|
||||
}
|
||||
}, [apiCall]);
|
||||
|
||||
const actualizarPendiente = useCallback(async (id: string, datos: Partial<Pendiente>) => {
|
||||
try {
|
||||
await apiCall('PUT', `/pendientes/${id}`, datos);
|
||||
setState(prev => ({
|
||||
...prev,
|
||||
pendientes: (prev.pendientes || []).map(p => p.id === id ? { ...p, ...datos } : p),
|
||||
}));
|
||||
} catch (err) {
|
||||
console.error('Error al actualizar pendiente:', err);
|
||||
throw err;
|
||||
}
|
||||
}, [apiCall]);
|
||||
|
||||
const eliminarPendiente = useCallback(async (id: string) => {
|
||||
try {
|
||||
await apiCall('DELETE', `/pendientes/${id}`);
|
||||
setState(prev => ({
|
||||
...prev,
|
||||
pendientes: (prev.pendientes || []).filter(p => p.id !== id),
|
||||
}));
|
||||
} catch (err) {
|
||||
console.error('Error al eliminar pendiente:', err);
|
||||
throw err;
|
||||
}
|
||||
}, [apiCall]);
|
||||
|
||||
const getPendientesByPaciente = useCallback((pacienteId: string) => {
|
||||
return (state.pendientes || [])
|
||||
.filter(p => p.pacienteId === pacienteId)
|
||||
.sort((a, b) => new Date(`${b.fechaCreacion}T${b.horaCreacion || '00:00'}`).getTime() - new Date(`${a.fechaCreacion}T${a.horaCreacion || '00:00'}`).getTime());
|
||||
}, [state.pendientes]);
|
||||
|
||||
const getEstadisticas = useCallback(() => {
|
||||
const camasEnArea = state.camas.filter(c => !isCamaFueraDeGrupo(c));
|
||||
const camasFueraDeArea = state.camas.filter(c => isCamaFueraDeGrupo(c));
|
||||
@@ -1434,6 +1492,10 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P
|
||||
getGlucemiasByInternacion,
|
||||
getAcidosBaseByInternacion,
|
||||
getCultivosByInternacion,
|
||||
agregarPendiente,
|
||||
actualizarPendiente,
|
||||
eliminarPendiente,
|
||||
getPendientesByPaciente,
|
||||
setCurrentInternacion,
|
||||
getEstadisticas,
|
||||
login,
|
||||
|
||||
Reference in New Issue
Block a user