Skip to content

Commit

Permalink
feat(mapa-camas): nuevo pase de UO configurable por maquina de estados
Browse files Browse the repository at this point in the history
  • Loading branch information
GaboCancellieri authored and liquid36 committed Feb 9, 2021
1 parent 51cfdbb commit a06f1fc
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/app/apps/rup/mapa-camas/interfaces/IMaquinaEstados.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ export interface IMaquinaEstados {
columns: MapaCamaListadoColumns;
ingresos: { [key: string]: string };
turnero: { [key: string]: string };

historialMedico?: boolean;
configPases: {
sala: string;
allowCama: boolean;
};
}

export interface IMAQEstado {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,38 @@
<ng-content></ng-content>
</plex-title>
<fieldset>
<ng-container *ngIf="camasDisponibles$ | async as camasDisponibles">
<plex-select [required]="true" [(ngModel)]="nuevaCama" name="cama"
[data]="(cambiarUO) ? camasDisponibles.camasDistintaUO : camasDisponibles.camasMismaUO"
placeholder="Elija cama" label="Cama" idField="id"
labelField="nombre + '(' + sectorName + ')'">
</plex-select>
<ng-container *ngIf="cambiarUO; else cambioNormal">
<ng-container *ngIf="paseConfig; else cambioNormal">
<plex-bool *ngIf="allowCama" label="¿Desea elegir cama destino?" [(ngModel)]="selectCama" name="selectCama" type="slide" (click)="nuevaCama = null"></plex-bool>
<ng-container *ngIf="selectCama; else onlySala">
<ng-container *ngIf="camasParaPases$ | async as camasParaPases">
<ng-container *ngIf="camasParaPases.length > 0; else noHayCamas">
<plex-select [required]="true" [(ngModel)]="nuevaCama" name="cama"
[data]="camasParaPases"
placeholder="Elija cama" label="Cama" idField="id"
labelField="nombre + '(' + sectorName + ')'">
</plex-select>
</ng-container>
<ng-template #noHayCamas>
<plex-label titulo="No hay camas disponibles."></plex-label>
</ng-template>
</ng-container>
</ng-container>
<ng-template #onlySala>
<ng-container *ngIf="salaPases$ | async as salaPases">
<plex-label size="lg" type="info" titulo="Sala" [subtitulo]="salaPases.nombre"></plex-label>
</ng-container>
</ng-template>
</ng-container>
</ng-container>
<ng-template #cambioNormal>
<ng-container *ngIf="camasDisponibles$ | async as camasDisponibles">
<plex-select [required]="true" [(ngModel)]="nuevaCama" name="cama"
[data]="(cambiarUO) ? camasDisponibles.camasDistintaUO : camasDisponibles.camasMismaUO"
placeholder="Elija cama" label="Cama" idField="id"
labelField="nombre + '(' + sectorName + ')'">
</plex-select>
</ng-container>
</ng-template>
</fieldset>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Component, OnInit, Input, Output, EventEmitter, OnDestroy } from '@angu
import { Auth } from '@andes/auth';
import { MapaCamasService } from '../../services/mapa-camas.service';
import { Plex } from '@andes/plex';
import { Observable, combineLatest, Subscription, forkJoin } from 'rxjs';
import { Observable, combineLatest, Subscription, forkJoin, of } from 'rxjs';
import { ISnapshot } from '../../interfaces/ISnapshot';
import { switchMap, take } from 'rxjs/operators';
import { filter, map, switchMap, take } from 'rxjs/operators';
import { IMaquinaEstados } from '../../interfaces/IMaquinaEstados';

@Component({
selector: 'app-cambiar-cama',
Expand All @@ -27,6 +28,11 @@ export class CambiarCamaComponent implements OnInit, OnDestroy {
public disableButton = false;

public camaSelectedSegunView$: Observable<ISnapshot> = this.mapaCamasService.camaSelectedSegunView$;
public salaPases$: Observable<any>;
public camasParaPases$: Observable<ISnapshot[]>;
public paseConfig = false;
public allowCama = false;
public selectCama = false;

constructor(
public auth: Auth,
Expand All @@ -35,26 +41,60 @@ export class CambiarCamaComponent implements OnInit, OnDestroy {
) { }

ngOnDestroy() {

}

ngOnInit() {
this.camasDisponibles$ = this.camaSelectedSegunView$.pipe(
switchMap(cama => this.mapaCamasService.getCamasDisponibles(cama))
);
combineLatest([
this.mapaCamasService.maquinaDeEstado$,
this.camaSelectedSegunView$
]).pipe(take(1)).subscribe(([maquinaEstados, camaActual]) => {
this.camasDisponibles$ = this.camaSelectedSegunView$.pipe(
switchMap(cama => this.mapaCamasService.getCamasDisponibles(cama))
);

this.salaPases$ = of({});

if (maquinaEstados.configPases && maquinaEstados.configPases.allowCama) {
this.allowCama = true;
}

if (maquinaEstados.configPases && maquinaEstados.configPases.sala) {
if (maquinaEstados.configPases.sala !== camaActual.id) {
this.paseConfig = true;
this.salaPases$ = this.camasDisponibles$.pipe(
map(cama => {
const sala = cama.camasDistintaUO.filter((c: ISnapshot) => c.sala && c.id === maquinaEstados.configPases.sala)[0];
return sala;
})
);

this.camasParaPases$ = combineLatest([
this.camasDisponibles$,
this.salaPases$,
]).pipe(
map(([camasDisp, sala]) => {
return camasDisp.camasDistintaUO.filter((c: ISnapshot) => c.id !== sala.id);
})
);
}
}

});
}

guardar(valid) {
if (valid.formValid) {
this.disableButton = true;
combineLatest(
this.mapaCamasService.fecha2,
this.camaSelectedSegunView$
this.camaSelectedSegunView$,
this.salaPases$,
).pipe(
take(1),
switchMap(([fechaCambio, camaActual]) => {
switchMap(([fechaCambio, camaActual, salaPases]) => {
this.fecha = fechaCambio;
return this.cambiarCama(camaActual, this.nuevaCama, fechaCambio);
const proximaCama = this.nuevaCama || salaPases;
return this.cambiarCama(camaActual, proximaCama, fechaCambio);
})
).subscribe(
() => {
Expand Down

0 comments on commit a06f1fc

Please sign in to comment.