Skip to content

Commit

Permalink
feat(CIT): implementa control de turnos pendientes (#1981)
Browse files Browse the repository at this point in the history
  • Loading branch information
ma7payne authored Dec 18, 2024
1 parent 8620b9a commit e9a21a2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions modules/turnos/routes/listaEspera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as express from 'express';
import * as moment from 'moment';
import * as mongoose from 'mongoose';
import { Auth } from '../../../auth/auth.class';
import { getHistorialPaciente } from '../controller/turnosController';
import { Agenda } from '../schemas/agenda';
import { demanda, listaEspera } from '../schemas/listaEspera';
import { defaultLimit, maxLimit } from './../../../config';
Expand Down Expand Up @@ -29,10 +30,10 @@ router.get('/listaEspera/:id*?', (req, res, next) => {
}

if (req.query.fechaDesde) {
const fechaDesde = moment(req.query.fechaDesde).startOf('day').toDate();
const fechaDesde = moment(new Date(req.query.fechaDesde)).startOf('day').toDate();

if (req.query.fechaHasta) {
const fechaHasta = moment(req.query.fechaHasta).endOf('day').toDate();
const fechaHasta = moment(new Date(req.query.fechaHasta)).endOf('day').toDate();
opciones['fecha'] = { $gte: fechaDesde, $lte: fechaHasta };
} else {
opciones['fecha'] = { $gte: fechaDesde };
Expand Down Expand Up @@ -126,6 +127,19 @@ router.get('/listaEspera/:id*?', (req, res, next) => {
});

router.post('/listaEspera', async (req, res, next) => {
const historial = await getHistorialPaciente({
...req, query: {
pacienteId: req.body.paciente.id, turnosProximos: true, estado: 'asignado', conceptId: req.body.tipoPrestacion.conceptId
}
});

const turno = historial.length ? historial.filter(item => moment(item.horaInicio).isAfter(moment())) : null;

if (turno?.length) {
// si existe un turno a futuro, no se debería poder cargar la demanda insatisfecha
return res.status(422).json({ code: 'turno_existente', data: turno[0] });
}

const params = {
'paciente.id': req.body.paciente.id,
'tipoPrestacion.conceptId': req.body.tipoPrestacion.conceptId,
Expand Down Expand Up @@ -156,7 +170,8 @@ router.post('/listaEspera', async (req, res, next) => {
Auth.audit(newListaDocument, req);
listaSaved = await newListaDocument.save();
}
res.json(listaSaved);

res.json({ data: { listado: listaSaved } });
} catch (error) {
return next(error);
}
Expand Down

0 comments on commit e9a21a2

Please sign in to comment.