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 Jun 12, 2024
1 parent ce714c6 commit eb5b475
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 11 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 [editable]="estadoPrestacion !== 'validada'"
*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,195 @@
import { Plex } from '@andes/plex';
import { Component, ElementRef, Input, OnInit, ViewChild } 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 = null;
camaEsCensable = false;
loading = false;

@Input() editable;
@ViewChild('scrollbottom') sidebar: ElementRef;

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;
}
});

this.initNuevoPeriodo();
}

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

private periodoInvalido(desde, hasta) {
if (desde > hasta) {
this.error = 'El periodo elegido es inválido';
return true;
}

return false;
}

private periodoDuplicado(desde, hasta) {
if (this.periodos.find((periodo) => moment(periodo.desde)?.isSame(desde, 'day') && moment(periodo.hasta)?.isSame(hasta, 'day'))) {
this.error = 'El periodo ingresado ya existe';
return true;
};

return false;
}

public periodoSuperpuesto(desde, hasta) {
let superpuesto = false;
const existeIlimitado = this.periodos.some(periodo => periodo.hasta === null);

if (!hasta && existeIlimitado) {
superpuesto = true;
}

for (const periodo of this.periodos) {
const periodoDesde = moment(periodo.desde);
const periodoHasta = moment(periodo.hasta);

if (hasta) {
if (periodoHasta.isBetween(desde, hasta) || periodoDesde.isBetween(desde, hasta)) {
superpuesto = true;
break;
}
} else {
if (periodoHasta.isAfter(desde) || periodoHasta.isSame(desde, 'day')) {
superpuesto = true;
break;
}
}
}

if (superpuesto) {
this.error = 'El periodo no debe superponerse a otro';
}

return superpuesto;
}

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);
}

private addPeriodoSinLimite(desde) {
const nuevoPeriodo = { desde, hasta: null };

if (!this.periodoSuperpuesto(desde, null)) {
this.guardarPeriodo(nuevoPeriodo);
}
}

public addPeriodoLimitado(desde, hasta) {
const fechaHasta = moment(hasta);

if (!this.periodoInvalido(desde, hasta)) {
if (!this.periodoDuplicado(desde, hasta) && !this.periodoSuperpuesto(desde, hasta)) {
this.guardarPeriodo({ ...this.nuevoPeriodo, fechaHasta });
}
}
}

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

if (hasta) {
if (!this.periodoInvalido(desde, hasta)) {
this.addPeriodoLimitado(desde, hasta);
}
} else {
this.addPeriodoSinLimite(desde);
}
}

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

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

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

private scrollBottom() {
const sidebar = document.getElementById('sidebarCamas').querySelector('.plex-box-content');
sidebar.scrollTo(0, sidebar.scrollHeight);
}

public guardarPeriodo(nuevoPeriodo) {
this.error = null;
this.loading = true;
this.periodos.push(nuevoPeriodo);

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

public cancelar() {
this.agregar = false;
this.error = null;
this.initNuevoPeriodo();
this.scrollBottom();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<ng-container>
<plex-title size="sm" justify titulo="PERIODOS CENSABLES">
<plex-button *ngIf="!agregar && editable" icon="pencil" type="warning" size="sm" class="mr-1"
(click)="toggleAgregar()" tooltip="Editar periodos" tooltipPosition="left">
</plex-button>
<plex-button *ngIf="agregar" icon="close" type="danger" size="sm" class="mr-1" (click)="cancelar()" tooltip="Cerrar" tooltipPosition="left">
</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" [max]="nuevoPeriodo.hasta">
</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" (click)="agregarPeriodo()"
class="mr-1" [disabled]="loading"></plex-button>
</div>
<div class="periodo-controls mt-2">
<span *ngIf="error" class="periodo-error text-danger">{{ error }}</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 ? (periodo.hasta | fecha) : 'Sin fecha'}}">
</plex-label>
<div>
<plex-button *ngIf="agregar" type="danger" tooltip="Eliminar periodo" tooltipPosition="left" 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export class CensosDiariosComponent implements OnInit {
generarCensoDiario() {
this.censoPacientes = [];
this.censo = {};

this.mapaCamasService.censoDiario(moment(this.fecha).toDate(), this.selectedUnidadOranizativa.conceptId)
.subscribe((censoDiario: any) => {
this.censo = {
Expand Down Expand Up @@ -120,13 +119,12 @@ export class CensosDiariosComponent implements OnInit {
tipo: 'diario',
fecha: this.fecha,
unidadOrganizativa: this.selectedUnidadOranizativa.conceptId
},
'CENSODIARIO'
).subscribe(() => {
this.plex.toast('success', 'Descarga exitosa');
}, error => {
this.plex.toast('danger', 'Descarga fallida');
});
}, 'CENSODIARIO')
.subscribe(() => {
this.plex.toast('success', 'Descarga exitosa');
}, error => {
this.plex.toast('danger', 'Descarga fallida');
});
}

descargarCenso() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
</plex-layout-main>


<plex-layout-sidebar type="invert">
<plex-layout-sidebar type="invert" id="sidebarCamas">
<app-estado-servicio *ngIf="!accion"></app-estado-servicio>

<app-ingreso-paciente-workflow *ngIf="accion === 'internarPaciente'" (cancel)="volverADetalle()"
Expand Down

0 comments on commit eb5b475

Please sign in to comment.