adding swagger
This commit is contained in:
parent
704a5474d1
commit
baf52c207b
|
@ -185,8 +185,6 @@ exports.createSubmission = function(req, res) {
|
|||
percentageComplete: req.body.percentageComplete
|
||||
});
|
||||
|
||||
if(!!form.plugins.oscarhost.baseUrl) submission.hasPlugins.oscarhost = true;
|
||||
|
||||
if(form.pdf) submission.pdf = form.pdf;
|
||||
|
||||
//Save submitter's IP Address
|
||||
|
@ -280,10 +278,7 @@ exports.create = function(req, res) {
|
|||
* Show the current form
|
||||
*/
|
||||
exports.read = function(req, res) {
|
||||
var validUpdateTypes= Form.schema.path('plugins.oscarhost.settings.updateType').enumValues;
|
||||
|
||||
var newForm = req.form.toJSON({virtuals : true});
|
||||
newForm.plugins.oscarhost.settings.validUpdateTypes = validUpdateTypes;
|
||||
|
||||
if (req.userId) {
|
||||
if(req.form.admin._id+'' === req.userId+''){
|
||||
|
@ -294,7 +289,7 @@ exports.read = function(req, res) {
|
|||
});
|
||||
}
|
||||
return res.json(newForm);
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,11 +92,6 @@ var FormSchema = new Schema({
|
|||
default: 'en',
|
||||
required: 'Form must have a language'
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
|
||||
analytics:{
|
||||
gaCode: {
|
||||
type: String
|
||||
|
@ -187,8 +182,7 @@ var FormSchema = new Schema({
|
|||
default: '#333'
|
||||
}
|
||||
},
|
||||
font: String,
|
||||
backgroundImage: { type: Schema.Types.Mixed }
|
||||
font: String
|
||||
},
|
||||
|
||||
plugins: {
|
||||
|
@ -367,11 +361,6 @@ FormSchema.pre('save', function (next) {
|
|||
}
|
||||
});
|
||||
}, function(cb) {
|
||||
//DAVID: TODO: Make this so we don't have to update the validFields property ever save
|
||||
if (that.plugins.oscarhost.hasOwnProperty('baseUrl')) {
|
||||
var validUpdateTypes = mongoose.model('Form').schema.path('plugins.oscarhost.settings.updateType').enumValues;
|
||||
that.plugins.oscarhost.settings.validUpdateTypes = validUpdateTypes;
|
||||
}
|
||||
return cb(null);
|
||||
},
|
||||
function(cb) {
|
||||
|
|
|
@ -157,88 +157,7 @@ FormSubmissionSchema.pre('save', function (next) {
|
|||
// console.log(_form);
|
||||
// console.log('should push to api');
|
||||
// console.log( (!this.oscarDemoNum && !!_form.plugins.oscarhost.baseUrl && !!_form.plugins.oscarhost.settings.fieldMap) );
|
||||
if(!this.oscarDemoNum && _form.plugins.oscarhost.baseUrl && _form.plugins.oscarhost.settings.fieldMap){
|
||||
console.log('OSCARHOST API HOOK');
|
||||
var url_login = _form.plugins.oscarhost.baseUrl+'/LoginService?wsdl',
|
||||
url_demo = _form.plugins.oscarhost.baseUrl+'/DemographicService?wsdl';
|
||||
|
||||
var args_login = {arg0: config.oscarhost.auth.user, arg1: config.oscarhost.auth.pass};
|
||||
|
||||
var options = {
|
||||
ignoredNamespaces: {
|
||||
namespaces: ['targetNamespace', 'typedNamespace'],
|
||||
override: true
|
||||
}
|
||||
};
|
||||
// console.log(self.form_fields);
|
||||
|
||||
//Generate demographics from hashmap
|
||||
var generateDemo = function(formFields, conversionMap, demographicsTemplate){
|
||||
console.log('generating Demo fields');
|
||||
console.log(conversionMap);
|
||||
var _generatedDemo = {}, currField, propertyName;
|
||||
|
||||
for(var y=0; y<formFields.length; y++){
|
||||
currField = formFields[y];
|
||||
propertyName = conversionMap[currField._id];
|
||||
|
||||
if(demographicsTemplate.hasOwnProperty(conversionMap[currField._id])){
|
||||
_generatedDemo[propertyName] = currField.fieldValue+'';
|
||||
}else if(propertyName === 'DOB'){
|
||||
var date = new Date(currField.fieldValue);
|
||||
_generatedDemo.dateOfBirth = date.getDate()+'';
|
||||
_generatedDemo.yearOfBirth = date.getFullYear()+'';
|
||||
_generatedDemo.monthOfBirth = date.getMonth()+'';
|
||||
}
|
||||
}
|
||||
var currDate = new Date();
|
||||
var dateString = currDate.toISOString().split('T')[0] + ' ' + currDate.toISOString().split('T')[1].slice(0,8);
|
||||
_generatedDemo.lastUpdateDate = currDate.toISOString();
|
||||
return _generatedDemo;
|
||||
};
|
||||
|
||||
var submissionDemographic = generateDemo(self.form_fields, _form.plugins.oscarhost.settings.fieldMap, newDemoTemplate);
|
||||
|
||||
console.log(submissionDemographic);
|
||||
async.waterfall([
|
||||
function (callback) {
|
||||
//Authenticate with API
|
||||
soap.createClient(url_login, options, function(err, client) {
|
||||
client.login(args_login, function (err, result) {
|
||||
if(err) return callback(err);
|
||||
console.log('SOAP authenticated');
|
||||
return callback(null, result.return);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
function (security_obj, callback) {
|
||||
//Force Add Demographic
|
||||
if(_form.plugins.oscarhost.settings.updateType === 'force_add'){
|
||||
soap.createClient(url_demo, options, function(err, client) {
|
||||
if(err) return callback(err);
|
||||
client.setSecurity(new OscarSecurity(security_obj.securityId, security_obj.securityTokenKey) );
|
||||
|
||||
client.addDemographic({ arg0: submissionDemographic }, function (err, result) {
|
||||
console.log('FORCE ADDING DEMOGRAPHIC \n');
|
||||
// console.log(result.return);
|
||||
if(err) return callback(err);
|
||||
return callback(null, result);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
], function(err, result) {
|
||||
if(err) return next(err);
|
||||
|
||||
self.oscarDemoNum = parseInt(result.return, 10);
|
||||
console.log('self.oscarDemoNum: '+self.oscarDemoNum);
|
||||
return next();
|
||||
});
|
||||
}else{
|
||||
return next();
|
||||
}
|
||||
return next();
|
||||
});
|
||||
}else{
|
||||
return next();
|
||||
|
|
|
@ -150,13 +150,6 @@ describe('FormSubmission Model Unit Tests:', function() {
|
|||
beforeEach(function(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+''] = 'DOB';
|
||||
myFieldMap[myForm.form_fields[4]._id+''] = 'phone';
|
||||
|
||||
myForm.plugins.oscarhost.settings.fieldMap = myFieldMap;
|
||||
|
||||
myForm.save(function(err, form){
|
||||
if(err) done(err);
|
||||
|
@ -175,49 +168,6 @@ describe('FormSubmission Model Unit Tests:', function() {
|
|||
});
|
||||
});
|
||||
|
||||
// it('should add Patient to OscarHost EMR after save', function(done){
|
||||
// var url_login = myForm.plugins.oscarhost.baseUrl+'/LoginService?wsdl',
|
||||
// url_demo = myForm.plugins.oscarhost.baseUrl+'/DemographicService?wsdl',
|
||||
// args_login = {arg0: config.oscarhost.auth.user, arg1: config.oscarhost.auth.pass};
|
||||
|
||||
// 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) {
|
||||
// soap.createClient(url_demo, options, function(err, client) {
|
||||
// client.setSecurity(new OscarSecurity(security_obj.securityId, security_obj.securityTokenKey) );
|
||||
|
||||
// client.getDemographic({ arg0: oscar_demo_num }, function (err, result) {
|
||||
// if(err) callback(err);
|
||||
// callback(null, result);
|
||||
// });
|
||||
// });
|
||||
// },
|
||||
|
||||
// ], function(err, result) {
|
||||
// if(err) done(err);
|
||||
|
||||
// should.exist(result);
|
||||
// console.log(result.return);
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
});
|
||||
|
||||
describe('Method Find', function(){
|
||||
|
|
468
swagger.json
Normal file
468
swagger.json
Normal file
|
@ -0,0 +1,468 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "TellForm API",
|
||||
"contact": {
|
||||
"name": "TellForm Team",
|
||||
"url": "http://tellform.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "Creative Commons 4.0 International",
|
||||
"url": "http://creativecommons.org/licenses/by/4.0/"
|
||||
}
|
||||
},
|
||||
"host": "tellform.com",
|
||||
"basePath": "/api",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"paths": {
|
||||
"/forms": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"Form Operations"
|
||||
],
|
||||
"summary": "Finds forms in the system",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "forms response",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Form"
|
||||
}
|
||||
},
|
||||
"headers": {
|
||||
"x-expires": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"User": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"language",
|
||||
"email",
|
||||
"username"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
},
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastName": {
|
||||
"type": "string"
|
||||
},
|
||||
"language": {
|
||||
"type": "string",
|
||||
"enum": ["en", "fr", "es", "it", "de"],
|
||||
"default": "en",
|
||||
"required": "User must have a language"
|
||||
},
|
||||
"email": {
|
||||
"type": "string",
|
||||
"format": "email",
|
||||
"required": "User email cannot be blank",
|
||||
"unique": "true"
|
||||
},
|
||||
"username": {
|
||||
"type": "string",
|
||||
"required": "Username cannot be blank"
|
||||
"unique": "true"
|
||||
},
|
||||
"passwordHash": {
|
||||
"type": "string",
|
||||
"default": ""
|
||||
},
|
||||
"salt": {
|
||||
"type": "string"
|
||||
},
|
||||
"provider": {
|
||||
"type": "string",
|
||||
"required": "provider is required",
|
||||
"default": "local"
|
||||
},
|
||||
"providerData": {
|
||||
"type": "object"
|
||||
},
|
||||
"additionalProvidersData": {
|
||||
"type": "object"
|
||||
},
|
||||
"roles": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"enum": ["user", "admin", "superuser"]
|
||||
},
|
||||
"default": ["user"]
|
||||
}
|
||||
}
|
||||
"lastModified": {
|
||||
"type": "date"
|
||||
},
|
||||
"created": {
|
||||
"type": "date"
|
||||
},
|
||||
"resetPasswordToken": {
|
||||
"type": "string"
|
||||
},
|
||||
"resetPasswordExpires": {
|
||||
"type": "date"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
},
|
||||
"apiKey": {
|
||||
"type": "string",
|
||||
"unique": true,
|
||||
"index": true,
|
||||
"sparse": true
|
||||
}
|
||||
},
|
||||
|
||||
"LogicJump"
|
||||
|
||||
"FieldOption": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"option_id": {
|
||||
"type": "number"
|
||||
},
|
||||
"option_title": {
|
||||
"type": "string"
|
||||
},
|
||||
"option_value": {
|
||||
"type": "string",
|
||||
"trim": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"RatingField": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"steps": {
|
||||
"type": "number",
|
||||
"min": 1,
|
||||
"max": 10
|
||||
},
|
||||
"shape": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Heart",
|
||||
"Star",
|
||||
"thumbs-up",
|
||||
"thumbs-down",
|
||||
"Circle",
|
||||
"Square",
|
||||
"Check Circle",
|
||||
"Smile Outlined",
|
||||
"Hourglass",
|
||||
"bell",
|
||||
"Paper Plane",
|
||||
"Comment",
|
||||
"Trash"
|
||||
]
|
||||
},
|
||||
"validShapes": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"FormField": {
|
||||
"required":[
|
||||
"title",
|
||||
"fieldType"
|
||||
],
|
||||
"properties": {
|
||||
|
||||
"isSubmission": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"submissionId": {
|
||||
"type": "string"
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"trim": true,
|
||||
"required": "Field Title cannot be blank"
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"default": ""
|
||||
},
|
||||
|
||||
"logicJump": {
|
||||
"$ref": "#/definitions/FormFields"
|
||||
},
|
||||
|
||||
"ratingOptions": {
|
||||
"type": "#/definitions/RatingField",
|
||||
},
|
||||
"fieldOptions": {
|
||||
"type": "array",
|
||||
"items": "#/definitions/FieldOption"
|
||||
},
|
||||
"required": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"disabled": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
|
||||
"deletePreserved": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"validFieldTypes": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"fieldType": {
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"enum": [
|
||||
"textfield",
|
||||
"date",
|
||||
"email",
|
||||
"link",
|
||||
"legal",
|
||||
"url",
|
||||
"textarea",
|
||||
"statement",
|
||||
"welcome",
|
||||
"thankyou",
|
||||
"file",
|
||||
"dropdown",
|
||||
"scale",
|
||||
"rating",
|
||||
"radio",
|
||||
"checkbox",
|
||||
"hidden",
|
||||
"yes_no",
|
||||
"natural",
|
||||
"stripe",
|
||||
"number"
|
||||
]
|
||||
},
|
||||
"fieldValue": {
|
||||
"type": "string"
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
"VisitorData": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"referrer": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastActiveField": {
|
||||
"type": "string"
|
||||
},
|
||||
"timeElapsed": {
|
||||
"type": "number"
|
||||
},
|
||||
"isSubmitted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"language": {
|
||||
"type": "string"
|
||||
},
|
||||
"ipAddr": {
|
||||
"type": "string",
|
||||
"default": ""
|
||||
},
|
||||
"deviceType": {
|
||||
"type": "string",
|
||||
"enum": ["desktop", "phone", "tablet", "other"],
|
||||
"default": "other"
|
||||
},
|
||||
"userAgent": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Button": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"url": {
|
||||
"type": "string",
|
||||
"pattern": "/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/"
|
||||
},
|
||||
"action": {
|
||||
"type": "string"
|
||||
},
|
||||
"text": {
|
||||
"type": "string"
|
||||
},
|
||||
"bgColor": {
|
||||
"type": "string",
|
||||
"pattern": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
|
||||
"default": "5bc0de"
|
||||
},
|
||||
"color": {
|
||||
"type": "string",
|
||||
"pattern": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
|
||||
"default": "#ffffff"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Form": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"language",
|
||||
"admin",
|
||||
"title"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"required": "Form Title cannot be blank"
|
||||
},
|
||||
"language": {
|
||||
"type": "string",
|
||||
"enum": ["en", "fr", "es", "it", "de"],
|
||||
"default": "en",
|
||||
"required": "Form must have a language"
|
||||
},
|
||||
"analytics": {
|
||||
"properties": {
|
||||
"gaCode": {
|
||||
"type": "string"
|
||||
},
|
||||
"visitors": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "#/definitions/VisitorData"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"form_fields": {
|
||||
"type": "array",
|
||||
"items": "#/definitions/FormFields"
|
||||
},
|
||||
"submissions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/FormSubmission"
|
||||
}
|
||||
},
|
||||
|
||||
"admin": {
|
||||
"$ref": "#/definitions/User",
|
||||
"required": "Form must have an Admin"
|
||||
},
|
||||
|
||||
"pdf": {
|
||||
"type": "object"
|
||||
},
|
||||
"pdfFieldMap": {
|
||||
"type": "object"
|
||||
},
|
||||
|
||||
"startPage": {
|
||||
"properties": {
|
||||
"showStart": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"introTitle": {
|
||||
"type": "string",
|
||||
"default": "Welcome to Form"
|
||||
},
|
||||
"introParagraph": {
|
||||
"type": "string"
|
||||
},
|
||||
"introButtonText": {
|
||||
"type": "string",
|
||||
"default": "Start"
|
||||
},
|
||||
"buttons": {
|
||||
"type": "array",
|
||||
"items": "#/definitions/Button"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"hideFooter": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"isGenerated": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"isLive": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"autofillPDFs": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
|
||||
"design": {
|
||||
"colors":{
|
||||
"backgroundColor": {
|
||||
"type": "string",
|
||||
"pattern": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
|
||||
"default": "#fff"
|
||||
},
|
||||
"questionColor": {
|
||||
"type": "string",
|
||||
"match": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
|
||||
"default": "#333"
|
||||
},
|
||||
"answerColor"": {
|
||||
"type": "string",
|
||||
"match": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
|
||||
"default": "#333"
|
||||
},
|
||||
"buttonColor": {
|
||||
"type": "string"
|
||||
"match": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
|
||||
"default": "#fff"
|
||||
},
|
||||
"buttonTextColor": {
|
||||
"type": "string",
|
||||
"pattern": "[/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/]",
|
||||
"default": "#333"
|
||||
}
|
||||
},
|
||||
"font": "string"
|
||||
}
|
||||
},
|
||||
"Address": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"addressLine1": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue