openchs-models 1.17.1 → 1.17.4

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.
@@ -164,7 +164,8 @@ class Observation {
164
164
  }
165
165
 
166
166
  getReadableValue() {
167
- let value = this.getValue();
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, obs => ({
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;
@@ -234,10 +234,19 @@ class ObservationsHolder {
234
234
  }
235
235
 
236
236
  updatePrimitiveCodedObs(applicableFormElements, formElementStatuses) {
237
+ const updateQuestionGroupObs = (parentFormElement, questionGroupIndex, fe, value) => {
238
+ parentFormElement.repeatable ? this.updateRepeatableGroupQuestion(questionGroupIndex, parentFormElement, fe, value) : this.updateGroupQuestion(parentFormElement, fe, value);
239
+ };
240
+
237
241
  applicableFormElements.forEach(fe => {
238
- let value = _lodash.default.find(formElementStatuses, formElementStatus => {
239
- return fe.uuid === formElementStatus.uuid;
240
- }).value;
242
+ const formElementStatus = _lodash.default.find(formElementStatuses, formElementStatus => {
243
+ return fe.uuid === formElementStatus.uuid && (_lodash.default.isNil(fe.questionGroupIndex) || fe.questionGroupIndex === formElementStatus.questionGroupIndex);
244
+ });
245
+
246
+ const {
247
+ value,
248
+ questionGroupIndex
249
+ } = formElementStatus;
241
250
 
242
251
  if (!_lodash.default.isNil(value)) {
243
252
  const concept = fe.concept;
@@ -247,7 +256,35 @@ class ObservationsHolder {
247
256
  uuid
248
257
  }) => fe.groupUuid === uuid);
249
258
 
250
- this.updateGroupQuestion(parentFormElement, fe, value);
259
+ updateQuestionGroupObs(parentFormElement, questionGroupIndex, fe, value);
260
+ } else if (concept.isQuestionGroup() && _lodash.default.isArray(value)) {
261
+ const observation = this.findObservation(concept);
262
+ const questionGroup = observation && observation.getValueWrapper();
263
+ const size = questionGroup ? questionGroup.size() : 0;
264
+
265
+ if (size >= value.length) {
266
+ // Don't populate the values if already done. This will allow users to edit the prepopulated values.
267
+ // This check is added to make sure user can update the group values.
268
+ return;
269
+ }
270
+
271
+ _lodash.default.forEach(value, (questionGroupValue, index) => {
272
+ if (fe.repeatable && size < index + 1) {
273
+ this.updateRepeatableGroupQuestion(index, fe, null, null, 'add');
274
+ }
275
+
276
+ _lodash.default.forEach(questionGroupValue, (answerValue, conceptUUID) => {
277
+ const childFormElement = _lodash.default.find(fe.formElementGroup.getFormElements(), ({
278
+ concept
279
+ }) => concept.uuid === conceptUUID);
280
+
281
+ if (childFormElement.concept.isCodedConcept() && childFormElement.isMultiSelect() && _lodash.default.isArray(answerValue)) {
282
+ _lodash.default.forEach(answerValue, v => updateQuestionGroupObs(fe, index, childFormElement, v));
283
+ } else {
284
+ updateQuestionGroupObs(fe, index, childFormElement, answerValue);
285
+ }
286
+ });
287
+ });
251
288
  } else {
252
289
  concept.isCodedConcept() ? this.addOrUpdateCodedObs(concept, value, fe.isSingleSelect()) : this.addOrUpdatePrimitiveObs(concept, value);
253
290
  }
@@ -333,7 +370,7 @@ class ObservationsHolder {
333
370
  }
334
371
  }
335
372
 
336
- if (childConcept.isCodedConcept()) {
373
+ if (childConcept.isCodedConcept() || childConcept.isMediaConcept()) {
337
374
  let observation = childObservations.getObservation(childConcept);
338
375
  const isSingleSelect = childFormElement.isSingleSelect();
339
376
 
@@ -21,8 +21,6 @@ var _QuestionGroup = _interopRequireDefault(require("../observation/QuestionGrou
21
21
 
22
22
  var _RepeatableQuestionGroup = _interopRequireDefault(require("../observation/RepeatableQuestionGroup"));
23
23
 
24
- var _ValidationResult = _interopRequireDefault(require("./ValidationResult"));
25
-
26
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
25
 
28
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; }
@@ -81,21 +79,10 @@ class FormElementGroup {
81
79
 
82
80
  if (formElement.repeatable) {
83
81
  const repeatableQuestionGroup = _lodash.default.isEmpty(observations) ? new _RepeatableQuestionGroup.default() : observations.getValueWrapper();
84
- const groupValidationResults = [];
85
82
 
86
83
  _lodash.default.forEach(repeatableQuestionGroup.getAllQuestionGroupObservations(), (questionGroup, index) => {
87
- const childValidations = [];
88
- this.validateQuestionGroup(questionGroup, childFormElements, childValidations, index);
89
- groupValidationResults.push(childValidations);
84
+ this.validateQuestionGroup(questionGroup, childFormElements, validationResults, index);
90
85
  });
91
-
92
- const isSuccess = _lodash.default.every(groupValidationResults, childValidations => _lodash.default.every(childValidations, ({
93
- success
94
- }) => success));
95
-
96
- const validationResult = new _ValidationResult.default(isSuccess, formElement.uuid);
97
- validationResult.groupValidations = groupValidationResults;
98
- validationResults.push(validationResult);
99
86
  } else {
100
87
  const questionGroup = _lodash.default.isEmpty(observations) ? new _QuestionGroup.default() : observations.getValueWrapper();
101
88
  this.validateQuestionGroup(questionGroup, childFormElements, validationResults, 0);
@@ -109,12 +96,13 @@ class FormElementGroup {
109
96
 
110
97
  validateQuestionGroup(questionGroup, childFormElements, validationResults, questionGroupIndex) {
111
98
  _lodash.default.filter(childFormElements, fe => _lodash.default.isNil(fe.questionGroupIndex) || fe.questionGroupIndex === questionGroupIndex).forEach(formElement => {
112
- return this.validateFormElement(formElement, questionGroup.findObservation(formElement.concept), validationResults);
99
+ return this.validateFormElement(formElement, questionGroup.findObservation(formElement.concept), validationResults, questionGroupIndex);
113
100
  });
114
101
  }
115
102
 
116
- validateFormElement(formElement, observation, validationResults) {
103
+ validateFormElement(formElement, observation, validationResults, questionGroupIndex) {
117
104
  const validationResult = formElement.validate(_lodash.default.isNil(observation) ? null : observation.getValue());
105
+ validationResult.addQuestionGroupIndex(questionGroupIndex);
118
106
  validationResults.push(validationResult);
119
107
  }
120
108
 
@@ -12,12 +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.groupValidations = [];
20
+ this.questionGroupIndex = questionGroupIndex;
21
+ }
22
+
23
+ addQuestionGroupIndex(index) {
24
+ this.questionGroupIndex = index;
21
25
  }
22
26
 
23
27
  static successful(formIdentifier) {
@@ -38,7 +42,7 @@ class ValidationResult {
38
42
 
39
43
 
40
44
  static clone(validationResult) {
41
- 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);
42
46
  }
43
47
 
44
48
  static findByFormIdentifier(validationResults, formIdentifier) {
@@ -79,6 +79,14 @@ class QuestionGroup {
79
79
  return this.groupObservations;
80
80
  }
81
81
 
82
+ getReadableValue() {
83
+ return _lodash.default.map(this.groupObservations, obs => {
84
+ return {
85
+ [obs.concept.name]: obs.getReadableValue()
86
+ };
87
+ });
88
+ }
89
+
82
90
  isRepeatable() {
83
91
  return false;
84
92
  }
@@ -34,6 +34,12 @@ class RepeatableQuestionGroup {
34
34
  return this.repeatableObservations;
35
35
  }
36
36
 
37
+ getReadableValue() {
38
+ return _lodash.default.map(this.repeatableObservations, questionGroup => {
39
+ return questionGroup.getReadableValue();
40
+ });
41
+ }
42
+
37
43
  isRepeatable() {
38
44
  return true;
39
45
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "openchs-models",
3
3
  "description": "OpenCHS data model to be used by front end clients",
4
- "version": "1.17.1",
4
+ "version": "1.17.4",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",