From 9457795392ec265c72ca76f9009f06c9626a0993 Mon Sep 17 00:00:00 2001 From: Shyam Date: Thu, 30 Nov 2023 15:23:45 -0600 Subject: [PATCH 1/7] Implement fallback calculation for alerts if weight-for-length percentile can't be calculated --- .../js/views/PhysicalEvaluation-0.3-peds.js | 52 ++++++++++++++++--- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js index e15d32f1e..10383af2c 100644 --- a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js +++ b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js @@ -146,6 +146,20 @@ let viewExtension = Backbone.View.extend({ this.handleOutOfRangePercentileWarning(); }, calculateWeightForLengthPercentile: function (sex) { + const lmsValues = this.getWeightForLengthLMSValues(sex); + if (lmsValues) { + let avgWeight = parseFloat($("#mean-weight").attr("data-mean")); + const percentileElement = this.$("#percentile-" + sex + "-weight-for-length"); + const zScore = this.getZScore(avgWeight, lmsValues); + console.log("weight-for-length", "Zscore", zScore); + percentileElement.attr("data-zscore", zScore); + const percentile = this.getPercentile(zScore); + percentileElement.html("" + this.addPercentileSuffix(percentile) + ""); + percentileElement.attr("data-percentile", percentile); + this.handleOutOfRangePercentileWarning(); + } + }, + getWeightForLengthLMSValues: function (sex) { let avgWeight = parseFloat($("#mean-weight").attr("data-mean")); let avgLength = parseFloat($("#mean-height").attr("data-mean")); if (avgWeight && avgLength) { @@ -158,16 +172,10 @@ let viewExtension = Backbone.View.extend({ lmsValues["S"] = item.S; } }); - const percentileElement = this.$("#percentile-" + sex + "-weight-for-length"); console.log("weight-for-length", "lms", lmsValues); - const zScore = this.getZScore(avgWeight, lmsValues); - console.log("weight-for-length", "Zscore", zScore); - percentileElement.attr("data-zscore", zScore); - const percentile = this.getPercentile(zScore); - percentileElement.html("" + this.addPercentileSuffix(percentile) + ""); - percentileElement.attr("data-percentile", percentile); - this.handleOutOfRangePercentileWarning(); + return lmsValues; } + return []; }, getZScore: function (X, lmsValues) { const L = parseFloat(lmsValues["L"]); @@ -219,6 +227,15 @@ let viewExtension = Backbone.View.extend({ } return ""; }, + getX: function (zScore, lmsValues) { + const L = parseFloat(lmsValues["L"]); + const M = parseFloat(lmsValues["M"]); + const S = parseFloat(lmsValues["S"]); + if (L === 0) { + return null; + } + return M * Math.pow(zScore * L * S + 1, 1 / L); + }, handleOutOfRangePercentileWarning: function () { const displayWarning = (percentileIds, warningFieldId) => { let hasWarning = false; @@ -585,14 +602,33 @@ let viewExtension = Backbone.View.extend({ if (warning.hasOwnProperty("percentile")) { let percentileField = warning.percentile; let percentileMale, percentileFemale, conditionMale, conditionFemale; + const zScore = -2; // 2.3rd percentile zScore + const avgWeight = parseFloat($("#mean-weight").attr("data-mean")); if (this.sexAtBirth === 0) { percentileMale = $("#percentile-1-" + percentileField).attr("data-percentile"); percentileFemale = $("#percentile-2-" + percentileField).attr("data-percentile"); + // Fallback calculation if weight-for-length percentile can't be calculated + if (warning.percentile === "weight-for-length" && (percentileMale === "" || percentileFemale === "")) { + if (percentileMale === "") { + conditionMale = avgWeight < this.getX(zScore, this.getWeightForLengthLMSValues(1)); + } + if (percentileFemale === "") { + conditionFemale = avgWeight < this.getX(zScore, this.getWeightForLengthLMSValues(2)); + } + if (conditionMale || conditionFemale) { + return true; + } + } conditionMale = percentileMale !== "" && parseFloat(percentileMale) < warning.min; conditionFemale = percentileFemale !== "" && parseFloat(percentileFemale) < warning.min; return conditionMale || conditionFemale; } let percentile = $("#percentile-" + this.sexAtBirth + "-" + percentileField).attr("data-percentile"); + if (percentile === "" && warning.percentile === "weight-for-length") { + const lmsValues = this.getWeightForLengthLMSValues(this.sexAtBirth); + const weight = this.getX(zScore, lmsValues); + return avgWeight < weight; + } return percentile !== "" && parseFloat(percentile) < warning.min; } if (warning.hasOwnProperty("age")) { From 2d4b00ca88486028549cbaa4e3258dcf5b2d0177 Mon Sep 17 00:00:00 2001 From: Shyam Date: Thu, 30 Nov 2023 16:55:51 -0600 Subject: [PATCH 2/7] Handle growth percentile warnings --- .../js/views/PhysicalEvaluation-0.3-peds.js | 62 +++++++++++-------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js index 10383af2c..790536c56 100644 --- a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js +++ b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js @@ -52,6 +52,7 @@ let viewExtension = Backbone.View.extend({ calculateMean: function (field) { let fieldSelector = ".field-" + field; let values = []; + let mean; this.$(fieldSelector) .find("input") .each(function () { @@ -78,19 +79,9 @@ let viewExtension = Backbone.View.extend({ }, 0 ); - let mean = (sum / values.length).toFixed(1); + mean = (sum / values.length).toFixed(1); meanElement.html("" + mean + ""); meanElement.attr("data-mean", mean); - if (this.percentileFields.hasOwnProperty(field) && mean) { - let percentileFields = this.percentileFields[field]; - percentileFields.forEach((percentileField) => { - if (percentileField === "weight-for-length") { - this.calculateWeightForLengthPercentileMaleFemale(); - } else { - this.calculatePercentileMaleFemale(percentileField, parseFloat(mean)); - } - }); - } if (this.conversions[field]) { let converted = this.convert(this.conversions[field], mean); this.$("#convert-" + field).html("(" + converted + ")"); @@ -104,6 +95,17 @@ let viewExtension = Backbone.View.extend({ meanElement.attr("data-mean", ""); this.$("#convert-" + field).html(""); } + if (this.percentileFields.hasOwnProperty(field)) { + let percentileFields = this.percentileFields[field]; + percentileFields.forEach((percentileField) => { + if (percentileField === "weight-for-length") { + this.calculateWeightForLengthPercentileMaleFemale(); + } else { + mean = mean ? parseFloat(mean) : ""; + this.calculatePercentileMaleFemale(percentileField, mean); + } + }); + } }, calculatePercentileMaleFemale: function (field, X) { const sex = this.sexAtBirth; @@ -125,7 +127,7 @@ let viewExtension = Backbone.View.extend({ }, calculatePercentile: function (field, X, sex) { const ageInMonths = this.ageInMonths; - const lmsValues = []; + let lmsValues = []; let charts = this.growthCharts[field]; charts.forEach((item) => { if (item.sex === sex && Math.floor(item.month) === ageInMonths) { @@ -136,28 +138,38 @@ let viewExtension = Backbone.View.extend({ }); console.log(field, "lms", lmsValues); const percentileElement = this.$("#percentile-" + sex + "-" + field); - const zScore = this.getZScore(X, lmsValues); + const zScore = X ? this.getZScore(X, lmsValues) : ""; console.log(field, "Zscore", zScore); percentileElement.attr("data-zscore", zScore); - const percentile = this.getPercentile(zScore); + const percentile = zScore ? this.getPercentile(zScore) : ""; console.log("percentile", percentile); percentileElement.html("" + this.addPercentileSuffix(percentile) + ""); percentileElement.attr("data-percentile", percentile); this.handleOutOfRangePercentileWarning(); }, calculateWeightForLengthPercentile: function (sex) { - const lmsValues = this.getWeightForLengthLMSValues(sex); - if (lmsValues) { - let avgWeight = parseFloat($("#mean-weight").attr("data-mean")); - const percentileElement = this.$("#percentile-" + sex + "-weight-for-length"); - const zScore = this.getZScore(avgWeight, lmsValues); - console.log("weight-for-length", "Zscore", zScore); - percentileElement.attr("data-zscore", zScore); - const percentile = this.getPercentile(zScore); - percentileElement.html("" + this.addPercentileSuffix(percentile) + ""); - percentileElement.attr("data-percentile", percentile); - this.handleOutOfRangePercentileWarning(); + let avgWeight = parseFloat($("#mean-weight").attr("data-mean")); + let avgLength = parseFloat($("#mean-height").attr("data-mean")); + let lmsValues = []; + if (avgLength) { + let charts = this.growthCharts["weight-for-length"]; + charts.forEach((item) => { + if (item.sex === sex && Math.round(item.length) === Math.round(avgLength)) { + lmsValues["L"] = item.L; + lmsValues["M"] = item.M; + lmsValues["S"] = item.S; + } + }); } + const percentileElement = this.$("#percentile-" + sex + "-weight-for-length"); + console.log("weight-for-length", "lms", lmsValues); + const zScore = avgWeight && Object.keys(lmsValues).length > 0 ? this.getZScore(avgWeight, lmsValues) : ""; + console.log("weight-for-length", "Zscore", zScore); + percentileElement.attr("data-zscore", zScore); + const percentile = zScore ? this.getPercentile(zScore) : ""; + percentileElement.html("" + this.addPercentileSuffix(percentile) + ""); + percentileElement.attr("data-percentile", percentile); + this.handleOutOfRangePercentileWarning(); }, getWeightForLengthLMSValues: function (sex) { let avgWeight = parseFloat($("#mean-weight").attr("data-mean")); From 1422e8490d2a80d9271e684900dbfd807f19aaca Mon Sep 17 00:00:00 2001 From: Shyam Date: Fri, 1 Dec 2023 10:49:32 -0600 Subject: [PATCH 3/7] Optimize code --- web/assets/js/views/PhysicalEvaluation-0.3-peds.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js index 790536c56..903684d3a 100644 --- a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js +++ b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js @@ -150,20 +150,10 @@ let viewExtension = Backbone.View.extend({ calculateWeightForLengthPercentile: function (sex) { let avgWeight = parseFloat($("#mean-weight").attr("data-mean")); let avgLength = parseFloat($("#mean-height").attr("data-mean")); - let lmsValues = []; - if (avgLength) { - let charts = this.growthCharts["weight-for-length"]; - charts.forEach((item) => { - if (item.sex === sex && Math.round(item.length) === Math.round(avgLength)) { - lmsValues["L"] = item.L; - lmsValues["M"] = item.M; - lmsValues["S"] = item.S; - } - }); - } + let lmsValues = this.getWeightForLengthLMSValues(sex); const percentileElement = this.$("#percentile-" + sex + "-weight-for-length"); console.log("weight-for-length", "lms", lmsValues); - const zScore = avgWeight && Object.keys(lmsValues).length > 0 ? this.getZScore(avgWeight, lmsValues) : ""; + const zScore = avgWeight && avgLength ? this.getZScore(avgWeight, lmsValues) : ""; console.log("weight-for-length", "Zscore", zScore); percentileElement.attr("data-zscore", zScore); const percentile = zScore ? this.getPercentile(zScore) : ""; From 2cfe31de28edc3faef0e92622b4c6b797b32f8f6 Mon Sep 17 00:00:00 2001 From: Shyam Date: Fri, 1 Dec 2023 11:34:46 -0600 Subject: [PATCH 4/7] Implement fallback calculation for weight-for-age growth percentile can't be determined --- .../js/views/PhysicalEvaluation-0.3-peds.js | 64 ++++++++++++------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js index 903684d3a..56c263b61 100644 --- a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js +++ b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js @@ -126,17 +126,7 @@ let viewExtension = Backbone.View.extend({ } }, calculatePercentile: function (field, X, sex) { - const ageInMonths = this.ageInMonths; - let lmsValues = []; - let charts = this.growthCharts[field]; - charts.forEach((item) => { - if (item.sex === sex && Math.floor(item.month) === ageInMonths) { - lmsValues["L"] = item.L; - lmsValues["M"] = item.M; - lmsValues["S"] = item.S; - } - }); - console.log(field, "lms", lmsValues); + const lmsValues = this.getLMSValues(sex, field); const percentileElement = this.$("#percentile-" + sex + "-" + field); const zScore = X ? this.getZScore(X, lmsValues) : ""; console.log(field, "Zscore", zScore); @@ -148,9 +138,9 @@ let viewExtension = Backbone.View.extend({ this.handleOutOfRangePercentileWarning(); }, calculateWeightForLengthPercentile: function (sex) { - let avgWeight = parseFloat($("#mean-weight").attr("data-mean")); - let avgLength = parseFloat($("#mean-height").attr("data-mean")); - let lmsValues = this.getWeightForLengthLMSValues(sex); + const avgWeight = parseFloat($("#mean-weight").attr("data-mean")); + const avgLength = parseFloat($("#mean-height").attr("data-mean")); + const lmsValues = this.getWeightForLengthLMSValues(sex); const percentileElement = this.$("#percentile-" + sex + "-weight-for-length"); console.log("weight-for-length", "lms", lmsValues); const zScore = avgWeight && avgLength ? this.getZScore(avgWeight, lmsValues) : ""; @@ -161,11 +151,25 @@ let viewExtension = Backbone.View.extend({ percentileElement.attr("data-percentile", percentile); this.handleOutOfRangePercentileWarning(); }, + getLMSValues: function (sex, field) { + const ageInMonths = this.ageInMonths; + let lmsValues = []; + let charts = this.growthCharts[field]; + charts.forEach((item) => { + if (item.sex === sex && Math.floor(item.month) === ageInMonths) { + lmsValues["L"] = item.L; + lmsValues["M"] = item.M; + lmsValues["S"] = item.S; + } + }); + console.log(field, "lms", lmsValues); + return lmsValues; + }, getWeightForLengthLMSValues: function (sex) { - let avgWeight = parseFloat($("#mean-weight").attr("data-mean")); - let avgLength = parseFloat($("#mean-height").attr("data-mean")); + const avgWeight = parseFloat($("#mean-weight").attr("data-mean")); + const avgLength = parseFloat($("#mean-height").attr("data-mean")); + let lmsValues = []; if (avgWeight && avgLength) { - const lmsValues = []; let charts = this.growthCharts["weight-for-length"]; charts.forEach((item) => { if (item.sex === sex && Math.round(item.length) === Math.round(avgLength)) { @@ -174,10 +178,9 @@ let viewExtension = Backbone.View.extend({ lmsValues["S"] = item.S; } }); - console.log("weight-for-length", "lms", lmsValues); - return lmsValues; } - return []; + console.log("weight-for-length", "lms", lmsValues); + return lmsValues; }, getZScore: function (X, lmsValues) { const L = parseFloat(lmsValues["L"]); @@ -605,11 +608,23 @@ let viewExtension = Backbone.View.extend({ let percentileField = warning.percentile; let percentileMale, percentileFemale, conditionMale, conditionFemale; const zScore = -2; // 2.3rd percentile zScore + const thirdPercentileZScore = -1.88; const avgWeight = parseFloat($("#mean-weight").attr("data-mean")); if (this.sexAtBirth === 0) { percentileMale = $("#percentile-1-" + percentileField).attr("data-percentile"); percentileFemale = $("#percentile-2-" + percentileField).attr("data-percentile"); - // Fallback calculation if weight-for-length percentile can't be calculated + // Fallback calculation if weight-for-age/weight-for-length percentile can't be calculated + if (warning.percentile === "weight-for-age" && (percentileMale === "" || percentileFemale === "")) { + if (percentileMale === "") { + conditionMale = val < this.getX(zScore, this.getLMSValues(1, percentileField)); + } + if (percentileFemale === "") { + conditionFemale = val < this.getX(zScore, this.getLMSValues(2, percentileField)); + } + if (conditionMale || conditionFemale) { + return true; + } + } if (warning.percentile === "weight-for-length" && (percentileMale === "" || percentileFemale === "")) { if (percentileMale === "") { conditionMale = avgWeight < this.getX(zScore, this.getWeightForLengthLMSValues(1)); @@ -626,7 +641,12 @@ let viewExtension = Backbone.View.extend({ return conditionMale || conditionFemale; } let percentile = $("#percentile-" + this.sexAtBirth + "-" + percentileField).attr("data-percentile"); - if (percentile === "" && warning.percentile === "weight-for-length") { + if (warning.percentile === "weight-for-age" && percentile === "") { + const lmsValues = this.getLMSValues(this.sexAtBirth, percentileField); + const weight = this.getX(thirdPercentileZScore, lmsValues); + return val < weight; + } + if (warning.percentile === "weight-for-length" && percentile === "") { const lmsValues = this.getWeightForLengthLMSValues(this.sexAtBirth); const weight = this.getX(zScore, lmsValues); return avgWeight < weight; From 5bad55c81ebe738f92eaee6e28ae6df4dc44fb04 Mon Sep 17 00:00:00 2001 From: Shyam Date: Fri, 1 Dec 2023 12:04:30 -0600 Subject: [PATCH 5/7] Refactor weight-for-age/weight-for-length warning percentile logic --- .../js/views/PhysicalEvaluation-0.3-peds.js | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js index 56c263b61..709916102 100644 --- a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js +++ b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js @@ -607,30 +607,21 @@ let viewExtension = Backbone.View.extend({ if (warning.hasOwnProperty("percentile")) { let percentileField = warning.percentile; let percentileMale, percentileFemale, conditionMale, conditionFemale; - const zScore = -2; // 2.3rd percentile zScore + const twoThirdPercentileZScore = -2; const thirdPercentileZScore = -1.88; const avgWeight = parseFloat($("#mean-weight").attr("data-mean")); if (this.sexAtBirth === 0) { percentileMale = $("#percentile-1-" + percentileField).attr("data-percentile"); percentileFemale = $("#percentile-2-" + percentileField).attr("data-percentile"); // Fallback calculation if weight-for-age/weight-for-length percentile can't be calculated - if (warning.percentile === "weight-for-age" && (percentileMale === "" || percentileFemale === "")) { - if (percentileMale === "") { - conditionMale = val < this.getX(zScore, this.getLMSValues(1, percentileField)); + if (percentileMale === "" || percentileFemale === "") { + if (warning.percentile === "weight-for-age") { + conditionMale = percentileMale === "" && val < this.getX(thirdPercentileZScore, this.getLMSValues(1, percentileField)); + conditionFemale = percentileFemale === "" && val < this.getX(thirdPercentileZScore, this.getLMSValues(2, percentileField)); } - if (percentileFemale === "") { - conditionFemale = val < this.getX(zScore, this.getLMSValues(2, percentileField)); - } - if (conditionMale || conditionFemale) { - return true; - } - } - if (warning.percentile === "weight-for-length" && (percentileMale === "" || percentileFemale === "")) { - if (percentileMale === "") { - conditionMale = avgWeight < this.getX(zScore, this.getWeightForLengthLMSValues(1)); - } - if (percentileFemale === "") { - conditionFemale = avgWeight < this.getX(zScore, this.getWeightForLengthLMSValues(2)); + if (warning.percentile === "weight-for-length") { + conditionMale = percentileMale === "" && avgWeight < this.getX(twoThirdPercentileZScore, this.getWeightForLengthLMSValues(1)); + conditionFemale = percentileFemale === "" && avgWeight < this.getX(twoThirdPercentileZScore, this.getWeightForLengthLMSValues(2)); } if (conditionMale || conditionFemale) { return true; @@ -641,15 +632,13 @@ let viewExtension = Backbone.View.extend({ return conditionMale || conditionFemale; } let percentile = $("#percentile-" + this.sexAtBirth + "-" + percentileField).attr("data-percentile"); - if (warning.percentile === "weight-for-age" && percentile === "") { - const lmsValues = this.getLMSValues(this.sexAtBirth, percentileField); - const weight = this.getX(thirdPercentileZScore, lmsValues); - return val < weight; - } - if (warning.percentile === "weight-for-length" && percentile === "") { - const lmsValues = this.getWeightForLengthLMSValues(this.sexAtBirth); - const weight = this.getX(zScore, lmsValues); - return avgWeight < weight; + if (percentile === "") { + if (warning.percentile === "weight-for-age") { + return val < this.getX(thirdPercentileZScore, this.getLMSValues(this.sexAtBirth, percentileField)); + } + if (warning.percentile === "weight-for-length") { + return avgWeight < this.getX(twoThirdPercentileZScore, this.getWeightForLengthLMSValues(this.sexAtBirth)); + } } return percentile !== "" && parseFloat(percentile) < warning.min; } From eab29e8359a1af45f1812ab5ef6744ca351080e2 Mon Sep 17 00:00:00 2001 From: Shyam Date: Fri, 1 Dec 2023 14:06:03 -0600 Subject: [PATCH 6/7] Display right weight-for-length/age warnings on save --- .../js/views/PhysicalEvaluation-0.3-peds.js | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js index 709916102..1a48aabca 100644 --- a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js +++ b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js @@ -616,12 +616,20 @@ let viewExtension = Backbone.View.extend({ // Fallback calculation if weight-for-age/weight-for-length percentile can't be calculated if (percentileMale === "" || percentileFemale === "") { if (warning.percentile === "weight-for-age") { - conditionMale = percentileMale === "" && val < this.getX(thirdPercentileZScore, this.getLMSValues(1, percentileField)); - conditionFemale = percentileFemale === "" && val < this.getX(thirdPercentileZScore, this.getLMSValues(2, percentileField)); + conditionMale = + percentileMale === "" && + val < this.getX(thirdPercentileZScore, this.getLMSValues(1, percentileField)); + conditionFemale = + percentileFemale === "" && + val < this.getX(thirdPercentileZScore, this.getLMSValues(2, percentileField)); } if (warning.percentile === "weight-for-length") { - conditionMale = percentileMale === "" && avgWeight < this.getX(twoThirdPercentileZScore, this.getWeightForLengthLMSValues(1)); - conditionFemale = percentileFemale === "" && avgWeight < this.getX(twoThirdPercentileZScore, this.getWeightForLengthLMSValues(2)); + conditionMale = + percentileMale === "" && + avgWeight < this.getX(twoThirdPercentileZScore, this.getWeightForLengthLMSValues(1)); + conditionFemale = + percentileFemale === "" && + avgWeight < this.getX(twoThirdPercentileZScore, this.getWeightForLengthLMSValues(2)); } if (conditionMale || conditionFemale) { return true; @@ -637,7 +645,10 @@ let viewExtension = Backbone.View.extend({ return val < this.getX(thirdPercentileZScore, this.getLMSValues(this.sexAtBirth, percentileField)); } if (warning.percentile === "weight-for-length") { - return avgWeight < this.getX(twoThirdPercentileZScore, this.getWeightForLengthLMSValues(this.sexAtBirth)); + return ( + avgWeight < + this.getX(twoThirdPercentileZScore, this.getWeightForLengthLMSValues(this.sexAtBirth)) + ); } } return percentile !== "" && parseFloat(percentile) < warning.min; @@ -690,7 +701,18 @@ let viewExtension = Backbone.View.extend({ let val = input.val(); $.each(warnings, function (key, warning) { if (!warning.consecutive && self.warningConditionMet(warning, val)) { - container.append($('
').text(warning.message)); + if ( + (warning.hasOwnProperty("percentile") && warning.percentile === "weight-for-length") || + warning.percentile === "bmi-for-age" + ) { + $("#" + warning.percentile + "-warning").html(warning.message); + return true; + } else { + container.append($('
').text(warning.message)); + } + if (warning.hasOwnProperty("percentile") && warning.percentile === "weight-for-age") { + return true; + } return false; // only show first (highest priority) warning } }); From 64987351870140d7cbe83eb103822e8cb1f7b0a2 Mon Sep 17 00:00:00 2001 From: Shyam Date: Mon, 4 Dec 2023 13:59:08 -0600 Subject: [PATCH 7/7] Handle multiple field warning messages --- web/assets/js/views/PhysicalEvaluation-0.3-peds.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js index 1a48aabca..733cb3799 100644 --- a/web/assets/js/views/PhysicalEvaluation-0.3-peds.js +++ b/web/assets/js/views/PhysicalEvaluation-0.3-peds.js @@ -797,6 +797,9 @@ let viewExtension = Backbone.View.extend({ return; } let val = input.val(); + if (val === "") { + this.displayWarnings(); + } if (this.warnings[field]) { let warned = false; $.each(this.warnings[field], function (key, warning) {