Solucionar rutas API de otros laboratorios, ajuste de servidor y modal de confirmacion para eliminar registros

This commit is contained in:
2026-08-13 04:01:31 +00:00
parent 652bd363b7
commit 796ff5737e
3 changed files with 63 additions and 25 deletions
+4 -3
View File
@@ -428,13 +428,14 @@ app.get('/api/otros-laboratorios', async (req, res) => {
app.post('/api/otros-laboratorios', async (req, res) => { app.post('/api/otros-laboratorios', async (req, res) => {
try { try {
const { pacienteId, fecha, observaciones } = req.body; const { pacienteId, fecha } = req.body;
if (!pacienteId || !fecha || !observaciones) { if (!pacienteId || !fecha) {
return res.status(400).json({ error: 'pacienteId, fecha and observaciones are required' }); return res.status(400).json({ error: 'pacienteId and fecha are required' });
} }
const record = { const record = {
id: generateUUID(), id: generateUUID(),
observaciones: '',
...req.body ...req.body
}; };
+3 -3
View File
@@ -753,7 +753,7 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P
id: generateUUID(), id: generateUUID(),
}; };
try { try {
await apiCall('POST', '/api/otros-laboratorios', nuevo); await apiCall('POST', '/otros-laboratorios', nuevo);
setState(prev => ({ setState(prev => ({
...prev, ...prev,
otrosLaboratorios: [...prev.otrosLaboratorios, nuevo], otrosLaboratorios: [...prev.otrosLaboratorios, nuevo],
@@ -767,7 +767,7 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P
const eliminarOtroLaboratorio = useCallback(async (id: string) => { const eliminarOtroLaboratorio = useCallback(async (id: string) => {
try { try {
await apiCall('DELETE', `/api/otros-laboratorios/${id}`); await apiCall('DELETE', `/otros-laboratorios/${id}`);
setState(prev => ({ setState(prev => ({
...prev, ...prev,
otrosLaboratorios: prev.otrosLaboratorios.filter(o => o.id !== id), 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<OtroLaboratorio>) => { const actualizarOtroLaboratorio = useCallback(async (id: string, datos: Partial<OtroLaboratorio>) => {
try { try {
await apiCall('PUT', `/api/otros-laboratorios/${id}`, datos); await apiCall('PUT', `/otros-laboratorios/${id}`, datos);
setState(prev => ({ setState(prev => ({
...prev, ...prev,
otrosLaboratorios: prev.otrosLaboratorios.map(o => o.id === id ? { ...o, ...datos } : o), otrosLaboratorios: prev.otrosLaboratorios.map(o => o.id === id ? { ...o, ...datos } : o),
+56 -19
View File
@@ -1110,19 +1110,33 @@ function SeccionLaboratorios({ lab, otrosLaboratorios = [], patientId, internaci
setEditOtrosItem(null); 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' }) => { const handleDeleteOtros = (item: { id: string; source: 'lab' | 'otros' }) => {
if (window.confirm('¿Está seguro de que desea eliminar este registro?')) { setItemToDeleteOtros(item);
if (item.source === 'otros') { setDeleteOtrosDialog(true);
};
const handleConfirmDeleteOtros = async () => {
if (!itemToDeleteOtros) return;
try {
if (itemToDeleteOtros.source === 'otros') {
if (delOtroLaboratorio) { if (delOtroLaboratorio) {
delOtroLaboratorio(item.id); await delOtroLaboratorio(itemToDeleteOtros.id);
toast.success('Registro eliminado'); toast.success('Registro eliminado');
} }
} else if (item.source === 'lab') { } else if (itemToDeleteOtros.source === 'lab') {
if (update) { if (update) {
update(item.id, { observaciones: '' }); await update(itemToDeleteOtros.id, { observaciones: '' });
toast.success('Observación de laboratorio eliminada'); 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
<Button variant="outline" onClick={() => setNuevoOtroDialog(false)}> <Button variant="outline" onClick={() => setNuevoOtroDialog(false)}>
Cancelar Cancelar
</Button> </Button>
<Button onClick={() => { <Button onClick={async () => {
if (addOtroLaboratorio && nuevaObsTexto.trim() !== '') { if (addOtroLaboratorio && nuevaObsTexto.trim() !== '') {
addOtroLaboratorio({ try {
pacienteId: patientId, await addOtroLaboratorio({
internacionId, pacienteId: patientId,
fecha: nuevaObsFecha, internacionId,
hora: new Date().toTimeString().slice(0, 5), fecha: nuevaObsFecha,
observaciones: nuevaObsTexto, hora: new Date().toTimeString().slice(0, 5),
categoria: nuevaObsCategoria observaciones: nuevaObsTexto,
}); categoria: nuevaObsCategoria
setNuevaObsTexto(''); });
setNuevaObsFecha(getLocalToday()); setNuevaObsTexto('');
setNuevaObsCategoria('Otros'); setNuevaObsFecha(getLocalToday());
setNuevoOtroDialog(false); setNuevaObsCategoria('Otros');
toast.success('Registro guardado correctamente'); setNuevoOtroDialog(false);
toast.success('Registro guardado correctamente');
} catch {
toast.error('Error al guardar la determinación de laboratorio');
}
} }
}} disabled={!nuevaObsTexto.trim()}> }} disabled={!nuevaObsTexto.trim()}>
<Save className="h-4 w-4 mr-1.5" /> Guardar <Save className="h-4 w-4 mr-1.5" /> Guardar
@@ -1984,6 +2002,25 @@ function SeccionLaboratorios({ lab, otrosLaboratorios = [], patientId, internaci
</DialogContent> </DialogContent>
</Dialog> </Dialog>
<Dialog open={deleteOtrosDialog} onOpenChange={setDeleteOtrosDialog}>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>Confirmar eliminación</DialogTitle>
</DialogHeader>
<p className="text-sm text-muted-foreground my-2">
¿Está seguro de que desea eliminar este registro de determinación de laboratorio? Esta acción no se puede deshacer.
</p>
<div className="flex justify-end gap-2 mt-4">
<Button variant="outline" onClick={() => setDeleteOtrosDialog(false)}>
Cancelar
</Button>
<Button variant="destructive" onClick={handleConfirmDeleteOtros}>
Eliminar
</Button>
</div>
</DialogContent>
</Dialog>
<Dialog open={evolDialog} onOpenChange={setEvolDialog}> <Dialog open={evolDialog} onOpenChange={setEvolDialog}>
<DialogContent className="sm:max-w-2xl max-h-[90vh] overflow-y-auto"> <DialogContent className="sm:max-w-2xl max-h-[90vh] overflow-y-auto">
<DialogHeader> <DialogHeader>