openchs-models 1.33.38 → 1.33.39
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.
|
@@ -152,8 +152,12 @@ class ObservationsHolder {
|
|
|
152
152
|
});
|
|
153
153
|
const inApplicableFormElements = _lodash.default.differenceWith(formElementsIncludingRepeatableElements, applicableFormElements, (a, b) => a.uuid === b.uuid && a.questionGroupIndex === b.questionGroupIndex);
|
|
154
154
|
applicableFormElements.forEach(fe => {
|
|
155
|
-
|
|
155
|
+
const hasFilters = !_lodash.default.isEmpty(fe.answersToShow) || !_lodash.default.isEmpty(fe.answersToExclude);
|
|
156
|
+
if (!hasFilters) return;
|
|
157
|
+
if (fe.concept.isCodedConcept()) {
|
|
156
158
|
fe.isQuestionGroup() ? this.removeNonApplicableAnswersFromQuestionGroup(fe, fe.isSingleSelect(), allFormElements) : this.removeNonApplicableAnswers(fe, fe.isSingleSelect(), this.getObservation(fe.concept));
|
|
159
|
+
} else if (fe.concept.isSubjectConcept()) {
|
|
160
|
+
this.removeNonApplicableSubjectAnswers(fe, fe.isSingleSelect(), this.getObservation(fe.concept));
|
|
157
161
|
}
|
|
158
162
|
});
|
|
159
163
|
return _lodash.default.flatten(inApplicableFormElements.map(fe => this._removeObs(fe))).filter(obs => !_lodash.default.isEmpty(obs));
|
|
@@ -202,6 +206,24 @@ class ObservationsHolder {
|
|
|
202
206
|
}
|
|
203
207
|
}
|
|
204
208
|
|
|
209
|
+
//private
|
|
210
|
+
removeNonApplicableSubjectAnswers(fe, isSingleSelect, observation) {
|
|
211
|
+
if (_lodash.default.isEmpty(observation)) return;
|
|
212
|
+
const allowedUUIDs = fe.getApplicableSubjectUUIDs();
|
|
213
|
+
const excludedUUIDs = fe.getExcludedSubjectUUIDs();
|
|
214
|
+
const currentValues = _lodash.default.flatten([observation.getValue()]);
|
|
215
|
+
const applicableValues = _lodash.default.filter(currentValues, value => {
|
|
216
|
+
if (allowedUUIDs && !_lodash.default.includes(allowedUUIDs, value)) return false;
|
|
217
|
+
if (_lodash.default.includes(excludedUUIDs, value)) return false;
|
|
218
|
+
return true;
|
|
219
|
+
});
|
|
220
|
+
if (applicableValues.length === currentValues.length) return;
|
|
221
|
+
_ArrayHelper.default.remove(this.observations, obs => obs.concept.uuid === observation.concept.uuid);
|
|
222
|
+
const newValue = isSingleSelect ? new _SingleCodedValue.default(_lodash.default.head(applicableValues)) : new _MultipleCodedValues.default(applicableValues);
|
|
223
|
+
const newObservation = _Observation.default.create(observation.concept, newValue);
|
|
224
|
+
this.observations.push(newObservation);
|
|
225
|
+
}
|
|
226
|
+
|
|
205
227
|
/*
|
|
206
228
|
Called from wizard after the update of the fields is called for all types. This is to sync up the coded fields based on the rules.
|
|
207
229
|
*/
|
|
@@ -217,6 +217,13 @@ class FormElement extends _BaseEntity.default {
|
|
|
217
217
|
getApplicableAnswerConceptUUIDs() {
|
|
218
218
|
return _lodash.default.map(this.getAnswers(), ca => ca.concept.uuid);
|
|
219
219
|
}
|
|
220
|
+
getApplicableSubjectUUIDs() {
|
|
221
|
+
if (!_lodash.default.isEmpty(this.answersToShow)) return [...this.answersToShow];
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
getExcludedSubjectUUIDs() {
|
|
225
|
+
return _lodash.default.isEmpty(this.answersToExclude) ? [] : [...this.answersToExclude];
|
|
226
|
+
}
|
|
220
227
|
getAnswerWithConceptName(conceptName) {
|
|
221
228
|
return _lodash.default.find(this.concept.getAnswers(), answer => answer.concept.name === conceptName);
|
|
222
229
|
}
|