fix(HistoriaClinica): agregar handlers de otrosLaboratorios en store y corregir ReferenceError

This commit is contained in:
2026-08-12 22:18:27 +00:00
parent ed31b23159
commit 6fb825778f
12 changed files with 851 additions and 32 deletions
+56
View File
@@ -8,6 +8,7 @@ import { initDb,
getAllInternaciones, getInternacionById, createInternacion, updateInternacion, deleteInternacion,
getAllEvoluciones, createEvolucion, updateEvolucion, deleteEvolucion,
getAllLaboratorios, createLaboratorio, updateLaboratorio, deleteLaboratorio,
getAllOtrosLaboratorios, createOtroLaboratorio, updateOtroLaboratorio, deleteOtroLaboratorio,
getAllGlucemias, createGlucemia, updateGlucemia, deleteGlucemia,
getAllAcidosBase, createAcidoBase, updateAcidoBase, deleteAcidoBase,
getAllCultivos, createCultivo, updateCultivo, deleteCultivo,
@@ -90,6 +91,7 @@ app.get('/api/state', async (req, res) => {
examenFisico: typeof e.examenFisico === 'string' ? JSON.parse(e.examenFisico) : e.examenFisico
})),
laboratorios: (await getAllLaboratorios()).map(l => ({ ...l, resultados: typeof l.resultados === 'string' ? JSON.parse(l.resultados) : l.resultados })),
otrosLaboratorios: await getAllOtrosLaboratorios(),
glucemias: await getAllGlucemias(),
acidosBase: await getAllAcidosBase(),
cultivos: await getAllCultivos(),
@@ -412,6 +414,60 @@ app.delete('/api/laboratorios/:id', async (req, res) => {
}
});
// ========== OTROS LABORATORIOS ==========
app.get('/api/otros-laboratorios', async (req, res) => {
try {
const records = await getAllOtrosLaboratorios();
res.json(records);
} catch (error) {
console.error('Error fetching otros-laboratorios:', error);
res.status(500).json({ error: 'Failed to fetch otros-laboratorios' });
}
});
app.post('/api/otros-laboratorios', async (req, res) => {
try {
const { pacienteId, fecha, observaciones } = req.body;
if (!pacienteId || !fecha || !observaciones) {
return res.status(400).json({ error: 'pacienteId, fecha and observaciones are required' });
}
const record = {
id: generateUUID(),
...req.body
};
const newRecord = await createOtroLaboratorio(record);
res.status(201).json(newRecord);
} catch (error) {
console.error('Error creating otro laboratorio:', error);
res.status(500).json({ error: 'Failed to create otro laboratorio' });
}
});
app.put('/api/otros-laboratorios/:id', async (req, res) => {
try {
const result = await updateOtroLaboratorio(req.params.id, req.body);
if (!result.success) return res.status(404).json({ error: 'Record not found' });
res.json(result);
} catch (error) {
console.error('Error updating otro laboratorio:', error);
res.status(500).json({ error: 'Failed to update otro laboratorio' });
}
});
app.delete('/api/otros-laboratorios/:id', async (req, res) => {
try {
const result = await deleteOtroLaboratorio(req.params.id);
if (!result.success) return res.status(404).json({ error: 'Record not found' });
res.json({ message: 'Deleted successfully' });
} catch (error) {
console.error('Error deleting otro laboratorio:', error);
res.status(500).json({ error: 'Failed to delete otro laboratorio' });
}
});
// ========== GLUCEMIAS ==========
app.get('/api/glucemias', async (req, res) => {
try {