Permalink
Browse files

Merge pull request #53 from madanpiyush/master

RAXAJSS-46 Test for BMI
  • Loading branch information...
2 parents 67645a9 + 7a37682 commit 13ee2f8a16b0ac81feec914f5fed39f68d357ad5 @sunbiz sunbiz committed May 23, 2012
Showing with 129 additions and 56 deletions.
  1. +76 −27 src/registration/app/controller/Main.js
  2. +1 −1 src/registration/run-tests.html
  3. +52 −28 test/specs/registration/BmiPageSpec.js
@@ -6,7 +6,7 @@ Ext.define('RaxaEmr.Registration.controller.Main', {
config: {
control: {
'button[action=CalculateBmiAction]': {
- tap: 'CalculateBmiMethod'
+ tap: 'getBmiData'
}
},
@@ -17,40 +17,89 @@ Ext.define('RaxaEmr.Registration.controller.Main', {
searchPatientsForm: '#searchPatientsForm'
}
},
-
- //function to calculate bmi (from Bmi.js)
- CalculateBmiMethod: function () {
+ //get values from Bmi Form and calls neccessary methods to calculate BMI & display on Screen (from Bmi.js)
+ getBmiData: function () {
var weight_kg = parseInt(Ext.getCmp('weightId').getValue()); //Get Weight value from Form
var height_cm = parseInt(Ext.getCmp('heightCmId').getValue()); //Get Height(cm) value from Form
- var height_m = height_cm / 100; //Convert cm in to m
- var bmi = (weight_kg) / (height_m * height_m); //BMI Calculation
- var bmi_rounded = Math.round(bmi * 100) / 100; //Rouded till 2 digits
- Ext.getCmp('BMITextFieldId').setPlaceHolder(bmi_rounded); //Bmi displayed to user
- Ext.getCmp('bmiSlider').setValue(bmi); //Slider set to calculated Bmi
- // Bmi status from WHO Standards
- var WHO_BMI_UNDERWEIGHT = 18.5;
- var WHO_BMI_NORMAL = 25;
- var WHO_BMI_OVERWEIGHT = 30;
+ var bmiInfo = this.calculateBmi(weight_kg, height_cm);
+ this.updateBmiDisplay(bmiInfo.color, bmiInfo.status, bmiInfo.bmi_rounded, bmiInfo.bmi);
+ },
- if (bmi < WHO_BMI_UNDERWEIGHT) {
- this.updateBmiDisplay('red', 'Underweight');
- }
- if (bmi >= WHO_BMI_UNDERWEIGHT && bmi < WHO_BMI_NORMAL) {
- this.updateBmiDisplay('green', 'Normal');
- }
- if (bmi >= WHO_BMI_NORMAL && bmi < WHO_BMI_OVERWEIGHT) {
- this.updateBmiDisplay('blue', 'Overweight');
- }
- if (bmi >= WHO_BMI_OVERWEIGHT) {
- this.updateBmiDisplay('red', 'Obese');
- }
+ //function to calculate bmi
+ calculateBmi: function (weight_kg, height_cm) {
+ console.log('calculateBmi');
+ if (weight_kg == 0 || height_cm == 0) {
+ color = 'red';
+ bmi_rounded = 'Illegal';
+ bmi = 'Illegal';
+ if (weight_kg == 0 && height_cm == 0) {
+ status = 'Height & Weight cant be zero. Please check the entered values';
+ } else {
+ if (weight_kg == 0) {
+ status = 'Weight cant be zero. Please check the entered value';
+ }
+ if (height_cm == 0) {
+ status = 'Height cant be zero. Please check the entered value';
+ }
+ }
+
+ return {
+ color: color,
+ status: status,
+ bmi_rounded: bmi_rounded,
+ bmi: bmi
+ }
+ } else {
+ var height_m = height_cm / 100; //Convert cm in to m
+ var bmi = (weight_kg) / (height_m * height_m); //BMI Calculation
+ var bmi_rounded = Math.round(bmi * 100) / 100; //Rouded till 2 digits
+ // Bmi status from WHO Standards
+ var WHO_BMI_UNDERWEIGHT = 18.5;
+ var WHO_BMI_NORMAL = 25;
+ var WHO_BMI_OVERWEIGHT = 30;
+ var color = '';
+ var status = '';
+
+ if (bmi < WHO_BMI_UNDERWEIGHT) {
+ color = 'red';
+ status = 'Underweight';
+ }
+ if (bmi >= WHO_BMI_UNDERWEIGHT && bmi < WHO_BMI_NORMAL) {
+ color = 'green';
+ status = 'Normal';
+ }
+ if (bmi >= WHO_BMI_NORMAL && bmi < WHO_BMI_OVERWEIGHT) {
+ color = 'blue';
+ status = 'Overweight';
+ }
+ if (bmi >= WHO_BMI_OVERWEIGHT) {
+ color = 'red';
+ status = 'Obese';
+ }
+ if (bmi_rounded > 60.00 || bmi_rounded < 0.00) {
+ color = 'red';
+ status = 'Height & weight combination is illegal. Please check the values';
+ bmi_rounded = 'Illegal';
+ bmi = 'Illegal';
+ }
+ return {
+ color: color,
+ status: status,
+ bmi_rounded: bmi_rounded,
+ bmi: bmi
+ };
+
+ }
},
- updateBmiDisplay: function (color, bmiStatusText) {
+ updateBmiDisplay: function (color, bmiStatusText, bmi_rounded, bmi) {
var updatedHtml = '<div align="center" style="color:' + color + '"><b>BMI Status: ' + bmiStatusText + '</div>';
Ext.getCmp('BmiStatusId').setHtml(updatedHtml);
+ Ext.getCmp('BMITextFieldId').setValue(bmi_rounded); //Bmi displayed to user
+ Ext.getCmp('BMITextFieldId').setReadOnly(1);
+ Ext.getCmp('bmiSlider').setValue(bmi); //Slider set to calculated Bmi
},
init: function () {
@@ -129,4 +178,4 @@ Ext.define('RaxaEmr.Registration.controller.Main', {
wasPatientFound = (rec === null) ? "No patient found" : "Patient found";
alert("Searching for patient with first name = '" + query + "'..." + wasPatientFound);
}
-});
+});
@@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="../../test/lib/jasmine-1.1.0/jasmine.css">
<!-- Sencha library -->
- <script type="text/javascript" src="../lib/touch/builds/sencha-touch-all-debug.js"></script>
+ <script type="text/javascript" src="../lib/touch/sencha-touch-all-debug.js"></script>
<!-- Jasmine Test framework -->
<script type="text/javascript" src="../../test/lib/jasmine-1.1.0/jasmine.js"></script>
@@ -22,30 +22,61 @@ describe("Bmi", function () {
// BMI warning messages
it("Displays low BMI warning if bmi <= LOW_BMI", function () {
- // TODO: Set BMI <= LOW_BMI
- // var LOW_BMI = 20;
- // expect(isBmiLow(LOW_BMI)).toBeTruthy();
- // expect(false).toBeTruthy();
+ var height = 166;
+ var weight = 30;
+ var expectedStatus = 'Underweight';
+ var returnedtatus = mainController.calculateBmi(weight, height).status;
+ expect(returnedtatus).toEqual(expectedStatus);
});
it("Displays no BMI warning if LOW_BMI < bmi < HIGH_BMI", function () {
- // expect(false).toBeTruthy();
+ var height = 166;
+ var weight = 65;
+ var expectedStatus = 'Normal';
+ var returnedtatus = mainController.calculateBmi(weight, height).status;
+ expect(returnedtatus).toEqual(expectedStatus);
});
it("Displays high BMI warning if bmi >= HIGH_BMI", function () {
- // expect(false).toBeTruthy();
+ var height = 166;
+ var weight = 75;
+ var expectedStatus = 'Overweight';
+ var returnedtatus = mainController.calculateBmi(weight, height).status;
+ expect(returnedtatus).toEqual(expectedStatus);
});
it("Throws an error if BMI is out of bounds", function () {
- // expect(false).toBeTruthy();
+ var height = 166;
+ var weight = 500;
+ var statusError = 'Height & weight combination is illegal. Please check the values';
+ expect(mainController.calculateBmi(weight, height).status).toEqual(statusError);
});
- // Color
- // if bmi falls in range [x_1,x_2] -> color = green
- // if bmi falls in range [x_1,x_2] -> color = yellow
- // ...
- // if bmi falls in range [x_1,x_2] -> color = red
- // Inputs
+ it("Displays error if entered height & weight is zero", function () {
+ var height = 0;
+ var weight = 0;
+ var expectedStatus = 'Height & Weight cant be zero. Please check the entered values';
+ var returnedtatus = mainController.calculateBmi(weight, height).status;
+ expect(returnedtatus).toEqual(expectedStatus);
+ });
+
+ it("Displays error if entered weight is zero", function () {
+ var height = 166;
+ var weight = 0;
+ var expectedStatus = 'Weight cant be zero. Please check the entered value';
+ var returnedtatus = mainController.calculateBmi(weight, height).status;
+ expect(returnedtatus).toEqual(expectedStatus);
+ });
+
+ it("Displays error if entered height is zero", function () {
+ var height = 0;
+ var weight = 45;
+ var expectedStatus = 'Height cant be zero. Please check the entered value';
+ var returnedtatus = mainController.calculateBmi(weight, height).status;
+ expect(returnedtatus).toEqual(expectedStatus);
+ });
+
+
it("Can input a value into the weight box", function () {
// expect(false).toBeTruthy();
});
@@ -67,17 +98,15 @@ describe("Bmi", function () {
// Functionality Verifications
/////////////////////////////////
// Verify that BMI calculator works
- it("if height = h_1 and weight = w_1, then BMI = bmi_1", function () {
- var height = 1;
- var weight = 2;
- var expectedBmi = 2;
- /*expect(calculateBmi(height, weight)).toEqual(expectedBmi);*/
+ it("if height = 166 and weight = 30, then BMI = 10.89", function () {
+ var height = 166;
+ var weight = 30;
+ var expectedBmi = 10.89;
+ var calculatedBmi = mainController.calculateBmi(weight, height); //.bmi_rounded;
+ expect(calculatedBmi.bmi_rounded).toEqual(expectedBmi);
});
- // verify if height = h_2, weight = w_2, then BMI => BMI_2
- // ...
- // verify if height = h_n, weight = w_n, then BMI => BMI_n
- // Verify Patient object is kept up-to-date
+
it("Verify that pressing submit button causes patient object to get updated BMI", function () {
/*expect(false).toBeTruthy();*/
});
@@ -87,9 +116,4 @@ describe("Bmi", function () {
/*expect(false).toBeTruthy();*/
});
- // TODO: Remove this. This is just an example to show how to hook into a
- // controller
- it("Verify example function returns true", function () {
- expect(mainController.testFunction()).toBeTruthy();
- });
-});
+});

0 comments on commit 13ee2f8

Please sign in to comment.