1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var router = require('qewd-router');
|
32 | var routes;
|
33 |
|
34 | var initialise = require('./user/initialise');
|
35 | var authenticate = require('./sessions/authenticate');
|
36 | var mpv = require('./patients/mpv');
|
37 | var spv = require('./patients/spv');
|
38 | var getUser = require('./user/getUser');
|
39 | var getApplicationData = require('./application/getApplicationData');
|
40 | var setApplicationData = require('./application/setApplicationData');
|
41 | var patientSummary = require('./patients/patientSummary');
|
42 | var patientHeadingTable = require('./patients/patientHeadingTable');
|
43 | var patientHeadingDetail = require('./patients/patientHeadingDetail');
|
44 | var postHeading = require('./patients/postHeading');
|
45 | var deleteHeading = require('./patients/deleteHeading');
|
46 | var dicom = require('./dicom/dicom');
|
47 | var clinicalStatements = require('./clinicalStatements/clinicalStatements');
|
48 | var events = require('./events/endpoints');
|
49 | var advancedSearch = require('./patients/advancedSearch');
|
50 | var clinicalSearch = require('./clinicalSearch/clinicalSearch');
|
51 | var getDocumentSummary = require('./documents/getDocumentSummary');
|
52 | var getDocumentDetail = require('./documents/getDocumentDetail');
|
53 | var getPictures = require('./pictures/getPictures');
|
54 | var getPicture = require('./pictures/getPicture');
|
55 | var savePicture = require('./pictures/savePicture');
|
56 | var updatePicture = require('./pictures/updatePicture');
|
57 | var getAvailableOrders = require('./terminology/availableOrders');
|
58 | var searchByPatient = require('./search/byPatient');
|
59 | var contentStore = require('qewd-content-store').rest;
|
60 | var getSessionToken = require('./auth0/token');
|
61 |
|
62 | var setTransferOfCare = require('./events/setTransferOfCare');
|
63 | var getTransferOfCareSummary = require('./events/getTransferOfCareSummary');
|
64 | var getTransferOfCareDetail = require('./events/getTransferOfCareDetail');
|
65 | var createSession = require('./sessions/create');
|
66 | var ui = require('./ui');
|
67 |
|
68 | var postDocumentOld = require('./documents/documents').postDocument;
|
69 | var postDocument = require('./documents/postDocument');
|
70 |
|
71 |
|
72 | module.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 |
|
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 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 | ];
|
280 |
|
281 | routes = router.initialise(routes, module.exports);
|
282 | router.setErrorResponse(404, 'Not Found');
|
283 |
|
284 | this.setCustomErrorResponse.call(this, {
|
285 |
|
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 |
|
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 |
|
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 |
|
327 |
|
328 | finished({
|
329 | ok: true
|
330 | });
|
331 | }
|
332 | }
|
333 | };
|
334 |
|