UNPKG

4.52 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: 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 16 March 2017
28
29*/
30
31
32function indexOneRecord(patientId, sourceId, statementObj) {
33
34 if (typeof patientId === 'undefined' || patientId === '' || typeof sourceId === 'undefined' || sourceId === '' || !statementObj) return;
35
36 console.log('statementObj = ' + JSON.stringify(statementObj));
37
38 var docName = this.userDefined.clinicalStatementsDocumentName;
39
40 var dateCreated = statementObj.dateCreated;
41
42 new this.documentStore.DocumentNode(docName, ['bySourceId', sourceId]).value = patientId;
43 if (dateCreated && dateCreated !== '') {
44 new this.documentStore.DocumentNode(docName, ['byDateCreated', dateCreated, patientId, sourceId]).value = '';
45 }
46
47 var byTagIndex = new this.documentStore.DocumentNode(docName, ['byTag']);
48
49 var tags = statementObj.tags;
50 if (tags) {
51 for (var tag in tags) {
52 byTagIndex.$([tag, patientId, sourceId]).value = '';
53 }
54 }
55
56 var bySubjectIndex = new this.documentStore.DocumentNode(docName, ['bySubject']);
57 var byValueIndex = new this.documentStore.DocumentNode(docName, ['byValue']);
58 var byUnitIndex = new this.documentStore.DocumentNode(docName, ['byUnit']);
59
60 if (statementObj.phrases) {
61 statementObj.phrases.forEach(function(phrase) {
62 if (phrase.subject && phrase.subject !== '') {
63 bySubjectIndex.$([phrase.subject, patientId, sourceId]).value = '';
64 }
65 if (phrase.value && phrase.value !== '') {
66 byValueIndex.$([phrase.value, patientId, sourceId]).value = '';
67 }
68 if (phrase.unit && phrase.unit !== '') {
69 byUnitIndex.$([phrase.unit, patientId, sourceId]).value = '';
70 }
71 });
72 }
73
74}
75
76function reIndex() {
77
78 console.log('reIndex - this: ' + JSON.stringify(this, null, 2));
79 console.log('reIndex - this.userDefined: ' + JSON.stringify(this.userDefined, null, 2));
80
81 var docName = this.userDefined.clinicalStatementsDocumentName;
82 var clinicalStatementsDoc = new this.documentStore.DocumentNode(docName);
83
84 clinicalStatementsDoc.$('bySourceId').delete();
85 clinicalStatementsDoc.$('bySubject').delete();
86 clinicalStatementsDoc.$('byTag').delete();
87 clinicalStatementsDoc.$('byValue').delete();
88 clinicalStatementsDoc.$('byUnit').delete();
89 clinicalStatementsDoc.$('byDateCreated').delete();
90
91 var self = this;
92 clinicalStatementsDoc.$('byPatient').forEachChild(function(patientId, patientStatements) {
93 patientStatements.forEachChild(function(sourceId, statementNode) {
94 var statement = statementNode.getDocument(true);
95 indexOneRecord.call(self, patientId, sourceId, statement);
96 });
97 });
98
99}
100
101module.exports = {
102 forOneRecord: indexOneRecord,
103 reIndex: reIndex
104}