UNPKG

4.71 kBJavaScriptView Raw
1/*
2
3 ----------------------------------------------------------------------------
4 | qewd-ripple: QEWD-based Middle Tier for Ripple OSI |
5 | |
6 | Copyright (c) 2016-17 Ripple Foundation Community Interest Company |
7 | All rights reserved. |
8 | |
9 | http://rippleosi.org |
10 | Email: code.custodian@rippleosi.org |
11 | |
12 | Author: Rob Tweed, M/Gateway Developments Ltd |
13 | |
14 | Licensed under the Apache License, Version 2.0 (the "License"); |
15 | you may not use this file except in compliance with the License. |
16 | You may obtain a copy of the License at |
17 | |
18 | http://www.apache.org/licenses/LICENSE-2.0 |
19 | |
20 | Unless required by applicable law or agreed to in writing, software |
21 | distributed under the License is distributed on an "AS IS" BASIS, |
22 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
23 | See the License for the specific language governing permissions and |
24 | limitations under the License. |
25 ----------------------------------------------------------------------------
26
27 11 October 2017
28
29*/
30
31var qewd = require('qewd').master;
32
33function start(config) {
34
35 var cookiePath = '/';
36
37 var routes = [
38 {
39 path: '/api',
40 module: 'qewd-ripple'
41 }
42 ];
43
44 if (!config.webServerRootPath) config.webServerRootPath = process.cwd() + '/www';
45 if (!config.database) config.database = {type: 'gtm'};
46 if (!config.serverName) config.serverName = 'RippleOSI QEWD Server';
47 if (!config.managementPassword) config.managementPassword = 'keepThisSecret!';
48
49 var q = qewd.start(config, routes);
50
51 if (config.auth0) {
52 var passport = require('passport');
53 var Auth0Strategy = require('passport-auth0');
54
55 var strategy = new Auth0Strategy({
56 domain: config.auth0.domain,
57 clientID: config.auth0.clientID,
58 clientSecret: config.auth0.clientSecret,
59 callbackURL: config.auth0.callbackURL,
60 },
61 function(accessToken, refreshToken, extraParams, profile, done) {
62 return done(null, profile);
63 }
64 );
65
66 passport.use(strategy);
67 passport.serializeUser(function(user, done) {
68 done(null, user);
69 });
70 passport.deserializeUser(function(user, done) {
71 done(null, user);
72 });
73
74 var failURL = config.auth0.failURL || '/fail.html';
75 var callbackPath = config.auth0.callbackPath || '/auth0/token';
76
77 var app = qewd.intercept().app;
78 app.use(passport.initialize());
79 app.use(passport.session());
80 app.get(callbackPath,
81 passport.authenticate('auth0', { failureRedirect: failURL }),
82 function(req, res) {
83 var message = {
84 type: 'ewd-qoper8-express',
85 expressType: 'auth0-register',
86 application: 'qewd-ripple',
87 params: req.user
88 };
89 q.handleMessage(message, function(response) {
90 console.log('*** auth0-register response: ' + JSON.stringify(response));
91 res.cookie('JSESSIONID', response.message.token, {path: cookiePath});
92 res.redirect(config.auth0.indexURL);
93 });
94 }
95 );
96 q.userDefined['auth0'] = config.auth0;
97 }
98
99 var pasConfig = {
100 openEHR: {
101 pasModule: 'mysqlPAS',
102 summaryHeadings: ['allergies', 'problems', 'medications', 'contacts', {name: 'transfers', value: true}]
103 }
104 };
105 if (config.ripple && config.ripple.pas) pasConfig = config.ripple.pas;
106
107 var pas = process.argv[2] || 'openEHR'
108 q.userDefined['rippleUser'] = pasConfig[pas];
109 var mode = 'demo';
110 if (config.ripple && config.ripple.mode) mode = config.ripple.mode;
111 q.userDefined['rippleMode'] = mode;
112
113 q.userDefined['sessionTimeout'] = config.sessionTimeout || 900; // 15 minutes session timeout
114 q.userDefined.clinicalStatementsDocumentName = 'rippleClinStatements';
115 q.userDefined.tocDocumentName = 'rippleTOC';
116
117}
118
119module.exports = {
120 start: start
121};
122
123
124