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 May 13, 2024
1 parent 0b706d6 commit 757c342
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 3 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,187 @@
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 = null;
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 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) {
if (hasta) {
if (desde < periodo.hasta && hasta > periodo.desde) {
superpuesto = true;
}
} else {
if (desde <= periodo.hasta) {
superpuesto = true;
}
}
}

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 addNuevo(nuevoPeriodo) {
this.error = null;
this.periodos.push(nuevoPeriodo);
this.initNuevoPeriodo();
}

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

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

public addPeriodoLimitado(desde, hasta) {
if (!this.periodoInvalido(desde, hasta)) {
if (!this.periodoDuplicado(desde, hasta) && !this.periodoSuperpuesto(desde, hasta)) {
this.addNuevo({ ...this.nuevoPeriodo, hasta });
}
}
}

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

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.error = null;
this.initNuevoPeriodo();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<ng-container>
<plex-title size="sm" justify titulo="PERIODOS CENSABLES">

<plex-button *ngIf="!agregar" icon="pencil" type="warning" 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" [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"></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 @@ -57,6 +57,16 @@ export class CensosDiariosComponent implements OnInit {
this.censoPacientes = [];
this.censo = {};

// debe chequear que los periodos no se superpongan con la fecha de egreso
// const periodoIndex = this.prestacion.periodosCensables?.findIndex(periodo => periodo.hasta === null);

// if (periodoIndex > -1) {
// this.prestacion.periodosCensables[periodoIndex].hasta = this.registro.valor.InformeEgreso.fechaEgreso;
// }

// console.log('periodos', this.prestacion.periodosCensables);


this.mapaCamasService.censoDiario(moment(this.fecha).toDate(), this.selectedUnidadOranizativa.conceptId)
.subscribe((censoDiario: any) => {
this.censo = {
Expand Down Expand Up @@ -121,7 +131,7 @@ export class CensosDiariosComponent implements OnInit {
fecha: this.fecha,
unidadOrganizativa: this.selectedUnidadOranizativa.conceptId
},
'CENSODIARIO'
'CENSODIARIO'

Check failure on line 134 in src/app/apps/rup/mapa-camas/views/censos/censo-diario/censo-diario.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 8 spaces but found 12

Check failure on line 134 in src/app/apps/rup/mapa-camas/views/censos/censo-diario/censo-diario.component.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 8 spaces but found 12
).subscribe(() => {
this.plex.toast('success', 'Descarga exitosa');
}, error => {
Expand Down

0 comments on commit 757c342

Please sign in to comment.