diff --git a/src/app/core/mpi/services/paciente-buscar.service.ts b/src/app/core/mpi/services/paciente-buscar.service.ts
index ec3d85b412..745404c43d 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,26 @@ 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?.fechaNacimientoDesde || this.filtros?.fechaNacimientoHasta) {
+ let fechaRango = '';
+ if (this.filtros.fechaNacimientoDesde && this.filtros.fechaNacimientoHasta) {
+ fechaRango = `${moment(this.filtros.fechaNacimientoDesde).format('YYYY-MM-DD')}|${moment(this.filtros.fechaNacimientoHasta).format('YYYY-MM-DD')}`;
+ } else if (this.filtros.fechaNacimientoDesde) {
+ fechaRango = `>=${moment(this.filtros.fechaNacimientoDesde).format('YYYY-MM-DD')}`;
+ } else if (this.filtros.fechaNacimientoHasta) {
+ fechaRango = `<=${moment(this.filtros.fechaNacimientoHasta).format('YYYY-MM-DD')}`;
+ }
+ params.fechaNacimiento = fechaRango;
+ }
+ 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..ba1462211a 100644
--- a/src/app/modules/mpi/components/paciente-buscar.component.ts
+++ b/src/app/modules/mpi/components/paciente-buscar.component.ts
@@ -21,6 +21,11 @@ interface PacienteEscaneado {
})
export class PacienteBuscarComponent implements OnInit, OnDestroy {
public textoLibre: string = null;
+ public busquedaAvanzada = false;
+ public localidad: string = null;
+ public fechaNacimientoDesde: Date = null;
+ public fechaNacimientoHasta: Date = null;
+ public obraSocial: string = null;
public autoFocus = 0;
public routes;
private pacienteRoute = '/apps/mpi/paciente';
@@ -64,18 +69,29 @@ export class PacienteBuscarComponent implements OnInit, OnDestroy {
}
}
+ public toggleBusquedaAvanzada() {
+ this.busquedaAvanzada = !this.busquedaAvanzada;
+ if (!this.busquedaAvanzada) {
+ this.localidad = null;
+ this.fechaNacimientoDesde = null;
+ this.fechaNacimientoHasta = 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?.type) {
return;
}
this.pacienteCache.clearPaciente();
this.pacienteCache.clearScanState();
- const textoLibre = (this.textoLibre && this.textoLibre.length) ? this.textoLibre.trim() : '';
- if (textoLibre && textoLibre.length) {
+ const textoLibre = this.textoLibre?.length ? this.textoLibre.trim() : '';
+ if (textoLibre?.length) {
// Controla el scanner
if (!this.pacienteBuscar.controlarScanner(textoLibre)) {
this.plex.info('warning', 'El lector de código de barras no está configurado. Comuníquese con la Mesa de Ayuda de TICS');
@@ -85,7 +101,13 @@ 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?.length ? this.localidad.trim() : null,
+ fechaNacimientoDesde: this.fechaNacimientoDesde ? this.fechaNacimientoDesde : null,
+ fechaNacimientoHasta: this.fechaNacimientoHasta ? this.fechaNacimientoHasta : null,
+ 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..b47a94ac60 100644
--- a/src/app/modules/mpi/components/paciente-buscar.html
+++ b/src/app/modules/mpi/components/paciente-buscar.html
@@ -1,9 +1,29 @@