Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions modules/mobileApp/routes/turnos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,37 @@ router.get('/turnos', async (req: any, res, next) => {
if (req.query.codificado) {
matchTurno['bloques.turnos.diagnosticos.0'] = { $exists: true };
}
const matchTurnoPost = { ...matchTurno };

if (req.query.horaInicio) {
matchTurno['bloques.turnos.horaInicio'] = { $gte: new Date(req.query.horaInicio) };
matchTurno['horaFin'] = { $gte: new Date(req.query.horaInicio) };
matchTurnoPost['$expr'] = {
$gte: [
{
$add: [
'$bloques.turnos.horaInicio',
{ $multiply: ['$bloques.duracionTurno', 60, 1000] }
]
},
new Date(req.query.horaInicio)
]
};
}

if (req.query.horaFinal) {
matchTurno['bloques.turnos.horaInicio'] = { $lt: new Date(req.query.horaFinal) };
matchTurno['horaInicio'] = { $lt: new Date(req.query.horaFinal) };
matchTurnoPost['bloques.turnos.horaInicio'] = { $lt: new Date(req.query.horaFinal) };
}

if (req.query.tiposTurno) {
matchTurno['bloques.turnos.tipoTurno'] = { $in: req.query.tiposTurno };
matchTurnoPost['bloques.turnos.tipoTurno'] = { $in: req.query.tiposTurno };
}

pipelineTurno.push({ $match: matchTurno });
pipelineTurno.push({ $unwind: '$bloques' });
pipelineTurno.push({ $unwind: '$bloques.turnos' });
pipelineTurno.push({ $match: matchTurno });
pipelineTurno.push({ $match: matchTurnoPost });
pipelineTurno.push({
$group: {
_id: { id: '$_id', bloqueId: '$bloques._id' },
Expand Down Expand Up @@ -124,10 +138,12 @@ router.get('/turnos', async (req: any, res, next) => {
turno.duracionTurno = elem.duracionTurno;
turno.bloque_id = elem.bloque_id;
turno.agenda_estado = elem.agenda_estado;
turno.webexLinks = elem.bloques.turnos.webexLinks;

delete turno.updatedBy;
delete turno.updatedAt;


/* Busco el turno anterior cuando fue reasignado */
const reasignado = turno.reasignado && turno.reasignado.siguiente;

Expand Down
2 changes: 1 addition & 1 deletion modules/webex/webex.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const dbgWebex = debug('dbgWebex');
export async function generateWebexLinks(turno: any, agenda: any, usuario: string) {
try {
const params = {
idTurno: String(turno._id || turno.horaInicio),
idTurno: String(turno._id || turno.horaInicio || turno.horaFin),
};

const servicio = services.get('teleconsulta');
Expand Down
Loading