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'); util = require('util');
//Mongoose Models //Mongoose Models
var FieldSchema = require('./form_field.server.model.js'), var FormSubmissionSchema = require('./form_submission.server.model.js'),
FormSubmissionSchema = require('./form_submission.server.model.js'), FieldSchema = require('./form_field.server.model.js'),
Field = mongoose.model('Field', FieldSchema), Field = mongoose.model('Field', FieldSchema),
FormSubmission = mongoose.model('FormSubmission', FormSubmissionSchema) FormSubmission = mongoose.model('FormSubmission', FormSubmissionSchema);
var ButtonSchema = new Schema({ var ButtonSchema = new Schema({
url: { url: {
@ -41,7 +41,7 @@ var ButtonSchema = new Schema({
/** /**
* Form Schema * Form Schema
*/ */
var LogicJumpSchema = new Schema({ var FormSchema = new Schema({
created: { created: {
type: Date, type: Date,
default: Date.now default: Date.now
@ -64,9 +64,10 @@ var LogicJumpSchema = new Schema({
type: String, type: String,
default: '', default: '',
}, },
form_fields: { form_fields: [Field],
type: [FieldSchema], //form_fields: {
}, // type: [FieldSchema],
//},
submissions: [{ submissions: [{
type: Schema.Types.ObjectId, type: Schema.Types.ObjectId,
@ -139,12 +140,42 @@ var LogicJumpSchema = new Schema({
}, },
font: String, font: String,
backgroundImage: { type: Schema.Types.Mixed } 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 //Delete template PDF of current Form
LogicJumpSchema.pre('remove', function (next) { FormSchema.pre('remove', function (next) {
if(this.pdf && process.env.NODE_ENV === 'development'){ if(this.pdf && process.env.NODE_ENV === 'development'){
//Delete template form //Delete template form
fs.unlink(this.pdf.path, function(err){ fs.unlink(this.pdf.path, function(err){
@ -157,7 +188,7 @@ LogicJumpSchema.pre('remove', function (next) {
var _original; var _original;
//Set _original //Set _original
LogicJumpSchema.pre('save', function (next) { FormSchema.pre('save', function (next) {
// console.log(this.constructor.model); // console.log(this.constructor.model);
// console.log(FormModel); // console.log(FormModel);
this.constructor // ≈ mongoose.model('…', FieldSchema).findById this.constructor // ≈ mongoose.model('…', FieldSchema).findById
@ -175,7 +206,7 @@ LogicJumpSchema.pre('save', function (next) {
}); });
//Update lastModified and created everytime we save //Update lastModified and created everytime we save
LogicJumpSchema.pre('save', function (next) { FormSchema.pre('save', function (next) {
var now = new Date(); var now = new Date();
this.lastModified = now; this.lastModified = now;
if( !this.created ){ if( !this.created ){
@ -198,7 +229,7 @@ function getDeletedIndexes(needle, haystack){
} }
//Move PDF to permanent location after new template is uploaded //Move PDF to permanent location after new template is uploaded
LogicJumpSchema.pre('save', function (next) { FormSchema.pre('save', function (next) {
if(this.pdf){ if(this.pdf){
var that = this; var that = this;
async.series([ async.series([
@ -311,7 +342,7 @@ LogicJumpSchema.pre('save', function (next) {
next(); next();
}); });
LogicJumpSchema.pre('save', function (next) { FormSchema.pre('save', function (next) {
// var _original = this._original; // var _original = this._original;
// console.log('_original\n------------'); // console.log('_original\n------------');
// console.log(_original); // console.log(_original);
@ -445,21 +476,4 @@ LogicJumpSchema.pre('save', function (next) {
} }
}); });
// LogicJumpSchema.methods.generateFDFTemplate = function() { mongoose.model('Form', FormSchema);
// 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);

View file

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

View file

@ -11,7 +11,37 @@ var mongoose = require('mongoose'),
config = require('../../config/config'), config = require('../../config/config'),
path = require('path'), path = require('path'),
fs = require('fs-extra'), 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 * Form Submission Schema
@ -30,7 +60,7 @@ var FormSubmissionSchema = new Schema({
ref: 'User', ref: 'User',
required: true required: true
}, },
form_fields: [Schema.Types.Mixed],//[FieldSchema], form_fields: [Field],
form: { form: {
type:Schema.Types.ObjectId, type:Schema.Types.ObjectId,
ref:'Form', ref:'Form',
@ -59,13 +89,84 @@ var FormSubmissionSchema = new Schema({
}, },
percentageComplete: { percentageComplete: {
type: Number, type: Number,
},
//TODO: DAVID: Need to not have this hardcoded
oscarDemoNum: {
type: Number,
} }
}); });
//Mongoose Relationship initialization //Oscarhost API hook
// FormSubmissionSchema.plugin(relationship, { relationshipPathName:'form' }); 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 //Check for IP Address of submitting person
FormSubmissionSchema.pre('save', function (next){ FormSubmissionSchema.pre('save', function (next){
@ -79,7 +180,6 @@ FormSubmissionSchema.pre('save', function (next){
}); });
} }
} }
// console.log('ipAddr check');
next(); next();
}); });
@ -108,9 +208,8 @@ FormSubmissionSchema.pre('save', function (next) {
} else { } else {
next(); next();
} }
}); });
module.exports = FormSubmissionSchema; module.exports = FormSubmissionSchema;
// mongoose.model('FormSubmission', FormSubmissionSchema); //mongoose.model('FormSubmission', FormSubmissionSchema);

View file

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

View file

@ -1,189 +1,260 @@
// 'use strict'; 'use strict';
// /** /**
// * Module dependencies. * Module dependencies.
// */ */
// var should = require('should'), var should = require('should'),
// mongoose = require('mongoose'), mongoose = require('mongoose'),
// User = mongoose.model('User'), User = mongoose.model('User'),
// Form = mongoose.model('Form'), Form = mongoose.model('Form'),
// _ = require('lodash'), _ = require('lodash'),
// FormSubmission = mongoose.model('FormSubmission'); config = require('../../config/config'),
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();
// });
// });
// });
// describe('Test FormField and Submission Logic', function() { var exampleDemo = {
// var new_form_fields_add1, new_form_fields_del, submission_fields, old_fields, form; 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); * Globals
// new_form_fields_add1.push( */
// {'fieldType':'textfield', 'title':'Last Name', 'fieldValue': ''} 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 = _.clone(myForm.toObject().form_fields);
// submission_fields[0].fieldValue = 'David'; submission_fields[0].fieldValue = 'David';
// submission_fields[1].fieldValue = true; submission_fields[1].fieldValue = true;
// submission_fields[2].fieldValue = true; submission_fields[2].fieldValue = true;
// mySubmission = new FormSubmission({ mySubmission = new FormSubmission({
// form_fields: submission_fields, form_fields: submission_fields,
// admin: user, admin: user,
// form: myForm, form: myForm,
// timeElapsed: 17.55 timeElapsed: 17.55
// }); });
// }); });
// beforeEach(function(done){ beforeEach(function(done){
// myForm.save(function(){ myForm.save(function(){
// mySubmission.save(function(){ mySubmission.save(function(){
// done(); done();
// }); });
// }); });
// }); });
// afterEach(function(done){ afterEach(function(done){
// mySubmission.remove(function(){ mySubmission.remove(function(){
// done(); 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; // old_fields = myForm.toObject().form_fields;
// // // console.log(old_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.not.exist(err);
// // should.exist(_form); // should.exist(_form);
// // // var actual_fields = _.map(_form.toObject().form_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')}); // // old_fields = _.map(old_fields, function(o){ _.omit(o, '_id')});
// // // console.log(old_fields); // // 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'); // should.deepEqual(JSON.stringify(_form.toObject().form_fields), JSON.stringify(old_fields), 'old form_fields not equal to newly saved form_fields');
// // done(); // 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.form_fields = new_form_fields_del;
// // myForm.save(function(err, form // myForm.save(function(err, form
// // should.not.exist(err); // should.not.exist(err);
// // (form.form_fields).should.be.eql(old_fields, 'old form_fields not equal to newly saved form_fields'); // (form.form_fields).should.be.eql(old_fields, 'old form_fields not equal to newly saved form_fields');
// // //Remove submission // //Remove submission
// // mySubmission.remove(function(err){ // mySubmission.remove(function(err){
// // myForm.submissions.should.have.length(0); // myForm.submissions.should.have.length(0);
// // myForm.form_fields.should.not.containDeep(old_fields[0]); // myForm.form_fields.should.not.containDeep(old_fields[0]);
// // }); // });
// // }); // });
// // }); // });
// }); });
// // describe('Method generateFDFTemplate', function() { describe('Submission of Form should add Patient to OscarHost', function() {
// // var FormFDF; var mySubmission;
// // before(function(done){ before(function(done){
// // return myForm.save(function(err, form){ myForm.form_fields = [
new Field({'fieldType':'textfield', 'title':'What\'s your first name', 'fieldValue': ''}),
// // FormFDF = { new Field({'fieldType':'textfield', 'title':'And your last name', 'fieldValue': ''}),
// // 'First Name': '', 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': ''}),
// // 'nascar': '', new Field({'fieldType':'date', 'title':'When were you born?', 'fieldValue': ''}),
// // 'hockey': '' new Field({'fieldType':'number', 'title':'What\'s your phone #?', 'fieldValue': ''}),
// // }; ];
// // done(); 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() { myForm.plugins.oscarhost = {
// // var fdfTemplate = myForm.generateFDFTemplate(); baseUrl: config.oscarhost.baseUrl,
// // (fdfTemplate).should.be.eql(FormFDF); settings: {
// // }); lookupField: '',
// // }); updateType: 'force_add',
fieldMap: myFieldMap,
},
auth: config.oscarhost.auth,
};
// afterEach(function(done) { myForm.save(function(err, form){
// Form.remove().exec(function() { if(err) done(err);
// User.remove().exec(done);
// }); 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'), // mongoose = require('mongoose'),
// User = mongoose.model('User'), // User = mongoose.model('User'),
// Form = mongoose.model('Form'), // Form = mongoose.model('Form'),
// Field = mongoose.model('Field'),
// FormSubmission = mongoose.model('FormSubmission'), // FormSubmission = mongoose.model('FormSubmission'),
// agent = request.agent(app); // agent = request.agent(app);
@ -52,9 +53,9 @@
// language: 'english', // language: 'english',
// admin: user._id, // admin: user._id,
// form_fields: [ // form_fields: [
// {'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''}, // new Field({'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''}),
// {'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''}, // new Field({'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''}),
// {'fieldType':'checkbox', 'title':'hockey', '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'), // var should = require('should'),
_ = require('lodash'), // _ = require('lodash'),
app = require('../../server'), // app = require('../../server'),
request = require('supertest'), // request = require('supertest'),
Session = require('supertest-session')({ // Session = require('supertest-session')({
app: app // app: app
}), // }),
mongoose = require('mongoose'), // mongoose = require('mongoose'),
User = mongoose.model('User'), // User = mongoose.model('User'),
config = require('../../config/config'), // config = require('../../config/config'),
tmpUser = mongoose.model(config.tempUserCollection), // tmpUser = mongoose.model(config.tempUserCollection),
agent = request.agent(app), // agent = request.agent(app),
url = require('url'); // url = require('url');
var mailosaur = require('mailosaur')(config.mailosaur.key), // var mailosaur = require('mailosaur')(config.mailosaur.key),
mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id); // 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 // * Globals
*/ // */
var credentials, _User, _Session; // var credentials, _User, _Session;
/** // /**
* Form routes tests // * Form routes tests
*/ // */
describe('User CRUD tests', function() { // describe('User CRUD tests', function() {
this.timeout(15000); // this.timeout(15000);
var userSession; // var userSession;
beforeEach(function() { // beforeEach(function() {
//Initialize Session // //Initialize Session
userSession = new Session(); // userSession = new Session();
// Create user credentials // // Create user credentials
credentials = { // credentials = {
username: 'be1e58fb@mailosaur.in', // username: 'be1e58fb@mailosaur.in',
password: 'password' // password: 'password'
}; // };
// Create a new user // // Create a new user
_User = { // _User = {
firstName: 'Full', // firstName: 'Full',
lastName: 'Name', // lastName: 'Name',
email: credentials.username, // email: credentials.username,
username: credentials.username, // username: credentials.username,
password: credentials.password, // password: credentials.password,
}; // };
}); // });
// describe('Create, Verify and Activate a User', function() { // // describe('Create, Verify and Activate a User', function() {
var username = 'testActiveAccount.be1e58fb@mailosaur.in'; // var username = 'testActiveAccount.be1e58fb@mailosaur.in';
var link, _tmpUser, activateToken = ''; // var link, _tmpUser, activateToken = '';
it('should be able to create a temporary (non-activated) User', function(done) { // it('should be able to create a temporary (non-activated) User', function(done) {
_User.email = _User.username = username; // _User.email = _User.username = username;
request(app).post('/auth/signup') // request(app).post('/auth/signup')
.send(_User) // .send(_User)
.expect(200, 'An email has been sent to you. Please check it to verify your account.') // .expect(200, 'An email has been sent to you. Please check it to verify your account.')
.end(function(FormSaveErr, FormSaveRes) { // .end(function(FormSaveErr, FormSaveRes) {
// (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.'); // // (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.');
done(); // done();
// tmpUser.findOne({username: _User.username}, function (err, user) { // // tmpUser.findOne({username: _User.username}, function (err, user) {
// should.not.exist(err); // // should.not.exist(err);
// should.exist(user); // // should.exist(user);
// _tmpUser = user; // // _tmpUser = user;
// _User.username.should.equal(user.username); // // _User.username.should.equal(user.username);
// _User.firstName.should.equal(user.firstName); // // _User.firstName.should.equal(user.firstName);
// _User.lastName.should.equal(user.lastName); // // _User.lastName.should.equal(user.lastName);
// // mandrill('/messages/search', { // // // mandrill('/messages/search', {
// // query: "subject:Confirm", // // // query: "subject:Confirm",
// // senders: [ // // // senders: [
// // "test@forms.polydaic.com" // // // "test@forms.polydaic.com"
// // ], // // // ],
// // limit: 1 // // // limit: 1
// // }, function(error, emails) { // // // }, function(error, emails) {
// // if (error) console.log( JSON.stringify(error) ); // // // if (error) console.log( JSON.stringify(error) );
// // var confirmation_email = emails[0]; // // // var confirmation_email = emails[0];
// // mandrill('/messages/content', { // // // mandrill('/messages/content', {
// // id: confirmation_email._id // // // id: confirmation_email._id
// // }, function(error, email) { // // // }, function(error, email) {
// // if (error) console.log( JSON.stringify(error) ); // // // if (error) console.log( JSON.stringify(error) );
// // // console.log(email); // // // // console.log(email);
// // var link = _(email.text.split('\n')).reverse().value()[1]; // // // var link = _(email.text.split('\n')).reverse().value()[1];
// // console.log(link); // // // console.log(link);
// // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0]; // // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0];
// // console.log('actual activateToken: '+ activateToken); // // // console.log('actual activateToken: '+ activateToken);
// // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL); // // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL);
// // done(); // // // done();
// // }); // // // });
// // }); // // // });
// // mailbox.getEmails(function(err, _emails) { // // // mailbox.getEmails(function(err, _emails) {
// // if(err) done(err); // // // if(err) done(err);
// // var emails = _emails; // // // var emails = _emails;
// // console.log('mailbox.getEmails:'); // // // console.log('mailbox.getEmails:');
// // console.log(emails[0].text.links); // // // console.log(emails[0].text.links);
// // var link = emails[0].text.links[0].href; // // // var link = emails[0].text.links[0].href;
// // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0]; // // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0];
// // console.log('actual activateToken: '+ activateToken); // // // console.log('actual activateToken: '+ activateToken);
// // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL); // // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL);
// // (activateToken).should.equal(user.GENERATED_VERIFYING_URL); // // // (activateToken).should.equal(user.GENERATED_VERIFYING_URL);
// // done(); // // // done();
// // }); // // // });
// }); // // });
}); // });
}); // });
// it('should be able to verify a User Account', function(done) { // // it('should be able to verify a User Account', function(done) {
// userSession.get('/auth/verify/'+activateToken) // // userSession.get('/auth/verify/'+activateToken)
// .expect(200) // // .expect(200)
// .end(function(VerifyErr, VerifyRes) { // // .end(function(VerifyErr, VerifyRes) {
// should.not.exist(VerifyErr); // // should.not.exist(VerifyErr);
// (VerifyRes.text).should.equal('User successfully verified'); // // (VerifyRes.text).should.equal('User successfully verified');
// done(); // // done();
// }); // // });
// }); // // });
// it('should receive confirmation email after verifying a User Account', function(done) { // // it('should receive confirmation email after verifying a User Account', function(done) {
// mailbox.getEmails(function(err, _emails) { // // mailbox.getEmails(function(err, _emails) {
// if(err) throw err; // // if(err) throw err;
// var email = _emails[0]; // // var email = _emails[0];
// // console.log('mailbox.getEmails:'); // // // console.log('mailbox.getEmails:');
// console.log(email); // // console.log(email);
// (email.subject).should.equal('Account successfully verified!'); // // (email.subject).should.equal('Account successfully verified!');
// done(); // // done();
// }); // // });
// }); // // });
// }); // // });
// it('should be able to login and logout a User', function (done) { // // it('should be able to login and logout a User', function (done) {
// var username = 'testActiveAccount.be1e58fb@mailosaur.in'; // // var username = 'testActiveAccount.be1e58fb@mailosaur.in';
// _User.email = _User.username = credentials.username = username; // // _User.email = _User.username = credentials.username = username;
// userSession.post('/auth/signup') // // userSession.post('/auth/signup')
// .send(_User) // // .send(_User)
// .expect(200) // // .expect(200)
// .end(function(FormSaveErr, FormSaveRes) { // // .end(function(FormSaveErr, FormSaveRes) {
// (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.'); // // (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.');
// userSession.post('/auth/signin') // // userSession.post('/auth/signin')
// .send(credentials) // // .send(credentials)
// .expect('Content-Type', /json/) // // .expect('Content-Type', /json/)
// .expect(200) // // .expect(200)
// .end(function(signinErr, signinRes) { // // .end(function(signinErr, signinRes) {
// // Handle signin error // // // Handle signin error
// if (signinErr) throw signinErr; // // if (signinErr) throw signinErr;
// userSession.get('/auth/signout') // // userSession.get('/auth/signout')
// .expect(200) // // .expect(200)
// .end(function(signoutErr, signoutRes) { // // .end(function(signoutErr, signoutRes) {
// // Handle signout error // // // Handle signout error
// if (signoutErr) throw signoutErr; // // 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) { // afterEach(function(done) {
User.remove().exec(function () { // User.remove().exec(function () {
tmpUser.remove().exec(function(){ // tmpUser.remove().exec(function(){
// mailbox.deleteAllEmail(function (err, body) { // // mailbox.deleteAllEmail(function (err, body) {
// if(err) throw err; // // if(err) throw err;
userSession.destroy(); // userSession.destroy();
done(); // 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'), var soap = require('soap'),
request = require('request'),
async = require('async'), async = require('async'),
demo = require('./test_headless'),
OscarSecurity = require('./OscarSecurity'); 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', var fakeDemo = {
url_demo = 'http://someurl.com/ws?wsdl', "activeCount": 1,
args_demo = {arg0: 12351235}, "address": "880-9650 Velit. St.",
args_login = {arg0: 'mylogin', arg1: 'mypassword'}; "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 = { var options = {
ignoredNamespaces: { ignoredNamespaces: {
@ -18,32 +46,49 @@ var options = {
async.waterfall([ async.waterfall([
function (callback) { function (callback) {
//Authenticate with API
soap.createClient(url_login, options, function(err, client) { soap.createClient(url_login, options, function(err, client) {
client.login(args_login, function (err, result) { client.login(args_login, function (err, result) {
if(err) callback(err); if(err) callback(err);
callback(null, result.return); 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) { function (security_obj, callback) {
//Get demographic
console.log(security_obj);
soap.createClient(url_demo, options, function(err, client) { soap.createClient(url_demo, options, function(err, client) {
client.setSecurity(new OscarSecurity(security_obj.securityId, security_obj.securityTokenKey) ); client.setSecurity(new OscarSecurity(security_obj.securityId, security_obj.securityTokenKey) );
client.getDemographic(args_demo, function (err, result) { client.getDemographic(args_demo, function (err, result) {
if(err) callback(err); if(err) callback(err);
console.log('My Demographic:')
console.log(result); 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) { ], function(err, result) {
if(err) throw err; if(err) throw err;
console.log(result); 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);
});
});