Skip to content

Commit

Permalink
feat(IN): implementa periodos censables en internacion
Browse files Browse the repository at this point in the history
  • Loading branch information
ma7payne committed Apr 24, 2024
1 parent 0b706d6 commit 8a48365
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/app/apps/rup/mapa-camas/mapa-camas.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { SalaComunService } from './views/sala-comun/sala-comun.service';
import { TimelineMapaCamasComponent } from './views/timelinea-mapa-camas/timeline-mapa-camas.component';
import { VistaCDAComponent } from './views/mapa-camas-capa/vista-cda/vista-cda.component';
import { IngresoPacienteService } from './sidebar/ingreso/ingreso-paciente-workflow/ingreso-paciente-workflow.service';
import { PeriodosCensablesComponent } from './sidebar/periodos-censables/periodos-censables.component';



Expand Down Expand Up @@ -113,7 +114,8 @@ export const INTERNACION_COMPONENTS = [
FiltrosListadoCapasComponent,
RecursosListadoComponent,
ResumenInternacionComponent,
TimelineMapaCamasComponent
TimelineMapaCamasComponent,
PeriodosCensablesComponent
];

export const INTERNACION_PROVIDERS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
</plex-button>
</ng-container>
</app-informe-ingreso>

<app-periodos-censables *ngIf="capa === 'estadistica' || capa === 'estadistica-v2'">
<plex-button title="volver" icon="arrow-left" type="danger" size="sm" (click)="toggleEdit()">
</plex-button>
</app-periodos-censables>
</ng-container>

