qrisk2-2014
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -51,2 +51,8 @@ /* | ||
module.exports.isInSet = function(value, expected){ | ||
return expected.some(function(item){ | ||
return item === value; | ||
}); | ||
}; | ||
module.exports.isInRange = function (value, min, max) { | ||
@@ -53,0 +59,0 @@ return !(value < min || value > max); |
@@ -47,7 +47,7 @@ /* | ||
validate.propertyIsInRange('bmi', 20, 40), | ||
validate.propertyIsInRange('ethrisk', 1, 9), | ||
validate.propertyIsInSet('ethrisk', [1, 2, 3, 4, 5, 6, 7, 8, 9]), | ||
validate.propertyIsZeroOrOne('fh_cvd'), | ||
validate.propertyIsInRange('rati', 1, 12), | ||
validate.propertyIsInRange('sbp', 70, 210), | ||
validate.propertyIsInRange('smoke_cat', 0, 4), | ||
validate.propertyIsInSet('smoke_cat', [0, 1, 2, 3, 4]), | ||
validate.propertyHasValue('surv', 10), | ||
@@ -54,0 +54,0 @@ validate.propertyIsInRange('town', -7, 11) |
@@ -47,7 +47,7 @@ /* | ||
validate.propertyIsInRange('bmi', 20, 40), | ||
validate.propertyIsInRange('ethrisk', 1, 9), | ||
validate.propertyIsInSet('ethrisk', [1, 2, 3, 4, 5, 6, 7, 8, 9]), | ||
validate.propertyIsZeroOrOne('fh_cvd'), | ||
validate.propertyIsInRange('rati', 1, 12), | ||
validate.propertyIsInRange('sbp', 70, 210), | ||
validate.propertyIsInRange('smoke_cat', 0, 4), | ||
validate.propertyIsInSet('smoke_cat', [0, 1, 2, 3, 4]), | ||
validate.propertyHasValue('surv', 10), | ||
@@ -54,0 +54,0 @@ validate.propertyIsInRange('town', -7, 11) |
@@ -58,2 +58,14 @@ /* | ||
module.exports.propertyIsInSet = function(propertyName, expected) { | ||
return { | ||
getValue: function (object) { | ||
return object[propertyName] | ||
}, | ||
isMet: function (value) { | ||
return check.isInSet(value, expected); | ||
}, | ||
error: propertyName + ' must be in set [' + expected.join(' ') + ']' | ||
} | ||
}; | ||
module.exports.propertyIsZeroOrOne = function(propertyName) { | ||
@@ -60,0 +72,0 @@ return { |
{ | ||
"name": "qrisk2-2014", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "QRisk2-2014 10 year cardiovascular risk prediction algorithms", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -18,3 +18,3 @@ QRisk2-2014 | ||
An additional set of regression tests can be found at qrisk2-2014-regression | ||
An additional set of regression tests can be found at [qrisk2-2014-regression](https://github.com/BlackPearSw/qrisk2-2014-regression) | ||
@@ -21,0 +21,0 @@ Use |
@@ -81,3 +81,19 @@ /* | ||
describe('isInRange', function () { | ||
describe('isInSet', function () { | ||
it('should return false when input 5 and set is [1, 2, 3]', function () { | ||
var result = utils.isInSet(5, [1, 2, 3]); | ||
result.should.be.false; | ||
}); | ||
it('should return true when input 5 and set is [1, 2, 3, 4, 5]', function () { | ||
var result = utils.isInSet(5, [1, 2, 3, 4, 5]); | ||
result.should.be.true; | ||
}); | ||
}); | ||
describe('isInRange', function () { | ||
it('should return false when input 24 and range 25-84', function () { | ||
@@ -84,0 +100,0 @@ var result = utils.isInRange(24, 25, 84); |
@@ -19,2 +19,3 @@ /* | ||
var objectHasProperties = require('../lib/validation').objectHasProperties; | ||
var propertyIsInSet = require('../lib/validation').propertyIsInSet; | ||
var propertyIsInRange = require('../lib/validation').propertyIsInRange; | ||
@@ -40,7 +41,7 @@ var propertyIsZeroOrOne = require('../lib/validation').propertyIsZeroOrOne; | ||
propertyIsInRange('bmi', 20, 40), | ||
propertyIsInRange('ethrisk', 1, 9), | ||
propertyIsInSet('ethrisk', [1, 2, 3, 4, 5, 6, 7, 8, 9]), | ||
propertyIsZeroOrOne('fh_cvd'), | ||
propertyIsInRange('rati', 1, 12), | ||
propertyIsInRange('sbp', 70, 210), | ||
propertyIsInRange('smoke_cat', 0, 4), | ||
propertyIsInSet('smoke_cat', [0, 1, 2, 3, 4]), | ||
propertyHasValue('surv', 10), | ||
@@ -90,5 +91,2 @@ propertyIsInRange('town', -7, 11) | ||
{ | ||
field: 'ethrisk', min: 1, max: 9 | ||
}, | ||
{ | ||
field: 'rati', min: 1, max: 12 | ||
@@ -100,5 +98,2 @@ }, | ||
{ | ||
field: 'smoke_cat', min: 0, max: 4 | ||
}, | ||
{ | ||
field: 'town', min: -7, max: 11 | ||
@@ -150,3 +145,37 @@ } | ||
var categoricalFields = [ | ||
{ | ||
field: 'ethrisk', expected: [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
}, | ||
{ | ||
field: 'smoke_cat', expected: [0, 1, 2, 3, 4] | ||
} | ||
]; | ||
categoricalFields.forEach(function (params) { | ||
describe('should check ' + params.field + ' is in set [' + params.expected.join(' ') + ']', function () { | ||
var args; | ||
var msg = params.field + ' must be in set [' + params.expected.join(' ') + ']'; | ||
beforeEach(function () { | ||
args = makeValidArgs(); | ||
}); | ||
it('returning error when ' + params.field + ' is not in set', function () { | ||
args[params.field] = -999; | ||
var result = getValidationErrors(args, rules); | ||
expect(result).to.include(msg); | ||
}); | ||
it('returning no error when ' + params.field + ' is in set', function () { | ||
args[params.field] = params.expected[0]; | ||
var result = getValidationErrors(args, rules); | ||
expect(result).to.not.include(msg); | ||
}); | ||
}); | ||
}); | ||
var bitFields = ['b_AF', 'b_ra', 'b_renal', 'b_treatedhyp', 'b_type1', 'b_type2', 'fh_cvd']; | ||
@@ -153,0 +182,0 @@ bitFields.forEach(function (field) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65667
1154