feat: implement tracking for medical indication changes with a new database table and management hooks

This commit is contained in:
2026-04-21 22:18:51 -03:00
parent b7d207bf01
commit e1b2e907ca
6 changed files with 216 additions and 69 deletions
+20 -1
View File
@@ -41,6 +41,7 @@ interface HospitalState {
interconsultas: Interconsulta[];
atb: ATB[];
indicaciones: Indicacion[];
movimientosIndicaciones: any[];
vistaActual: Vista;
currentInternacionId?: string | null;
}
@@ -61,6 +62,7 @@ const defaultState = (): HospitalState => ({
atb: [],
vistaActual: 'dashboard',
indicaciones: [],
movimientosIndicaciones: [],
camas: []
});
@@ -77,7 +79,9 @@ export function useHospitalStore() {
if (!res.ok) throw new Error('no state');
const body = await res.json();
if (mounted && body) {
setState(body as HospitalState);
const normalized = body as HospitalState;
normalized.movimientosIndicaciones = normalized.movimientosIndicaciones || [];
setState(normalized);
}
} catch (err) {
// no remote state or unreachable — keep defaults
@@ -428,6 +432,19 @@ const finalizarInternacion = useCallback((internacionId: string, datos: {
}));
}, []);
const agregarMovimientoIndicacion = useCallback((movimiento: any) => {
setState(prev => ({
...prev,
movimientosIndicaciones: [...(prev.movimientosIndicaciones || []), { ...movimiento, id: generateUUID() }],
}));
}, []);
const getMovimientosByInternacion = useCallback((internacionId: string) => {
return (state.movimientosIndicaciones || [])
.filter((m: any) => m.internacionId === internacionId)
.sort((a: any, b: any) => new Date(b.fecha).getTime() - new Date(a.fecha).getTime());
}, [state.movimientosIndicaciones]);
// Acciones de areas
const agregarArea = useCallback((area: Omit<Area, 'id'>) => {
const nuevaArea: Area = { ...area, id: generateUUID() };
@@ -560,6 +577,8 @@ const getEstadisticas = useCallback(() => {
agregarIndicacion,
actualizarIndicacion,
eliminarIndicacion,
agregarMovimientoIndicacion,
getMovimientosByInternacion,
agregarArea,
actualizarArea,
eliminarArea,