openchs-models 1.16.2 → 1.17.2
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/Concept.js +3 -1
- package/dist/Observation.js +3 -4
- package/dist/ObservationsHolder.js +100 -19
- package/dist/application/Form.js +6 -2
- package/dist/application/FormElement.js +26 -0
- package/dist/application/FormElementGroup.js +48 -14
- package/dist/application/FormElementStatus.js +5 -0
- package/dist/application/ValidationResult.js +7 -2
- package/dist/index.js +8 -0
- package/dist/observation/QuestionGroup.js +38 -1
- package/dist/observation/RepeatableQuestionGroup.js +97 -0
- package/dist/utility/General.js +13 -3
- package/package.json +1 -1
package/dist/Concept.js
CHANGED
|
@@ -31,6 +31,8 @@ var _Identifier = _interopRequireDefault(require("./Identifier"));
|
|
|
31
31
|
|
|
32
32
|
var _QuestionGroup = _interopRequireDefault(require("./observation/QuestionGroup"));
|
|
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; }
|
|
@@ -206,7 +208,7 @@ class Concept {
|
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
if (this.isQuestionGroup()) {
|
|
209
|
-
return _QuestionGroup.default.fromObs(obsValue);
|
|
211
|
+
return 'repeatableObservations' in obsValue ? _RepeatableQuestionGroup.default.fromObs(obsValue) : _QuestionGroup.default.fromObs(obsValue);
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
return new _PrimitiveValue.default(obsValue, this.datatype);
|
package/dist/Observation.js
CHANGED
|
@@ -164,7 +164,8 @@ class Observation {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
getReadableValue() {
|
|
167
|
-
|
|
167
|
+
const valueWrapper = this.getValueWrapper();
|
|
168
|
+
let value = valueWrapper.getValue();
|
|
168
169
|
|
|
169
170
|
if (!_lodash.default.isNil(value)) {
|
|
170
171
|
if (this.concept.isCodedConcept()) {
|
|
@@ -188,9 +189,7 @@ class Observation {
|
|
|
188
189
|
});
|
|
189
190
|
}
|
|
190
191
|
} else if (this.concept.isQuestionGroup()) {
|
|
191
|
-
return _lodash.default.map(value,
|
|
192
|
-
[obs.concept.name]: obs.getReadableValue()
|
|
193
|
-
}));
|
|
192
|
+
return valueWrapper.isRepeatable() ? _lodash.default.map(value, qg => qg.getReadableValue()) : valueWrapper.getReadableValue();
|
|
194
193
|
}
|
|
195
194
|
|
|
196
195
|
return value;
|
|
@@ -27,6 +27,8 @@ var _QuestionGroup = _interopRequireDefault(require("./observation/QuestionGroup
|
|
|
27
27
|
|
|
28
28
|
var _General = _interopRequireDefault(require("./utility/General"));
|
|
29
29
|
|
|
30
|
+
var _RepeatableQuestionGroup = _interopRequireDefault(require("./observation/RepeatableQuestionGroup"));
|
|
31
|
+
|
|
30
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
33
|
|
|
32
34
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -146,32 +148,76 @@ class ObservationsHolder {
|
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
removeNonApplicableObs(allFormElements, applicableFormElements) {
|
|
149
|
-
const
|
|
151
|
+
const formElementsIncludingRepeatableElements = [];
|
|
152
|
+
|
|
153
|
+
_lodash.default.forEach(allFormElements, fe => {
|
|
154
|
+
if (fe.concept.isQuestionGroup()) {
|
|
155
|
+
const observations = this.findObservation(fe.concept);
|
|
156
|
+
const questionGroupObs = observations && observations.getValueWrapper();
|
|
157
|
+
const size = questionGroupObs ? questionGroupObs.size() : 1;
|
|
158
|
+
|
|
159
|
+
const childFormElements = _lodash.default.filter(allFormElements, ({
|
|
160
|
+
groupUuid
|
|
161
|
+
}) => groupUuid === fe.uuid);
|
|
162
|
+
|
|
163
|
+
_lodash.default.forEach(childFormElements, cfe => {
|
|
164
|
+
_lodash.default.range(size).forEach(questionGroupIndex => {
|
|
165
|
+
const newFormElement = cfe.clone();
|
|
166
|
+
newFormElement.questionGroupIndex = _lodash.default.isEmpty(cfe.rule) ? undefined : questionGroupIndex;
|
|
167
|
+
formElementsIncludingRepeatableElements.push(newFormElement);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
} else if (_lodash.default.isNil(fe.groupUuid)) {
|
|
171
|
+
formElementsIncludingRepeatableElements.push(fe);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const inApplicableFormElements = _lodash.default.differenceWith(formElementsIncludingRepeatableElements, applicableFormElements, (a, b) => a.uuid === b.uuid && a.questionGroupIndex === b.questionGroupIndex);
|
|
150
176
|
|
|
151
177
|
applicableFormElements.forEach(fe => {
|
|
152
178
|
if (fe.concept.isCodedConcept() && (!_lodash.default.isEmpty(fe.answersToShow) || !_lodash.default.isEmpty(fe.answersToExclude))) {
|
|
153
|
-
this.removeNonApplicableAnswers(fe, fe.isSingleSelect());
|
|
179
|
+
fe.isQuestionGroup() ? this.removeNonApplicableAnswersFromQuestionGroup(fe, fe.isSingleSelect(), allFormElements) : this.removeNonApplicableAnswers(fe, fe.isSingleSelect(), this.getObservation(fe.concept));
|
|
154
180
|
}
|
|
155
181
|
});
|
|
156
|
-
return _lodash.default.flatten(inApplicableFormElements.map(fe => this._removeObs(fe
|
|
182
|
+
return _lodash.default.flatten(inApplicableFormElements.map(fe => this._removeObs(fe))).filter(obs => !_lodash.default.isEmpty(obs));
|
|
157
183
|
}
|
|
158
184
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
185
|
+
removeNonApplicableAnswersFromQuestionGroup(fe, isSingleSelect, allFormElements) {
|
|
186
|
+
const questionGroup = this.getQuestionGroups(fe);
|
|
187
|
+
const questionGroupObservation = questionGroup && questionGroup.getGroupObservationAtIndex(fe.questionGroupIndex);
|
|
188
|
+
const observation = questionGroupObservation && questionGroupObservation.getObservation(fe.concept);
|
|
189
|
+
|
|
190
|
+
if (!_lodash.default.isEmpty(observation)) {
|
|
191
|
+
questionGroupObservation.removeExistingObs(fe.concept);
|
|
192
|
+
const applicableConceptAnswerUUIDs = fe.getApplicableAnswerConceptUUIDs();
|
|
193
|
+
|
|
194
|
+
const applicableAnswers = _lodash.default.filter(_lodash.default.flatten([observation.getValue()]), value => _lodash.default.includes(applicableConceptAnswerUUIDs, value));
|
|
195
|
+
|
|
196
|
+
const newValue = isSingleSelect ? new _SingleCodedValue.default(_lodash.default.head(applicableAnswers)) : new _MultipleCodedValues.default(applicableAnswers);
|
|
197
|
+
|
|
198
|
+
const newObservation = _Observation.default.create(observation.concept, newValue);
|
|
164
199
|
|
|
165
|
-
|
|
166
|
-
|
|
200
|
+
questionGroupObservation.addObservation(newObservation);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
_removeObs(formElement) {
|
|
205
|
+
if (formElement.isQuestionGroup()) {
|
|
206
|
+
const questionGroup = this.getQuestionGroups(formElement);
|
|
207
|
+
const questionGroupObservation = questionGroup && questionGroup.getGroupObservationAtIndex(formElement.questionGroupIndex);
|
|
208
|
+
return questionGroupObservation && questionGroupObservation.removeExistingObs(formElement.concept);
|
|
167
209
|
} else {
|
|
168
210
|
return _lodash.default.remove(this.observations, obs => obs.concept.uuid === formElement.concept.uuid);
|
|
169
211
|
}
|
|
170
212
|
}
|
|
171
213
|
|
|
172
|
-
|
|
173
|
-
const
|
|
214
|
+
getQuestionGroups(formElement) {
|
|
215
|
+
const parentFormElement = formElement.getParentFormElement();
|
|
216
|
+
const questionGroupObservations = this.getObservation(parentFormElement.concept);
|
|
217
|
+
return questionGroupObservations && questionGroupObservations.getValueWrapper();
|
|
218
|
+
}
|
|
174
219
|
|
|
220
|
+
removeNonApplicableAnswers(fe, isSingleSelect, observation) {
|
|
175
221
|
if (!_lodash.default.isEmpty(observation)) {
|
|
176
222
|
_lodash.default.remove(this.observations, obs => obs.concept.uuid === observation.concept.uuid);
|
|
177
223
|
|
|
@@ -189,9 +235,14 @@ class ObservationsHolder {
|
|
|
189
235
|
|
|
190
236
|
updatePrimitiveCodedObs(applicableFormElements, formElementStatuses) {
|
|
191
237
|
applicableFormElements.forEach(fe => {
|
|
192
|
-
|
|
193
|
-
return fe.uuid === formElementStatus.uuid;
|
|
194
|
-
})
|
|
238
|
+
const formElementStatus = _lodash.default.find(formElementStatuses, formElementStatus => {
|
|
239
|
+
return fe.uuid === formElementStatus.uuid && (_lodash.default.isNil(fe.questionGroupIndex) || fe.questionGroupIndex === formElementStatus.questionGroupIndex);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const {
|
|
243
|
+
value,
|
|
244
|
+
questionGroupIndex
|
|
245
|
+
} = formElementStatus;
|
|
195
246
|
|
|
196
247
|
if (!_lodash.default.isNil(value)) {
|
|
197
248
|
const concept = fe.concept;
|
|
@@ -201,7 +252,7 @@ class ObservationsHolder {
|
|
|
201
252
|
uuid
|
|
202
253
|
}) => fe.groupUuid === uuid);
|
|
203
254
|
|
|
204
|
-
this.
|
|
255
|
+
parentFormElement.repeatable ? this.updateRepeatableGroupQuestion(questionGroupIndex, parentFormElement, fe, value) : this.updateGroupQuestion(parentFormElement, fe, value);
|
|
205
256
|
} else {
|
|
206
257
|
concept.isCodedConcept() ? this.addOrUpdateCodedObs(concept, value, fe.isSingleSelect()) : this.addOrUpdatePrimitiveObs(concept, value);
|
|
207
258
|
}
|
|
@@ -261,9 +312,21 @@ class ObservationsHolder {
|
|
|
261
312
|
return observation;
|
|
262
313
|
}
|
|
263
314
|
|
|
264
|
-
updateGroupQuestion(
|
|
315
|
+
updateGroupQuestion(parentFormElement, childFormElement, value) {
|
|
316
|
+
const parentConcept = parentFormElement.concept;
|
|
265
317
|
const parentObservation = this.getObservation(parentConcept);
|
|
266
318
|
const childObservations = _lodash.default.isEmpty(parentObservation) ? new _QuestionGroup.default() : parentObservation.getValueWrapper();
|
|
319
|
+
this.updateChildObservations(childFormElement, childObservations, value);
|
|
320
|
+
|
|
321
|
+
this._removeExistingObs(parentConcept);
|
|
322
|
+
|
|
323
|
+
if (!childObservations.isEmpty()) {
|
|
324
|
+
this.observations.push(_Observation.default.create(parentConcept, childObservations));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
updateChildObservations(childFormElement, childObservations, value) {
|
|
329
|
+
const childConcept = childFormElement.concept;
|
|
267
330
|
|
|
268
331
|
if (childConcept.isPrimitive() && _lodash.default.isNil(childFormElement.durationOptions)) {
|
|
269
332
|
childObservations.removeExistingObs(childConcept);
|
|
@@ -290,11 +353,29 @@ class ObservationsHolder {
|
|
|
290
353
|
}
|
|
291
354
|
}
|
|
292
355
|
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
updateRepeatableGroupQuestion(index, parentFormElement, childFormElement, value, action) {
|
|
359
|
+
const parentConcept = parentFormElement.concept;
|
|
360
|
+
const observations = this.getObservation(parentConcept);
|
|
361
|
+
const repeatableObservations = _lodash.default.isEmpty(observations) ? new _RepeatableQuestionGroup.default() : observations.getValueWrapper();
|
|
362
|
+
|
|
363
|
+
if (action === _RepeatableQuestionGroup.default.actions.add) {
|
|
364
|
+
repeatableObservations.addQuestionGroup();
|
|
365
|
+
return;
|
|
366
|
+
} else if (action === _RepeatableQuestionGroup.default.actions.remove) {
|
|
367
|
+
repeatableObservations.removeQuestionGroup(index);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const childObservations = repeatableObservations.getGroupObservationAtIndex(index);
|
|
372
|
+
this.updateChildObservations(childFormElement, childObservations, value);
|
|
373
|
+
repeatableObservations.updateGroupObservationsAtIndex(childObservations, index);
|
|
293
374
|
|
|
294
375
|
this._removeExistingObs(parentConcept);
|
|
295
376
|
|
|
296
|
-
if (!
|
|
297
|
-
this.observations.push(_Observation.default.create(parentConcept,
|
|
377
|
+
if (!repeatableObservations.isEmpty()) {
|
|
378
|
+
this.observations.push(_Observation.default.create(parentConcept, repeatableObservations));
|
|
298
379
|
}
|
|
299
380
|
}
|
|
300
381
|
|
package/dist/application/Form.js
CHANGED
|
@@ -23,6 +23,8 @@ var _moment = _interopRequireDefault(require("moment"));
|
|
|
23
23
|
|
|
24
24
|
var _QuestionGroup = _interopRequireDefault(require("../observation/QuestionGroup"));
|
|
25
25
|
|
|
26
|
+
var _RepeatableQuestionGroup = _interopRequireDefault(require("../observation/RepeatableQuestionGroup"));
|
|
27
|
+
|
|
26
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
29
|
|
|
28
30
|
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; }
|
|
@@ -203,8 +205,10 @@ class Form {
|
|
|
203
205
|
|
|
204
206
|
if (!_lodash.default.isNil(foundObs) && concept.isQuestionGroup()) {
|
|
205
207
|
const clonedObs = foundObs.cloneForEdit();
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
+
const valueWrapper = clonedObs.getValueWrapper();
|
|
209
|
+
const isRepeatable = valueWrapper.isRepeatable();
|
|
210
|
+
const sortedChildObs = isRepeatable ? _lodash.default.flatMap(valueWrapper.getValue(), questionGroup => new _QuestionGroup.default(this.orderQuestionGroupObservations(questionGroup.getValue(), formElement.uuid))) : this.orderQuestionGroupObservations(valueWrapper.getValue(), formElement.uuid);
|
|
211
|
+
clonedObs.valueJSON = JSON.stringify(isRepeatable ? new _RepeatableQuestionGroup.default(sortedChildObs) : new _QuestionGroup.default(sortedChildObs));
|
|
208
212
|
if (!_lodash.default.isEmpty(sortedChildObs)) orderedObservations.push(clonedObs);
|
|
209
213
|
} else {
|
|
210
214
|
if (!_lodash.default.isNil(foundObs)) orderedObservations.push(foundObs);
|
|
@@ -178,6 +178,11 @@ class FormElement {
|
|
|
178
178
|
return _lodash.default.isNil(editable) ? true : editable.getValue();
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
get repeatable() {
|
|
182
|
+
const repeatable = this.recordByKey("repeatable");
|
|
183
|
+
return _lodash.default.isNil(repeatable) ? false : repeatable.getValue();
|
|
184
|
+
}
|
|
185
|
+
|
|
181
186
|
get datePickerMode() {
|
|
182
187
|
const datePickerMode = this.recordByKey("datePickerMode");
|
|
183
188
|
return _lodash.default.isNil(datePickerMode) ? null : datePickerMode.getValue();
|
|
@@ -253,6 +258,27 @@ class FormElement {
|
|
|
253
258
|
return _lodash.default.isNil(allowedMaxSize) ? oneMBInBytes : _lodash.default.toNumber(allowedMaxSize.getValue()) * oneMBInBytes;
|
|
254
259
|
}
|
|
255
260
|
|
|
261
|
+
getParentFormElement() {
|
|
262
|
+
return _lodash.default.find(this.formElementGroup.getFormElements(), fe => fe.uuid === this.groupUuid);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
clone() {
|
|
266
|
+
const formElement = new FormElement();
|
|
267
|
+
formElement.uuid = this.uuid;
|
|
268
|
+
formElement.name = this.name;
|
|
269
|
+
formElement.displayOrder = this.displayOrder;
|
|
270
|
+
formElement.mandatory = this.mandatory;
|
|
271
|
+
formElement.keyValues = this.keyValues;
|
|
272
|
+
formElement.concept = this.concept;
|
|
273
|
+
formElement.type = this.type;
|
|
274
|
+
formElement.formElementGroup = this.formElementGroup;
|
|
275
|
+
formElement.validFormat = this.validFormat;
|
|
276
|
+
formElement.voided = this.voided;
|
|
277
|
+
formElement.rule = this.rule;
|
|
278
|
+
formElement.groupUuid = this.groupUuid;
|
|
279
|
+
return formElement;
|
|
280
|
+
}
|
|
281
|
+
|
|
256
282
|
}
|
|
257
283
|
|
|
258
284
|
_defineProperty(FormElement, "schema", {
|
|
@@ -19,6 +19,8 @@ var _lodash = _interopRequireDefault(require("lodash"));
|
|
|
19
19
|
|
|
20
20
|
var _QuestionGroup = _interopRequireDefault(require("../observation/QuestionGroup"));
|
|
21
21
|
|
|
22
|
+
var _RepeatableQuestionGroup = _interopRequireDefault(require("../observation/RepeatableQuestionGroup"));
|
|
23
|
+
|
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
25
|
|
|
24
26
|
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; }
|
|
@@ -70,21 +72,37 @@ class FormElementGroup {
|
|
|
70
72
|
validate(observationHolder, filteredFormElements) {
|
|
71
73
|
const validationResults = [];
|
|
72
74
|
filteredFormElements.forEach(formElement => {
|
|
73
|
-
if (formElement.isQuestionGroup()) {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
if (formElement.concept.isQuestionGroup()) {
|
|
76
|
+
const childFormElements = _lodash.default.filter(filteredFormElements, fe => fe.groupUuid === formElement.uuid);
|
|
77
|
+
|
|
78
|
+
const observations = observationHolder.findObservation(formElement.concept);
|
|
79
|
+
|
|
80
|
+
if (formElement.repeatable) {
|
|
81
|
+
const repeatableQuestionGroup = _lodash.default.isEmpty(observations) ? new _RepeatableQuestionGroup.default() : observations.getValueWrapper();
|
|
82
|
+
|
|
83
|
+
_lodash.default.forEach(repeatableQuestionGroup.getAllQuestionGroupObservations(), (questionGroup, index) => {
|
|
84
|
+
this.validateQuestionGroup(questionGroup, childFormElements, validationResults, index);
|
|
85
|
+
});
|
|
86
|
+
} else {
|
|
87
|
+
const questionGroup = _lodash.default.isEmpty(observations) ? new _QuestionGroup.default() : observations.getValueWrapper();
|
|
88
|
+
this.validateQuestionGroup(questionGroup, childFormElements, validationResults, 0);
|
|
89
|
+
}
|
|
90
|
+
} else if (!formElement.isQuestionGroup()) {
|
|
80
91
|
this.validateFormElement(formElement, observationHolder.findObservation(formElement.concept), validationResults);
|
|
81
92
|
}
|
|
82
93
|
});
|
|
83
94
|
return validationResults;
|
|
84
95
|
}
|
|
85
96
|
|
|
86
|
-
|
|
97
|
+
validateQuestionGroup(questionGroup, childFormElements, validationResults, questionGroupIndex) {
|
|
98
|
+
_lodash.default.filter(childFormElements, fe => _lodash.default.isNil(fe.questionGroupIndex) || fe.questionGroupIndex === questionGroupIndex).forEach(formElement => {
|
|
99
|
+
return this.validateFormElement(formElement, questionGroup.findObservation(formElement.concept), validationResults, questionGroupIndex);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
validateFormElement(formElement, observation, validationResults, questionGroupIndex) {
|
|
87
104
|
const validationResult = formElement.validate(_lodash.default.isNil(observation) ? null : observation.getValue());
|
|
105
|
+
validationResult.addQuestionGroupIndex(questionGroupIndex);
|
|
88
106
|
validationResults.push(validationResult);
|
|
89
107
|
}
|
|
90
108
|
|
|
@@ -116,13 +134,29 @@ class FormElementGroup {
|
|
|
116
134
|
}
|
|
117
135
|
|
|
118
136
|
filterElements(formElementStatuses) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
137
|
+
const filteredFormElements = [];
|
|
138
|
+
const allFormElements = this.getFormElements();
|
|
139
|
+
|
|
140
|
+
_lodash.default.forEach(formElementStatuses, ({
|
|
141
|
+
questionGroupIndex,
|
|
142
|
+
uuid,
|
|
143
|
+
visibility,
|
|
144
|
+
answersToShow,
|
|
145
|
+
answersToSkip
|
|
146
|
+
}) => {
|
|
147
|
+
const formElement = _lodash.default.find(allFormElements, fe => fe.uuid === uuid);
|
|
148
|
+
|
|
149
|
+
if (visibility && formElement) {
|
|
150
|
+
//clone is required to assign different questionGroupIndex to the same form element
|
|
151
|
+
const newFormElement = formElement.clone();
|
|
152
|
+
newFormElement.setAnswersToShow = answersToShow;
|
|
153
|
+
newFormElement.answersToSkip = answersToSkip;
|
|
154
|
+
newFormElement.questionGroupIndex = questionGroupIndex;
|
|
155
|
+
filteredFormElements.push(newFormElement);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
124
158
|
|
|
125
|
-
return FormElementGroup._sortedFormElements(
|
|
159
|
+
return FormElementGroup._sortedFormElements(filteredFormElements);
|
|
126
160
|
}
|
|
127
161
|
|
|
128
162
|
toJSON() {
|
|
@@ -23,9 +23,14 @@ class FormElementStatus {
|
|
|
23
23
|
oredFormElementStatus.answersToSkip = this.answersToSkip;
|
|
24
24
|
oredFormElementStatus.validationErrors = this.validationErrors;
|
|
25
25
|
oredFormElementStatus.answersToShow = this.answersToShow;
|
|
26
|
+
oredFormElementStatus.questionGroupIndex = this.questionGroupIndex;
|
|
26
27
|
return oredFormElementStatus;
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
addQuestionGroupInformation(questionGroupIndex) {
|
|
31
|
+
this.questionGroupIndex = questionGroupIndex;
|
|
32
|
+
}
|
|
33
|
+
|
|
29
34
|
or(formElementStatus) {
|
|
30
35
|
return this._bool(formElementStatus, (a, b) => a || b);
|
|
31
36
|
}
|
|
@@ -12,11 +12,16 @@ var _BaseEntity = _interopRequireDefault(require("../BaseEntity"));
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
14
|
class ValidationResult {
|
|
15
|
-
constructor(success, formIdentifier, messageKey, extra) {
|
|
15
|
+
constructor(success, formIdentifier, messageKey, extra, questionGroupIndex) {
|
|
16
16
|
this.success = success;
|
|
17
17
|
this.formIdentifier = formIdentifier;
|
|
18
18
|
this.messageKey = messageKey;
|
|
19
19
|
this.extra = extra;
|
|
20
|
+
this.questionGroupIndex = questionGroupIndex;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
addQuestionGroupIndex(index) {
|
|
24
|
+
this.questionGroupIndex = index;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
static successful(formIdentifier) {
|
|
@@ -37,7 +42,7 @@ class ValidationResult {
|
|
|
37
42
|
|
|
38
43
|
|
|
39
44
|
static clone(validationResult) {
|
|
40
|
-
return new ValidationResult(validationResult.success, validationResult.formIdentifier, validationResult.messageKey, validationResult.extra);
|
|
45
|
+
return new ValidationResult(validationResult.success, validationResult.formIdentifier, validationResult.messageKey, validationResult.extra, validationResult.questionGroupIndex);
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
static findByFormIdentifier(validationResults, formIdentifier) {
|
package/dist/index.js
CHANGED
|
@@ -651,6 +651,12 @@ Object.defineProperty(exports, "QuestionGroup", {
|
|
|
651
651
|
return _QuestionGroup.default;
|
|
652
652
|
}
|
|
653
653
|
});
|
|
654
|
+
Object.defineProperty(exports, "RepeatableQuestionGroup", {
|
|
655
|
+
enumerable: true,
|
|
656
|
+
get: function () {
|
|
657
|
+
return _RepeatableQuestionGroup.default;
|
|
658
|
+
}
|
|
659
|
+
});
|
|
654
660
|
|
|
655
661
|
var _AbstractEncounter = _interopRequireDefault(require("./AbstractEncounter"));
|
|
656
662
|
|
|
@@ -866,6 +872,8 @@ var _SubjectMigration = _interopRequireDefault(require("./SubjectMigration"));
|
|
|
866
872
|
|
|
867
873
|
var _QuestionGroup = _interopRequireDefault(require("./observation/QuestionGroup"));
|
|
868
874
|
|
|
875
|
+
var _RepeatableQuestionGroup = _interopRequireDefault(require("./observation/RepeatableQuestionGroup"));
|
|
876
|
+
|
|
869
877
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
870
878
|
|
|
871
879
|
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; }
|
|
@@ -25,7 +25,20 @@ class QuestionGroup {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
get toResource() {
|
|
28
|
-
|
|
28
|
+
const resource = {};
|
|
29
|
+
|
|
30
|
+
_lodash.default.forEach(this.groupObservations, obs => {
|
|
31
|
+
const {
|
|
32
|
+
conceptUUID,
|
|
33
|
+
value
|
|
34
|
+
} = obs.toResource;
|
|
35
|
+
|
|
36
|
+
_lodash.default.assign(resource, {
|
|
37
|
+
[conceptUUID]: value
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return resource;
|
|
29
42
|
}
|
|
30
43
|
|
|
31
44
|
static fromObs({
|
|
@@ -66,12 +79,32 @@ class QuestionGroup {
|
|
|
66
79
|
return this.groupObservations;
|
|
67
80
|
}
|
|
68
81
|
|
|
82
|
+
getReadableValue() {
|
|
83
|
+
return _lodash.default.map(this.groupObservations, obs => {
|
|
84
|
+
return {
|
|
85
|
+
[obs.concept.name]: obs.getReadableValue()
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
isRepeatable() {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
69
94
|
findObservation(concept) {
|
|
70
95
|
return _lodash.default.find(this.groupObservations, observation => {
|
|
71
96
|
return observation.concept.uuid === concept.uuid;
|
|
72
97
|
});
|
|
73
98
|
}
|
|
74
99
|
|
|
100
|
+
findObservationByConceptUUID(conceptNameOrUUID) {
|
|
101
|
+
return _lodash.default.find(this.groupObservations, obs => obs.concept.uuid === conceptNameOrUUID || obs.concept.name === conceptNameOrUUID);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getGroupObservationAtIndex(index) {
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
75
108
|
getObservation(concept) {
|
|
76
109
|
return this.findObservation(concept);
|
|
77
110
|
}
|
|
@@ -99,6 +132,10 @@ class QuestionGroup {
|
|
|
99
132
|
return _lodash.default.isEmpty(this.groupObservations);
|
|
100
133
|
}
|
|
101
134
|
|
|
135
|
+
size() {
|
|
136
|
+
return 1;
|
|
137
|
+
}
|
|
138
|
+
|
|
102
139
|
}
|
|
103
140
|
|
|
104
141
|
var _default = QuestionGroup;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
+
|
|
10
|
+
var _QuestionGroup = _interopRequireDefault(require("./QuestionGroup"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
|
|
16
|
+
class RepeatableQuestionGroup {
|
|
17
|
+
constructor(groupObservations) {
|
|
18
|
+
this.repeatableObservations = _lodash.default.isEmpty(groupObservations) ? [new _QuestionGroup.default()] : groupObservations;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get toResource() {
|
|
22
|
+
return _lodash.default.map(this.repeatableObservations, obs => obs.toResource);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static fromObs({
|
|
26
|
+
repeatableObservations
|
|
27
|
+
}) {
|
|
28
|
+
const newObs = _lodash.default.map(repeatableObservations, obs => _QuestionGroup.default.fromObs(obs));
|
|
29
|
+
|
|
30
|
+
return new RepeatableQuestionGroup(newObs);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getValue() {
|
|
34
|
+
return this.repeatableObservations;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getReadableValue() {
|
|
38
|
+
return _lodash.default.map(this.repeatableObservations, questionGroup => {
|
|
39
|
+
return questionGroup.getReadableValue();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
isRepeatable() {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
cloneForEdit() {
|
|
48
|
+
const newObs = _lodash.default.map(this.repeatableObservations, o => o.cloneForEdit());
|
|
49
|
+
|
|
50
|
+
return new RepeatableQuestionGroup(newObs);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
isEmpty() {
|
|
54
|
+
return _lodash.default.isEmpty(this.repeatableObservations);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
updateGroupObservationsAtIndex(groupObservations, index) {
|
|
58
|
+
if (!groupObservations.isEmpty()) {
|
|
59
|
+
this.repeatableObservations.splice(index, 1, groupObservations);
|
|
60
|
+
} else {
|
|
61
|
+
this.repeatableObservations.splice(index, 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getGroupObservationAtIndex(index) {
|
|
66
|
+
return this.repeatableObservations[index];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
size() {
|
|
70
|
+
return _lodash.default.size(this.repeatableObservations);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
nonEmptySize() {
|
|
74
|
+
return _lodash.default.size(_lodash.default.filter(this.repeatableObservations, questionGroup => !questionGroup.isEmpty()));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
addQuestionGroup() {
|
|
78
|
+
this.repeatableObservations.push(new _QuestionGroup.default());
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
removeQuestionGroup(index) {
|
|
82
|
+
this.repeatableObservations.splice(index, 1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getAllQuestionGroupObservations() {
|
|
86
|
+
return this.repeatableObservations;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
_defineProperty(RepeatableQuestionGroup, "actions", {
|
|
92
|
+
add: 'add',
|
|
93
|
+
remove: 'remove'
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
var _default = RepeatableQuestionGroup;
|
|
97
|
+
exports.default = _default;
|
package/dist/utility/General.js
CHANGED
|
@@ -17,6 +17,8 @@ var _Concept = _interopRequireDefault(require("../Concept"));
|
|
|
17
17
|
|
|
18
18
|
var _QuestionGroup = _interopRequireDefault(require("../observation/QuestionGroup"));
|
|
19
19
|
|
|
20
|
+
var _RepeatableQuestionGroup = _interopRequireDefault(require("../observation/RepeatableQuestionGroup"));
|
|
21
|
+
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
23
|
|
|
22
24
|
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; }
|
|
@@ -156,8 +158,8 @@ class General {
|
|
|
156
158
|
observation.concept = concept;
|
|
157
159
|
|
|
158
160
|
if (concept.isQuestionGroup()) {
|
|
159
|
-
const
|
|
160
|
-
observation.valueJSON = JSON.stringify(
|
|
161
|
+
const valueJson = _lodash.default.isArray(value) ? this.getRepeatableQuestionValue(value, entityService) : this.createQuestionGroupObservations(value, entityService);
|
|
162
|
+
observation.valueJSON = JSON.stringify(valueJson);
|
|
161
163
|
} else {
|
|
162
164
|
observation.valueJSON = JSON.stringify(observation.concept.getValueWrapperFor(value));
|
|
163
165
|
}
|
|
@@ -171,13 +173,21 @@ class General {
|
|
|
171
173
|
return dest;
|
|
172
174
|
}
|
|
173
175
|
|
|
176
|
+
static getRepeatableQuestionValue(values, entityService) {
|
|
177
|
+
const repeatableValues = _lodash.default.map(values, value => this.createQuestionGroupObservations(value, entityService));
|
|
178
|
+
|
|
179
|
+
return new _RepeatableQuestionGroup.default(repeatableValues);
|
|
180
|
+
}
|
|
181
|
+
|
|
174
182
|
static createQuestionGroupObservations(keyValues, entityService) {
|
|
175
|
-
|
|
183
|
+
const questionGroupObservations = _lodash.default.map(_lodash.default.toPairs(keyValues), ([conceptUUID, value]) => {
|
|
176
184
|
const observation = new _Observation.default();
|
|
177
185
|
observation.concept = entityService.findByKey("uuid", conceptUUID, _Concept.default.schema.name);
|
|
178
186
|
observation.valueJSON = observation.concept.getValueWrapperFor(value);
|
|
179
187
|
return observation;
|
|
180
188
|
});
|
|
189
|
+
|
|
190
|
+
return new _QuestionGroup.default(questionGroupObservations);
|
|
181
191
|
}
|
|
182
192
|
|
|
183
193
|
static pick(from, attributes, listAttributes) {
|