Implement logic to finalize current ATB on modification date and start a new ATB on modification date
This commit is contained in:
@@ -2940,8 +2940,22 @@ function SeccionATB({ atb, internacionId, pacienteId, add, update, del, canEdit
|
|||||||
|
|
||||||
const handleGuardar = () => {
|
const handleGuardar = () => {
|
||||||
if (!antibiotico.trim() || !fechaInicio) return;
|
if (!antibiotico.trim() || !fechaInicio) return;
|
||||||
|
const todayStr = new Date().toISOString().split('T')[0];
|
||||||
if (edit) {
|
if (edit) {
|
||||||
update(edit.id, { antibiotico, fechaInicio, fechaFinalizacion: fechaFinalizacion || undefined });
|
// 1. Modificar el antibiótico actual agregando como fecha de finalización la fecha actual en qué se modifica (manteniendo el nombre y fecha de inicio original)
|
||||||
|
update(edit.id, {
|
||||||
|
antibiotico: edit.antibiotico,
|
||||||
|
fechaInicio: edit.fechaInicio,
|
||||||
|
fechaFinalizacion: todayStr
|
||||||
|
});
|
||||||
|
// 2. Agregar un nuevo esquema antibiótico con el antibiótico nuevo y fecha de inicio de hoy
|
||||||
|
add({
|
||||||
|
pacienteId,
|
||||||
|
internacionId,
|
||||||
|
antibiotico,
|
||||||
|
fechaInicio: todayStr,
|
||||||
|
fechaFinalizacion: fechaFinalizacion || undefined
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
add({ pacienteId, internacionId, antibiotico, fechaInicio, fechaFinalizacion: fechaFinalizacion || undefined });
|
add({ pacienteId, internacionId, antibiotico, fechaInicio, fechaFinalizacion: fechaFinalizacion || undefined });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,6 +177,32 @@ export function SeccionIndicaciones({ recomendaciones, internacionId, pacienteId
|
|||||||
const now = new Date();
|
const now = new Date();
|
||||||
const fecha = now.toISOString().split('T')[0] + ' ' + now.toTimeString().split(' ')[0].substring(0, 5);
|
const fecha = now.toISOString().split('T')[0] + ' ' + now.toTimeString().split(' ')[0].substring(0, 5);
|
||||||
if (edit) {
|
if (edit) {
|
||||||
|
if (edit.tipo === 'Farmacologica Antibiótico' && updateATB && addATB && atbList && pacienteId) {
|
||||||
|
const oldDrug = edit.droga || '';
|
||||||
|
const newDrug = droga || '';
|
||||||
|
if (oldDrug.toLowerCase() !== newDrug.toLowerCase()) {
|
||||||
|
const activeATB = atbList.find(a =>
|
||||||
|
a.internacionId === internacionId &&
|
||||||
|
a.antibiotico.toLowerCase() === oldDrug.toLowerCase() &&
|
||||||
|
!a.fechaFinalizacion
|
||||||
|
);
|
||||||
|
if (activeATB) {
|
||||||
|
const todayStr = now.toISOString().split('T')[0];
|
||||||
|
try {
|
||||||
|
await updateATB(activeATB.id, { fechaFinalizacion: todayStr });
|
||||||
|
await addATB({
|
||||||
|
pacienteId,
|
||||||
|
internacionId,
|
||||||
|
antibiotico: newDrug,
|
||||||
|
fechaInicio: todayStr,
|
||||||
|
});
|
||||||
|
} catch (atbErr) {
|
||||||
|
console.error('Error al actualizar ATB en modificación de indicación:', atbErr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (onAgregarMovimiento) {
|
if (onAgregarMovimiento) {
|
||||||
await onAgregarMovimiento({
|
await onAgregarMovimiento({
|
||||||
indicacionId: edit.id,
|
indicacionId: edit.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user