Skip to content

Commit

Permalink
feat(mapa-camas): filtro por obra social
Browse files Browse the repository at this point in the history
  • Loading branch information
liquid36 committed May 21, 2021
1 parent b58a90e commit fa53c16
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 82 deletions.
21 changes: 21 additions & 0 deletions projects/shared/src/lib/operators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,24 @@ export function saveAs(fileName: string, type: Extensiones, timestamp = true) {

export * from './cache-storage';
export * from './not-null';

export function arrayToSet(array, key, itemFn) {
const listado = [];
array.forEach(elem => {
const item = itemFn(elem);
if (item && Array.isArray(item)) {
item.forEach(inside => {
const index = listado.findIndex(i => i[key] === inside[key]);
if (index < 0) {
listado.push(inside);
}
});
} else if (item) {
const index = listado.findIndex(i => i[key] === item[key]);
if (index < 0) {
listado.push(item);
}
}
});
return listado;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,14 @@ import { Observable, Subject, combineLatest, BehaviorSubject } from 'rxjs';
import { map, switchMap, take, tap, pluck, catchError } from 'rxjs/operators';
import { PrestacionesService } from '../../../../../modules/rup/services/prestaciones.service';
import { Auth } from '@andes/auth';
import { cache, notNull } from '@andes/shared';
import { arrayToSet, cache, notNull } from '@andes/shared';
import { Router } from '@angular/router';
import { IPrestacion } from '../../../../../modules/rup/interfaces/prestacion.interface';
import { RegistroHUDSItemAccion } from './registros-huds-item/registros-huds-item.component';
import { IMAQEstado } from '../../interfaces/IMaquinaEstados';
import { ModalMotivoAccesoHudsService } from '../../../../../modules/rup/components/huds/modal-motivo-acceso-huds.service';
import { IPaciente } from '../../../../../core/mpi/interfaces/IPaciente';

function arrayToSet(array, key, itemFn) {
const listado = [];
array.forEach(elem => {
const item = itemFn(elem);
if (Array.isArray(item)) {
item.forEach(inside => {
const index = listado.findIndex(i => i[key] === inside[key]);
if (index < 0) {
listado.push(inside);
}
});
} else {
const index = listado.findIndex(i => i[key] === item[key]);
if (index < 0) {
listado.push(item);
}
}
});
return listado;
}

@Component({
selector: 'app-registros-huds-detalle',
templateUrl: './registros-huds-detalle.component.html'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { MapaCamasService } from '../../../services/mapa-camas.service';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import { map } from 'rxjs/operators';
import { IntegridadService } from '../integridad.service';
import { arrayToSet } from '@andes/shared';

function arrayToSet(array, key, itemFn) {
const listado = [];
array.forEach(elem => {
const item = itemFn(elem);
if (Array.isArray(item)) {
item.forEach(inside => {
const index = listado.findIndex(i => i[key] === inside[key]);
if (index < 0) {
listado.push(inside);
}
});
} else {
const index = listado.findIndex(i => i[key] === item[key]);
if (index < 0) {
listado.push(item);
}
}
});
return listado;
}

@Component({
selector: 'app-filtros-inconsistencias',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</plex-datetime>
<div collapse>
<plex-select name="obraSocial" label="Obra Social" [(ngModel)]="filtros.obraSocial" (change)="filtrar()"
(getData)="loadObrasSociales($event)">
[data]="obraSociales$ | async" idField="_id">
</plex-select>
<plex-select [(ngModel)]="filtros.estado" [data]='estadosInternacion' label="Estado" (change)="filtrar()">
</plex-select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { DocumentosService } from '../../../../../../services/documentos.service
import { ListadoInternacionService } from '../listado-internacion.service';
import { PermisosMapaCamasService } from '../../../services/permisos-mapa-camas.service';
import { ObraSocialService } from 'src/app/services/obraSocial.service';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { arrayToSet } from '@andes/shared';

@Component({
selector: 'app-filtros-internacion',
Expand All @@ -21,16 +24,28 @@ export class FiltrosInternacionComponent implements OnInit {
estadosInternacion;
requestInProgress: boolean;

obraSociales$: Observable<any[]>;

constructor(
private auth: Auth,
private listadoInternacionService: ListadoInternacionService,
private servicioDocumentos: DocumentosService,
public permisosMapaCamasService: PermisosMapaCamasService,
private obraSocialService: ObraSocialService
public permisosMapaCamasService: PermisosMapaCamasService
) { }

ngOnInit() {
this.estadosInternacion = enumerados.getObjEstadoInternacion();

this.obraSociales$ = this.listadoInternacionService.listaInternacion$.pipe(
map((prestaciones) => {
const rs = arrayToSet(prestaciones, 'nombre', (item) => item.paciente.obraSocial);
rs.push({
_id: 'sin-obra-social',
nombre: 'SIN OBRA SOCIAL'
});
return rs;
})
);
}

filtrar() {
Expand Down Expand Up @@ -64,14 +79,5 @@ export class FiltrosInternacionComponent implements OnInit {
() => this.requestInProgress = false
);
}

loadObrasSociales(event) {
if (event.query) {
this.obraSocialService.getListado({ nombre: event.query }).subscribe(resultado => {
event.callback(resultado);
});
} else {
event.callback(null);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export class ListadoInternacionService {
listaInternacionFiltrada = listaInternacionFiltrada.filter((internacion: IPrestacion) => internacion.paciente.documento.includes(paciente));
} else {
listaInternacionFiltrada = listaInternacionFiltrada.filter((internacion: IPrestacion) =>
(internacion.paciente.nombre.toLowerCase().includes(paciente.toLowerCase()) ||
internacion.paciente.apellido.toLowerCase().includes(paciente.toLowerCase()))
(internacion.paciente.nombre.toLowerCase().includes(paciente.toLowerCase()) ||
internacion.paciente.apellido.toLowerCase().includes(paciente.toLowerCase()))
);
}
}
Expand All @@ -74,8 +74,13 @@ export class ListadoInternacionService {
);
}
if (obraSocial) {
listaInternacionFiltrada = listaInternacionFiltrada.filter((internacion: IPrestacion) =>
internacion.paciente.obraSocial?.nombre === obraSocial.nombre
listaInternacionFiltrada = listaInternacionFiltrada.filter(
(internacion: IPrestacion) => {
if (obraSocial._id === 'sin-obra-social') {
return !internacion.paciente.obraSocial;
}
return internacion.paciente.obraSocial?.nombre === obraSocial.nombre;
}
);
}
return listaInternacionFiltrada;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,9 @@ import { Component, OnInit } from '@angular/core';
import { MapaCamasService } from '../../../services/mapa-camas.service';
import { Observable, combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
import { arrayToSet } from '@andes/shared';


function arrayToSet(array, key, itemFn) {
const listado = [];
array.forEach(elem => {
const item = itemFn(elem);
if (Array.isArray(item)) {
item.forEach(inside => {
const index = listado.findIndex(i => i[key] === inside[key]);
if (index < 0) {
listado.push(inside);
}
});
} else {
const index = listado.findIndex(i => i[key] === item[key]);
if (index < 0) {
listado.push(item);
}
}
});
return listado;
}

@Component({
selector: 'app-filtros-camas',
Expand Down

0 comments on commit fa53c16

Please sign in to comment.