started oscarhost API update

This commit is contained in:
David Baldwynn 2015-09-10 15:06:28 -07:00
parent b038e53ee1
commit f3c751f6c9
14 changed files with 11701 additions and 734 deletions

View file

@ -14,10 +14,10 @@ var mongoose = require('mongoose'),
util = require('util');
//Mongoose Models
var FieldSchema = require('./form_field.server.model.js'),
FormSubmissionSchema = require('./form_submission.server.model.js'),
var FormSubmissionSchema = require('./form_submission.server.model.js'),
FieldSchema = require('./form_field.server.model.js'),
Field = mongoose.model('Field', FieldSchema),
FormSubmission = mongoose.model('FormSubmission', FormSubmissionSchema)
FormSubmission = mongoose.model('FormSubmission', FormSubmissionSchema);
var ButtonSchema = new Schema({
url: {
@ -41,7 +41,7 @@ var ButtonSchema = new Schema({
/**
* Form Schema
*/
var LogicJumpSchema = new Schema({
var FormSchema = new Schema({
created: {
type: Date,
default: Date.now
@ -64,9 +64,10 @@ var LogicJumpSchema = new Schema({
type: String,
default: '',
},
form_fields: {
type: [FieldSchema],
},
form_fields: [Field],
//form_fields: {
// type: [FieldSchema],
//},
submissions: [{
type: Schema.Types.ObjectId,
@ -139,12 +140,42 @@ var LogicJumpSchema = new Schema({
},
font: String,
backgroundImage: { type: Schema.Types.Mixed }
},
plugins: {
oscarhost: {
baseUrl: {
type: String,
},
settings: {
lookupField: {
type: Schema.Types.ObjectId,
ref: 'Field'
},
updateType: {
type: String,
enum: ['upsert', 'force_add', 'force_update', 'fetch'],
},
fieldMap: {
type: Schema.Types.Mixed,
}
},
auth: {
user: {
type: String,
required: true,
},
pass: {
type: String,
required: true,
}
}
}
}
});
//Delete template PDF of current Form
LogicJumpSchema.pre('remove', function (next) {
FormSchema.pre('remove', function (next) {
if(this.pdf && process.env.NODE_ENV === 'development'){
//Delete template form
fs.unlink(this.pdf.path, function(err){
@ -157,7 +188,7 @@ LogicJumpSchema.pre('remove', function (next) {
var _original;
//Set _original
LogicJumpSchema.pre('save', function (next) {
FormSchema.pre('save', function (next) {
// console.log(this.constructor.model);
// console.log(FormModel);
this.constructor // ≈ mongoose.model('…', FieldSchema).findById
@ -175,7 +206,7 @@ LogicJumpSchema.pre('save', function (next) {
});
//Update lastModified and created everytime we save
LogicJumpSchema.pre('save', function (next) {
FormSchema.pre('save', function (next) {
var now = new Date();
this.lastModified = now;
if( !this.created ){
@ -198,7 +229,7 @@ function getDeletedIndexes(needle, haystack){
}
//Move PDF to permanent location after new template is uploaded
LogicJumpSchema.pre('save', function (next) {
FormSchema.pre('save', function (next) {
if(this.pdf){
var that = this;
async.series([
@ -311,7 +342,7 @@ LogicJumpSchema.pre('save', function (next) {
next();
});
LogicJumpSchema.pre('save', function (next) {
FormSchema.pre('save', function (next) {
// var _original = this._original;
// console.log('_original\n------------');
// console.log(_original);
@ -445,21 +476,4 @@ LogicJumpSchema.pre('save', function (next) {
}
});
// LogicJumpSchema.methods.generateFDFTemplate = function() {
// var _keys = _.pluck(this.form_fields, 'title'),
// _values = _.pluck(this.form_fields, 'fieldValue');
// _values.forEach(function(val){
// if(val === true){
// val = 'Yes';
// }else if(val === false) {
// val = 'Off';
// }
// });
// var jsonObj = _.zipObject(_keys, _values);
// return jsonObj;
// };
mongoose.model('LogicJump', LogicJumpSchema);
mongoose.model('Form', FormSchema);

View file

@ -4,19 +4,7 @@
* Module dependencies.
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
nools = require('nools');
// /**
// * LogicJump Schema
// */
// var LogicJump = new Schema({
// [
// ]
// type: Schema.Types.ObjectId,
// ref: 'FormSubmission'
// });
Schema = mongoose.Schema;
/**
* Question Schema
@ -124,7 +112,6 @@ function validateFormFieldType(value) {
return true;
}
return false;
}
};
module.exports = FormFieldSchema;
module.exports = FormFieldSchema;

View file

@ -11,7 +11,37 @@ var mongoose = require('mongoose'),
config = require('../../config/config'),
path = require('path'),
fs = require('fs-extra'),
FieldSchema = require('./form_field.server.model.js');
Field = mongoose.model('Field'),
soap = require('soap'),
OscarSecurity = require('../../scripts/oscarhost/OscarSecurity');
var newDemoTemplate = {
"activeCount": 0,
"address": "",
"alias": "",
"anonymous": "",
"chartNo": "",
"children":"",
"citizenship":"",
"city": "",
"dateJoined": null,
"dateOfBirth": "",
"email": "",
"firstName": "",
"hin": 9146509343,
"lastName": "",
"lastUpdateDate": null,
"monthOfBirth": "",
"officialLanguage": "",
"phone": "",
"phone2": "",
"providerNo": 0,
"province": "",
"sex": "",
"spokenLanguage": "",
"postal": "",
"yearOfBirth": ""
};
/**
* Form Submission Schema
@ -30,7 +60,7 @@ var FormSubmissionSchema = new Schema({
ref: 'User',
required: true
},
form_fields: [Schema.Types.Mixed],//[FieldSchema],
form_fields: [Field],
form: {
type:Schema.Types.ObjectId,
ref:'Form',
@ -59,13 +89,84 @@ var FormSubmissionSchema = new Schema({
},
percentageComplete: {
type: Number,
},
//TODO: DAVID: Need to not have this hardcoded
oscarDemoNum: {
type: Number,
}
});
//Mongoose Relationship initialization
// FormSubmissionSchema.plugin(relationship, { relationshipPathName:'form' });
//Oscarhost API hook
FormSubmissionSchema.post('save', function (next) {
if(this.form.plugins.oscarhost.baseUrl){
var url_login = this.form.plugins.oscarhost.baseUrl+'/LoginService?wsdl',
url_demo = this.form.plugins.oscarhost.baseUrl+'/DemographicService?wsdl';
var options = {
ignoredNamespaces: {
namespaces: ['targetNamespace', 'typedNamespace'],
override: true
}
}
//Generate demographics from hashmap
var generateDemo = function(formFields, conversionMap, templateDemo){
var _generatedDemo = {};
for(var field in formFields){
if(templateDemo.hasOwnProperty(conversionMap[field._id])){
var propertyName = conversionMap[field._id];
if(propertyName === "unparsedDOB"){
var date = Date.parse(field.fieldValue);
generatedDemo['dateOfBirth'] = date.getDate();
generatedDemo['yearOfBirth'] = date.getFullYear();
generatedDemo['monthOfBirth'] = date.getMonth();
}else{
generatedDemo[propertyName] = field.fieldValue;
}
}
}
return _generatedDemo;
}
var submissionDemographic = generateDemo(this.form_fields, this.form.plugin.oscarhost.settings.fieldMap);
async.waterfall([
function (callback) {
//Authenticate with API
soap.createClient(url_login, options, function(err, client) {
client.login(args_login, function (err, result) {
if(err) callback(err);
callback(null, result.return);
});
});
},
function (security_obj, callback) {
//Force Add
if(this.plugins.oscarhost.settings.updateType === 'force_add'){
soap.createClient(url_demo, options, function(err, client) {
client.setSecurity(new OscarSecurity(security_obj.securityId, security_obj.securityTokenKey) );
client.addDemographic({ arg0: exampleDemo }, function (err, result) {
if(err) callback(err);
callback(null, result);
});
});
}
},
], function(err, result) {
if(err) throw err;
console.log(result);
this.oscarDemoNum = parseInt(result.return, 10);
});
}
});
//Check for IP Address of submitting person
FormSubmissionSchema.pre('save', function (next){
@ -79,7 +180,6 @@ FormSubmissionSchema.pre('save', function (next){
});
}
}
// console.log('ipAddr check');
next();
});
@ -108,9 +208,8 @@ FormSubmissionSchema.pre('save', function (next) {
} else {
next();
}
});
module.exports = FormSubmissionSchema;
// mongoose.model('FormSubmission', FormSubmissionSchema);
//mongoose.model('FormSubmission', FormSubmissionSchema);

View file

@ -6,12 +6,10 @@
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
_ = require('lodash'),
tree = require('mongoose-tree'),
math = require('math'),
deasync = require('fibers');
math = require('math');
var BooleanExpresssionSchema = new Schema({
var BooleanExpressionSchema = new Schema({
expressionString: {
type: String,
},
@ -29,7 +27,7 @@ BooleanExpresssionSchema.plugin(tree, {
});
*/
BooleanExpresssionSchema.methods.evaluate = function(){
BooleanExpressionSchema.methods.evaluate = function(){
//Get headNode
var headNode = math.parse(expressionString);
@ -40,7 +38,6 @@ BooleanExpresssionSchema.methods.evaluate = function(){
headNode.traverse(function (node, path, parent) {
if(node.type === 'SymbolNode'){
Fiber()
mongoose.model('Field')
.findOne({_id: node.name}).exec(function(err, field){
if(err) {
@ -64,9 +61,9 @@ BooleanExpresssionSchema.methods.evaluate = function(){
this.result = result;
return result;
});
};
mongoose.model('BooleanStatement', BooleanStatementSchema);
mongoose.model('BooleanExpression', BooleanExpressionSchema);
/**
* Form Schema
@ -87,4 +84,5 @@ var LogicJumpSchema = new Schema({
});
// return LogicJumpSchema;
mongoose.model('LogicJump', LogicJumpSchema);

View file

@ -1,189 +1,260 @@
// 'use strict';
'use strict';
// /**
// * Module dependencies.
// */
// var should = require('should'),
// mongoose = require('mongoose'),
// User = mongoose.model('User'),
// Form = mongoose.model('Form'),
// _ = require('lodash'),
// FormSubmission = mongoose.model('FormSubmission');
// /**
// * Globals
// */
// var user, myForm, mySubmission;
// /**
// * Unit tests
// */
// describe('Form Model Unit Tests:', function() {
// beforeEach(function(done) {
// user = new User({
// firstName: 'Full',
// lastName: 'Name',
// displayName: 'Full Name',
// email: 'test@test.com',
// username: 'username',
// password: 'password'
// });
// user.save(function() {
// myForm = new Form({
// title: 'Form Title',
// admin: user,
// language: 'english',
// form_fields: [
// {'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''},
// {'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''},
// {'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''}
// ]
// });
// done();
// });
// });
// describe('Method Save', function() {
// it('should be able to save without problems', function(done) {
// return myForm.save(function(err) {
// should.not.exist(err);
// done();
// });
// });
// it('should be able to show an error when try to save without title', function(done) {
// var _form = myForm;
// _form.title = '';
// return _form.save(function(err) {
// should.exist(err);
// should.equal(err.errors.title.message, 'Form Title cannot be blank');
// done();
// });
// });
// });
// describe('Method Find', function(){
// beforeEach(function(done){
// myForm.save(function(err) {
// done();
// });
// });
// it('should be able to findOne my form without problems', function(done) {
// return Form.findOne({_id: myForm._id}, function(err,form) {
// should.not.exist(err);
// should.exist(form);
// should.deepEqual(form.toObject(), myForm.toObject());
// done();
// });
// });
// });
/**
* Module dependencies.
*/
var should = require('should'),
mongoose = require('mongoose'),
User = mongoose.model('User'),
Form = mongoose.model('Form'),
_ = require('lodash'),
config = require('../../config/config'),
FormSubmission = mongoose.model('FormSubmission');
// describe('Test FormField and Submission Logic', function() {
// var new_form_fields_add1, new_form_fields_del, submission_fields, old_fields, form;
var exampleDemo = {
activeCount: 1,
unparsedDOB: '',
address: '880-9650 Velit. St.',
chartNo: '',
city: '',
dateJoined: Date.now(),
dateOfBirth: '10',
displayName: 'LITTLE, URIAH',
email: '',
familyDoctor: '<rdohip></rdohip><rd></rd>',
firstName: 'Uriah F.',
hcType: 'BC',
hin: '',
hsAlertCount: 0,
lastName: 'Little',
lastUpdateDate: Date.now(),
lastUpdateUser: '',
links: '',
monthOfBirth: '05',
officialLanguage: 'English',
patientStatus: 'AC',
patientStatusDate: Date.now(),
phone: '250-',
phone2: '',
postal: "S4M 7T8",
providerNo: '4',
province: 'BC',
rosterStatus: '',
sex: 'M',
sexDesc: 'Female',
sin: '',
spokenLanguage: 'English',
title: 'MS.',
yearOfBirth: '2015'
}
// before(function(){
// new_form_fields_add1 = _.clone(myForm.toObject().form_fields);
// new_form_fields_add1.push(
// {'fieldType':'textfield', 'title':'Last Name', 'fieldValue': ''}
// );
/**
* Globals
*/
var user, myForm, mySubmission;
// new_form_fields_del = _.clone(myForm.toObject().form_fields);
// new_form_fields_del.splice(0, 1);
/**
* Unit tests
*/
describe('Form Model Unit Tests:', function() {
beforeEach(function(done) {
user = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test@test.com',
username: 'username',
password: 'password'
});
user.save(function() {
myForm = new Form({
title: 'Form Title',
admin: user,
language: 'english',
});
myForm.form_fields.push({fieldType:'textfield', title:'First Name'});
myForm.form_fields.push({fieldType:'checkbox', title:'nascar'});
myForm.form_fields.push({fieldType:'checkbox', title:'hockey'});
done();
});
});
describe('Method Save', function() {
it('should be able to save without problems', function(done) {
return myForm.save(function(err) {
should.not.exist(err);
done();
});
});
it('should be able to show an error when try to save without title', function(done) {
var _form = myForm;
_form.title = '';
return _form.save(function(err) {
should.exist(err);
should.equal(err.errors.title.message, 'Form Title cannot be blank');
done();
});
});
});
describe('Method Find', function(){
beforeEach(function(done){
myForm.save(function(err) {
done();
});
});
it('should be able to findOne my form without problems', function(done) {
return Form.findOne({_id: myForm._id}, function(err,form) {
should.not.exist(err);
should.exist(form);
should.deepEqual(form.toObject(), myForm.toObject());
done();
});
});
});
describe('Test FormField and Submission Logic', function() {
var new_form_fields_add1, new_form_fields_del, submission_fields, old_fields, form;
before(function(){
new_form_fields_add1 = _.clone(myForm.toObject().form_fields);
new_form_fields_add1.push(
{'fieldType':'textfield', 'title':'Last Name', 'fieldValue': ''}
);
new_form_fields_del = _.clone(myForm.toObject().form_fields);
new_form_fields_del.splice(0, 1);
// submission_fields = _.clone(myForm.toObject().form_fields);
// submission_fields[0].fieldValue = 'David';
// submission_fields[1].fieldValue = true;
// submission_fields[2].fieldValue = true;
submission_fields = _.clone(myForm.toObject().form_fields);
submission_fields[0].fieldValue = 'David';
submission_fields[1].fieldValue = true;
submission_fields[2].fieldValue = true;
// mySubmission = new FormSubmission({
// form_fields: submission_fields,
// admin: user,
// form: myForm,
// timeElapsed: 17.55
// });
mySubmission = new FormSubmission({
form_fields: submission_fields,
admin: user,
form: myForm,
timeElapsed: 17.55
});
// });
});
// beforeEach(function(done){
// myForm.save(function(){
// mySubmission.save(function(){
// done();
// });
// });
// });
beforeEach(function(done){
myForm.save(function(){
mySubmission.save(function(){
done();
});
});
});
// afterEach(function(done){
// mySubmission.remove(function(){
// done();
// });
// });
afterEach(function(done){
mySubmission.remove(function(){
done();
});
});
// // it('should preserve deleted form_fields that have submissions without any problems', function(done) {
// it('should preserve deleted form_fields that have submissions without any problems', function(done) {
// // old_fields = myForm.toObject().form_fields;
// // // console.log(old_fields);
// old_fields = myForm.toObject().form_fields;
// // console.log(old_fields);
// // // var expected_fields = old_fields.slice(1,3).concat(old_fields.slice(0,1));
// // var expected_fields = old_fields.slice(1,3).concat(old_fields.slice(0,1));
// // myForm.form_fields = new_form_fields_del;
// myForm.form_fields = new_form_fields_del;
// // myForm.save(function(err, _form) {
// myForm.save(function(err, _form) {
// // should.not.exist(err);
// // should.exist(_form);
// should.not.exist(err);
// should.exist(_form);
// // // var actual_fields = _.map(_form.toObject().form_fields, function(o){ _.omit(o, '_id')});
// // // old_fields = _.map(old_fields, function(o){ _.omit(o, '_id')});
// // var actual_fields = _.map(_form.toObject().form_fields, function(o){ _.omit(o, '_id')});
// // old_fields = _.map(old_fields, function(o){ _.omit(o, '_id')});
// // // console.log(old_fields);
// // should.deepEqual(JSON.stringify(_form.toObject().form_fields), JSON.stringify(old_fields), 'old form_fields not equal to newly saved form_fields');
// // done();
// // });
// // });
// // console.log(old_fields);
// should.deepEqual(JSON.stringify(_form.toObject().form_fields), JSON.stringify(old_fields), 'old form_fields not equal to newly saved form_fields');
// done();
// });
// });
// // it('should delete \'preserved\' form_fields whose submissions have been removed without any problems', function(done) {
// it('should delete \'preserved\' form_fields whose submissions have been removed without any problems', function(done) {
// // myForm.form_fields = new_form_fields_del;
// // myForm.save(function(err, form
// // should.not.exist(err);
// // (form.form_fields).should.be.eql(old_fields, 'old form_fields not equal to newly saved form_fields');
// myForm.form_fields = new_form_fields_del;
// myForm.save(function(err, form
// should.not.exist(err);
// (form.form_fields).should.be.eql(old_fields, 'old form_fields not equal to newly saved form_fields');
// // //Remove submission
// // mySubmission.remove(function(err){
// // myForm.submissions.should.have.length(0);
// // myForm.form_fields.should.not.containDeep(old_fields[0]);
// // });
// // });
// // });
// });
// //Remove submission
// mySubmission.remove(function(err){
// myForm.submissions.should.have.length(0);
// myForm.form_fields.should.not.containDeep(old_fields[0]);
// });
// });
// });
});
// // describe('Method generateFDFTemplate', function() {
// // var FormFDF;
// // before(function(done){
// // return myForm.save(function(err, form){
// // FormFDF = {
// // 'First Name': '',
// // 'nascar': '',
// // 'hockey': ''
// // };
// // done();
// // });
// // });
describe('Submission of Form should add Patient to OscarHost', function() {
var mySubmission;
before(function(done){
myForm.form_fields = [
new Field({'fieldType':'textfield', 'title':'What\'s your first name', 'fieldValue': ''}),
new Field({'fieldType':'textfield', 'title':'And your last name', 'fieldValue': ''}),
new Field({'fieldType':'radio', 'title':'And your sex', 'fieldOptions': [{ 'option_id': 0, 'option_title': 'Male', 'option_value': 'M' }, { 'option_id': 1, 'option_title': 'Female', 'option_value': 'F' }], 'fieldValue': ''}),
new Field({'fieldType':'date', 'title':'When were you born?', 'fieldValue': ''}),
new Field({'fieldType':'number', 'title':'What\'s your phone #?', 'fieldValue': ''}),
];
var myFieldMap = {};
myFieldMap[myForm.form_fields[0]._id] = 'firstName';
myFieldMap[myForm.form_fields[1]._id] = 'lastName';
myFieldMap[myForm.form_fields[2]._id] = 'sex';
myFieldMap[myForm.form_fields[3]._id] = 'unparsedDOB';
myFieldMap[myForm.form_fields[4]._id] = 'phone';
// // it('should be able to generate a FDF template without any problems', function() {
// // var fdfTemplate = myForm.generateFDFTemplate();
// // (fdfTemplate).should.be.eql(FormFDF);
// // });
// // });
myForm.plugins.oscarhost = {
baseUrl: config.oscarhost.baseUrl,
settings: {
lookupField: '',
updateType: 'force_add',
fieldMap: myFieldMap,
},
auth: config.oscarhost.auth,
};
// afterEach(function(done) {
// Form.remove().exec(function() {
// User.remove().exec(done);
// });
// });
// });
myForm.save(function(err, form){
if(err) done(err);
var submission_fields = _.clone(myForm.toObject().form_fields);
submission_fields[0].fieldValue = 'David';
submission_fields[1].fieldValue = 'Baldwynn'+Date.now();
submission_fields[2].fieldValue = 'M';
submission_fields[3].fieldValue = Date.now();
submission_fields[4].fieldValue = 6043158008;
mySubmission = new FormSubmission({
form_fields: submission_fields,
admin: form.admin,
form: form,
timeElapsed: 17.55
});
done();
});
});
it('should be able to submit a valid form without problems', function(done) {
mySubmission.save(function(err, submission) {
should.not.exist(err);
should.exist(submission.oscarDemoNum);
done();
});
});
});
afterEach(function(done) {
Form.remove().exec(function() {
User.remove().exec(done);
});
});
});

View file

@ -10,6 +10,7 @@
// mongoose = require('mongoose'),
// User = mongoose.model('User'),
// Form = mongoose.model('Form'),
// Field = mongoose.model('Field'),
// FormSubmission = mongoose.model('FormSubmission'),
// agent = request.agent(app);
@ -52,9 +53,9 @@
// language: 'english',
// admin: user._id,
// form_fields: [
// {'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''},
// {'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''},
// {'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''}
// new Field({'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''}),
// new Field({'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''}),
// new Field({'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''})
// ]
// };

View file

@ -0,0 +1,70 @@
// 'use strict';
// var should = require('should'),
// mongoose = require('mongoose'),
// math = require('math'),
// Form = mongoose.model('Form'),
// LogicJump = mongoose.model('LogicJump'),
// BooleanƒExpression = mongoose.model('BooleanExpression'),
// Field = mongoose.model('Field');
// /**
// * Globals
// */
// var textField;
// /**
// * Form routes tests
// */
// describe('LogicJump Tests', function() {
// beforeEach(function(done) {
// textField = new Field({
// title: 'First Name',
// fieldType: 'textfield',
// fieldValue: 'David',
// });
// textField.save(function(err){
// if(err) done(err);
// done();
// });
// });
// describe('BooleanExpression', function(){
// var scope;
// beforeEach(function(){
// scope = {
// x: false,
// y: true,
// b: 5,
// a: 3
// }
// });
// it('should evaluate a simple boolean expression to be true', function(){
// var expression = 'and( or( x, y), (b > a))';
// var code = math.parse(expression);
// var actual = code.compile().eval(scope);
// // var expected = ( (false || true) && !!(5 > 3) );
// actual.should.equal(true);
// });
// afterEach(function(done){
// BooleanExpression.remove().exec(function() {
// done();
// });
// });
// });
// afterEach(function(done) {
// Field.remove().exec(function() {
// done();
// });
// });
// });

View file

@ -1,324 +0,0 @@
var RuleEngine = require('node-rules'),
should = require('should'),
rules = require('../../docs/Node-Rules/rules.logic-jump');
describe('Logic-Jump Rules Tests', function() {
describe('StringRules', function(){
describe('Contains Rule', function(){
it('should be TRUTHY if right IS a substring of left', function(done){
//initialize the rule engine
R = new RuleEngine(rules.StringRules.Contains);
//sample fact to run the rules on
var fact = {
left:"userblahblahnamenaoeuaoe",
right:"user",
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(true);
done();
});
});
it('should be FALSEY if right IS NOT a substring of left', function(done){
//initialize the rule engine
R = new RuleEngine(rules.StringRules.Contains);
//sample fact to run the rules on
var fact = {
left:"userblahblahnamenaoeuaoe",
right:"user1",
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(false);
done();
});
});
});
describe('NotContains Rule', function(){
it('should be TRUTHY if right IS NOT a substring of left', function(done){
//initialize the rule engine
R = new RuleEngine(rules.StringRules.NotContains);
//sample fact to run the rules on
var fact = {
"left":"userblahblahnamenaoeuaoe",
"right":"user1oe",
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(true);
done();
});
});
it('should be FALSEY if right IS a substring of left', function(done){
//initialize the rule engine
R = new RuleEngine(rules.StringRules.NotContains);
//sample fact to run the rules on
var fact = {
"left":"userblahblahnamenaoeuaoe",
"right":"user",
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(false);
done();
});
});
});
describe('BeginsWith Rule', function(){
it('should be TRUTHY if Left string DOES begin with Right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.StringRules.BeginsWith);
//sample fact to run the rules on
var fact = {
"left":"userblahblahnamenaoeuaoe",
"right":"user",
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(true);
done();
});
});
it('should be FALSEY if left DOES NOT begin with right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.StringRules.BeginsWith);
//sample fact to run the rules on
var fact = {
"left":"userblahblahnamenaoeuaoe",
"right":"euaoe",
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(false);
done();
});
});
});
describe('EndsWith Rule', function(){
it('should be TRUTHY if Left string DOES end with Right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.StringRules.EndsWith);
//sample fact to run the rules on
var fact = {
"left":"userblahblahnamenaoeuaoe",
"right":"euaoe",
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(true);
done();
});
});
it('should be FALSEY if left DOES NOT end with right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.StringRules.EndsWith);
//sample fact to run the rules on
var fact = {
"left":"userblahblahnamenaoeuaoe",
"right":"userb",
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(false);
done();
});
});
});
});
describe('NumberRules', function(){
describe('GreaterThan Rule', function(){
it('NumberRules.GreaterThan rule should be TRUTHY if left > right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.NumberRules.GreaterThan);
//sample fact to run the rules on
var fact = {
left:100,
right:5,
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(true);
done();
});
});
it('NumberRules.GreaterThan rule should be FALSEY if left < right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.NumberRules.GreaterThan);
//sample fact to run the rules on
var fact = {
left:100,
right:1000,
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(false);
done();
});
});
});
describe('SmallerThan Rule', function(){
it('should be TRUTHY if left < right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.NumberRules.SmallerThan);
//sample fact to run the rules on
var fact = {
left:100,
right:1000,
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(true);
done();
});
});
it('should be FALSEY if left > right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.NumberRules.SmallerThan);
//sample fact to run the rules on
var fact = {
left:100,
right:5,
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(false);
done();
});
});
});
describe('GreaterThanOrEqual Rule', function(){
it('should be TRUTHY if left == right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.NumberRules.GreaterThanOrEqual);
//sample fact to run the rules on
var fact = {
left:100,
right:100,
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(true);
done();
});
});
it('should be TRUTHY if left > right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.NumberRules.GreaterThanOrEqual);
//sample fact to run the rules on
var fact = {
left:100,
right:5,
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(true);
done();
});
});
it('should be FALSEY if left < right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.NumberRules.GreaterThanOrEqual);
//sample fact to run the rules on
var fact = {
left:100,
right:1000,
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(false);
done();
});
});
});
describe('SmallerThanOrEqual Rule', function(){
it('should be TRUTHY if left === right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.NumberRules.SmallerThanOrEqual);
//sample fact to run the rules on
var fact = {
left:100,
right:100,
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(true);
done();
});
});
it('should be FALSEY if left > right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.NumberRules.SmallerThanOrEqual);
//sample fact to run the rules on
var fact = {
left:100,
right:5,
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(false);
done();
});
});
it('should be TRUTHY if left < right', function(done){
//initialize the rule engine
R = new RuleEngine(rules.NumberRules.SmallerThanOrEqual);
//sample fact to run the rules on
var fact = {
left:100,
right:1000,
};
//Now pass the fact on to the rule engine for results
R.execute(fact,function(result){
result.result.should.equal(true);
done();
});
});
});
});
});

View file

@ -1,195 +1,195 @@
'use strict';
// 'use strict';
var should = require('should'),
_ = require('lodash'),
app = require('../../server'),
request = require('supertest'),
Session = require('supertest-session')({
app: app
}),
mongoose = require('mongoose'),
User = mongoose.model('User'),
config = require('../../config/config'),
tmpUser = mongoose.model(config.tempUserCollection),
agent = request.agent(app),
url = require('url');
// var should = require('should'),
// _ = require('lodash'),
// app = require('../../server'),
// request = require('supertest'),
// Session = require('supertest-session')({
// app: app
// }),
// mongoose = require('mongoose'),
// User = mongoose.model('User'),
// config = require('../../config/config'),
// tmpUser = mongoose.model(config.tempUserCollection),
// agent = request.agent(app),
// url = require('url');
var mailosaur = require('mailosaur')(config.mailosaur.key),
mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id);
// var mailosaur = require('mailosaur')(config.mailosaur.key),
// mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id);
var mandrill = require('node-mandrill')(config.mailer.options.auth.pass);
// var mandrill = require('node-mandrill')(config.mailer.options.auth.pass);
/**
* Globals
*/
var credentials, _User, _Session;
// /**
// * Globals
// */
// var credentials, _User, _Session;
/**
* Form routes tests
*/
describe('User CRUD tests', function() {
this.timeout(15000);
var userSession;
// /**
// * Form routes tests
// */
// describe('User CRUD tests', function() {
// this.timeout(15000);
// var userSession;
beforeEach(function() {
//Initialize Session
userSession = new Session();
// beforeEach(function() {
// //Initialize Session
// userSession = new Session();
// Create user credentials
credentials = {
username: 'be1e58fb@mailosaur.in',
password: 'password'
};
// // Create user credentials
// credentials = {
// username: 'be1e58fb@mailosaur.in',
// password: 'password'
// };
// Create a new user
_User = {
firstName: 'Full',
lastName: 'Name',
email: credentials.username,
username: credentials.username,
password: credentials.password,
};
});
// // Create a new user
// _User = {
// firstName: 'Full',
// lastName: 'Name',
// email: credentials.username,
// username: credentials.username,
// password: credentials.password,
// };
// });
// describe('Create, Verify and Activate a User', function() {
var username = 'testActiveAccount.be1e58fb@mailosaur.in';
var link, _tmpUser, activateToken = '';
// // describe('Create, Verify and Activate a User', function() {
// var username = 'testActiveAccount.be1e58fb@mailosaur.in';
// var link, _tmpUser, activateToken = '';
it('should be able to create a temporary (non-activated) User', function(done) {
_User.email = _User.username = username;
request(app).post('/auth/signup')
.send(_User)
.expect(200, 'An email has been sent to you. Please check it to verify your account.')
.end(function(FormSaveErr, FormSaveRes) {
// (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.');
done();
// tmpUser.findOne({username: _User.username}, function (err, user) {
// should.not.exist(err);
// should.exist(user);
// _tmpUser = user;
// it('should be able to create a temporary (non-activated) User', function(done) {
// _User.email = _User.username = username;
// request(app).post('/auth/signup')
// .send(_User)
// .expect(200, 'An email has been sent to you. Please check it to verify your account.')
// .end(function(FormSaveErr, FormSaveRes) {
// // (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.');
// done();
// // tmpUser.findOne({username: _User.username}, function (err, user) {
// // should.not.exist(err);
// // should.exist(user);
// // _tmpUser = user;
// _User.username.should.equal(user.username);
// _User.firstName.should.equal(user.firstName);
// _User.lastName.should.equal(user.lastName);
// // _User.username.should.equal(user.username);
// // _User.firstName.should.equal(user.firstName);
// // _User.lastName.should.equal(user.lastName);
// // mandrill('/messages/search', {
// // query: "subject:Confirm",
// // senders: [
// // "test@forms.polydaic.com"
// // ],
// // limit: 1
// // }, function(error, emails) {
// // if (error) console.log( JSON.stringify(error) );
// // // mandrill('/messages/search', {
// // // query: "subject:Confirm",
// // // senders: [
// // // "test@forms.polydaic.com"
// // // ],
// // // limit: 1
// // // }, function(error, emails) {
// // // if (error) console.log( JSON.stringify(error) );
// // var confirmation_email = emails[0];
// // // var confirmation_email = emails[0];
// // mandrill('/messages/content', {
// // id: confirmation_email._id
// // }, function(error, email) {
// // if (error) console.log( JSON.stringify(error) );
// // // mandrill('/messages/content', {
// // // id: confirmation_email._id
// // // }, function(error, email) {
// // // if (error) console.log( JSON.stringify(error) );
// // // console.log(email);
// // var link = _(email.text.split('\n')).reverse().value()[1];
// // console.log(link);
// // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0];
// // console.log('actual activateToken: '+ activateToken);
// // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL);
// // // // console.log(email);
// // // var link = _(email.text.split('\n')).reverse().value()[1];
// // // console.log(link);
// // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0];
// // // console.log('actual activateToken: '+ activateToken);
// // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL);
// // done();
// // // done();
// // });
// // });
// // // });
// // // });
// // mailbox.getEmails(function(err, _emails) {
// // if(err) done(err);
// // // mailbox.getEmails(function(err, _emails) {
// // // if(err) done(err);
// // var emails = _emails;
// // // var emails = _emails;
// // console.log('mailbox.getEmails:');
// // console.log(emails[0].text.links);
// // // console.log('mailbox.getEmails:');
// // // console.log(emails[0].text.links);
// // var link = emails[0].text.links[0].href;
// // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0];
// // console.log('actual activateToken: '+ activateToken);
// // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL);
// // (activateToken).should.equal(user.GENERATED_VERIFYING_URL);
// // // var link = emails[0].text.links[0].href;
// // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0];
// // // console.log('actual activateToken: '+ activateToken);
// // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL);
// // // (activateToken).should.equal(user.GENERATED_VERIFYING_URL);
// // done();
// // });
// });
});
});
// // // done();
// // // });
// // });
// });
// });
// it('should be able to verify a User Account', function(done) {
// userSession.get('/auth/verify/'+activateToken)
// .expect(200)
// .end(function(VerifyErr, VerifyRes) {
// should.not.exist(VerifyErr);
// (VerifyRes.text).should.equal('User successfully verified');
// done();
// });
// });
// // it('should be able to verify a User Account', function(done) {
// // userSession.get('/auth/verify/'+activateToken)
// // .expect(200)
// // .end(function(VerifyErr, VerifyRes) {
// // should.not.exist(VerifyErr);
// // (VerifyRes.text).should.equal('User successfully verified');
// // done();
// // });
// // });
// it('should receive confirmation email after verifying a User Account', function(done) {
// mailbox.getEmails(function(err, _emails) {
// if(err) throw err;
// var email = _emails[0];
// // it('should receive confirmation email after verifying a User Account', function(done) {
// // mailbox.getEmails(function(err, _emails) {
// // if(err) throw err;
// // var email = _emails[0];
// // console.log('mailbox.getEmails:');
// console.log(email);
// (email.subject).should.equal('Account successfully verified!');
// done();
// });
// });
// });
// // // console.log('mailbox.getEmails:');
// // console.log(email);
// // (email.subject).should.equal('Account successfully verified!');
// // done();
// // });
// // });
// // });
// it('should be able to login and logout a User', function (done) {
// var username = 'testActiveAccount.be1e58fb@mailosaur.in';
// _User.email = _User.username = credentials.username = username;
// userSession.post('/auth/signup')
// .send(_User)
// .expect(200)
// .end(function(FormSaveErr, FormSaveRes) {
// (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.');
// // it('should be able to login and logout a User', function (done) {
// // var username = 'testActiveAccount.be1e58fb@mailosaur.in';
// // _User.email = _User.username = credentials.username = username;
// // userSession.post('/auth/signup')
// // .send(_User)
// // .expect(200)
// // .end(function(FormSaveErr, FormSaveRes) {
// // (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.');
// userSession.post('/auth/signin')
// .send(credentials)
// .expect('Content-Type', /json/)
// .expect(200)
// .end(function(signinErr, signinRes) {
// // userSession.post('/auth/signin')
// // .send(credentials)
// // .expect('Content-Type', /json/)
// // .expect(200)
// // .end(function(signinErr, signinRes) {
// // Handle signin error
// if (signinErr) throw signinErr;
// // // Handle signin error
// // if (signinErr) throw signinErr;
// userSession.get('/auth/signout')
// .expect(200)
// .end(function(signoutErr, signoutRes) {
// // userSession.get('/auth/signout')
// // .expect(200)
// // .end(function(signoutErr, signoutRes) {
// // Handle signout error
// if (signoutErr) throw signoutErr;
// // // Handle signout error
// // if (signoutErr) throw signoutErr;
// (signoutRes.text).should.equal('Successfully logged out');
// // (signoutRes.text).should.equal('Successfully logged out');
// done();
// });
// });
// });
// });
// // done();
// // });
// // });
// // });
// // });
// it('should be able to reset a User\'s password');
// // it('should be able to reset a User\'s password');
// it('should be able to delete a User account without any problems');
// // it('should be able to delete a User account without any problems');
afterEach(function(done) {
User.remove().exec(function () {
tmpUser.remove().exec(function(){
// mailbox.deleteAllEmail(function (err, body) {
// if(err) throw err;
userSession.destroy();
done();
// });
});
});
});
});
// afterEach(function(done) {
// User.remove().exec(function () {
// tmpUser.remove().exec(function(){
// // mailbox.deleteAllEmail(function (err, body) {
// // if(err) throw err;
// userSession.destroy();
// done();
// // });
// });
// });
// });
// });

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,13 +1,41 @@
var soap = require('soap'),
request = require('request'),
async = require('async'),
demo = require('./test_headless'),
OscarSecurity = require('./OscarSecurity');
var url_demo = 'https://secure2.oscarhost.ca/kensington/ws/DemographicService?wsdl',
url_login = 'https://secure2.oscarhost.ca/kensington/ws/LoginService?wsdl',
args_demo = {arg0: 0},
args_login = {arg0: 'davieb', arg1: 'Temppass1'},
my_hin = 9146489321;
var url_login = 'http://someurl.com/ws?wsdl',
url_demo = 'http://someurl.com/ws?wsdl',
args_demo = {arg0: 12351235},
args_login = {arg0: 'mylogin', arg1: 'mypassword'};
var fakeDemo = {
"activeCount": 1,
"address": "880-9650 Velit. St.",
"alias": "",
"anonymous": "",
"chartNo": 200000,
"children": "",
"hin": 9146509343,
"city": "Lloydminster",
"dateJoined": new Date(),
"dateOfBirth": "10",
"demographicNo": 90348,
"email": "Sed.nunc@dis.co.uk",
"familyDoctor": "<rdohip></rdohip><rd></rd>",
"firstName": "Uriah F.",
"lastName": "Little",
"monthOfBirth": "05",
"officialLanguage": "English",
"phone": "(306) 872-3210",
"phone2": "(306) 556-8264",
"providerNo": 4,
"province": "SK",
"sex": "F",
"spokenLanguage": "English",
"postal": "S4M 7T8",
"yearOfBirth": "2015"
};
var options = {
ignoredNamespaces: {
@ -18,32 +46,49 @@ var options = {
async.waterfall([
function (callback) {
//Authenticate with API
soap.createClient(url_login, options, function(err, client) {
client.login(args_login, function (err, result) {
if(err) callback(err);
callback(null, result.return);
});
});
},
function (security_obj, callback){
//Search by HIN for demographic number
demo.getDemoByHIN(my_hin, function(demo_num){
args_demo.arg0 = demo_num;
callback(null, security_obj)
});
},
function (security_obj, callback) {
console.log(security_obj);
//Get demographic
soap.createClient(url_demo, options, function(err, client) {
client.setSecurity(new OscarSecurity(security_obj.securityId, security_obj.securityTokenKey) );
client.getDemographic(args_demo, function (err, result) {
if(err) callback(err);
console.log('My Demographic:')
console.log(result);
callback(null, 'DemographicService');
callback(null, security_obj);
});
});
}
},
function (security_obj, callback) {
//Add demographic
soap.createClient(url_demo, options, function(err, client) {
client.setSecurity(new OscarSecurity(security_obj.securityId, security_obj.securityTokenKey) );
client.addDemographic(fakeDemo, function (err, result) {
if(err) callback(err);
callback(null, result);
});
});
},
], function(err, result) {
if(err) throw err;
console.log(result);
});

View file

@ -1,8 +0,0 @@
var soap = require('soap');
var url = 'http://example.com/wsdl?wsdl';
var args = {name: 'value'};
soap.createClient(url, function(err, client) {
client.MyFunction(args, function(err, result) {
console.log(result);
});
});