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 | 17 May 2017
|
28 |
|
29 | */
|
30 |
|
31 | var uuid = require('uuid/v4');
|
32 | function setTransferOfCare(args, callback) {
|
33 |
|
34 | var patientId = args.patientId;
|
35 |
|
36 | if (typeof patientId === 'undefined' || patientId === '') {
|
37 | return callback({error: 'patientId not defined or invalid'});
|
38 | }
|
39 |
|
40 | var data = args.req.body;
|
41 |
|
42 | if (typeof data.from === 'undefined' || data.from === '') {
|
43 | return callback({error: '"from" field not defined or invalid'});
|
44 | }
|
45 |
|
46 | if (typeof data.to === 'undefined' || data.to === '') {
|
47 | return callback({error: '"to" field not defined or invalid'});
|
48 | }
|
49 |
|
50 | if (typeof data.transferDateTime === 'undefined' || data.transferDateTime === '') {
|
51 | return callback({error: '"transferDateTime" field not defined or invalid'});
|
52 | }
|
53 |
|
54 | if (typeof data.records === 'undefined' || !Array.isArray(data.records) || data.records.count < 1) {
|
55 | return callback({error: '"records" field not defined, not an array or empty'});
|
56 | }
|
57 |
|
58 | if (typeof data.clinicalSummary === 'undefined' || data.clinicalSummary === '') {
|
59 | return callback({error: '"clinicalSummary" field not defined or invalid'});
|
60 | }
|
61 |
|
62 | if (typeof data.reasonForContact === 'undefined' || data.reasonForContact === '') {
|
63 | return callback({error: '"reasonForContact" field not defined or invalid'});
|
64 | }
|
65 |
|
66 | // data good enough to save
|
67 |
|
68 | var sourceId = uuid();
|
69 | data.dateCreated = new Date().getTime();
|
70 | data.source = 'qewdDB';
|
71 |
|
72 | var docName = this.userDefined.tocDocumentName;
|
73 | var tocsDoc = new this.documentStore.DocumentNode(docName);
|
74 |
|
75 | // create main document record
|
76 |
|
77 | tocsDoc.$(['byPatient', patientId, sourceId]).setDocument(data);
|
78 |
|
79 | // create sourceId index
|
80 |
|
81 | tocsDoc.$(['bySourceId', sourceId]).value = patientId;
|
82 |
|
83 | callback({sourceId: sourceId});
|
84 | }
|
85 |
|
86 | module.exports = setTransferOfCare;
|