1
0

fixed merge conflicts in app/models and app/tests

This commit is contained in:
David Baldwynn 2015-10-06 13:24:02 -07:00
commit 6a9b8ee8a8
7 changed files with 435 additions and 52 deletions

View File

@ -67,9 +67,10 @@ var FormSchema = new Schema({
type: String,
default: '',
},
form_fields: {
type: [FieldSchema],
},
form_fields: [Field],
//form_fields: {
// type: [FieldSchema],
//},
submissions: [{
type: Schema.Types.ObjectId,

View File

@ -24,6 +24,7 @@ var FieldOptionSchema = new Schema({
},
});
/**
* FormField Schema
*/
@ -133,7 +134,6 @@ function validateFormFieldType(value) {
return false;
};
// var cloneFieldSchema = _.cloneDeep(FormFieldSchema);
mongoose.model('Field', FormFieldSchema);
module.exports = FormFieldSchema;

View File

@ -18,31 +18,31 @@ var mongoose = require('mongoose'),
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': ''
"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": ""
};
/**
@ -58,9 +58,12 @@ var FormSubmissionSchema = new Schema({
ref: 'User',
required: true
},
form_fields: {
type: [Schema.Types.Mixed],
},
// form_fields: [Field],
form: {
type: Schema.Types.ObjectId,
ref: 'Form',
@ -193,9 +196,7 @@ FormSubmissionSchema.pre('save', function (next) {
}else{
next();
}
});
});
//Check for IP Address of submitting person

View File

@ -12,6 +12,45 @@ var should = require('should'),
config = require('../../config/config'),
FormSubmission = mongoose.model('FormSubmission');
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'
}
/**
* Globals
*/
@ -23,7 +62,6 @@ var user, myForm, mySubmission;
describe('Form Model Unit Tests:', function() {
beforeEach(function(done) {
user = new User({
firstName: 'Full',
lastName: 'Name',
@ -34,13 +72,7 @@ describe('Form Model Unit Tests:', function() {
provider: 'local'
});
user.save(function(err) {
if(err){
console.log(err.errors);
done(err);
}
user.save(function() {
myForm = new Form({
title: 'Form Title',
admin: user,
@ -59,26 +91,18 @@ describe('Form Model Unit Tests:', function() {
describe('Method Save', function() {
it('should be able to save without problems', function(done) {
myForm.save(function(err) {
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 = 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': ''}
]
});
var _form = myForm;
_form.title = '';
_form.save(function(err) {
return _form.save(function(err) {
should.exist(err);
should.equal(err.errors.title.message, 'Form Title cannot be blank');
done();
@ -101,7 +125,141 @@ describe('Form Model Unit Tests:', function() {
});
});
});
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;
mySubmission = new FormSubmission({
form_fields: submission_fields,
admin: user,
form: myForm,
timeElapsed: 17.55
});
});
beforeEach(function(done){
myForm.save(function(){
mySubmission.save(function(){
done();
});
});
});
afterEach(function(done){
mySubmission.remove(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);
// // var expected_fields = old_fields.slice(1,3).concat(old_fields.slice(0,1));
// myForm.form_fields = new_form_fields_del;
// myForm.save(function(err, _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')});
// // 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) {
// 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]);
// });
// });
// });
});
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';
myForm.plugins.oscarhost = {
baseUrl: config.oscarhost.baseUrl,
settings: {
lookupField: '',
updateType: 'force_add',
fieldMap: myFieldMap,
},
auth: config.oscarhost.auth,
};
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

@ -102,6 +102,7 @@
// // // });
<<<<<<< HEAD
// // mailbox.getEmails(function(err, _emails) {
// // if(err) done(err);

View File

@ -0,0 +1,108 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.oscarehr.org/">
<soapenv:Header/>
<soapenv:Body>
<ws:addDemographic>
<!--Optional:-->
<arg0>
<!-- <activeCount>1</activeCount>-->
<!--Optional:-->
<address>2286 Ottawa</address>
<!--Optional:-->
<!-- <alias>?</alias>-->
<!--Optional:-->
<!-- <anonymous>?</anonymous>-->
<!--Optional:-->
<!-- <chartNo>?</chartNo>-->
<!--Optional:-->
<!-- <children>?</children>-->
<!--Optional:-->
<!-- <citizenship>?</citizenship>-->
<!--Optional:-->
<city>West Vancouver</city>
<!--Optional:-->
<!-- <dateJoined></dateJoined>-->
<!--Optional:-->
<dateOfBirth>06</dateOfBirth>
<!--Optional:-->
<!-- <demographicNo>?</demographicNo>-->
<!--Optional:-->
<displayName>TestUserAddDemographic</displayName>
<!--Optional:-->
<!-- <effDate></effDate>-->
<!--Optional:-->
<email>polydaic@gmail.com</email>
<!--Optional:-->
<!-- <endDate></endDate>-->
<!--Optional:-->
<!-- <familyDoctor> </familyDoctor>-->
<!--Optional:-->
<firstName>TestUser</firstName>
<!--Optional:-->
<!-- <hcRenewDate></hcRenewDate>-->
<!--Optional:-->
<!-- <hcType></hcType>-->
<!--Optional:-->
<!-- <headRecord></headRecord>-->
<!--Optional:-->
<!-- <hin></hin>-->
<!-- <hsAlertCount>0</hsAlertCount>-->
<!--Optional:-->
<lastName>AddDemographic</lastName>
<!--Optional:-->
<lastUpdateDate>2015-10-01T18:39:46.817Z</lastUpdateDate>
<!--Optional:-->
<!-- <lastUpdateUser> </lastUpdateUser>-->
<!--Optional:-->
<!-- <links> </links>-->
<!--Optional:-->
<monthOfBirth>06</monthOfBirth>
<!--Optional:-->
<!-- <myOscarUserName> </myOscarUserName>-->
<!--Optional:-->
<!-- <officialLanguage> </officialLanguage>-->
<!--Optional:-->
<!-- <patientStatus> </patientStatus>-->
<!--Optional:-->
<!-- <patientStatusDate></patientStatusDate>-->
<!--Optional:-->
<!-- <pcnIndicator> </pcnIndicator>-->
<!--Optional:-->
<phone>6048786969</phone>
<!--Optional:-->
<!-- <phone2> </phone2>-->
<!--Optional:-->
<postal>V8V5S8</postal>
<!--Optional:-->
<!-- <previousAddress> </previousAddress>-->
<!--Optional:-->
<!-- <providerNo> </providerNo>-->
<!--Optional:-->
<province>BC</province>
<!--Optional:-->
<!-- <rosterDate></rosterDate>-->
<!--Optional:-->
<!-- <rosterStatus> </rosterStatus>-->
<!--Optional:-->
<!-- <rosterTerminationDate></rosterTerminationDate>-->
<!--Optional:-->
<!-- <rosterTerminationReason> </rosterTerminationReason>-->
<!--Optional:-->
<sex>M</sex>
<!--Optional:-->
<!-- <sexDesc> </sexDesc>-->
<!--Optional:-->
<!-- <sin> </sin>-->
<!--Optional:-->
<!-- <sourceOfIncome> </sourceOfIncome>-->
<!--Optional:-->
<!-- <spokenLanguage> </spokenLanguage>-->
<!--Optional:-->
<title>Mr.</title>
<!--Optional:-->
<!-- <ver> </ver>-->
<!--Optional:-->
<yearOfBirth>1994</yearOfBirth>
</arg0>
</ws:addDemographic>
</soapenv:Body>
</soapenv:Envelope>

View File

@ -0,0 +1,114 @@
var soap = require('soap'),
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: 'username', arg1: 'password'},
my_hin = 1234123123;
var fakeDemo = {
"activeCount": 1,
"address": "880-9650 Velit. St.",
"alias": "",
"anonymous": "",
"chartNo": "",
"children":"",
"citizenship":"Canadian",
"city": "Lloydminster",
"dateJoined": new Date(),
"dateOfBirth": "10",
"demographicNo": 90348,
"email": "Sed.nunc@dis.co.uk",
"firstName": "Uriah F.",
"hin": 9146509343,
"lastName": "Little",
"lastUpdateDate": new Date(),
"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 exampleDemo = {
activeCount: 1,
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' }
var options = {
ignoredNamespaces: {
namespaces: ['targetNamespace', 'typedNamespace'],
override: true
}
}
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) {
//Add demographic
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);
console.log(client.describe());
callback(null, result);
});
});
},
], function(err, result) {
if(err) throw err;
console.log(result);
});