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
24 changes: 22 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,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
Expand Down
30 changes: 26 additions & 4 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,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';
Expand Down Expand Up @@ -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');
Expand All @@ -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);
}
Expand Down
28 changes: 24 additions & 4 deletions src/app/modules/mpi/components/paciente-buscar.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
<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="4">
<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)]="fechaNacimientoDesde" label="Fecha de nacimiento desde" (change)="buscar($event)"
[disabled]="disabled" name="fechaNacimientoDesde">
</plex-datetime>
<plex-datetime type="date" [(ngModel)]="fechaNacimientoHasta" label="Fecha de nacimiento hasta" (change)="buscar($event)"
[disabled]="disabled" name="fechaNacimientoHasta">
</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