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 | 8 March 2017
|
28 |
|
29 | */
|
30 |
|
31 | var mpv = require('./mpv'); // Multiple Patient View
|
32 | var spv = require('./spv'); // Single Patient View
|
33 | var events = require('../events/endpoints');
|
34 | var router = require('qewd-router');
|
35 | var authenticate = require('../sessions/authenticate');
|
36 |
|
37 | /*
|
38 |
|
39 | /api/patients -> mpv.getPatients()
|
40 | /api/patients/{{patientId}} -> spv.getPatientSummary(patientId) -> patientSummary.js
|
41 | /api/patients/{{patientId}}/{{heading}} -> spv.getHeadingTable(patientId, heading) -> patientHeadingTable.js
|
42 | /api/patients/{{patientId}}/{{heading}}/{{sourceId}} -> spv.getHeadingDetail(patientId, heading, sourceId) -> patientHeadingDetail.js
|
43 |
|
44 | */
|
45 |
|
46 | var routes = [
|
47 | {
|
48 | url: '/api/patients/:patientId/events/:eventType',
|
49 | method: 'GET',
|
50 | handler: events.getAll
|
51 | },
|
52 | {
|
53 | url: '/api/patients/:patientId/events/:eventType/:sourceId',
|
54 | method: 'GET',
|
55 | handler: events.getOne
|
56 | },
|
57 | {
|
58 | url: '/api/patients/:patientId/events/:eventType',
|
59 | method: 'POST',
|
60 | handler: events.post
|
61 | },
|
62 | {
|
63 | url: '/api/patients/:patientId/:heading/:sourceId/:identifier/:subId',
|
64 | handler: spv.probablyDicomL3
|
65 | },
|
66 | {
|
67 | url: '/api/patients/:patientId/:heading/:sourceId/:identifier',
|
68 | handler: spv.probablyDicomL2
|
69 | },
|
70 | {
|
71 | url: '/api/patients/:patientId/:heading/:sourceId',
|
72 | handler: spv.getHeadingDetail
|
73 | },
|
74 | {
|
75 | url: '/api/patients/:patientId/:heading',
|
76 | method: 'GET',
|
77 | handler: spv.getHeadingTable
|
78 | },
|
79 | {
|
80 | url: '/api/patients/:patientId/:heading',
|
81 | method: 'POST',
|
82 | handler: spv.postHeading
|
83 | },
|
84 | {
|
85 | url: '/api/patients/:patientId',
|
86 | handler: spv.getPatientSummary
|
87 | },
|
88 | {
|
89 | url: '/api/patients',
|
90 | handler: mpv.getPatients
|
91 | }
|
92 | ];
|
93 |
|
94 | routes = router.initialise(routes);
|
95 |
|
96 | function sendMessage(type, message, session) {
|
97 | var socketSession;
|
98 | var socketSessionToken = session.data.$(['ewd-session', 'socketSession']).value;
|
99 | if (socketSessionToken !== '') {
|
100 | //console.log('socketSessionToken = ' + socketSessionToken);
|
101 | var socketStatus = this.sessions.authenticate(socketSessionToken);
|
102 | //console.log('*** socketStatus = ' + JSON.stringify(socketStatus));
|
103 | socketSession = socketStatus.session;
|
104 | }
|
105 | else {
|
106 | socketSession = session;
|
107 | }
|
108 | socketSession.sendToSocket(type, message);
|
109 | }
|
110 |
|
111 | function patients(messageObj, finished) {
|
112 |
|
113 | var status = authenticate.call(this, messageObj);
|
114 | if (status.error) {
|
115 | finished(status);
|
116 | return;
|
117 | }
|
118 |
|
119 | var q = this;
|
120 |
|
121 | router.process.call(this, messageObj, status.session, routes, function(results) {
|
122 | if (results.error) {
|
123 | finished(results);
|
124 | }
|
125 | else {
|
126 | finished(results);
|
127 | }
|
128 | });
|
129 | }
|
130 |
|
131 | module.exports = {
|
132 | init: function() {
|
133 | mpv.init.call(this);
|
134 | spv.init.call(this);
|
135 | },
|
136 | api: patients
|
137 | };
|