diff --git a/src/app/pages/profesional/mpi/registro-paciente/registro-paciente.html b/src/app/pages/profesional/mpi/registro-paciente/registro-paciente.html index aced781b..1907c309 100644 --- a/src/app/pages/profesional/mpi/registro-paciente/registro-paciente.html +++ b/src/app/pages/profesional/mpi/registro-paciente/registro-paciente.html @@ -13,6 +13,18 @@ +
+ +
El paciente ya se encuentra registrado en ANDES
+
+
+ +
+ +
Usted va a registrar un nuevo paciente con los siguientes datos:
+
+
+ @@ -26,9 +38,7 @@ -

NUEVO

-

ACTUALIZAR

-

VALIDADO

+

VALIDADO

@@ -51,8 +61,14 @@

VALIDADO

+ + + Ir al inicio + + - Confirmar Datos + Registrar paciente diff --git a/src/app/pages/profesional/mpi/registro-paciente/registro-paciente.ts b/src/app/pages/profesional/mpi/registro-paciente/registro-paciente.ts index 9950685f..4838bfc7 100644 --- a/src/app/pages/profesional/mpi/registro-paciente/registro-paciente.ts +++ b/src/app/pages/profesional/mpi/registro-paciente/registro-paciente.ts @@ -69,29 +69,59 @@ export class RegistroPacientePage { this.mpiService.get(search).then((resultado: any[]) => { if (resultado.length) { - this.paciente = resultado[0]; - this.estado = this.paciente.estado; - this.paciente.scan = scan; - this.paciente.nombre = datos.nombre.toUpperCase(); - this.paciente.apellido = datos.apellido.toUpperCase(); - this.paciente.fechaNacimiento = moment(datos.fechaNacimiento, 'DD/MM/YYYY'); - this.paciente.sexo = datos.sexo.toLowerCase(); - this.paciente.documento = datos.documento; - this.inProgress = false; + // CASO 1: 100% - Ya registrado + this.actualizarDatosPaciente(resultado[0], datos, scan); + this.estado = 'validado'; } else { - // No existe el paciente - this.estado = 'nuevo'; - this.paciente.nombre = datos.nombre.toUpperCase(); - this.paciente.apellido = datos.apellido.toUpperCase(); - this.paciente.fechaNacimiento = moment(datos.fechaNacimiento, 'DD/MM/YYYY'); - this.paciente.sexo = datos.sexo.toLowerCase(); - this.paciente.documento = datos.documento; - this.paciente.scan = datos.scan; - this.paciente.estado = 'validado'; - this.paciente.genero = datos.sexo.toLowerCase(); - this.inProgress = false; + // Buscamos sugeridos para ver si hay posibles duplicados (> 94%) + this.mpiService.match(datos).then((sugeridos: any[]) => { + const candidatos = sugeridos.filter(s => s._score >= 0.94); + this.prepararPacienteNuevo(datos, scan); // Primero creamos el objeto base + this.paciente.estado = 'validado'; + + if (candidatos.length > 0) { + // Ahora que el objeto existe, le añadimos los duplicados + this.paciente.posibleDuplicado = candidatos.map(c => ({ + id: c.id, + score: c._score, + fecha: new Date() + })); + } + this.inProgress = false; + }).catch(() => { + this.prepararPacienteNuevo(datos, scan); + this.inProgress = false; + }); } }); } + private actualizarDatosPaciente(pacienteEncontrado, datosScan, scanText) { + this.paciente = pacienteEncontrado; + this.paciente.scan = scanText; + this.paciente.nombre = datosScan.nombre.toUpperCase(); + this.paciente.apellido = datosScan.apellido.toUpperCase(); + this.paciente.fechaNacimiento = moment(datosScan.fechaNacimiento, 'DD/MM/YYYY'); + this.paciente.sexo = datosScan.sexo.toLowerCase(); + this.paciente.documento = datosScan.documento; + this.inProgress = false; + } + + private prepararPacienteNuevo(datos, scan) { + this.paciente = { + nombre: datos.nombre.toUpperCase(), + apellido: datos.apellido.toUpperCase(), + fechaNacimiento: moment(datos.fechaNacimiento, 'DD/MM/YYYY'), + sexo: datos.sexo.toLowerCase(), + documento: datos.documento, + scan: scan, + genero: datos.sexo.toLowerCase() + }; + this.estado = 'nuevo'; + } + + public irAlInicio() { + this.router.navigate(['/home/paciente']); + } + } diff --git a/src/app/pages/profesional/mpi/scan-documento/scan-documento.ts b/src/app/pages/profesional/mpi/scan-documento/scan-documento.ts index 7aa2af93..0906664f 100644 --- a/src/app/pages/profesional/mpi/scan-documento/scan-documento.ts +++ b/src/app/pages/profesional/mpi/scan-documento/scan-documento.ts @@ -18,6 +18,6 @@ export class ScanDocumentoPage { } scanner() { - this.barcodeScannerService.scannerProfesional(); + this.barcodeScannerService.scannerParaMPI(); } } diff --git a/src/providers/library-services/barcode-scanner.service.ts b/src/providers/library-services/barcode-scanner.service.ts index 4d008be2..94c28780 100644 --- a/src/providers/library-services/barcode-scanner.service.ts +++ b/src/providers/library-services/barcode-scanner.service.ts @@ -95,6 +95,23 @@ export class BarcodeScannerService { } ); } + scannerParaMPI() { + + const options = configScan.setOptions(); + this.barcodeScanner.scan(options).then((barcodeData) => { + const datos = this.scanParser.scan(barcodeData.text); + if (datos) { + this.router.navigate(['profesional/registro-paciente'], + { queryParams: { datos: JSON.stringify(datos), scan: barcodeData.text } }); + } else { + this.toastCtrl.danger('Documento inválido.'); + } + + }, (err) => { + this.scanFail(err); + }); + } + async scanFail(error) { const alert = await this.alertCtrl.create({ diff --git a/src/providers/paciente-mpi.ts b/src/providers/paciente-mpi.ts index 15f0fee6..6f057802 100644 --- a/src/providers/paciente-mpi.ts +++ b/src/providers/paciente-mpi.ts @@ -24,4 +24,8 @@ export class PacienteMPIService { } } + match(params) { + return this.network.post(this.pacienteUrl + '/match', params); + } + }