Skip to content

Commit

Permalink
feat(MAT-174): Validar profesional con Renaper
Browse files Browse the repository at this point in the history
  • Loading branch information
MarianoCampetella committed Sep 12, 2024
1 parent 061c162 commit add95d6
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 71 deletions.
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,6 +8,8 @@
<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>
Expand Down
130 changes: 84 additions & 46 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 @@ -89,36 +91,36 @@ export class ProfesionalComponent implements OnInit {
ultimaActualizacion: new Date(),
activo: true
},
{
tipo: 'legal',
valor: null,
codigoPostal: null,
ubicacion: {
localidad: null,
provincia: null,
pais: {
'id': '57f3b5c469fe79a598e6281f',
'nombre': 'Argentina'
},
},
ultimaActualizacion: new Date(),
activo: true
},
{
tipo: 'profesional',
valor: null,
codigoPostal: null,
ubicacion: {
localidad: null,
provincia: null,
pais: {
'id': '57f3b5c469fe79a598e6281f',
'nombre': 'Argentina'
},
},
ultimaActualizacion: new Date(),
activo: true
}],
{

Check failure on line 94 in src/app/components/profesionales/profesional.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 21 spaces but found 8
tipo: 'legal',

Check failure on line 95 in src/app/components/profesionales/profesional.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 25 spaces but found 12
valor: null,

Check failure on line 96 in src/app/components/profesionales/profesional.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 25 spaces but found 12
codigoPostal: null,

Check failure on line 97 in src/app/components/profesionales/profesional.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 25 spaces but found 12
ubicacion: {

Check failure on line 98 in src/app/components/profesionales/profesional.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 25 spaces but found 12
localidad: null,

Check failure on line 99 in src/app/components/profesionales/profesional.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 29 spaces but found 16
provincia: null,

Check failure on line 100 in src/app/components/profesionales/profesional.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 29 spaces but found 16
pais: {

Check failure on line 101 in src/app/components/profesionales/profesional.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 29 spaces but found 16
'id': '57f3b5c469fe79a598e6281f',

Check failure on line 102 in src/app/components/profesionales/profesional.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 33 spaces but found 20
'nombre': 'Argentina'

Check failure on line 103 in src/app/components/profesionales/profesional.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 33 spaces but found 20
},
},
ultimaActualizacion: new Date(),
activo: true
},
{
tipo: 'profesional',
valor: null,
codigoPostal: null,
ubicacion: {
localidad: null,
provincia: null,
pais: {
'id': '57f3b5c469fe79a598e6281f',
'nombre': 'Argentina'
},
},
ultimaActualizacion: new Date(),
activo: true
}],
fotoArchivo: null,
firmas: null,
profesionalMatriculado: false,
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,34 @@ 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);
console.log(responseActualizar[0]);
// 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;
}
this.profesional.id = undefined;
return of(null); // no actualiza
if (responseActualizar[1] !== null) {
// hubo match
if (responseActualizar[1]) {
// actualizar candidato
return this._profesionalService.patchProfesional(this.profesional.id, this.profesional);
}
this.profesional.id = undefined;
}
// 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 +501,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
49 changes: 25 additions & 24 deletions src/app/components/turnos/solicitar-turno-renovacion.component.ts
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 Expand Up @@ -70,30 +71,30 @@ export class SolicitarTurnoRenovacionComponent implements OnInit {
ultimaActualizacion: new Date(),
activo: true
},
{
tipo: 'legal',
valor: null,
codigoPostal: null,
ubicacion: {
localidad: null,
provincia: null,
pais: null,
},
ultimaActualizacion: new Date(),
activo: true
},
{
tipo: 'profesional',
valor: null,
codigoPostal: null,
ubicacion: {
localidad: null,
provincia: null,
pais: null,
},
ultimaActualizacion: new Date(),
activo: true
}
{
tipo: 'legal',
valor: null,
codigoPostal: null,
ubicacion: {
localidad: null,
provincia: null,
pais: null,
},
ultimaActualizacion: new Date(),
activo: true
},
{
tipo: 'profesional',
valor: null,
codigoPostal: null,
ubicacion: {
localidad: null,
provincia: null,
pais: null,
},
ultimaActualizacion: new Date(),
activo: true
}
],
fotoArchivo: null,
firmas: 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 });
}

}

0 comments on commit add95d6

Please sign in to comment.