UNPKG

3.2 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: 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
31var uuid = require('uuid/v4');
32
33function savePicture(args, finished) {
34
35 /*
36 {
37 "name": {{picture name}},
38 "author": {{author}},
39 "drawing-base64": {{b64encodedstring}}
40 }
41
42 */
43
44 var patientId = args.patientId;
45
46 if (typeof patientId === 'undefined' || patientId === '') {
47 return finished({error: 'Missing or empty patient Id'});
48 }
49
50 var data = args.req.body;
51
52 if (typeof data.name === 'undefined' || data.name === '') {
53 return finished({error: '"name" field not defined or invalid'});
54 }
55
56 if (typeof data.author === 'undefined' || data.author === '') {
57 return finished({error: '"author" field not defined or invalid'});
58 }
59
60 if (typeof data.drawingBase64 === 'undefined' || data.drawingBase64 === '') {
61 return finished({error: '"drawingBase64" field not defined or invalid'});
62 }
63
64 data.drawingBase64 = data.drawingBase64.match(/.{1,4000}/g); // split into max 4000 chunks
65
66 var sourceId = uuid();
67 data.sourceId = sourceId;
68 data.dateCreated = new Date().getTime();
69 data.source = 'qewdDB';
70
71 var pictureDoc = new this.documentStore.DocumentNode('ripplePictures', ["byPatientId", patientId, sourceId]);
72
73 pictureDoc.setDocument(data);
74
75 return finished({
76 ok: true,
77 sourceId: sourceId
78 });
79}
80
81module.exports = savePicture;