Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAT - Validar profesional con Renaper #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ScrollComponent } from './components/base/plex-scroll.component';

// Servicios
import { AgendaService } from './services/agenda.service';
import { ValidacionService } from './services/validacion.service';
import { CambioDniService } from './services/cambioDni.service';
import { PaisService } from './services/pais.service';
import { ProvinciaService } from './services/provincia.service';
Expand Down Expand Up @@ -210,7 +211,8 @@ import { FiltrosRenovacionComponent } from './components/profesionales/filtros-r
ListadoTurnosPdfComponent,
ZonaSanitariaService,
DriveService,
PdfService
PdfService,
ValidacionService
],
bootstrap: [AppComponent]
})
Expand Down
4 changes: 4 additions & 0 deletions src/app/components/profesionales/header-profesional.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

<plex-badge *ngIf='!profesional.supervisor' type="info"> No tiene supervisor</plex-badge>

<plex-badge type="{{profesional.validadoRenaper ? 'success':'warning'}}">
{{profesional.validadoRenaper ? "VALIDADO":"NO VALIDADO"}}
</plex-badge>

<div subtitle>
<plex-button type="info" size="sm" (click)="editar()">editar</plex-button>
<plex-button *ngIf="estaHabilitado" class='ml-2' type="warning" size="sm" (click)="habilitar()">Deshabilitar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
<img *ngIf='tieneFoto' [src]="foto" class="img-circle" />
<plex-badge size="lg" type="{{profesional.profesionalMatriculado?'success':'danger'}}">{{
profesional.profesionalMatriculado?'MATRICULADO':'NO MATRICULADO' }}</plex-badge>
<plex-badge type="{{profesional.validadoRenaper ? 'info':'warning'}}">
{{profesional.validadoRenaper ? 'VALIDADO':'NO VALIDADO' }}</plex-badge>
<div title> {{ profesional.apellido + ', '+ profesional.nombre}} </div>
<div subtitle> {{ profesional.documento }} </div>
<plex-label titulo="Fecha de nacimiento" subtitulo="{{profesional.fechaNacimiento | fecha}}"></plex-label>
<plex-label titulo="Edad" subtitulo="{{profesional | edad}}"></plex-label>
<plex-label titulo="Sexo" subtitulo="{{profesional.sexo}}"></plex-label>
<plex-label titulo="CUIT" subtitulo="{{profesional.cuit}}"></plex-label>
<plex-label titulo="Naciolalidad" subtitulo="{{profesional.nacionalidad.nombre}}"></plex-label>
<plex-label titulo="Nacionalidad" subtitulo="{{profesional.nacionalidad.nombre}}"></plex-label>
</plex-detail>
<plex-title titulo="Posgrados" size="md">
</plex-title>
Expand Down
69 changes: 53 additions & 16 deletions src/app/components/profesionales/profesional.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import { Auth } from '@andes/auth';
import { ActivatedRoute, Router } from '@angular/router';
import { TurnoService } from '../../services/turno.service';
import { catchError, map, switchMap } from 'rxjs/operators';
import { of, Observable } from 'rxjs';
import { of, Observable, forkJoin } from 'rxjs';
import * as moment from 'moment';
import { ValidacionService } from './../../services/validacion.service';

