Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IN (Fix) - Desbloqueo de cama duplicado #2804

Merged
merged 2 commits into from
Jan 19, 2023
Merged
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
6 changes: 5 additions & 1 deletion src/app/apps/rup/mapa-camas/interfaces/ISnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export interface ISnapshot {
idInternacion?: String;
tipo_egreso?: String;
idMovimiento?: string;

prestamo?: boolean;
devolucion?: boolean;
edicionCama?: boolean;
cambioDeCama?: boolean;
desbloqueo?: boolean;
};
nota: String;
prioridad?: {
Expand Down
22 changes: 11 additions & 11 deletions src/app/apps/rup/mapa-camas/services/mapa-camas.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ export class MapaCamasService {
private conceptosTurneablesService: ConceptosTurneablesService,
public auth: Auth,
) {
this.maquinaDeEstado$ = combineLatest(
this.maquinaDeEstado$ = combineLatest([
this.ambito2,
this.capa2,
this.organizacion2
).pipe(
]).pipe(
switchMap(([ambito, capa, organizacion]) => {
return this.maquinaEstadosHTTP.getOne(ambito, capa, organizacion);
}),
Expand All @@ -99,11 +99,11 @@ export class MapaCamasService {
this.estado$ = this.maquinaDeEstado$.pipe(pluck('estados'));
this.relaciones$ = this.maquinaDeEstado$.pipe(pluck('relaciones'));

this.snapshot$ = combineLatest(
this.snapshot$ = combineLatest([
this.ambito2,
this.capa2,
this.fecha2
).pipe(
]).pipe(
switchMap(([ambito, capa, fecha]) => {
return this.camasHTTP.snapshot(ambito, capa, fecha).pipe(
map(snapshot => [snapshot, fecha])
Expand Down Expand Up @@ -140,7 +140,7 @@ export class MapaCamasService {
cache()
);

this.snapshotFiltrado$ = combineLatest(
this.snapshotFiltrado$ = combineLatest([
this.snapshot$,
this.pacienteText,
this.unidadOrganizativaSelected,
Expand All @@ -149,29 +149,29 @@ export class MapaCamasService {
this.esCensable,
this.estadoSelected,
this.equipamientoSelected
).pipe(
]).pipe(
map(([camas, paciente, unidadOrganizativa, sector, tipoCama, esCensable, estado, equipamiento]) =>
this.filtrarSnapshot(camas, paciente, unidadOrganizativa, sector, tipoCama, esCensable, estado, equipamiento)
)
);

this.snapshotOrdenado$ = combineLatest(
this.snapshotOrdenado$ = combineLatest([
this.snapshotFiltrado$,
this.sortBy,
this.sortOrder
).pipe(
]).pipe(
map(([camas, sortBy, sortOrder]) =>
this.sortSnapshots(camas, sortBy, sortOrder)
)
);

// Devuelve la prestación que contiene el informe de ingreso
this.prestacion$ = combineLatest(
this.prestacion$ = combineLatest([
this.selectedPrestacion,
this.selectedCama,
this.view,
this.capa2
).pipe(
]).pipe(
switchMap(([prestacion, cama, view, capa]) => {
if (view === 'listado-internacion') {
// estadistica || estadistica-v2 (listadoInternacion || listadoInternacionUnificado)
Expand Down Expand Up @@ -300,7 +300,7 @@ export class MapaCamasService {
}

getRelacionesPosibles(cama: ISnapshot) {
return combineLatest(this.estado$, this.relaciones$).pipe(
return combineLatest([this.estado$, this.relaciones$]).pipe(
map(([estados, relaciones]) => {
return this.getEstadosRelacionesCama(cama, estados, relaciones);
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
<form #formGenerico="ngForm">
<form #form="ngForm">
<plex-title [titulo]="titulo">
<plex-button title="Guardar" icon="check" type="success" size="sm" [validateForm]="formGenerico"
(click)="guardar($event)">
<plex-button title="Guardar" icon="check" type="success" size="sm" [validateForm]="form"
[disabled]="form.invalid || (disableGuardar$ | async) || inProgress" (click)="guardar($event)">
</plex-button>
<ng-content></ng-content>
</plex-title>
<fieldset>
<div class="row">
<div class="col-md">
<label><strong>Cama:</strong></label>
<p>{{ selectedCama.nombre }}</p>
</div>
</div>
<div class="row">
<div class="col-md">
<plex-datetime type="datetime" [(ngModel)]="fecha" [required]="true" [min]="selectedCama.fecha"
[max]="mapaCamasService.fechaActual$ | async" name="fechaIngreso" label="Fecha"
(change)="setFecha()" [debounce]="600">
</plex-datetime>
</div>
</div>
<ng-container *ngFor="let param of relacion.parametros">
<div class="row">
<div class="col-md">
<plex-select *ngIf="param.options" name="opcionGenerica" [required]="true" [data]="param.options"
idField='nombre' labelField="nombre" [(ngModel)]="selectedCama.observaciones"
label="{{ param.label }}">
</plex-select>
<plex-text *ngIf="!param.options" label="{{ param.label }}" name="accionGenerica"
[(ngModel)]="selectedCama.observaciones" [required]="true"></plex-text>
</div>
</div>
</ng-container>
</fieldset>

<plex-label titulo="Cama:" [tituloBold]="true" subtitulo=""></plex-label>
<plex-label>{{ selectedCama.nombre }}</plex-label>

<plex-datetime type="datetime" [(ngModel)]="fecha" [required]="true" [min]="fechaMin"
[max]="mapaCamasService.fechaActual$ | async" name="fechaIngreso" label="Fecha" (change)="setFecha()"
[debounce]="600">
</plex-datetime>

<ng-container *ngFor="let param of relacion.parametros">
<plex-select *ngIf="param.options" name="opcionGenerica" [required]="true" [data]="param.options"
idField='nombre' labelField="nombre" [(ngModel)]="selectedCama.observaciones"
label="{{ param.label }}">
</plex-select>
<plex-text *ngIf="!param.options" label="{{ param.label }}" name="accionGenerica"
[(ngModel)]="selectedCama.observaciones" [required]="true">
</plex-text>
</ng-container>

<plex-label *ngIf="mensaje.length">{{ mensaje }}</plex-label>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,34 @@ import { Component, OnInit, Input, Output, EventEmitter, OnDestroy } from '@angu
import { MapaCamasService } from '../../services/mapa-camas.service';
import { Plex } from '@andes/plex';
import { ISnapshot } from '../../interfaces/ISnapshot';
import { Observable, Subscription, combineLatest } from 'rxjs';
import { Observable, Subscription, combineLatest, of } from 'rxjs';
import { map } from 'rxjs/operators';

@Component({
selector: 'app-cama-destino-generico',
templateUrl: 'cama-destino-generico.component.html',
})

export class CamaDestinoGenericoComponent implements OnInit, OnDestroy {
camas$: Observable<ISnapshot[]>;
selectedCama$: Observable<ISnapshot>;

@Input() relacion: any;
@Input() listaMotivosBloqueo: any[];

@Output() onSave = new EventEmitter<any>();

public fecha;
public fechaMax = moment().toDate();
public fechaMin;
public selectedCama;
public capa;
public destino;
public titulo: string;
public disableGuardar$: Observable<Boolean> = of(true);
public inProgress = true;
public mensaje = '';

private subscription: Subscription;

constructor(
private plex: Plex,
public mapaCamasService: MapaCamasService
) {

}
) { }

ngOnDestroy() {
if (this.subscription) {
Expand All @@ -44,29 +41,67 @@ export class CamaDestinoGenericoComponent implements OnInit, OnDestroy {
this.destino = this.relacion.destino;
this.fecha = this.mapaCamasService.fecha;

this.subscription = combineLatest(
this.mapaCamasService.capa,
this.subscription = combineLatest([
this.mapaCamasService.selectedCama,
).subscribe(([capa, cama]) => {
this.capa = capa;
this.mapaCamasService.snapshotFiltrado$,
]).subscribe(([cama, snap]) => {
this.selectedCama = cama;
this.fechaMin = this.fecha;
const camaSnap = snap.find(c => c.id === cama.id); // la cama seleccionada durante la fecha seleccionada

if (!camaSnap) {
// Puede pasar por error en la cama o durante el proceso de guardado con conexion lenta
this.disableGuardar$ = of(true);
return;
}
// Se verifican los estados actual y destino (Al cambiar la fecha puede haber cambiado el estado de la cama)
const permiteAccion = camaSnap?.estado === this.relacion.origen;
if (!permiteAccion) {
this.inProgress = false;
this.disableGuardar$ = of(true);
this.mensaje = `No se puede realizar esta acción ya que la cama se encuentra ${camaSnap.estado} en esta fecha.`;
return;
}

if (camaSnap.estado === 'bloqueada') {
this.fechaMin = moment(camaSnap.fecha).add(1, 'minutes');
this.disableGuardar$ = this.mapaCamasService.historial('cama', this.fecha, null, camaSnap).pipe(
map(historial => {
this.inProgress = false;
// se permite el desbloqueo siempre que no se haya desbloqueado mas adelante
const permiteAccion = !historial.length || !historial[0]?.extras?.desbloqueo;
if (!permiteAccion) {
this.mensaje = `No se puede realizar esta acción ya que la cama estará desbloqueada el ${moment(historial[0].fecha).format('DD/MM/YYYY [a las] hh:mm')}.`;
}
return !permiteAccion;
})
);
} else {
if (this.destino === 'bloqueada') {
this.fechaMin = null; // se puede bloquear en el pasado
}
this.inProgress = false;
this.disableGuardar$ = of(false);
}
});

this.titulo = 'CAMBIAR A ' + this.destino.toUpperCase();
}

guardar(form) {
if (form.formValid) {
this.disableGuardar$ = of(true);
if (this.selectedCama) {
this.selectedCama.extras = null;
if (this.selectedCama.estado === 'bloqueada') {
this.selectedCama.observaciones = '';
this.selectedCama.extras = { desbloqueo: true };
}
// Se modifica el estado de la cama
this.selectedCama.estado = this.destino;
this.selectedCama.observaciones = ((typeof this.selectedCama.observaciones === 'string')) ? this.selectedCama.observaciones : (Object(this.selectedCama.observaciones).nombre);

this.mapaCamasService.save(this.selectedCama, this.fecha).subscribe(camaActualizada => {
this.mapaCamasService.save(this.selectedCama, this.fecha).subscribe(() => {
this.plex.info('success', 'Cama ' + this.destino);
this.mapaCamasService.setFecha(this.fecha);
this.onSave.emit({ cama: this.selectedCama });
Expand All @@ -79,6 +114,8 @@ export class CamaDestinoGenericoComponent implements OnInit, OnDestroy {

setFecha() {
this.mapaCamasService.setFecha(this.fecha);
this.inProgress = true;
this.mensaje = '';
}

selectCama(cama: ISnapshot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</ng-container>
</ng-container>
</ng-container>
<plex-button title="Editar Cama" icon="pencil" type="warning" size="sm" (click)="goTo(cama)"
*ngIf="capa !== 'interconsultores' && (cama.sala ? permisosMapaCamasService.salaEdit : permisosMapaCamasService.camaEdit)">
<plex-button *ngIf="capa !== 'interconsultores' && cama.estado !== 'bloqueada' && (cama.sala ? permisosMapaCamasService.salaEdit : permisosMapaCamasService.camaEdit)"
title="Editar Cama" icon="pencil" type="warning" size="sm" (click)="goTo(cama)">
</plex-button>
<ng-container
*ngIf="capa !== 'interconsultores' && !cama.sala && permisosMapaCamasService.camaPrestamo && ((organizacionV2$ | async) || cama.estado === 'disponible')">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
</ng-container>
</ng-container>
</ng-container>
<plex-button *ngIf="canEdit" title="Editar Cama" icon="pencil" type="warning" size="sm" (click)="goTo()">
<plex-button *ngIf="canEdit && cama.estado !== 'bloqueada'" title="Editar Cama" icon="pencil" type="warning"
size="sm" (click)="goTo()">
</plex-button>
</td>
</ng-container>
Expand Down