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
4 changes: 4 additions & 0 deletions initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export function initAPI(app: Express) {
const { Connections } = require('./connections');
Connections.initialize();

// Crea/actualiza motivos de acceso a HUDS por defecto
const { setUpMotivosHuds } = require('./modules/huds/motivosHuds');
setUpMotivosHuds();

// Inicializa la autenticación con Passport/JWT
Auth.initialize(app);

Expand Down
1 change: 1 addition & 0 deletions modules/huds/hudsAccesos.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export async function search(filtros) {
motivoAcceso: '$accesos.motivoAcceso',
organizacion: '$accesos.organizacion',
detalleMotivo: '$accesos.detalleMotivo',
datosAcceso: '$accesos.datosAcceso',
labelPaciente: {
$ifNull: [
'$accesos.labelPaciente',
Expand Down
2 changes: 1 addition & 1 deletion modules/huds/hudsAccesos.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ router.post('/accesos/token', asyncHandler(async (req: any, res) => {
const datosProfesional: any = await search({ id: idProfesional }, { matricula: 1 });
matricula = (datosProfesional.length && datosProfesional[0].matricula && datosProfesional[0].matricula.length) ? datosProfesional[0].matricula[0] : null;
}
logAcceso(req, req.body.paciente.id, matricula, req.body.motivo, req.body.idTurno, req.body.idPrestacion, req.body.detalleMotivo, req.body.modulo);
logAcceso(req, req.body.paciente.id, matricula, req.body.motivo, req.body.idTurno, req.body.idPrestacion, req.body.detalleMotivo, req.body.modulo, req.body.datosAcceso);
return res.json({ token: Auth.generateHudsToken(req.body.usuario, organizacionId, req.body.paciente) });
}));

Expand Down
2 changes: 2 additions & 0 deletions modules/huds/hudsAccesos.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const HudsAccesoSchema = new Schema({
matricula: String,
motivoAcceso: String,
detalleMotivo: String,
datosAcceso: SchemaTypes.Mixed,
labelPaciente: String,
modulo: String,
turno: SchemaTypes.ObjectId,
Expand Down Expand Up @@ -57,6 +58,7 @@ export interface IHudsAccesos extends Document {
matricula: string;
motivoAcceso: string;
detalleMotivo: string;
datosAcceso: any;
modulo: string;
turno: Types.ObjectId;
prestacion: Types.ObjectId;
Expand Down
7 changes: 4 additions & 3 deletions modules/huds/hudsAccesos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { HudsAcceso } from './hudsAccesos.schema';
import * as moment from 'moment';


export async function logAcceso(req, paciente, matricula, motivo, idTurno, idPrestacion, detalleMotivo, modulo) {
export async function logAcceso(req, paciente, matricula, motivo, idTurno, idPrestacion, detalleMotivo, modulo, datosAcceso = null) {
let bucketNumber = 0;
let retry = true;
while (retry) {
try {
await execLog(req, paciente, matricula, motivo, idTurno, idPrestacion, bucketNumber, detalleMotivo, modulo);
await execLog(req, paciente, matricula, motivo, idTurno, idPrestacion, bucketNumber, detalleMotivo, modulo, datosAcceso);
retry = false;
} catch (err) {
if (err.code === 17419) {
Expand All @@ -20,7 +20,7 @@ export async function logAcceso(req, paciente, matricula, motivo, idTurno, idPre
}
}

async function execLog(req, paciente, matricula, motivoAcceso, turno, prestacion, bucketNumber, detalleMotivo, modulo) {
async function execLog(req, paciente, matricula, motivoAcceso, turno, prestacion, bucketNumber, detalleMotivo, modulo, datosAcceso = null) {
const now = new Date();
const start = moment(now).startOf('year') as unknown as number;
return HudsAcceso.update(
Expand All @@ -43,6 +43,7 @@ async function execLog(req, paciente, matricula, motivoAcceso, turno, prestacion
matricula,
motivoAcceso,
detalleMotivo,
datosAcceso,
modulo,
turno,
prestacion,
Expand Down
18 changes: 18 additions & 0 deletions modules/huds/motivosHuds/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
import { MotivosHuds } from './motivosHuds.schema';

export { MotivosHudsRouter } from './motivosHuds.routes';

export async function setUpMotivosHuds() {
await MotivosHuds.updateOne(
{ key: 'exportacion-huds' },
{
$set: {
label: 'Exportación de HUDS',
key: 'exportacion-huds',
moduloDefault: ['exportar-huds'],
descripcion: 'Motivo utilizado por defecto para la exportación de HUDS',
activo: true
}
},
{ upsert: true }
);
}
Loading