<app-ingresar-paciente *ngIf="editar" (onSave)="toggleEdit()">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Plex, PlexOptionsComponent } from '@andes/plex';
import { Component, ContentChild, EventEmitter, OnInit, Output, AfterViewChecked, ChangeDetectorRef } from '@angular/core';
import { Component, ContentChild, EventEmitter, OnInit, Output, AfterViewChecked, ChangeDetectorRef, Input } from '@angular/core';
import { combineLatest, Observable, of } from 'rxjs';
import { auditTime, map, switchMap, take } from 'rxjs/operators';
import { PrestacionesService } from 'src/app/modules/rup/services/prestaciones.service';
Expand All @@ -24,6 +24,7 @@ export class InternacionDetalleComponent implements OnInit, AfterViewChecked {
public existeEgreso;
view$ = this.mapaCamasService.view;

@Input() cama;
@Output() cambiarCama = new EventEmitter<any>();
@Output() accion = new EventEmitter<any>();
@ContentChild(PlexOptionsComponent, { static: true }) plexOptions: PlexOptionsComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { Plex } from '@andes/plex';
import { Component, OnInit } from '@angular/core';
import { PrestacionesService } from 'src/app/modules/rup/services/prestaciones.service';
import { MapaCamasService } from '../../services/mapa-camas.service';

interface Periodo {
desde: moment.Moment;
hasta: moment.Moment;
}

@Component({
selector: 'app-periodos-censables',
templateUrl: './periodos-censables.html',
styleUrls: ['./periodos-censables.scss']
})

export class PeriodosCensablesComponent implements OnInit {
prestacion;
agregar = false;
nuevoPeriodo: Periodo;
periodos: Periodo[] = [];
error = false;
camaEsCensable = false;

constructor(
private mapaCamasService: MapaCamasService,
private servicioPrestacion: PrestacionesService,
private plex: Plex,
) { }

ngOnInit() {
this.mapaCamasService.prestacion$.subscribe((prestacion) => {
this.prestacion = prestacion;

const primerRegistro = prestacion?.ejecucion?.registros[0];

if (!!primerRegistro?.esCensable) {
this.periodos = this.prestacion?.periodosCensables;

if (!this.periodos.length) {
const fechaInicio = primerRegistro.createdAt;

this.periodos.push({ desde: moment(fechaInicio), hasta: moment() });
}
}
});

this.initNuevoPeriodo();
}

private initNuevoPeriodo() {
this.nuevoPeriodo = {
desde: moment(),
hasta: null
};
}

private periodoValido(desde, hasta) {
return hasta ? !this.periodos.find((periodo) => moment(periodo.desde)?.isSame(desde, 'day') && moment(periodo.hasta)?.isSame(hasta, 'day'))
: false;
}

private guardarPrestacion() {
const registros = this.prestacion.ejecucion.registros;

if (!!this.periodos?.length) {
registros[0].esCensable = true;
} else {
delete registros[0].esCensable;
}

const params: any = {
op: 'periodosCensables',
periodosCensables: this.periodos,
registros,
};

return this.servicioPrestacion.patch(this.prestacion.id, params);
}

public toggleAgregar() {
this.agregar = !this.agregar;
}

public eliminarPeriodo(index) {
this.periodos?.splice(index, 1);

this.guardarPrestacion().subscribe({
error: () => {
this.plex.toast('danger', 'Ha ocurrido un error al eliminar el periodo');
}
});
}

public agregarPeriodo() {
const { desde, hasta } = this.nuevoPeriodo;

if (this.periodoValido(desde, hasta)) {
this.error = false;
this.periodos.push({ ...this.nuevoPeriodo, hasta });

this.initNuevoPeriodo();
} else {
this.error = true;
}
}

public guardar() {
this.guardarPrestacion().subscribe({
complete: () => {
this.plex.info('success', 'Periodos guardados exitosamente');
this.toggleAgregar();
},
error: () => {
this.plex.toast('danger', 'Ha ocurrido un error al guardar el periodo');
}
});
}

public cancelar() {
this.agregar = false;
this.initNuevoPeriodo();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<ng-container>
<plex-title size="sm" justify titulo="PERIODOS CENSABLES">

<plex-button *ngIf="!agregar" title="Agregar" label="Editar" type="success" size="sm" class="mr-1"
(click)="toggleAgregar()">
</plex-button>

<plex-button *ngIf="agregar" label="Guardar" type="success" size="sm" class="mr-1" (click)="guardar()">Guardar
</plex-button>

<plex-button *ngIf="agregar" icon="close" type="danger" size="sm" class="mr-1" (click)="cancelar()">
</plex-button>


</plex-title>
<div *ngIf="agregar">
<div class="nuevo-periodo">
<div class="fechas-periodo">
<plex-datetime type="date" label="Inicio de censo" [(ngModel)]="nuevoPeriodo.desde" name="fechaDesde"
grow="full">
</plex-datetime>
<plex-datetime type="date" label="Fin de censo" [(ngModel)]="nuevoPeriodo.hasta" name="fechaHasta"
grow="full" [min]="nuevoPeriodo.desde">
</plex-datetime>
<plex-button icon="check" type="success" size="md" class="mr-1" (click)="agregarPeriodo()"
[disabled]="!nuevoPeriodo.hasta"></plex-button>
</div>
<div class="periodo-controls mt-2">
<span *ngIf="error" class="periodo-error text-danger">El periodo seleccionado ya existe</span>
</div>

</div>
</div>
<div *ngIf="periodos?.length" class="lista-periodos">
<div *ngFor="let periodo of periodos; let i = index" class="periodo">
<plex-label titulo="Desde" subtitulo="{{periodo.desde | fecha}}">
</plex-label>
<plex-label titulo="Hasta" subtitulo="{{periodo.hasta | fecha}}">
</plex-label>
<div>
<plex-button *ngIf="agregar" type="danger" size="sm" icon="delete" (click)="eliminarPeriodo(i)"
ariaLabel="Eliminar periodo">
</plex-button>
</div>
</div>
</div>
<div justify="center" *ngIf="!agregar && !periodos?.length">
<plex-label class="mt-2" direction="column" size="md" icon="" titulo="No hay periodos censables cargados"
icon="calendario-rango-bold">
</plex-label>
</div>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.nuevo-periodo {
display: flex;
flex-direction: column;
margin-top: 10px;
}

.periodo-controls {
display: flex;
justify-content: flex-end;

.periodo-error {
display: flex;
flex-grow: 1;
}
}

.fechas-periodo {
display: flex;
column-gap: 5px;
align-items: flex-end;
}

.lista-periodos {
margin-top: 10px;

.periodo {
display: flex;
padding: 5px;
align-items: center;
justify-content: space-between;
}
}

0 comments on commit 8a48365

Please sign in to comment.