const fs = require('fs'); let code = fs.readFileSync('src/hooks/useHospitalStore.ts', 'utf8'); // add import code = code.replace("Laboratorio, ", "Laboratorio, OtroLaboratorio, "); // add state array code = code.replace("laboratorios: Laboratorio[];", "laboratorios: Laboratorio[];\n otrosLaboratorios: OtroLaboratorio[];"); // add actions const actionsRegex = /eliminarLaboratorio: \(id: string\) => Promise;/; code = code.replace(actionsRegex, "eliminarLaboratorio: (id: string) => Promise;\n agregarOtroLaboratorio: (laboratorio: Omit) => Promise;\n actualizarOtroLaboratorio: (id: string, datos: Partial) => Promise;\n eliminarOtroLaboratorio: (id: string) => Promise;"); // add initial state code = code.replace("laboratorios: [],", "laboratorios: [],\n otrosLaboratorios: [],"); // fetch action (loadState) code = code.replace("laboratorios: data.laboratorios || [],", "laboratorios: data.laboratorios || [],\n otrosLaboratorios: data.otrosLaboratorios || [],"); // methods const methodsString = ` eliminarLaboratorio: async (id) => { try { await api.delete(\`/laboratorios/\${id}\`); set((state) => ({ laboratorios: state.laboratorios.filter((l) => l.id !== id), })); } catch (error) { console.error('Error deleting laboratorio:', error); throw error; } }, agregarOtroLaboratorio: async (laboratorio) => { try { const response = await api.post('/otros-laboratorios', laboratorio); set((state) => ({ otrosLaboratorios: [...state.otrosLaboratorios, response.data], })); } catch (error) { console.error('Error adding otro laboratorio:', error); throw error; } }, actualizarOtroLaboratorio: async (id, datos) => { try { await api.put(\`/otros-laboratorios/\${id}\`, datos); set((state) => ({ otrosLaboratorios: state.otrosLaboratorios.map((l) => l.id === id ? { ...l, ...datos } : l ), })); } catch (error) { console.error('Error updating otro laboratorio:', error); throw error; } }, eliminarOtroLaboratorio: async (id) => { try { await api.delete(\`/otros-laboratorios/\${id}\`); set((state) => ({ otrosLaboratorios: state.otrosLaboratorios.filter((l) => l.id !== id), })); } catch (error) { console.error('Error deleting otro laboratorio:', error); throw error; } }, `; const replaceMethods = ` eliminarLaboratorio: async (id) => { try { await api.delete(\`/laboratorios/\${id}\`); set((state) => ({ laboratorios: state.laboratorios.filter((l) => l.id !== id), })); } catch (error) { console.error('Error deleting laboratorio:', error); throw error; } }, `; code = code.replace(replaceMethods.trim(), methodsString.trim()); fs.writeFileSync('src/hooks/useHospitalStore.ts', code);