From 796ff5737e3a183d481bb51a22db7dede83d096d Mon Sep 17 00:00:00 2001 From: AI Studio Date: Thu, 13 Aug 2026 04:01:31 +0000 Subject: [PATCH] Solucionar rutas API de otros laboratorios, ajuste de servidor y modal de confirmacion para eliminar registros --- server/api-mongodb.js | 7 +-- src/hooks/useHospitalStore.ts | 6 +-- src/sections/HistoriaClinica.tsx | 75 ++++++++++++++++++++++++-------- 3 files changed, 63 insertions(+), 25 deletions(-) diff --git a/server/api-mongodb.js b/server/api-mongodb.js index 8ad1dc3..4d77b64 100644 --- a/server/api-mongodb.js +++ b/server/api-mongodb.js @@ -428,13 +428,14 @@ app.get('/api/otros-laboratorios', async (req, res) => { 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 { pacienteId, fecha } = req.body; + if (!pacienteId || !fecha) { + return res.status(400).json({ error: 'pacienteId and fecha are required' }); } const record = { id: generateUUID(), + observaciones: '', ...req.body }; diff --git a/src/hooks/useHospitalStore.ts b/src/hooks/useHospitalStore.ts index 8898a99..88c3bed 100644 --- a/src/hooks/useHospitalStore.ts +++ b/src/hooks/useHospitalStore.ts @@ -753,7 +753,7 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P id: generateUUID(), }; try { - await apiCall('POST', '/api/otros-laboratorios', nuevo); + await apiCall('POST', '/otros-laboratorios', nuevo); setState(prev => ({ ...prev, otrosLaboratorios: [...prev.otrosLaboratorios, nuevo], @@ -767,7 +767,7 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P const eliminarOtroLaboratorio = useCallback(async (id: string) => { try { - await apiCall('DELETE', `/api/otros-laboratorios/${id}`); + await apiCall('DELETE', `/otros-laboratorios/${id}`); setState(prev => ({ ...prev, otrosLaboratorios: prev.otrosLaboratorios.filter(o => o.id !== id), @@ -780,7 +780,7 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P const actualizarOtroLaboratorio = useCallback(async (id: string, datos: Partial) => { try { - await apiCall('PUT', `/api/otros-laboratorios/${id}`, datos); + await apiCall('PUT', `/otros-laboratorios/${id}`, datos); setState(prev => ({ ...prev, otrosLaboratorios: prev.otrosLaboratorios.map(o => o.id === id ? { ...o, ...datos } : o), diff --git a/src/sections/HistoriaClinica.tsx b/src/sections/HistoriaClinica.tsx index 9e8c71e..2003034 100644 --- a/src/sections/HistoriaClinica.tsx +++ b/src/sections/HistoriaClinica.tsx @@ -1110,19 +1110,33 @@ function SeccionLaboratorios({ lab, otrosLaboratorios = [], patientId, internaci setEditOtrosItem(null); }; + const [deleteOtrosDialog, setDeleteOtrosDialog] = useState(false); + const [itemToDeleteOtros, setItemToDeleteOtros] = useState<{ id: string; source: 'lab' | 'otros' } | null>(null); + const handleDeleteOtros = (item: { id: string; source: 'lab' | 'otros' }) => { - if (window.confirm('¿Está seguro de que desea eliminar este registro?')) { - if (item.source === 'otros') { + setItemToDeleteOtros(item); + setDeleteOtrosDialog(true); + }; + + const handleConfirmDeleteOtros = async () => { + if (!itemToDeleteOtros) return; + try { + if (itemToDeleteOtros.source === 'otros') { if (delOtroLaboratorio) { - delOtroLaboratorio(item.id); + await delOtroLaboratorio(itemToDeleteOtros.id); toast.success('Registro eliminado'); } - } else if (item.source === 'lab') { + } else if (itemToDeleteOtros.source === 'lab') { if (update) { - update(item.id, { observaciones: '' }); + await update(itemToDeleteOtros.id, { observaciones: '' }); toast.success('Observación de laboratorio eliminada'); } } + } catch { + toast.error('Error al eliminar el registro'); + } finally { + setDeleteOtrosDialog(false); + setItemToDeleteOtros(null); } }; @@ -1911,21 +1925,25 @@ function SeccionLaboratorios({ lab, otrosLaboratorios = [], patientId, internaci - + + + + +