diff --git a/src/app/core/mpi/services/paciente-buscar.service.ts b/src/app/core/mpi/services/paciente-buscar.service.ts index ec3d85b412..5a99ffc391 100644 --- a/src/app/core/mpi/services/paciente-buscar.service.ts +++ b/src/app/core/mpi/services/paciente-buscar.service.ts @@ -15,6 +15,7 @@ export interface PacienteEscaneado { @Injectable() export class PacienteBuscarService { private searchText; + private filtros: any = {}; private skip = 0; private limit = 10; private scrollEnd = false; @@ -143,10 +144,11 @@ export class PacienteBuscarService { /** * Busca paciente cada vez que el campo de busqueda cambia su valor */ - public search(searchText: string, returnScannedPatient = false) { + public search(searchText: string, returnScannedPatient = false, filtros: any = {}) { // Inicia búsqueda if (searchText) { this.searchText = searchText; + this.filtros = filtros; this.skip = 0; this.scrollEnd = false; // Si matchea una expresión regular, busca inmediatamente el paciente @@ -181,8 +183,18 @@ export class PacienteBuscarService { if (this.scrollEnd) { return EMPTY; } + const params: any = { search: this.searchText, activo: true, limit: this.limit, skip: this.skip }; + if (this.filtros?.localidad) { + params.localidad = '^' + this.filtros.localidad; + } + if (this.filtros?.fechaNacimiento) { + params.fechaNacimiento = moment(this.filtros.fechaNacimiento).format('YYYY-MM-DD'); + } + if (this.filtros?.obraSocial) { + params.obraSocial = '^' + this.filtros.obraSocial; + } // Busca por texto libre - return this.pacienteService.get({ search: this.searchText, activo: true, limit: this.limit, skip: this.skip }).pipe( + return this.pacienteService.get(params).pipe( map((resultado: any) => { this.skip += resultado.length; // si vienen menos resultado que {{ limit }} significa que ya se cargaron todos diff --git a/src/app/modules/mpi/components/paciente-buscar.component.ts b/src/app/modules/mpi/components/paciente-buscar.component.ts index 8f417bfb5b..2b69737514 100644 --- a/src/app/modules/mpi/components/paciente-buscar.component.ts +++ b/src/app/modules/mpi/components/paciente-buscar.component.ts @@ -21,6 +21,10 @@ interface PacienteEscaneado { }) export class PacienteBuscarComponent implements OnInit, OnDestroy { public textoLibre: string = null; + public busquedaAvanzada = false; + public localidad: string = null; + public fechaNacimiento: Date = null; + public obraSocial: string = null; public autoFocus = 0; public routes; private pacienteRoute = '/apps/mpi/paciente'; @@ -64,12 +68,22 @@ export class PacienteBuscarComponent implements OnInit, OnDestroy { } } + public toggleBusquedaAvanzada() { + this.busquedaAvanzada = !this.busquedaAvanzada; + if (!this.busquedaAvanzada) { + this.localidad = null; + this.fechaNacimiento = null; + this.obraSocial = null; + this.buscar({ type: null }); + } + } + /** * Busca paciente cada vez que el campo de busqueda cambia su valor */ public buscar($event) { /* Error en Plex, ejecuta un change cuando el input pierde el foco porque detecta que cambia el valor */ - if ($event.type) { + if ($event && $event.type) { return; } this.pacienteCache.clearPaciente(); @@ -85,7 +99,12 @@ export class PacienteBuscarComponent implements OnInit, OnDestroy { this.searchSubscription.unsubscribe(); } this.searchStart.emit(); - this.pacienteBuscar.search(textoLibre, this.returnScannedPatient).subscribe(respuesta => { + const filtros = { + localidad: (this.localidad && this.localidad.length) ? this.localidad.trim() : null, + fechaNacimiento: this.fechaNacimiento ? this.fechaNacimiento : null, + obraSocial: (this.obraSocial && this.obraSocial.length) ? this.obraSocial.trim() : null + }; + this.pacienteBuscar.search(textoLibre, this.returnScannedPatient, filtros).subscribe(respuesta => { if (respuesta) { this.searchEnd.emit(respuesta); } diff --git a/src/app/modules/mpi/components/paciente-buscar.html b/src/app/modules/mpi/components/paciente-buscar.html index bf3967bf8e..861fe0634a 100644 --- a/src/app/modules/mpi/components/paciente-buscar.html +++ b/src/app/modules/mpi/components/paciente-buscar.html @@ -1,9 +1,26 @@ + [autoFocus]="autoFocus" prefix="barcode-scan" + placeholder="Escanee un documento digital, o escriba un documento / apellido / nombre"> + + + [type]="disabled ? 'default' : 'primary'" [right]="true" [items]="routes" label="NUEVO PACIENTE"> - \ No newline at end of file + + +
+ + + + + + + + +
\ No newline at end of file