Skip to content
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
16 changes: 14 additions & 2 deletions src/app/core/mpi/services/paciente-buscar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions src/app/modules/mpi/components/paciente-buscar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esta condición podemos simplificarla de la manera if ($event?.type) { ... }

return;
}
this.pacienteCache.clearPaciente();
Expand All @@ -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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acá podemos simplificar de la manera (this. localidad?.length) ...

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);
}
Expand Down
25 changes: 21 additions & 4 deletions src/app/modules/mpi/components/paciente-buscar.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
<plex-wrapper>
<plex-text [(ngModel)]="textoLibre" (change)="buscar($event)" name='buscador' [debounce]="500"
[autoFocus]="autoFocus" prefix="barcode-scan"
placeholder="Escanee un documento digital, o escriba un documento / apellido / nombre">
[autoFocus]="autoFocus" prefix="barcode-scan"
placeholder="Escanee un documento digital, o escriba un documento / apellido / nombre">
</plex-text>
<plex-button type="info" [icon]="busquedaAvanzada ? 'chevron-up' : 'chevron-down'" label="Búsqueda avanzada"
(click)="toggleBusquedaAvanzada()" class="mr-1">
</plex-button>
<plex-dropdown *ngIf="create" class="mr-0 dropdown-inline" [disabled]="disabled"
[type]="disabled ? 'default' : 'primary'" [right]="true" [items]="routes" label="NUEVO PACIENTE">
[type]="disabled ? 'default' : 'primary'" [right]="true" [items]="routes" label="NUEVO PACIENTE">
</plex-dropdown>
</plex-wrapper>
</plex-wrapper>

<div *ngIf="busquedaAvanzada" class="mt-3 mb-4">
<plex-grid type="sm" cols="3">
<plex-text [(ngModel)]="localidad" label="Localidad" placeholder="Buscar por localidad"
(change)="buscar($event)" [disabled]="disabled" [debounce]="500" name="localidad">
</plex-text>
<plex-datetime type="date" [(ngModel)]="fechaNacimiento" label="Fecha de nacimiento" (change)="buscar($event)"
[disabled]="disabled" name="fechaNacimiento">
</plex-datetime>
<plex-text [(ngModel)]="obraSocial" label="Obra Social" placeholder="Buscar por obra social"
(change)="buscar($event)" [disabled]="disabled" [debounce]="500" name="obraSocial">
</plex-text>
</plex-grid>
</div>
Loading