Solucionar rutas API de otros laboratorios, ajuste de servidor y modal de confirmacion para eliminar registros
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -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<OtroLaboratorio>) => {
|
||||
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),
|
||||
|
||||
@@ -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
|
||||
<Button variant="outline" onClick={() => setNuevoOtroDialog(false)}>
|
||||
Cancelar
|
||||
</Button>
|
||||
<Button onClick={() => {
|
||||
<Button onClick={async () => {
|
||||
if (addOtroLaboratorio && nuevaObsTexto.trim() !== '') {
|
||||
addOtroLaboratorio({
|
||||
pacienteId: patientId,
|
||||
internacionId,
|
||||
fecha: nuevaObsFecha,
|
||||
hora: new Date().toTimeString().slice(0, 5),
|
||||
observaciones: nuevaObsTexto,
|
||||
categoria: nuevaObsCategoria
|
||||
});
|
||||
setNuevaObsTexto('');
|
||||
setNuevaObsFecha(getLocalToday());
|
||||
setNuevaObsCategoria('Otros');
|
||||
setNuevoOtroDialog(false);
|
||||
toast.success('Registro guardado correctamente');
|
||||
try {
|
||||
await addOtroLaboratorio({
|
||||
pacienteId: patientId,
|
||||
internacionId,
|
||||
fecha: nuevaObsFecha,
|
||||
hora: new Date().toTimeString().slice(0, 5),
|
||||
observaciones: nuevaObsTexto,
|
||||
categoria: nuevaObsCategoria
|
||||
});
|
||||
setNuevaObsTexto('');
|
||||
setNuevaObsFecha(getLocalToday());
|
||||
setNuevaObsCategoria('Otros');
|
||||
setNuevoOtroDialog(false);
|
||||
toast.success('Registro guardado correctamente');
|
||||
} catch {
|
||||
toast.error('Error al guardar la determinación de laboratorio');
|
||||
}
|
||||
}
|
||||
}} disabled={!nuevaObsTexto.trim()}>
|
||||
<Save className="h-4 w-4 mr-1.5" /> Guardar
|
||||
@@ -1984,6 +2002,25 @@ function SeccionLaboratorios({ lab, otrosLaboratorios = [], patientId, internaci
|
||||
</DialogContent>
|
||||
</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}>
|
||||
<DialogContent className="sm:max-w-2xl max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
|
||||
Reference in New Issue
Block a user