Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions core/tm/schemas/tipoPrestacion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ITipoPrestacion extends Document {
queries: [Types.ObjectId];
agendaDinamica?: Boolean;
teleConsulta?: Boolean;
videoConferencia?: Boolean;
Comment thread
JuanIRamirez marked this conversation as resolved.
}

export const tipoPrestacionSchema = new Schema({
Expand Down Expand Up @@ -53,6 +54,11 @@ export const tipoPrestacionSchema = new Schema({
type: Boolean,
required: false,
default: false
},
videoConferencia: {
type: Boolean,
required: false,
default: false
}
});

Expand Down
2 changes: 2 additions & 0 deletions modules/turnos/controller/agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export async function liberarTurno(req, data, turno) {
turno.nota = null;
turno.confirmedAt = null;
turno.reasignado = undefined; // Esto es necesario cuando se libera un turno reasignado
turno.webexLinks = null;
turno.updatedAt = new Date();
turno.updatedBy = req.user.usuario || req.user;
let cant = 1;
Expand Down Expand Up @@ -186,6 +187,7 @@ export function suspenderTurno(req, data, turno) {
const efector = data.organizacion;
delete turno.paciente;
delete turno.tipoPrestacion;
turno.webexLinks = null;
turno.motivoSuspension = req.body.motivoSuspension;
turno.avisoSuspension = req.body.avisoSuspension;
turno.updatedAt = new Date();
Expand Down
1 change: 1 addition & 0 deletions modules/turnos/controller/turnosController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export function getTurno(req) {
turno.bloque_id = elem.bloque_id;
turno.organizacion = elem.organizacion;
turno.profesionales = elem.profesionales;
turno.webexLinks = elem.webexLinks;
turno.paciente = (elem.pacientes_docs && elem.pacientes_docs.length > 0) ? elem.pacientes_docs[0] : elem.bloques.turnos.paciente;
turnos.push(turno);
});
Expand Down
38 changes: 36 additions & 2 deletions modules/turnos/routes/turno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NotificationService } from '../../mobileApp/controller/NotificationServ
import * as prepagasController from '../../obraSocial/controller/prepagas';
import { updateRegistroHistorialSolicitud } from '../../rup/controllers/prestacion';
import { turnosLog } from '../citasLog';
import * as webexController from '../../webex/webex.controller';
import { getHistorial } from '../controller/historialCitasController/historialCitasController';
import * as turnosController from '../controller/turnosController';
import { Agenda } from '../schemas/agenda';
Expand Down Expand Up @@ -72,7 +73,7 @@ router.patch('/turno/agenda/:idAgenda', async (req, res, next) => {
usuario.organizacion = (req as any).user.organizacion;
const tipoTurno = (esHoy ? 'delDia' : 'programado');
const fecha = new Date();
const turno = {
const turno: any = {
horaInicio: (agendaRes as any).horaInicio,
estado: 'asignado',
tipoTurno,
Expand All @@ -84,8 +85,11 @@ router.patch('/turno/agenda/:idAgenda', async (req, res, next) => {
updatedAt: fecha,
updatedBy: usuario,
fechaHoraDacion: fecha,
usuarioDacion: usuario
usuarioDacion: usuario,
videoConferencia: req.body.videoConferencia || false
};


const turnos = ((agendaRes as any).bloques[0].turnos);
turnos.push(turno);
let update;
Expand Down Expand Up @@ -309,6 +313,21 @@ router.patch('/turno/:idTurno/bloque/:idBloque/agenda/:idAgenda/', async (req: a
update[etiquetaMotivoConsulta] = req.body.motivoConsulta;
update[estadoFacturacion] = req.body.estadoFacturacion;

const etiquetaVideoConferencia = bloqueTurno + '.videoConferencia';
const etiquetaWebexLinks = bloqueTurno + '.webexLinks';
update[etiquetaVideoConferencia] = req.body.videoConferencia || false;

if (update[etiquetaVideoConferencia]) {
const profesional = agendaRes.profesionales?.[0] || usuario.documento;
const turnoObj = {
_id: req.body.idTurno,
horaInicio: agendaRes.bloques[posBloque].turnos[posTurno].horaInicio,
paciente: req.body.paciente
};
update[etiquetaWebexLinks] = await webexController.generateWebexLinks(turnoObj, agendaRes, profesional);
}


if (req.body.reasignado) {
update[etiquetaReasignado] = req.body.reasignado;
}
Expand Down Expand Up @@ -511,6 +530,21 @@ router.put('/turno/:idTurno/bloque/:idBloque/agenda/:idAgenda/', async (req, res

update[etiquetaTurno] = req.body.turno;

if (req.body.turno.videoConferencia) {

const profesional = agendaRes.profesionales?.[0] || usuario.documento;
const turnoObj = {
horaInicio: agendaRes.bloques[posBloque].turnos[posTurno].horaInicio,
paciente: req.body.turno.paciente
};

const link = await webexController.generateWebexLinks(turnoObj, agendaRes, profesional);


req.body.turno.webexLinks = link;
}


// Actualiza los audit de update de la agenda
update.updatedAt = new Date();
update.updatedBy = Auth.getAuditUser(req);
Expand Down
7 changes: 6 additions & 1 deletion modules/turnos/schemas/turno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ const turnoSchema = new mongoose.Schema({
fechaHoraDacion: Date,
usuarioDacion: mongoose.Schema.Types.Mixed,
profesional: mongoose.Schema.Types.ObjectId,
notificar: Boolean
notificar: Boolean,
videoConferencia: Boolean,
webexLinks: {
patientLink: String,
professionalLink: String
}
});

export = turnoSchema;
27 changes: 27 additions & 0 deletions modules/webex/webex.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as debug from 'debug';
import { services } from './../../services';

const dbgWebex = debug('dbgWebex');

export async function generateWebexLinks(turno: any, agenda: any, usuario: string) {
try {
const params = {
idTurno: String(turno._id || turno.horaInicio),
};

const servicio = services.get('teleconsulta');
const result: any = await servicio.exec(params);

if (result && result.baseUrl && result.host?.[0] && result.guest?.[0]) {
return {
professionalLink: result.baseUrl + result.host[0].short,
patientLink: result.baseUrl + result.guest[0].short,
};
}

return null;
} catch (error) {
dbgWebex('Error generating Webex links: %O', error?.message || error);
return null;
}
}
Loading