openchs-models 1.17.0 → 1.17.1
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.
|
@@ -148,32 +148,76 @@ class ObservationsHolder {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
removeNonApplicableObs(allFormElements, applicableFormElements) {
|
|
151
|
-
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);
|
|
152
176
|
|
|
153
177
|
applicableFormElements.forEach(fe => {
|
|
154
178
|
if (fe.concept.isCodedConcept() && (!_lodash.default.isEmpty(fe.answersToShow) || !_lodash.default.isEmpty(fe.answersToExclude))) {
|
|
155
|
-
this.removeNonApplicableAnswers(fe, fe.isSingleSelect());
|
|
179
|
+
fe.isQuestionGroup() ? this.removeNonApplicableAnswersFromQuestionGroup(fe, fe.isSingleSelect(), allFormElements) : this.removeNonApplicableAnswers(fe, fe.isSingleSelect(), this.getObservation(fe.concept));
|
|
156
180
|
}
|
|
157
181
|
});
|
|
158
|
-
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));
|
|
159
183
|
}
|
|
160
184
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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));
|
|
166
195
|
|
|
167
|
-
const
|
|
168
|
-
|
|
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);
|
|
199
|
+
|
|
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);
|
|
169
209
|
} else {
|
|
170
210
|
return _lodash.default.remove(this.observations, obs => obs.concept.uuid === formElement.concept.uuid);
|
|
171
211
|
}
|
|
172
212
|
}
|
|
173
213
|
|
|
174
|
-
|
|
175
|
-
const
|
|
214
|
+
getQuestionGroups(formElement) {
|
|
215
|
+
const parentFormElement = formElement.getParentFormElement();
|
|
216
|
+
const questionGroupObservations = this.getObservation(parentFormElement.concept);
|
|
217
|
+
return questionGroupObservations && questionGroupObservations.getValueWrapper();
|
|
218
|
+
}
|
|
176
219
|
|
|
220
|
+
removeNonApplicableAnswers(fe, isSingleSelect, observation) {
|
|
177
221
|
if (!_lodash.default.isEmpty(observation)) {
|
|
178
222
|
_lodash.default.remove(this.observations, obs => obs.concept.uuid === observation.concept.uuid);
|
|
179
223
|
|
|
@@ -258,6 +258,27 @@ class FormElement {
|
|
|
258
258
|
return _lodash.default.isNil(allowedMaxSize) ? oneMBInBytes : _lodash.default.toNumber(allowedMaxSize.getValue()) * oneMBInBytes;
|
|
259
259
|
}
|
|
260
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
|
+
|
|
261
282
|
}
|
|
262
283
|
|
|
263
284
|
_defineProperty(FormElement, "schema", {
|
|
@@ -83,9 +83,9 @@ class FormElementGroup {
|
|
|
83
83
|
const repeatableQuestionGroup = _lodash.default.isEmpty(observations) ? new _RepeatableQuestionGroup.default() : observations.getValueWrapper();
|
|
84
84
|
const groupValidationResults = [];
|
|
85
85
|
|
|
86
|
-
_lodash.default.forEach(repeatableQuestionGroup.getAllQuestionGroupObservations(), questionGroup => {
|
|
86
|
+
_lodash.default.forEach(repeatableQuestionGroup.getAllQuestionGroupObservations(), (questionGroup, index) => {
|
|
87
87
|
const childValidations = [];
|
|
88
|
-
this.validateQuestionGroup(questionGroup, childFormElements, childValidations);
|
|
88
|
+
this.validateQuestionGroup(questionGroup, childFormElements, childValidations, index);
|
|
89
89
|
groupValidationResults.push(childValidations);
|
|
90
90
|
});
|
|
91
91
|
|
|
@@ -98,7 +98,7 @@ class FormElementGroup {
|
|
|
98
98
|
validationResults.push(validationResult);
|
|
99
99
|
} else {
|
|
100
100
|
const questionGroup = _lodash.default.isEmpty(observations) ? new _QuestionGroup.default() : observations.getValueWrapper();
|
|
101
|
-
this.validateQuestionGroup(questionGroup, childFormElements, validationResults);
|
|
101
|
+
this.validateQuestionGroup(questionGroup, childFormElements, validationResults, 0);
|
|
102
102
|
}
|
|
103
103
|
} else if (!formElement.isQuestionGroup()) {
|
|
104
104
|
this.validateFormElement(formElement, observationHolder.findObservation(formElement.concept), validationResults);
|
|
@@ -107,8 +107,10 @@ class FormElementGroup {
|
|
|
107
107
|
return validationResults;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
validateQuestionGroup(questionGroup, childFormElements, validationResults) {
|
|
111
|
-
_lodash.default.
|
|
110
|
+
validateQuestionGroup(questionGroup, childFormElements, validationResults, questionGroupIndex) {
|
|
111
|
+
_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);
|
|
113
|
+
});
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
validateFormElement(formElement, observation, validationResults) {
|
|
@@ -144,13 +146,29 @@ class FormElementGroup {
|
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
filterElements(formElementStatuses) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
const filteredFormElements = [];
|
|
150
|
+
const allFormElements = this.getFormElements();
|
|
151
|
+
|
|
152
|
+
_lodash.default.forEach(formElementStatuses, ({
|
|
153
|
+
questionGroupIndex,
|
|
154
|
+
uuid,
|
|
155
|
+
visibility,
|
|
156
|
+
answersToShow,
|
|
157
|
+
answersToSkip
|
|
158
|
+
}) => {
|
|
159
|
+
const formElement = _lodash.default.find(allFormElements, fe => fe.uuid === uuid);
|
|
160
|
+
|
|
161
|
+
if (visibility && formElement) {
|
|
162
|
+
//clone is required to assign different questionGroupIndex to the same form element
|
|
163
|
+
const newFormElement = formElement.clone();
|
|
164
|
+
newFormElement.setAnswersToShow = answersToShow;
|
|
165
|
+
newFormElement.answersToSkip = answersToSkip;
|
|
166
|
+
newFormElement.questionGroupIndex = questionGroupIndex;
|
|
167
|
+
filteredFormElements.push(newFormElement);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
152
170
|
|
|
153
|
-
return FormElementGroup._sortedFormElements(
|
|
171
|
+
return FormElementGroup._sortedFormElements(filteredFormElements);
|
|
154
172
|
}
|
|
155
173
|
|
|
156
174
|
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
|
}
|
|
@@ -89,6 +89,14 @@ class QuestionGroup {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
findObservationByConceptUUID(conceptNameOrUUID) {
|
|
93
|
+
return _lodash.default.find(this.groupObservations, obs => obs.concept.uuid === conceptNameOrUUID || obs.concept.name === conceptNameOrUUID);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getGroupObservationAtIndex(index) {
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
|
|
92
100
|
getObservation(concept) {
|
|
93
101
|
return this.findObservation(concept);
|
|
94
102
|
}
|
|
@@ -116,6 +124,10 @@ class QuestionGroup {
|
|
|
116
124
|
return _lodash.default.isEmpty(this.groupObservations);
|
|
117
125
|
}
|
|
118
126
|
|
|
127
|
+
size() {
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
|
|
119
131
|
}
|
|
120
132
|
|
|
121
133
|
var _default = QuestionGroup;
|