1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function 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 |
|
76 | function 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 |
|
101 | module.exports = {
|
102 | forOneRecord: indexOneRecord,
|
103 | reIndex: reIndex
|
104 | }
|