Skip to content

Commit

Permalink
fix(CIT-254): Error en auditoria de agendas en turnos disponibles
Browse files Browse the repository at this point in the history
  • Loading branch information
MarianoCampetella committed May 23, 2024
1 parent 55a06ad commit 57e6b00
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion modules/turnos/routes/agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,28 @@ router.patch('/agenda/:id*?', (req, res, next) => {
// Loopear los turnos, si viene vacío, es porque viene un id solo
const turnos = req.body.turnos || [''];
const estadoAgenda = data.estado;
let indexTurno, indexSobreturno, turnoSinPaciente = false, tieneSobreTurno = false;

data.bloques.forEach(bloque => {
turnos.forEach(t => {
indexTurno = bloque.turnos.findIndex(bt => bt._id.toString() === t);
if (indexTurno > -1 && req.body.op === 'darAsistencia' && !data.bloques.some(b => b.turnos[indexTurno].paciente && b.turnos[indexTurno].estado !== 'turnoDoble')) {
turnoSinPaciente = true;
}
});
});

turnos.forEach(t => {
indexSobreturno = data.sobreturnos.findIndex(st => t === st._id.toString());
if (indexSobreturno > -1 && data.sobreturnos[indexSobreturno].estado !== 'suspendido' && data.sobreturnos[indexSobreturno].paciente) {
tieneSobreTurno = true;
}
});
if (turnoSinPaciente) {
return next('Error: Uno o varios turnos no presentan pacientes.');
} else if (!tieneSobreTurno && indexSobreturno > -1) {
return next('Error: El sobreturno se encuentra suspendido o no presenta paciente.');
}
for (let y = 0; y < turnos.length; y++) {
let turno;
switch (req.body.op) {
Expand Down Expand Up @@ -617,10 +639,10 @@ router.patch('/agenda/:id*?', (req, res, next) => {
return next('Error: No se seleccionó ninguna opción.');
}
}

Auth.audit(data, req);
data.save(async (error) => {
EventCore.emitAsync('citas:agenda:update', data);

if (event.data) {
EventCore.emitAsync(`citas:${event.object}:${event.accion}`, event.data);
}
Expand Down

0 comments on commit 57e6b00

Please sign in to comment.