From 60d4ffd2276f04558125d04dfa458e9b409667e2 Mon Sep 17 00:00:00 2001 From: Lars Olesen Date: Fri, 18 Oct 2019 19:30:21 +0000 Subject: [PATCH] Changed cooper test --- assets/js/cooper.js | 130 ++++++++++++++++++++++++++++++++++++++++++++ test/test.js | 15 +++-- 2 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 assets/js/cooper.js diff --git a/assets/js/cooper.js b/assets/js/cooper.js new file mode 100644 index 000000000000..253531d7291a --- /dev/null +++ b/assets/js/cooper.js @@ -0,0 +1,130 @@ +let motionsplan = {}; + +motionsplan.CooperClinicMortalityRiskIndex = function(age, hr, bloodpressure, diabetes, smoker, bmi, fitness) +{ + var age, hr, bloodpressure, diabetes, smoker, bmi, fitness; + + age = age; + hr = hr; + bloodpressure = bloodpressure; + diabetes = diabetes; + smoker = smoker; + bmi = bmi; + fitness = fitness; + + function getRisk() + { + var risk; + var point = getRiskPoint(); + if (point == 0) { + risk = 1.8; + } + else if (point == 1) { + risk = 2.2; + } + else if (point == 2) { + risk = 2.6; + } + else if (point == 3) { + risk = 3.1; + } + else if (point == 4) { + risk = 3.7; + } + else if (point == 5) { + risk = 4.4; + } + else if (point == 6) { + risk = 5.4; + } + else if (point == 7) { + risk = 6.5; + } + else if (point == 8) { + risk = 7.9; + } + else if (point == 9) { + risk = 9.7; + } + else if (point == 10) { + risk = 11.8; + } + else if (point == 11) { + risk = 14; + } + else if (point == 12) { + risk = 16.5; + } + else if (point == 13) { + risk = 20.4; + } + else if (point == 14) { + risk = 23.2; + } + else if (point == 15) { + risk = 28.1; + } + else if (point == 16) { + risk = 32.1; + } + else { + risk = 46.7; + } + + return risk; + } + + function getRiskPoint() + { + var point, alderpoint; + if (age == -1) { + alderpoint = 0; + } + else { + alderpoint = age; + } + point = alderpoint + hr + bloodpressure + diabetes + smoker + bmi + fitness; + return point; + } + + function getRisk3() + { + var risk2, risk3; + var risk = getRisk(); + if (age == -1) { + risk2 = risk / 2.4; + } + else if (age == 0) { + risk2 = risk / 2.6; + } + else if (age == 3) { + risk2 = risk / 4.6; + } + else if (age == 6) { + risk2 = risk / 8.2; + } + else if (age == 8) { + risk2 = risk / 12.6; + } + else if (age == 9) { + risk2 = risk / 16.1; + } + else { + risk2 = risk / 18.1; + } + risk3 = Math.round((risk2) * Math.pow(10, 1)) / Math.pow(10, 1); + return risk3; + } + + var publicAPI = { + getRiskPoint : getRiskPoint, + getRisk : getRisk, + getRisk3 : getRisk3 + + }; + + // To be returned upon creation of a new instance. + return publicAPI; +} + +module.exports = motionsplan; diff --git a/test/test.js b/test/test.js index 9306fc5eef47..00defb4b4eda 100644 --- a/test/test.js +++ b/test/test.js @@ -1,8 +1,15 @@ +require('../assets/js/cooper.js'); + var assert = require('assert'); -describe('Array', function() { - describe('#indexOf()', function() { - it('should return -1 when the value is not present', function() { - assert.equal([1, 2, 3].indexOf(4), -1); +describe('CooperClinicMortalityRiskIndex', function() { + describe('getRiskPoint', function() { + it('should return the correct number', function() { + + // age, heart rate, blood pressure, diabetes, smoker, bmi, fitness + var cooper = motionsplan.CooperClinicMortalityRiskIndex(40, 120, 0, 4, 0, 24, 56); + assert.equal(cooper.getRiskPoint(), 0.8); + assert.equal(cooper.getRisk(), 1); + assert.equal(cooper.getRisk3(), 4); }); }); });