openchs-models 1.31.61 → 1.31.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/application/Form.js
CHANGED
|
@@ -227,6 +227,32 @@ class Form extends _BaseEntity.default {
|
|
|
227
227
|
|
|
228
228
|
const extraObs = observations.filter(obs => _lodash.default.isNil(orderedObservations.find(oobs => oobs.concept.uuid === obs.concept.uuid)));
|
|
229
229
|
return orderedObservations.concat(extraObs);
|
|
230
|
+
} //TODO add tests
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
orderObservationsPerFEG(observations) {
|
|
234
|
+
const orderedObservations = [];
|
|
235
|
+
|
|
236
|
+
const formElementOrdering = _lodash.default.sortBy(this.formElementGroups, feg => feg.displayOrder).map(feg => {
|
|
237
|
+
let fegOrderedObservations = [];
|
|
238
|
+
const returnValue = {};
|
|
239
|
+
returnValue.uuid = feg.uuid;
|
|
240
|
+
returnValue.feg = feg;
|
|
241
|
+
returnValue.sortedObservationsArray = fegOrderedObservations;
|
|
242
|
+
this.orderObservationsWithinAFEG(feg.getFormElements(), observations, fegOrderedObservations);
|
|
243
|
+
orderedObservations.concat(fegOrderedObservations);
|
|
244
|
+
return returnValue;
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
return formElementOrdering;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
orderObservationsWithinAFEG(formElements, observations, orderedObservations) {
|
|
251
|
+
_lodash.default.sortBy(formElements, fe => fe.displayOrder).forEach(formElement => this.addSortedObservations(formElement, observations, orderedObservations));
|
|
252
|
+
|
|
253
|
+
const extraObs = observations.filter(obs => _lodash.default.isNil(orderedObservations.find(oobs => oobs.concept.uuid === obs.concept.uuid)));
|
|
254
|
+
orderedObservations.concat(extraObs);
|
|
255
|
+
return extraObs;
|
|
230
256
|
}
|
|
231
257
|
|
|
232
258
|
sectionWiseOrderedObservations(observations) {
|
|
@@ -31,6 +31,8 @@ var _BaseEntity = _interopRequireDefault(require("../BaseEntity"));
|
|
|
31
31
|
|
|
32
32
|
var _SchemaNames = _interopRequireDefault(require("../SchemaNames"));
|
|
33
33
|
|
|
34
|
+
var _RepeatableQuestionGroup = _interopRequireDefault(require("../observation/RepeatableQuestionGroup"));
|
|
35
|
+
|
|
34
36
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
37
|
|
|
36
38
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -149,8 +151,18 @@ class FormElement extends _BaseEntity.default {
|
|
|
149
151
|
return formElement;
|
|
150
152
|
}
|
|
151
153
|
|
|
154
|
+
newFormElement() {
|
|
155
|
+
return new FormElement();
|
|
156
|
+
}
|
|
157
|
+
|
|
152
158
|
getType() {
|
|
153
|
-
|
|
159
|
+
if (this.concept.datatype === _Concept.default.dataType.Coded) {
|
|
160
|
+
return this.type;
|
|
161
|
+
} else if (this.concept.datatype === _Concept.default.dataType.QuestionGroup && this.repeatable) {
|
|
162
|
+
return _RepeatableQuestionGroup.default.TypeName;
|
|
163
|
+
} else {
|
|
164
|
+
return this.concept.datatype;
|
|
165
|
+
}
|
|
154
166
|
}
|
|
155
167
|
|
|
156
168
|
isMultiSelect() {
|
|
@@ -386,8 +398,12 @@ class FormElement extends _BaseEntity.default {
|
|
|
386
398
|
return _lodash.default.find(this.formElementGroup.getFormElements(), fe => fe.uuid === this.groupUuid);
|
|
387
399
|
}
|
|
388
400
|
|
|
401
|
+
isRepeatableQuestionGroup() {
|
|
402
|
+
return this.concept.isQuestionGroup() && this.repeatable;
|
|
403
|
+
}
|
|
404
|
+
|
|
389
405
|
clone() {
|
|
390
|
-
const formElement =
|
|
406
|
+
const formElement = this.newFormElement();
|
|
391
407
|
formElement.uuid = this.uuid;
|
|
392
408
|
formElement.name = this.name;
|
|
393
409
|
formElement.displayOrder = this.displayOrder;
|
package/dist/index.js
CHANGED
|
@@ -783,6 +783,12 @@ Object.defineProperty(exports, "DashboardCacheFilter", {
|
|
|
783
783
|
return _DashboardCacheFilter.default;
|
|
784
784
|
}
|
|
785
785
|
});
|
|
786
|
+
Object.defineProperty(exports, "JSONStringify", {
|
|
787
|
+
enumerable: true,
|
|
788
|
+
get: function () {
|
|
789
|
+
return _JsonStringify.JSONStringify;
|
|
790
|
+
}
|
|
791
|
+
});
|
|
786
792
|
|
|
787
793
|
var _AbstractEncounter = _interopRequireDefault(require("./AbstractEncounter"));
|
|
788
794
|
|
|
@@ -1034,6 +1040,8 @@ var _AgeUtil = _interopRequireDefault(require("./utility/AgeUtil"));
|
|
|
1034
1040
|
|
|
1035
1041
|
var _DashboardCacheFilter = _interopRequireDefault(require("./application/DashboardCacheFilter"));
|
|
1036
1042
|
|
|
1043
|
+
var _JsonStringify = require("./utility/JsonStringify");
|
|
1044
|
+
|
|
1037
1045
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
1038
1046
|
|
|
1039
1047
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.JSONStringify = void 0;
|
|
7
|
+
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
//initial code from : https://javascript.plainenglish.io/create-your-own-implementation-of-json-stringify-simiplied-version-8ab6746cdd1
|
|
13
|
+
const isArray = function (value) {
|
|
14
|
+
return Array.isArray(value) && typeof value === 'object';
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const isObject = function (value) {
|
|
18
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const isString = function (value) {
|
|
22
|
+
return typeof value === 'string';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const isBoolean = function (value) {
|
|
26
|
+
return typeof value === 'boolean';
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const isNumber = function (value) {
|
|
30
|
+
return typeof value === 'number';
|
|
31
|
+
}; // Common check for number, string and boolean value
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
const restOfDataTypes = function (value) {
|
|
35
|
+
return isNumber(value) || isString(value) || isBoolean(value);
|
|
36
|
+
}; // This function will be used to remove extra comma from the arrays and object
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
const removeComma = function (str) {
|
|
40
|
+
const tempArr = str.split('');
|
|
41
|
+
tempArr.pop();
|
|
42
|
+
return tempArr.join('');
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const duckCheckNativeRealmCollection = function (obj) {
|
|
46
|
+
return typeof obj === "object" && !_lodash.default.isNil(_lodash.default.get(obj, "removeAllListeners")) && !_lodash.default.isNil(_lodash.default.get(obj, "snapshot"));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function duckCheckForError(obj) {
|
|
50
|
+
return obj.stack && obj.message;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const JSONStringifyInternal = function (obj, depth, objectMap, arrayWidth, objectKey) {
|
|
54
|
+
if (depth === 0) return "BELOW_DEPTH"; // Boolean and Number behave in a same way and String we need to add extra quotes
|
|
55
|
+
|
|
56
|
+
if (restOfDataTypes(obj)) {
|
|
57
|
+
const passQuotes = isString(obj) ? `"` : '';
|
|
58
|
+
return `${passQuotes}${obj}${passQuotes}`;
|
|
59
|
+
} // Recursive function call for Arrays to handle nested arrays
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
if (isArray(obj)) {
|
|
63
|
+
let arrStr = '';
|
|
64
|
+
obj.forEach((eachValue, index) => {
|
|
65
|
+
if (index === arrayWidth) arrStr += "....";
|
|
66
|
+
if (index >= arrayWidth) return;
|
|
67
|
+
arrStr += JSONStringifyInternal(eachValue, depth - 1, objectMap, arrayWidth);
|
|
68
|
+
arrStr += ',';
|
|
69
|
+
});
|
|
70
|
+
return `[` + removeComma(arrStr) + `]`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (duckCheckNativeRealmCollection(obj, objectKey)) {
|
|
74
|
+
return "<realm-collection>";
|
|
75
|
+
} // Recursive function call for Object to handle nested Object
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if (isObject(obj) && _lodash.default.isNil(objectMap.get(obj))) {
|
|
79
|
+
objectMap.set(obj, true);
|
|
80
|
+
let objStr = '';
|
|
81
|
+
const objKeys = Object.keys(obj);
|
|
82
|
+
objKeys.forEach(eachKey => {
|
|
83
|
+
const eachValue = obj[eachKey];
|
|
84
|
+
objStr += `"${eachKey}":${JSONStringifyInternal(eachValue, depth - 1, objectMap, arrayWidth, eachKey)},`;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (duckCheckForError(obj)) {
|
|
88
|
+
objStr += `message:${obj.message},`;
|
|
89
|
+
objStr += `stack:${obj.stack},`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return `{` + removeComma(objStr) + `}`;
|
|
93
|
+
} else if (!_lodash.default.isNil(objectMap.get(obj))) {
|
|
94
|
+
return "<object_repeated>";
|
|
95
|
+
} else {
|
|
96
|
+
return obj;
|
|
97
|
+
}
|
|
98
|
+
}; // This class is not meant for production purposes, it is to be used for developer assistance like logging.
|
|
99
|
+
// It supports recursive object structure, native realm collection, restricting array width (number of elements that can be stringified), and object tree depth
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
const JSONStringify = function (obj, objectTreeDepth = 3, arrayWidth = 4) {
|
|
103
|
+
const objectMap = new Map();
|
|
104
|
+
return JSONStringifyInternal(obj, objectTreeDepth, objectMap, arrayWidth);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
exports.JSONStringify = JSONStringify;
|