@Component({
selector: 'app-profesional',
Expand Down Expand Up @@ -56,6 +57,7 @@ export class ProfesionalComponent implements OnInit {
@Input() public profesional: IProfesional = {
id: null,
habilitado: true,
validadoRenaper: false,
nombre: null,
apellido: null,
tipoDocumento: null,
Expand Down Expand Up @@ -167,7 +169,8 @@ export class ProfesionalComponent implements OnInit {
public auth: Auth,
private router: Router,
private route: ActivatedRoute,
private location: Location
private location: Location,
private validacionService: ValidacionService
) { }

ngOnInit() {
Expand Down Expand Up @@ -305,18 +308,33 @@ export class ProfesionalComponent implements OnInit {
}
return null;
}),
switchMap(candidato => {
const profValid = this.validacionService.post({ documento: this.profesional.documento, sexo: this.profesional.sexo });
return forkJoin([profValid, of(candidato)]);
}),
switchMap(responseActualizar => {
if (responseActualizar !== null) {
// hubo match
if (responseActualizar) {
// actualizar candidato
return this._profesionalService.patchProfesional(this.profesional.id, this.profesional);
// Verificamos si esta validado por renaper. En caso de ser extranjero se registra sin problemas.
if (this.profesional.nacionalidad.nombre !== 'Argentina' || !responseActualizar[0].error || responseActualizar[0].menssage) {
// Si el profesional es extranjero entonces no puede ser validado por renaper.
if (this.profesional.nacionalidad.nombre === 'Argentina') {
this.profesional.validadoRenaper = true;
}
if (responseActualizar[1] !== null) {
// hubo match
if (responseActualizar[1]) {
// actualizar candidato
return this._profesionalService.patchProfesional(this.profesional.id, this.profesional);
}
this.profesional.id = undefined;
}
this.profesional.id = undefined;
return of(null); // no actualiza
// no hubo match
this.profesional.validadoRenaper = true;
return this._profesionalService.saveProfesional({ profesional: this.profesional });
} else { // No existe profesional con ese dni y sexo
this.plex.info('warning', 'Revise los datos ingresados.', 'Profesional no encontrado en renaper.');
this.deshabilitarBoton = false;
}
// no hubo match
return this._profesionalService.saveProfesional({ profesional: this.profesional });
return of(null);
}),
switchMap(profesionalSaved => {
if (!profesionalSaved) {
Expand Down Expand Up @@ -482,13 +500,32 @@ export class ProfesionalComponent implements OnInit {
elem.tipo = ((typeof elem.tipo === 'string') ? elem.tipo : (Object(elem.tipo).id));
return elem;
});
this._profesionalService.putProfesional(this.profesional)
.subscribe(resp => {

this.validacionService.post({
documento: this.profesional.documento,
sexo: this.profesional.sexo
}).pipe(
switchMap(resultado => {
if (resultado.error || resultado.message) {
this.plex.info('warning', 'Revise los datos ingresados', 'Profesional no encontrado');
return of(null);
} else {
this.profesional.validadoRenaper = true;
return this._profesionalService.putProfesional(this.profesional);
}
}),
catchError(() => {
this.plex.info('danger', 'Error durante la validación');
return of(null);
})
).subscribe(resp => {
if (resp) {
this.profesional = resp;
this.plex.toast('success', 'Se modificó con éxito!', 'informacion', 1000);
this.editado.emit(true);
});
this.volverProfesional();
this.plex.toast('success', 'Se modificó con éxito!', 'informacion', 1000);
this.volverProfesional();
}
});
} else {
this.plex.toast('danger', 'Falta completar los campos requeridos', 'informacion', 1000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class SolicitarTurnoRenovacionComponent implements OnInit {
@Input() public profesional: IProfesional = {
id: null,
habilitado: true,
validadoRenaper: false,
nombre: null,
apellido: null,
tipoDocumento: null,
Expand Down
1 change: 1 addition & 0 deletions src/app/interfaces/IProfesional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
export interface IProfesional {
id: String;
habilitado: Boolean;
validadoRenaper?: Boolean;
nombre: String;
apellido: String;
tipoDocumento: String;
Expand Down
16 changes: 16 additions & 0 deletions src/app/services/validacion.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Injectable } from '@angular/core';
import { Server } from '@andes/shared';
import { Observable } from 'rxjs';


@Injectable()
export class ValidacionService {

private url = '/core-v2/mpi/validacion';
constructor(private server: Server) { }

post(params: any): Observable<any> {
return this.server.post(this.url, params, { showError: false });
}

}
Loading