Skip to content

Commit

Permalink
feat(MAT): quitar validacion de nro de tramite (#1692)
Browse files Browse the repository at this point in the history
  • Loading branch information
plammel committed Aug 3, 2022
1 parent 1b68c60 commit f66f34e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
8 changes: 4 additions & 4 deletions auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,18 @@ export async function createUser(data) {
return await user.save();
}

export async function getTemporyTokenCOVID(username) {
export async function getTemporyTokenGenerarUsuario(username) {
const organizacion = await Organizacion.findOne({ matriculacion: true });
const permisos = getPermisosByType('inscripcionProfesionalesCovid19');
const permisos = getPermisosByType('generarUsuario');
return Auth.generateUserTokenTemporaly(username, permisos, organizacion._id);
}

function getPermisosByType(tipoPermisos) {
let permisos;
if (tipoPermisos === 'certificadosCovid19') {
permisos = ['mpi:paciente:getbyId', 'rup:tipoPrestacion:604793e28566033a409007ea'];
} else if (tipoPermisos === 'inscripcionProfesionalesCovid19') {
permisos = ['usuarios:read', 'usuarios:write', 'matriculaciones:profesionales:putProfesional'];
} else if (tipoPermisos === 'generarUsuario') {
permisos = ['usuarios:read', 'usuarios:write', 'matriculaciones:profesionales:putProfesional', 'log:post'];
}
return permisos;
}
3 changes: 1 addition & 2 deletions core/tm/controller/profesional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as base64 from 'base64-stream';
import * as moment from 'moment';
import * as mongoose from 'mongoose';
import * as stream from 'stream';
import { userScheduler } from '../../../config.private';
import { userScheduler, sisa as sisaConfig } from '../../../config.private';
import * as turno from '../../../modules/matriculaciones/schemas/turno';
import { turnoSolicitado } from '../../../modules/matriculaciones/schemas/turnoSolicitado';
import { makeFsFirmaAdmin } from '../schemas/firmaAdmin';
Expand Down Expand Up @@ -228,4 +228,3 @@ export async function saveFirma(data, admin = false) {
input.end(_base64);
});
}

51 changes: 31 additions & 20 deletions core/tm/routes/profesional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import * as fs from 'fs';
import { Types } from 'mongoose';
import * as stream from 'stream';
import { Auth } from '../../../auth/auth.class';
import { getTemporyTokenCOVID } from '../../../auth/auth.controller';
import { services } from '../../../services';
import { sendSms } from '../../../utils/roboSender/sendSms';
import { makePattern, toArray } from '../../../utils/utils';
import { streamToBase64 } from '../controller/file-storage';
Expand All @@ -21,6 +19,11 @@ import { Profesional } from '../schemas/profesional';
import { profesion } from '../schemas/profesion_model';
import { defaultLimit, maxLimit } from './../../../config';
import { userScheduler } from './../../../config.private';
import { getTemporyTokenGenerarUsuario } from '../../../auth/auth.controller';
import { services } from '../../../services';
import { Matching } from '@andes/match';
import { mpi, algoritmo } from './../../../config';

import moment = require('moment');


Expand Down Expand Up @@ -1192,31 +1195,39 @@ router.post('/profesionales/formacionCero', async (req, res, next) => {
});

router.post('/profesionales/validar', async (req, res, next) => {
const { documento, sexo, nroTramite } = req.body;
try {
const { documento, sexo, nombre, apellido, fechaNacimiento } = req.body;
if (documento && sexo && nombre && apellido && fechaNacimiento) {
const regexSexo = (value) => new RegExp(['^', value, '$'].join(''), 'i');

const params = {
documento,
sexo: regexSexo(sexo),
};
const profesional = await Profesional.findOne(params);
if (!profesional) {
return next('El profesional no se encuentra registrado en Andes.');
}

const resRenaper = await services.get('renaper').exec({
documento, sexo
});
const profesionalCompare = { documento, sexo: sexo.toLowerCase(), nombre, apellido, fechaNacimiento };
profesional.sexo = profesional.sexo.toLowerCase();

const valorMatching = new Matching().matchPersonas(profesional, profesionalCompare , mpi.weightsDefault, algoritmo);

if (resRenaper && resRenaper.idTramite === Number(nroTramite)) {
const regexSexo = new RegExp(['^', sexo, '$'].join(''), 'i');
const profesional = await Profesional.findOne({ documento, sexo: regexSexo, profesionalMatriculado: true });
const token = await getTemporyTokenCOVID(documento);
if (profesional) {
return res.json({ profesional, token });
if (valorMatching >= 0.95) {
const resRenaper = await services.get('renaper').exec({ documento, sexo });
if (resRenaper) {
const token = await getTemporyTokenGenerarUsuario(documento);
return res.json({ profesional, token });
}
}
}
return next('El profesional no se encuentra registrado en Andes.');
} else {
return next('No se pudo validar el profesional. Por favor revise los datos ingresados.');
} catch (err) {
return next(500);
}
});

// router.post('/profesionales/vencimientoPosGrado', async (req, res, next) => {
// let ress = await vencimientoMatriculaPosgrado();
// res.json(ress);

// });

export = router;

function createResponseArray(matriculas: any[], req: any) {
Expand Down
2 changes: 1 addition & 1 deletion jobs/verificaMatriculasGrado.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { vencimientoMatriculaGrado, vencimientoMatriculaPosgrado } from './../core/tm/controller/profesional';
import { vencimientoMatriculaGrado } from './../core/tm/controller/profesional';

async function run(done) {
await vencimientoMatriculaGrado(done);
Expand Down
4 changes: 4 additions & 0 deletions modules/gestor-usuarios/usuarios.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ UsuariosRouter.post('/usuarios/create', Auth.authenticate(), async (req, res, ne
return next(403);
}
try {
const existsUser = await AuthUsers.findOne({ usuario: req.body.documento });
if (existsUser) {
return next('Ya posee un usuario en Andes');
}
const user = await createUser(req.body);
await setValidationTokenAndNotify(req.body.documento);
return res.json(user);
Expand Down

0 comments on commit f66f34e

Please sign in to comment.