Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIT - implementa control de turnos y solicitudes pendientes #1981

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
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
Loading