UNPKG

11 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 30 October 2017
28
29*/
30
31var router = require('qewd-router');
32var routes;
33
34var initialise = require('./user/initialise');
35var authenticate = require('./sessions/authenticate');
36var mpv = require('./patients/mpv'); // Multiple Patient View
37var spv = require('./patients/spv'); // Single Patient View
38var getUser = require('./user/getUser');
39var getApplicationData = require('./application/getApplicationData');
40var setApplicationData = require('./application/setApplicationData');
41var patientSummary = require('./patients/patientSummary');
42var patientHeadingTable = require('./patients/patientHeadingTable');
43var patientHeadingDetail = require('./patients/patientHeadingDetail');
44var postHeading = require('./patients/postHeading');
45var deleteHeading = require('./patients/deleteHeading');
46var dicom = require('./dicom/dicom');
47var clinicalStatements = require('./clinicalStatements/clinicalStatements');
48var events = require('./events/endpoints');
49var advancedSearch = require('./patients/advancedSearch');
50var clinicalSearch = require('./clinicalSearch/clinicalSearch');
51var getDocumentSummary = require('./documents/getDocumentSummary');
52var getDocumentDetail = require('./documents/getDocumentDetail');
53var getPictures = require('./pictures/getPictures');
54var getPicture = require('./pictures/getPicture');
55var savePicture = require('./pictures/savePicture');
56var updatePicture = require('./pictures/updatePicture');
57var getAvailableOrders = require('./terminology/availableOrders');
58var searchByPatient = require('./search/byPatient');
59var contentStore = require('qewd-content-store').rest;
60var getSessionToken = require('./auth0/token');
61
62var setTransferOfCare = require('./events/setTransferOfCare');
63var getTransferOfCareSummary = require('./events/getTransferOfCareSummary');
64var getTransferOfCareDetail = require('./events/getTransferOfCareDetail');
65var createSession = require('./sessions/create');
66var ui = require('./ui');
67
68var postDocumentOld = require('./documents/documents').postDocument;
69var postDocument = require('./documents/postDocument'); // *** incomplete - will replace postDocumentOld
70
71
72module.exports = {
73
74 init: function() {
75 if (this.initialised) return;
76 var q = this;
77
78 if (this.isFirst) {
79 console.log('************');
80 console.log('**** clearing down ripple cache Globals ********');
81 console.log('************');
82 new this.documentStore.DocumentNode('ripplePAS').delete();
83 //new this.documentStore.DocumentNode('ripplePatients').delete();
84 new this.documentStore.DocumentNode('rippleGPs').delete();
85 new this.documentStore.DocumentNode('rippleMedicalDepts').delete();
86 new this.documentStore.DocumentNode('rippleNHSNoMap').delete();
87 new this.documentStore.DocumentNode('rippleEhrIdMap').delete();
88 }
89
90 mpv.init.call(this);
91 spv.init.call(this);
92 contentStore.init.call(this);
93 this.initialised = true;
94
95 routes = [
96 {
97 url: '/api/initialise',
98 method: 'GET',
99 handler: initialise
100 },
101 {
102 url: '/api/patients/advancedSearch',
103 method: 'POST',
104 handler: advancedSearch
105 },
106 {
107 url: '/api/patients/querySearch',
108 method: 'POST',
109 handler: clinicalSearch
110 },
111 {
112 url: '/api/patients/:patientId/events/toc',
113 method: 'GET',
114 handler: getTransferOfCareSummary
115 },
116 {
117 url: '/api/patients/:patientId/events/toc',
118 method: 'POST',
119 handler: setTransferOfCare
120 },
121 {
122 url: '/api/patients/:patientId/events/toc/:sourceId',
123 method: 'GET',
124 handler: getTransferOfCareDetail
125 },
126 {
127 url: '/api/patients/:patientId/clinicalStatements',
128 method: 'GET',
129 handler: clinicalStatements.getSummary
130 },
131 {
132 url: '/api/patients/:patientId/clinicalStatements',
133 method: 'POST',
134 handler: clinicalStatements.post
135 },
136 {
137 url: '/api/patients/:patientId/clinicalStatements/:sourceId',
138 method: 'GET',
139 handler: clinicalStatements.getDetail
140 },
141 {
142 url: '/api/patients/:patientId/dicom/:sourceId/:identifier/:subId',
143 method: 'GET',
144 handler: dicom.detailL3
145 },
146 {
147 url: '/api/patients/:patientId/dicom/:sourceId/:identifier',
148 method: 'GET',
149 handler: dicom.detailL2
150 },
151 {
152 url: '/api/patients/:patientId/dicom/:sourceId',
153 method: 'GET',
154 handler: dicom.studies
155 },
156 {
157 url: '/api/patients/:patientId/:heading/:sourceId',
158 method: 'GET',
159 handler: patientHeadingDetail
160 },
161 {
162 url: '/api/patients/:patientId/:heading/:sourceId',
163 method: 'DELETE',
164 handler: deleteHeading
165 },
166 {
167 url: '/api/patients/:patientId/:heading',
168 method: 'GET',
169 handler: patientHeadingTable
170 },
171 {
172 url: '/api/patients/:patientId/:heading',
173 method: 'POST',
174 handler: postHeading
175 },
176 {
177 url: '/api/patients/:patientId',
178 method: 'GET',
179 handler: patientSummary.get
180 },
181 {
182 url: '/api/patients',
183 method: 'GET',
184 handler: mpv.getPatients
185 },
186 {
187 url: '/api/user',
188 method: 'GET',
189 handler: getUser
190 },
191 {
192 url: '/api/application',
193 method: 'GET',
194 handler: getApplicationData
195 },
196 {
197 url: '/api/application',
198 method: 'POST',
199 handler: setApplicationData
200 },
201 {
202 url: '/api/application',
203 method: 'PUT',
204 handler: setApplicationData
205 },
206 {
207 url: '/api/documents/patient/:patientId/:sourceId',
208 method: 'GET',
209 handler: getDocumentDetail
210 },
211 {
212 url: '/api/documents/patient/:patientId',
213 method: 'GET',
214 handler: getDocumentSummary
215 },
216 {
217 url: '/api/documents/patient/:patientId/:host',
218 method: 'POST',
219 handler: postDocumentOld
220 },
221 {
222 url: '/api/documents/new/patient/:patientId/:host',
223 method: 'POST',
224 handler: postDocument
225 },
226 {
227 url: '/api/pictures/:patientId',
228 method: 'GET',
229 handler: getPictures
230 },
231 {
232 url: '/api/pictures/:patientId',
233 method: 'POST',
234 handler: savePicture
235 },
236 {
237 url: '/api/pictures/:patientId/:sourceId',
238 method: 'PUT',
239 handler: updatePicture
240 },
241 {
242 url: '/api/pictures/:patientId/:sourceId',
243 method: 'GET',
244 handler: getPicture
245 },
246 {
247 url: '/api/terminology/list/order',
248 method: 'GET',
249 handler: getAvailableOrders
250 },
251 {
252 url: '/api/search/patient/table',
253 method: 'POST',
254 handler: searchByPatient
255 },
256 {
257 url: '/api/contentStore/:storeName/phrases',
258 method: 'GET',
259 handler: contentStore.getPhrases
260 },
261 {
262 url: '/api/contentStore/:storeName/tags',
263 method: 'GET',
264 handler: contentStore.getTags
265 },
266 {
267 url: '/api/ui/:uiType',
268 method: 'GET',
269 handler: ui.swap
270 }
271
272 /*
273 {
274 url: '/api/token',
275 method: 'GET',
276 handler: getSessionToken // for Auth0 session establishment
277 }
278 */
279 ];
280
281 routes = router.initialise(routes, module.exports);
282 router.setErrorResponse(404, 'Not Found');
283
284 this.setCustomErrorResponse.call(this, {
285 //application: application,
286 application: 'api',
287 errorType: 'noTypeHandler',
288 text: 'Resource Not Found',
289 statusCode: '404'
290 });
291
292 },
293
294 restModule: true,
295
296 beforeHandler: function(messageObj, finished) {
297
298 console.log('beforeHandler - messageObj = ' + JSON.stringify(messageObj));
299
300 if (messageObj.expressType === 'auth0-register') return;
301
302 if (messageObj.path !== '/api/initialise' && messageObj.path !== '/api/token') {
303
304 // authenticate the request
305
306 var status = authenticate.call(this, messageObj);
307 if (status.error) {
308 finished(status);
309 return false;
310 }
311 messageObj.session = status.session;
312 }
313 },
314
315 handlers: {
316
317 'auth0-register': function(messageObj, finished) {
318 // handle callback from Auth0 - create session, store JWT data and return token to browser
319
320 var session = createSession.call(this);
321 session.authenticated = true;
322 session.data.$('auth0').setDocument(messageObj.params);
323 finished({token: session.token});
324 },
325 'webrtc:confirmSession': function(messageObj, session, send, finished) {
326 // if it got here, the user has a valid session
327
328 finished({
329 ok: true
330 });
331 }
332 }
333};
334