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) => { 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) => { 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);