diff --git a/core/tm/conceptos-turneables.routes.ts b/core/tm/conceptos-turneables.routes.ts index 836668e1a5..49a8619d4e 100644 --- a/core/tm/conceptos-turneables.routes.ts +++ b/core/tm/conceptos-turneables.routes.ts @@ -24,7 +24,8 @@ class ConceptoTurneableResource extends ResourceBase { return { $in: value }; } }, - ids: MongoQuery.inArray.withField('_id') + ids: MongoQuery.inArray.withField('_id'), + teleConsulta: MongoQuery.equalMatch }; middlewares = [Auth.authenticate()]; routesAuthorization = { diff --git a/core/tm/schemas/tipoPrestacion.ts b/core/tm/schemas/tipoPrestacion.ts index 7b2415b01b..3608009d11 100644 --- a/core/tm/schemas/tipoPrestacion.ts +++ b/core/tm/schemas/tipoPrestacion.ts @@ -17,9 +17,9 @@ export interface ITipoPrestacion extends Document { ambito: String[]; queries: [Types.ObjectId]; agendaDinamica?: Boolean; + teleConsulta?: Boolean; } - export const tipoPrestacionSchema = new Schema({ conceptId: String, term: String, @@ -48,7 +48,12 @@ export const tipoPrestacionSchema = new Schema({ type: Boolean, required: false }, - queries: [Types.ObjectId] + queries: [Types.ObjectId], + teleConsulta: { + type: Boolean, + required: false, + default: false + } }); /* Se definen los campos virtuals */ diff --git a/modules/mobileApp/routes/agendas.ts b/modules/mobileApp/routes/agendas.ts index 39df5017b9..2e82eb02eb 100644 --- a/modules/mobileApp/routes/agendas.ts +++ b/modules/mobileApp/routes/agendas.ts @@ -6,6 +6,7 @@ import { getDistanceBetweenPoints } from '../../../utils/utilCoordenadas'; import { verificarCondicionPaciente } from '../../../modules/turnos/condicionPaciente/condicionPaciente.controller'; import { CondicionPaciente } from '../../../modules/turnos/condicionPaciente/condicionPaciente.schema'; import { Constantes, Constante } from '../../../modules/constantes/constantes.schema'; +import { tipoPrestacion } from '../../../core/tm/schemas/tipoPrestacion'; const router = express.Router(); @@ -27,9 +28,14 @@ router.get('/agendasDisponibles', async (req: any, res, next) => { } } } - if (req.query.conceptId) { matchAgendas['tipoPrestaciones.conceptId'] = req.query.conceptId; + } else { + if (!req.query.teleConsulta) { + const conceptosTurneables: any = await tipoPrestacion.find({ teleConsulta: true }); + const conceptIdArray = conceptosTurneables?.map(ct => ct.conceptId); + matchAgendas['tipoPrestaciones.conceptId'] = { $nin: conceptIdArray }; + } } matchAgendas['horaInicio'] = { $gt: new Date(moment().format('YYYY-MM-DD HH:mm')) }; matchAgendas['bloques.restantesProgramados'] = { $gt: 0 }; @@ -67,7 +73,6 @@ router.get('/agendasDisponibles', async (req: any, res, next) => { pipelineAgendas.push({ $sort: { 'agendas.horaInicio': 1 } }); - try { let agendasResultado = await Agenda.aggregate(pipelineAgendas); if (req.query.userLocation) { diff --git a/modules/turnos/routes/agenda.ts b/modules/turnos/routes/agenda.ts index aa11bb499c..e721cb09ee 100644 --- a/modules/turnos/routes/agenda.ts +++ b/modules/turnos/routes/agenda.ts @@ -17,6 +17,7 @@ import * as AgendasEstadisticas from '../controller/estadisticas'; import { getPlanillaC1, getResumenDiarioMensual } from '../controller/reportesDiariosController'; import { Agenda } from '../schemas/agenda'; import { Auth } from './../../../auth/auth.class'; +import { tipoPrestacion } from '../../../core/tm/schemas/tipoPrestacion'; const router = express.Router(); @@ -155,11 +156,10 @@ router.get('/agenda/diagnosticos', async (req, res, next) => { } catch (err) { return next(err); } }); -router.get('/agenda/:id?', (req, res, next) => { +router.get('/agenda/:id?', async (req, res, next) => { if (mongoose.Types.ObjectId.isValid(req.params.id)) { - - Agenda.findById(req.params.id, (err, data) => { + await Agenda.findById(req.params.id, (err, data) => { if (err) { return next(err); } @@ -250,6 +250,17 @@ router.get('/agenda/:id?', (req, res, next) => { query.where('bloques.turnos._id').equals(req.query.turno); } + if (!req.query.teleConsulta) { + const conceptosTurneables: any = await tipoPrestacion.find({ teleConsulta: true }); + const conceptId = []; + if (conceptosTurneables.length > 0) { + for (const ct of conceptosTurneables) { + conceptId.push(ct.conceptId); + } + query.where('tipoPrestaciones.conceptId').nin(conceptId); + } + } + // Si rango es true se buscan las agendas que se solapen con la actual en algĂșn punto if (req.query.rango) { const variable: any[] = []; @@ -678,9 +689,9 @@ router.patch('/agenda/:id*?', (req, res, next) => { router.post('/dashboard', async (req, res, next) => { const permisos: any = {}; - const tipoPrestacion = Auth.getPermissions(req, 'visualizacionInformacion:dashboard:citas:tipoPrestacion:?'); - if (tipoPrestacion.length > 0 && tipoPrestacion[0] !== '*') { - permisos.tipoPrestacion = tipoPrestacion; + const permisosTP = Auth.getPermissions(req, 'visualizacionInformacion:dashboard:citas:tipoPrestacion:?'); + if (permisosTP.length > 0 && permisosTP[0] !== '*') { + permisos.tipoPrestacion = permisosTP; } try { @@ -734,9 +745,9 @@ router.post('/dashboard/descargarCsv', async (req, res, next) => { router.post('/dashboard/localidades', async (req, res, next) => { const permisos: any = {}; - const tipoPrestacion = Auth.getPermissions(req, 'visualizacionInformacion:dashboard:citas:tipoPrestacion:?'); - if (tipoPrestacion.length > 0 && tipoPrestacion[0] !== '*') { - permisos.tipoPrestacion = tipoPrestacion; + const permisosTP = Auth.getPermissions(req, 'visualizacionInformacion:dashboard:citas:tipoPrestacion:?'); + if (permisosTP.length > 0 && permisosTP[0] !== '*') { + permisos.tipoPrestacion = permisosTP; } try {