Skip to content

Commit

Permalink
Merge branch 'release-4.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamzcode committed Dec 6, 2023
2 parents e3d2789 + c96c750 commit 2cc196f
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 35 deletions.
4 changes: 4 additions & 0 deletions src/Form/PediatricMeasurementType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
if (isset($field->decimals)) {
$fieldOptions['scale'] = $field->decimals;
}
if (isset($field->inputType)) {
$attributes['data-parsley-type'] = $field->inputType;
$attributes['data-parsley-type-message'] = 'Please enter a valid whole number';
}
if (isset($field->max)) {
$constraints[] = new Constraints\LessThan($field->max);
$attributes['data-parsley-lt'] = $field->max;
Expand Down
1 change: 1 addition & 0 deletions src/Model/Measurement/versions/0.3.3-peds-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
"unit": "bpm",
"replicates": 3,
"max": 300,
"inputType": "integer",
"warnings": [
{
"age": [0, 11],
Expand Down
1 change: 1 addition & 0 deletions src/Model/Measurement/versions/0.3.3-peds-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@
"unit": "bpm",
"replicates": 3,
"max": 300,
"inputType": "integer",
"warnings": [
{
"max": 175,
Expand Down
3 changes: 3 additions & 0 deletions src/Model/Measurement/versions/0.3.3-peds-3.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@
"unit": "mmHg",
"replicates": 3,
"max": 300,
"inputType": "integer",
"warnings": [
{
"addValue": 30,
Expand Down Expand Up @@ -382,6 +383,7 @@
"unit": "mmHg",
"replicates": 3,
"max": 300,
"inputType": "integer",
"compare": {
"type": "less-than",
"field": "blood-pressure-systolic",
Expand Down Expand Up @@ -449,6 +451,7 @@
"unit": "bpm",
"replicates": 3,
"max": 300,
"inputType": "integer",
"warnings": [
{
"max": 175,
Expand Down
3 changes: 3 additions & 0 deletions src/Model/Measurement/versions/0.3.3-peds-4.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
"unit": "mmHg",
"replicates": 3,
"max": 300,
"inputType": "integer",
"warnings": [
{
"addValue": 30,
Expand Down Expand Up @@ -383,6 +384,7 @@
"unit": "mmHg",
"replicates": 3,
"max": 300,
"inputType": "integer",
"compare": {
"type": "less-than",
"field": "blood-pressure-systolic",
Expand Down Expand Up @@ -450,6 +452,7 @@
"unit": "bpm",
"replicates": 3,
"max": 300,
"inputType": "integer",
"warnings": [
{
"age": [12, 72],
Expand Down
142 changes: 107 additions & 35 deletions web/assets/js/views/PhysicalEvaluation-0.3-peds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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("<strong>" + mean + "</strong>");
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 + ")");
Expand All @@ -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;
Expand All @@ -124,8 +126,34 @@ let viewExtension = Backbone.View.extend({
}
},
calculatePercentile: function (field, X, sex) {
const lmsValues = this.getLMSValues(sex, field);
const percentileElement = this.$("#percentile-" + sex + "-" + field);
const zScore = X ? this.getZScore(X, lmsValues) : "";
console.log(field, "Zscore", zScore);
percentileElement.attr("data-zscore", zScore);
const percentile = zScore ? this.getPercentile(zScore) : "";
console.log("percentile", percentile);
percentileElement.html("<strong>" + this.addPercentileSuffix(percentile) + "</strong>");
percentileElement.attr("data-percentile", percentile);
this.handleOutOfRangePercentileWarning();
},
calculateWeightForLengthPercentile: function (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) : "";
console.log("weight-for-length", "Zscore", zScore);
percentileElement.attr("data-zscore", zScore);
const percentile = zScore ? this.getPercentile(zScore) : "";
percentileElement.html("<strong>" + this.addPercentileSuffix(percentile) + "</strong>");
percentileElement.attr("data-percentile", percentile);
this.handleOutOfRangePercentileWarning();
},
getLMSValues: function (sex, field) {
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) {
Expand All @@ -135,21 +163,13 @@ let viewExtension = Backbone.View.extend({
}
});
console.log(field, "lms", lmsValues);
const percentileElement = this.$("#percentile-" + sex + "-" + field);
const zScore = this.getZScore(X, lmsValues);
console.log(field, "Zscore", zScore);
percentileElement.attr("data-zscore", zScore);
const percentile = this.getPercentile(zScore);
console.log("percentile", percentile);
percentileElement.html("<strong>" + this.addPercentileSuffix(percentile) + "</strong>");
percentileElement.attr("data-percentile", percentile);
this.handleOutOfRangePercentileWarning();
return lmsValues;
},
calculateWeightForLengthPercentile: function (sex) {
let avgWeight = parseFloat($("#mean-weight").attr("data-mean"));
let avgLength = parseFloat($("#mean-height").attr("data-mean"));
getWeightForLengthLMSValues: function (sex) {
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)) {
Expand All @@ -158,16 +178,9 @@ 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("<strong>" + this.addPercentileSuffix(percentile) + "</strong>");
percentileElement.attr("data-percentile", percentile);
this.handleOutOfRangePercentileWarning();
}
console.log("weight-for-length", "lms", lmsValues);
return lmsValues;
},
getZScore: function (X, lmsValues) {
const L = parseFloat(lmsValues["L"]);
Expand Down Expand Up @@ -219,6 +232,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;
Expand Down Expand Up @@ -585,14 +607,50 @@ let viewExtension = Backbone.View.extend({
if (warning.hasOwnProperty("percentile")) {
let percentileField = warning.percentile;
let percentileMale, percentileFemale, conditionMale, conditionFemale;
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 (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 (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;
}
}
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 === "") {
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;
}
if (warning.hasOwnProperty("age")) {
Expand Down Expand Up @@ -643,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($('<div class="metric-warnings text-warning">').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($('<div class="metric-warnings text-warning">').text(warning.message));
}
if (warning.hasOwnProperty("percentile") && warning.percentile === "weight-for-age") {
return true;
}
return false; // only show first (highest priority) warning
}
});
Expand Down Expand Up @@ -728,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) {
Expand Down

0 comments on commit 2cc196f

Please sign in to comment.