Skip to content

Commit

Permalink
RUP: Control requerido en formulas editables (#2744)
Browse files Browse the repository at this point in the history
* ref(rup): control requerido en formulas editables

* agrega control a requeridos antes de calcular
  • Loading branch information
negro89 authored Apr 3, 2023
1 parent b422341 commit 6329d23
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
15 changes: 10 additions & 5 deletions src/app/modules/rup/components/elementos/FormulaBase.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class FormulaBaseComponent extends RUPComponent implements OnInit {
}
this.hasRules = this.elementoRUP.rules?.length > 0;
this.valorEditable = this.elementoRUP.params?.valorEditable;
this.emitChange2();

this.addFact('value', this.registro.valor);

Expand All @@ -58,7 +57,7 @@ export class FormulaBaseComponent extends RUPComponent implements OnInit {
});
}
const ultimaConsulta = consultas[0]?.registro;
const esFutura = moment(ultimaConsulta.updatedAt).diff(fechaPrestacion) > 0;
const esFutura = moment(ultimaConsulta?.updatedAt).diff(fechaPrestacion) > 0;

if (!esFutura) {
this.registro.registros.map(reg => {
Expand All @@ -81,8 +80,14 @@ export class FormulaBaseComponent extends RUPComponent implements OnInit {

emitChange2() {
if (!this.valorManual) {
this.resultado = this.formulaProvider.calcular(this.paciente, this.prestacion, this.registro.registros);
this.registro.valor = this.resultado.value;
const conceptosRequeridos = this.elementoRUP.requeridos.map(elem => elem.concepto.conceptId);
// si todos los campos requeridos estan completos, entonces realiza el cálculo
if (conceptosRequeridos.every(requerido => this.registro.registros.find(reg => reg.concepto.conceptId === requerido && reg.valor))) {
this.resultado = this.formulaProvider.calcular(this.paciente, this.prestacion, this.registro.registros);
this.registro.valor = this.resultado.value;
} else {
this.registro.valor = null;
}
}
this.onChange();
}
Expand All @@ -100,7 +105,7 @@ export class FormulaBaseComponent extends RUPComponent implements OnInit {
this.registro.registros.map(reg => reg.valor = null);
} else {
delete this.registro.valorManual;
this.registro.valor = 0;
this.registro.valor = null;
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions src/app/modules/rup/components/elementos/FormulaBase.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
<ng-container *ngIf="!valorManual">
<ng-container *ngFor="let item of elementoRUP.requeridos; let i = index">
<div *ngIf="item.elementoRUP" class="pr-3">
<rup [ngClass]="{'readonly': valorManual}" [elementoRUP]="item.elementoRUP"
[paciente]="paciente" [params]="item.params" [prestacion]="prestacion"
[registro]="registro.registros[i]" [soloValores]="soloValores" (change)="emitChange2()"
(ejecutarAccion)="emitEjecutarAccion($event)" [habilitado]="valorManual">
<rup [elementoRUP]="item.elementoRUP" [paciente]="paciente" [params]="item.params"
[prestacion]="prestacion" [registro]="registro.registros[i]" [soloValores]="soloValores"
(change)="emitChange2()" (ejecutarAccion)="emitEjecutarAccion($event)"
[habilitado]="valorManual">
</rup>
</div>
</ng-container>
</ng-container>
<ng-container *ngIf="valorManual">
<ng-container *ngFor="let item of elementoRUP.requeridos; let i = index">
<div *ngIf="item.elementoRUP" class="pr-3">
<rup [ngClass]="{'readonly': !valorManual}" [elementoRUP]="item.elementoRUP"
[paciente]="paciente" [params]="item.params" [prestacion]="prestacion"
<rup [readonly]="false" [elementoRUP]="item.elementoRUP" [paciente]="paciente"
[params]="{ title: item.params.title, type: item.params.type }" [prestacion]="prestacion"
[registro]="registro.registros[i]" [soloValores]="soloValores" (change)="emitChange2()"
(ejecutarAccion)="emitEjecutarAccion($event)" [habilitado]="valorManual">
</rup>
Expand Down Expand Up @@ -46,14 +46,15 @@
<!-- Campo para ingreso manual del valor del registro -->
<form #form="ngForm">
<ng-container *ngIf="!soloValores && valorEditable">
<plex-float [label]="params?.title || registro.concepto.term" *ngIf="valorManual"
<plex-float *ngIf="valorManual" [label]="params?.title || registro.concepto.term"
placeholder="Ingrese un valor" [(ngModel)]="registro.valor" label=''
name="valorCalculo" (change)="emitChange2()" [disabled]="!valorManual"
[required]="true">
[required]="true" [min]="params?.min" [max]="params?.max">
</plex-float>
<plex-float [label]="params?.title || registro.concepto.term" *ngIf="!valorManual"
<plex-float *ngIf="!valorManual" [label]="params?.title || registro.concepto.term"
[(ngModel)]="registro.valor" [disabled]="true"
[ngModelOptions]="{standalone: true}">
[ngModelOptions]="{standalone: true}" [required]="true" [min]="params?.min"
[max]="params?.max">
</plex-float>
</ng-container>
</form>
Expand Down

0 comments on commit 6329d23

Please sign in to comment.