fix(HistoriaClinica): agregar handlers de otrosLaboratorios en store y corregir ReferenceError
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
const fs = require('fs');
|
||||
let code = fs.readFileSync('src/hooks/useHospitalStore.ts', 'utf8');
|
||||
|
||||
const regexLab = /const eliminarLaboratorio = useCallback\(async \(id: string\) => \{[\s\S]*?\}\, \[state\.laboratorios\, apiCall\]\);/;
|
||||
|
||||
const addMethods = `
|
||||
const agregarOtroLaboratorio = useCallback(async (otroLaboratorio: Omit<OtroLaboratorio, 'id'>) => {
|
||||
try {
|
||||
const { data } = await apiCall('POST', '/api/otros-laboratorios', otroLaboratorio);
|
||||
if (data) {
|
||||
setState(prev => ({ ...prev, otrosLaboratorios: [...prev.otrosLaboratorios, data] }));
|
||||
return data.id;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error adding otro laboratorio', err);
|
||||
throw err;
|
||||
}
|
||||
return null;
|
||||
}, [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 updating 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 deleting otro laboratorio', err);
|
||||
throw err;
|
||||
}
|
||||
}, [apiCall]);
|
||||
`;
|
||||
|
||||
code = code.replace(regexLab, match => match + "\n\n" + addMethods);
|
||||
|
||||
const returnObjRegex = /return \{[\s\S]*?isLoaded,\s*\};/;
|
||||
const match = code.match(returnObjRegex);
|
||||
if (match) {
|
||||
let newReturn = match[0].replace(
|
||||
"eliminarLaboratorio,",
|
||||
"eliminarLaboratorio,\n agregarOtroLaboratorio,\n actualizarOtroLaboratorio,\n eliminarOtroLaboratorio,"
|
||||
);
|
||||
code = code.replace(match[0], newReturn);
|
||||
}
|
||||
|
||||
fs.writeFileSync('src/hooks/useHospitalStore.ts', code);
|
||||
Reference in New Issue
Block a user