fix(HistoriaClinica): agregar handlers de otrosLaboratorios en store y corregir ReferenceError
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -56,6 +56,7 @@ const memStore = {
|
||||
internaciones: [],
|
||||
evoluciones: [],
|
||||
laboratorios: [],
|
||||
otrosLaboratorios: [],
|
||||
glucemias: [],
|
||||
acidosbase: [],
|
||||
cultivos: [],
|
||||
@@ -1058,3 +1059,63 @@ export async function importAllData(dump) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function getAllOtrosLaboratorios() {
|
||||
if (db) {
|
||||
const records = await db.collection('otros-laboratorios').find().toArray();
|
||||
return cleanDocs(records);
|
||||
}
|
||||
return [...memStore.otrosLaboratorios];
|
||||
}
|
||||
|
||||
export async function createOtroLaboratorio(record) {
|
||||
const doc = {
|
||||
id: record.id,
|
||||
pacienteId: record.pacienteId,
|
||||
internacionId: record.internacionId,
|
||||
fecha: record.fecha,
|
||||
hora: record.hora,
|
||||
observaciones: record.observaciones,
|
||||
createdAt: new Date().toISOString()
|
||||
};
|
||||
|
||||
if (db) {
|
||||
await db.collection('otros-laboratorios').insertOne(doc);
|
||||
return cleanDoc(doc);
|
||||
}
|
||||
|
||||
memStore.otrosLaboratorios.push(doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
export async function updateOtroLaboratorio(id, updates) {
|
||||
if (db) {
|
||||
await db.collection('otros-laboratorios').updateOne(
|
||||
{ id },
|
||||
{ $set: { ...updates, updatedAt: new Date().toISOString() } }
|
||||
);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
const idx = memStore.otrosLaboratorios.findIndex(x => x.id === id);
|
||||
if (idx !== -1) {
|
||||
memStore.otrosLaboratorios[idx] = { ...memStore.otrosLaboratorios[idx], ...updates, updatedAt: new Date().toISOString() };
|
||||
return { success: true };
|
||||
}
|
||||
return { success: false };
|
||||
}
|
||||
|
||||
export async function deleteOtroLaboratorio(id) {
|
||||
if (db) {
|
||||
await db.collection('otros-laboratorios').deleteOne({ id });
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
const idx = memStore.otrosLaboratorios.findIndex(x => x.id === id);
|
||||
if (idx !== -1) {
|
||||
memStore.otrosLaboratorios.splice(idx, 1);
|
||||
return { success: true };
|
||||
}
|
||||
return { success: false };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user