Skip to content

Commit

Permalink
(FEAT) Demanda Insatisfecha: pasar funcionalidad
Browse files Browse the repository at this point in the history
a API
  • Loading branch information
JuanIRamirez committed May 23, 2024
1 parent df85964 commit 1929aee
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
56 changes: 42 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,48 @@ 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 query: any = await listaEspera.find(params, (data: any) => { return data; });
if (query[0]?.demandas) {
const newDemanda = new demanda(unaDemanda);
Auth.audit(newDemanda, req);
query[0].demandas.push(newDemanda);
const editItem = new listaEspera(query[0]);
Auth.audit(editItem, req);
await editItem.save((err) => {
if (err) {
return next(err);
}
res.json(editItem);
});
} else {
const newItem = new listaEspera(req.body);
Auth.audit(newItem, req);
await newItem.save((err) => {
if (err) {
return next(err);
}
res.json(newItem);
});
}
Logger.log(req, req.body.demandas[0].origen, 'lista espera', (errLog) => {
if (errLog) {
return next(err);
}
});
res.json(newItem);
});
} 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);

0 comments on commit 1929aee

Please sign in to comment.