From 6329d230ab9f05ed4a3b9462b15f365ecce5ce12 Mon Sep 17 00:00:00 2001 From: Lautaro Molina Date: Mon, 3 Apr 2023 14:58:02 -0300 Subject: [PATCH] RUP: Control requerido en formulas editables (#2744) * ref(rup): control requerido en formulas editables * agrega control a requeridos antes de calcular --- .../elementos/FormulaBase.component.ts | 15 ++++++++----- .../rup/components/elementos/FormulaBase.html | 21 ++++++++++--------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/app/modules/rup/components/elementos/FormulaBase.component.ts b/src/app/modules/rup/components/elementos/FormulaBase.component.ts index e583f5a59b..4633afe6bf 100644 --- a/src/app/modules/rup/components/elementos/FormulaBase.component.ts +++ b/src/app/modules/rup/components/elementos/FormulaBase.component.ts @@ -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); @@ -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 => { @@ -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(); } @@ -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; } } } diff --git a/src/app/modules/rup/components/elementos/FormulaBase.html b/src/app/modules/rup/components/elementos/FormulaBase.html index 0685e7e15e..7dad3abeef 100644 --- a/src/app/modules/rup/components/elementos/FormulaBase.html +++ b/src/app/modules/rup/components/elementos/FormulaBase.html @@ -5,10 +5,10 @@
- +
@@ -16,8 +16,8 @@
- @@ -46,14 +46,15 @@
- + [required]="true" [min]="params?.min" [max]="params?.max"> - + [ngModelOptions]="{standalone: true}" [required]="true" [min]="params?.min" + [max]="params?.max">