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: Will Weatherill |
|
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 | 9 June 2017
|
28 |
|
29 | */
|
30 |
|
31 |
|
32 | function getPicture(args, finished) {
|
33 |
|
34 | /*
|
35 | {
|
36 | "name": {{picture name}},
|
37 | "date": {{ date/time in getTime() format }},
|
38 | "source": "qewdDB",
|
39 | "sourceId": {{sourceId}}
|
40 | "author": {{author}},
|
41 | "drawing-base64": {{b64encodedstring}}
|
42 | }
|
43 |
|
44 | */
|
45 |
|
46 | var patientId = args.patientId;
|
47 |
|
48 | if (typeof patientId === 'undefined' || patientId === '') {
|
49 | return finished({error: 'Missing or empty patient Id'});
|
50 | }
|
51 |
|
52 | var sourceId = args.sourceId;
|
53 |
|
54 | if (typeof sourceId === 'undefined' || sourceId === '') {
|
55 | return finished({error: 'Missing or empty sourceId'});
|
56 | }
|
57 |
|
58 | var pictureDoc = new this.documentStore.DocumentNode('ripplePictures', ["byPatientId", patientId, sourceId]);
|
59 | if (!pictureDoc.exists) {
|
60 | return finished({});
|
61 | }
|
62 |
|
63 | var data = pictureDoc.getDocument(true);
|
64 | if (Array.isArray(data.drawingBase64)) {
|
65 | data.drawingBase64 = data.drawingBase64.join('');
|
66 | }
|
67 |
|
68 | return finished(data);
|
69 | }
|
70 |
|
71 | module.exports = getPicture;
|