openchs-models 1.17.2 → 1.17.3

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.
@@ -234,6 +234,10 @@ 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
242
  const formElementStatus = _lodash.default.find(formElementStatuses, formElementStatus => {
239
243
  return fe.uuid === formElementStatus.uuid && (_lodash.default.isNil(fe.questionGroupIndex) || fe.questionGroupIndex === formElementStatus.questionGroupIndex);
@@ -252,7 +256,35 @@ class ObservationsHolder {
252
256
  uuid
253
257
  }) => fe.groupUuid === uuid);
254
258
 
255
- parentFormElement.repeatable ? this.updateRepeatableGroupQuestion(questionGroupIndex, parentFormElement, fe, value) : 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
+ });
256
288
  } else {
257
289
  concept.isCodedConcept() ? this.addOrUpdateCodedObs(concept, value, fe.isSingleSelect()) : this.addOrUpdatePrimitiveObs(concept, value);
258
290
  }
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.2",
4
+ "version": "1.17.3",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",