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 | 6 April 2017
|
28 |
|
29 | */
|
30 |
|
31 | var headingsLib = require('../headings/headings');
|
32 | var headings = headingsLib.headings;
|
33 | var headingHelpers = require('../headings/headingHelpers');
|
34 | var transform = require('qewd-transform-json').transform;
|
35 |
|
36 | function patientHeadingDetail(patientId, headingName, sourceId, session) {
|
37 |
|
38 | if (!headings[headingName]) {
|
39 | console.log('*** ' + heading + ' has not yet been added to middle-tier processing');
|
40 | return {error: headingName + ' has not yet been added to middle-tier processing'};
|
41 | }
|
42 |
|
43 | var heading = headings[headingName].name;
|
44 |
|
45 | console.log('*** patientHeadingDetail - heading = ' + heading + '; session ' + session.id);
|
46 |
|
47 | var patient = session.data.$(['patients', patientId]);
|
48 |
|
49 | var patientHeadingIndex = patient.$(['headingIndex', heading]);
|
50 |
|
51 | //console.log('**** sourceId: ' + sourceId);
|
52 | var indexSource = patientHeadingIndex.$(sourceId);
|
53 | if (!indexSource.exists) {
|
54 | return {error: 'Invalid sourceId ' + sourceId + ' for patient ' + patientId + ' / heading ' + heading};
|
55 | }
|
56 | var index = indexSource.getDocument();
|
57 |
|
58 | if (typeof index.recNo === 'undefined' || index.recNo === '') {
|
59 | return {error: 'Unable to use the index to sourceId ' + sourceId + ' for patient ' + patientId + ' / heading ' + heading + ': recNo is missing'};
|
60 | }
|
61 |
|
62 | var patientHeading = patient.$(['headings', heading, index.host, index.recNo]);
|
63 | var input;
|
64 | if (typeof patientHeading === 'undefined') {
|
65 | input = {};
|
66 | }
|
67 | else {
|
68 | input = patientHeading.getDocument();
|
69 | }
|
70 | var template = headings[heading].get.transformTemplate;
|
71 | var helpers = headingHelpers(index.host, heading, 'get');
|
72 | var output = transform(template, input, helpers);
|
73 |
|
74 | return output;
|
75 | }
|
76 |
|
77 | module.exports = patientHeadingDetail;
|