fix(HistoriaClinica): agregar handlers de otrosLaboratorios en store y corregir ReferenceError
This commit is contained in:
@@ -7,7 +7,7 @@ import type {
|
||||
Grupo,
|
||||
Internacion,
|
||||
Evolucion,
|
||||
Laboratorio,
|
||||
Laboratorio, OtroLaboratorio,
|
||||
Glucemia,
|
||||
AcidoBase,
|
||||
Cultivo,
|
||||
@@ -41,6 +41,7 @@ interface HospitalState {
|
||||
internaciones: Internacion[];
|
||||
evoluciones: Evolucion[];
|
||||
laboratorios: Laboratorio[];
|
||||
otrosLaboratorios: OtroLaboratorio[];
|
||||
glucemias: Glucemia[];
|
||||
acidosBase: AcidoBase[];
|
||||
cultivos: Cultivo[];
|
||||
@@ -66,6 +67,7 @@ const defaultState = (): HospitalState => ({
|
||||
internaciones: [],
|
||||
evoluciones: [],
|
||||
laboratorios: [],
|
||||
otrosLaboratorios: [],
|
||||
glucemias: [],
|
||||
acidosBase: [],
|
||||
cultivos: [],
|
||||
@@ -744,6 +746,51 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P
|
||||
}
|
||||
}, [state, checkGrupoPermission, apiCall]);
|
||||
|
||||
// Acciones de otros laboratorios
|
||||
const agregarOtroLaboratorio = useCallback(async (otroLaboratorio: Omit<OtroLaboratorio, 'id'>) => {
|
||||
const nuevo: OtroLaboratorio = {
|
||||
...otroLaboratorio,
|
||||
id: generateUUID(),
|
||||
};
|
||||
try {
|
||||
await apiCall('POST', '/api/otros-laboratorios', nuevo);
|
||||
setState(prev => ({
|
||||
...prev,
|
||||
otrosLaboratorios: [...prev.otrosLaboratorios, nuevo],
|
||||
}));
|
||||
return nuevo.id;
|
||||
} catch (err) {
|
||||
console.error('Error al agregar otro laboratorio:', err);
|
||||
throw err;
|
||||
}
|
||||
}, [apiCall]);
|
||||
|
||||
const eliminarOtroLaboratorio = useCallback(async (id: string) => {
|
||||
try {
|
||||
await apiCall('DELETE', `/api/otros-laboratorios/${id}`);
|
||||
setState(prev => ({
|
||||
...prev,
|
||||
otrosLaboratorios: prev.otrosLaboratorios.filter(o => o.id !== id),
|
||||
}));
|
||||
} catch (err) {
|
||||
console.error('Error al eliminar otro laboratorio:', err);
|
||||
throw err;
|
||||
}
|
||||
}, [apiCall]);
|
||||
|
||||
const actualizarOtroLaboratorio = useCallback(async (id: string, datos: Partial<OtroLaboratorio>) => {
|
||||
try {
|
||||
await apiCall('PUT', `/api/otros-laboratorios/${id}`, datos);
|
||||
setState(prev => ({
|
||||
...prev,
|
||||
otrosLaboratorios: prev.otrosLaboratorios.map(o => o.id === id ? { ...o, ...datos } : o),
|
||||
}));
|
||||
} catch (err) {
|
||||
console.error('Error al actualizar otro laboratorio:', err);
|
||||
throw err;
|
||||
}
|
||||
}, [apiCall]);
|
||||
|
||||
// Acciones de glucemias
|
||||
const agregarGlucemia = useCallback(async (glucemia: Omit<Glucemia, 'id'>) => {
|
||||
const internacion = state.internaciones.find(i => i.id === glucemia.internacionId);
|
||||
@@ -1522,6 +1569,9 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P
|
||||
agregarLaboratorio,
|
||||
actualizarLaboratorio,
|
||||
eliminarLaboratorio,
|
||||
agregarOtroLaboratorio,
|
||||
actualizarOtroLaboratorio,
|
||||
eliminarOtroLaboratorio,
|
||||
agregarGlucemia,
|
||||
actualizarGlucemia,
|
||||
eliminarGlucemia,
|
||||
|
||||
Reference in New Issue
Block a user