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

(FEAT) Demanda Insatisfecha: pasar funcionalidad a API #1893

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 33 additions & 14 deletions modules/turnos/routes/listaEspera.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as express from 'express';
import * as moment from 'moment';
import { Logger } from '../../../utils/logService';
import * as utils from '../../../utils/utils';
import { Agenda } from '../schemas/agenda';
import * as listaEspera from '../schemas/listaEspera';
import { listaEspera, demanda } from '../schemas/listaEspera';
import { defaultLimit, maxLimit } from './../../../config';
import { Auth } from '../../../auth/auth.class';

Expand Down Expand Up @@ -54,19 +53,39 @@ router.get('/listaEspera/:id*?', (req, res, next) => {
});

router.post('/listaEspera', async (req, res, next) => {
const newItem = new listaEspera(req.body);
Auth.audit(newItem, req);
newItem.save((err) => {
if (err) {
return next(err);
const params = {
'paciente.id': req.body.paciente.id,
'tipoPrestacion.conceptId': req.body.tipoPrestacion.conceptId,
estado: 'pendiente'
};

const unaDemanda = {
profesional: req.body.demandas[0].Profesional,
organizacion: req.body.demandas[0].organizacion,
motivo: req.body.demandas[0].motivo,
fecha: moment().toDate(),
origen: req.body.demandas[0].origen
};

try {
const listaDocument: any = await listaEspera.findOne(params, (data: any) => { return data; });
let listaSaved;
if (listaDocument?.demandas) {
const newDemanda = new demanda(unaDemanda);
Auth.audit(newDemanda, req);
listaDocument.demandas.push(newDemanda);

Auth.audit(listaDocument, req);
listaSaved = await listaDocument.save();
} else {
const newListaDocument = new listaEspera(req.body);
Auth.audit(newListaDocument, req);
listaSaved = await newListaDocument.save();
}
Logger.log(req, req.body.demandas[0].origen, 'lista espera', (errLog) => {
if (errLog) {
return next(err);
}
});
res.json(newItem);
});
res.json(listaSaved);
} catch (error) {
return next(error);
}
});

router.put('/listaEspera/:id', (req, res, next) => {
Expand Down
7 changes: 3 additions & 4 deletions modules/turnos/schemas/listaEspera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ demandaSchema.plugin(AuditPlugin);
const listaEsperaSchema = new mongoose.Schema({
paciente: PacienteSubSchema,
tipoPrestacion: { type: tipoPrestacionSchema },
fecha: Date, // si es una solicitud es la fecha en que se solicitó, si es demanda rechazada es la fecha en que no se atendió la demanda
fecha: Date,
vencimiento: Date,
estado: {
type: String, enum: ['pendiente', 'resuelto', 'vencido'],
Expand All @@ -45,6 +45,5 @@ const listaEsperaSchema = new mongoose.Schema({
listaEsperaSchema.plugin(AuditPlugin);
listaEsperaSchema.index({ 'paciente.id': 1, 'tipoPrestacion.conceptId': 1, fecha: 1 });

const listaEspera = mongoose.model('listaEspera', listaEsperaSchema, 'listaEspera');

export = listaEspera;
export const listaEspera = mongoose.model('listaEspera', listaEsperaSchema, 'listaEspera');
export const demanda = mongoose.model('demanda', demandaSchema);