openchs-models 1.33.2 → 1.33.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.
- package/.circleci/config.yml +15 -5
- package/.commit-message.txt +21 -0
- package/.nvmrc +1 -1
- package/Makefile +32 -10
- package/REALM_V12_NOTES.md +46 -0
- package/dist/AbstractEncounter.js +4 -105
- package/dist/AddressLevel.js +5 -62
- package/dist/ApprovalStatus.js +4 -17
- package/dist/BaseEntity.js +5 -42
- package/dist/BeneficiaryModePin.js +4 -13
- package/dist/Checklist.js +6 -52
- package/dist/ChecklistDetail.js +4 -22
- package/dist/ChecklistItem.js +16 -96
- package/dist/ChecklistItemDetail.js +4 -43
- package/dist/ChecklistItemStatus.js +4 -33
- package/dist/Comment.js +6 -51
- package/dist/CommentThread.js +4 -26
- package/dist/CompositeDuration.js +1 -18
- package/dist/Concept.js +5 -107
- package/dist/ConceptAnswer.js +4 -21
- package/dist/CustomDashboardCache.js +4 -38
- package/dist/CustomFilter.js +5 -15
- package/dist/Dashboard.js +4 -23
- package/dist/DashboardCache.js +4 -23
- package/dist/DashboardSection.js +4 -24
- package/dist/DashboardSectionCardMapping.js +4 -21
- package/dist/Displayable.js +3 -11
- package/dist/Documentation.js +4 -21
- package/dist/DocumentationItem.js +4 -20
- package/dist/Duration.js +4 -39
- package/dist/Encounter.js +6 -41
- package/dist/EncounterType.js +4 -26
- package/dist/EntityApprovalStatus.js +6 -56
- package/dist/EntityMetaData.js +7 -105
- package/dist/EntityQueue.js +4 -15
- package/dist/EntityRule.js +1 -29
- package/dist/EntitySyncStatus.js +4 -19
- package/dist/Extension.js +4 -18
- package/dist/Family.js +4 -56
- package/dist/FileFormat.js +0 -7
- package/dist/Gender.js +4 -17
- package/dist/GroupDashboard.js +4 -23
- package/dist/GroupPrivileges.js +4 -28
- package/dist/GroupRole.js +4 -34
- package/dist/GroupSubject.js +6 -59
- package/dist/Groups.js +4 -14
- package/dist/Identifier.js +4 -20
- package/dist/IdentifierAssignment.js +6 -45
- package/dist/IdentifierSource.js +4 -15
- package/dist/Individual.js +17 -265
- package/dist/LocaleMapping.js +4 -13
- package/dist/LocationHierarchy.js +4 -25
- package/dist/Media.js +35 -35
- package/dist/MediaQueue.js +4 -26
- package/dist/MigrationsHelper.js +15 -22
- package/dist/MyGroups.js +4 -14
- package/dist/News.js +4 -31
- package/dist/Observation.js +4 -54
- package/dist/ObservationsHolder.js +104 -216
- package/dist/OrganisationConfig.js +4 -19
- package/dist/PersistedObject.js +1 -19
- package/dist/PhoneNumber.js +0 -11
- package/dist/PlatformTranslation.js +4 -17
- package/dist/Privilege.js +5 -22
- package/dist/Program.js +4 -39
- package/dist/ProgramEncounter.js +6 -48
- package/dist/ProgramEnrolment.js +8 -162
- package/dist/ReferenceEntity.js +1 -10
- package/dist/ReportCard.js +5 -60
- package/dist/ResetSync.js +4 -17
- package/dist/Rule.js +4 -28
- package/dist/RuleDependency.js +4 -17
- package/dist/RuleFailureTelemetry.js +4 -36
- package/dist/Schema.js +16 -268
- package/dist/SchemaNames.js +3 -46
- package/dist/Settings.js +4 -53
- package/dist/StandardReportCardType.js +4 -39
- package/dist/SubjectMigration.js +6 -45
- package/dist/SubjectType.js +6 -72
- package/dist/SyncTelemetry.js +4 -40
- package/dist/Translation.js +4 -17
- package/dist/UserInfo.js +4 -33
- package/dist/application/DashboardCacheFilter.js +4 -24
- package/dist/application/Filter.js +3 -16
- package/dist/application/Form.js +6 -93
- package/dist/application/FormElement.js +5 -100
- package/dist/application/FormElementGroup.js +4 -75
- package/dist/application/FormElementStatus.js +1 -11
- package/dist/application/FormMapping.js +6 -44
- package/dist/application/Format.js +4 -20
- package/dist/application/KeyValue.js +4 -19
- package/dist/application/MenuItem.js +4 -35
- package/dist/application/MultiSelectFilter.js +1 -11
- package/dist/application/NullProgramEnrolment.js +0 -8
- package/dist/application/SingleSelectFilter.js +1 -12
- package/dist/application/StaticFormElementGroup.js +0 -11
- package/dist/application/StringKeyNumericValue.js +4 -17
- package/dist/application/ValidationResult.js +6 -20
- package/dist/application/ValidationResults.js +1 -14
- package/dist/application/WorkItem.js +4 -20
- package/dist/application/WorkList.js +1 -24
- package/dist/application/WorkLists.js +1 -13
- package/dist/assignment/UserSubjectAssignment.js +6 -26
- package/dist/draft/DraftEncounter.js +4 -40
- package/dist/draft/DraftSubject.js +4 -46
- package/dist/error/IgnorableSyncError.js +1 -6
- package/dist/error/SyncError.js +1 -6
- package/dist/framework/ArrayHelper.js +3 -11
- package/dist/framework/DefinedObjectSchema.js +4 -12
- package/dist/framework/RealmCollectionHelper.js +1 -9
- package/dist/framework/RealmListProxy.js +1 -10
- package/dist/framework/RealmObjectSchema.js +1 -11
- package/dist/framework/RealmProxy.js +2 -31
- package/dist/framework/RealmResultsProxy.js +3 -37
- package/dist/framework/RealmResultsProxyHandler.js +2 -5
- package/dist/geo/Point.js +4 -17
- package/dist/index.js +2 -137
- package/dist/location/Locations.js +1 -6
- package/dist/observation/MultipleCodedValues.js +1 -21
- package/dist/observation/PrimitiveValue.js +1 -17
- package/dist/observation/QuestionGroup.js +1 -36
- package/dist/observation/RepeatableQuestionGroup.js +4 -27
- package/dist/observation/SingleCodedValue.js +1 -15
- package/dist/program/SubjectProgramEligibility.js +6 -56
- package/dist/relationship/IndividualRelation.js +6 -18
- package/dist/relationship/IndividualRelationGenderMapping.js +4 -22
- package/dist/relationship/IndividualRelationship.js +6 -51
- package/dist/relationship/IndividualRelationshipType.js +4 -24
- package/dist/relationship/IndividualRelative.js +4 -31
- package/dist/reports/DashboardFilter.js +4 -20
- package/dist/reports/DashboardFilterConfig.js +5 -85
- package/dist/reports/NestedReportCardResult.js +5 -35
- package/dist/reports/Range.js +4 -13
- package/dist/reports/ReportCardResult.js +5 -24
- package/dist/service/MetaDataService.js +1 -30
- package/dist/task/Task.js +6 -62
- package/dist/task/TaskStatus.js +4 -21
- package/dist/task/TaskType.js +4 -23
- package/dist/task/TaskUnAssignment.js +6 -30
- package/dist/utility/AgeUtil.js +1 -15
- package/dist/utility/ArrayUtil.js +1 -6
- package/dist/utility/AuditUtil.js +1 -8
- package/dist/utility/DateTimeUtil.js +1 -8
- package/dist/utility/General.js +4 -71
- package/dist/utility/JsonStringify.js +15 -28
- package/dist/utility/MergeUtil.js +1 -10
- package/dist/utility/ResourceUtil.js +1 -7
- package/dist/videos/Video.js +4 -23
- package/dist/videos/VideoTelemetric.js +6 -37
- package/package.json +6 -3
- package/scripts/validateSchemas.js +40 -0
- package/tsconfig.json +1 -1
- package/yarn.lock +0 -6744
|
@@ -4,69 +4,49 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _lodash = _interopRequireWildcard(require("lodash"));
|
|
9
|
-
|
|
10
8
|
var _Observation = _interopRequireDefault(require("./Observation"));
|
|
11
|
-
|
|
12
9
|
var _PrimitiveValue = _interopRequireDefault(require("./observation/PrimitiveValue"));
|
|
13
|
-
|
|
14
10
|
var _SingleCodedValue = _interopRequireDefault(require("./observation/SingleCodedValue"));
|
|
15
|
-
|
|
16
11
|
var _MultipleCodedValues = _interopRequireDefault(require("./observation/MultipleCodedValues"));
|
|
17
|
-
|
|
18
12
|
var _Concept = _interopRequireDefault(require("./Concept"));
|
|
19
|
-
|
|
20
13
|
var _CompositeDuration = _interopRequireDefault(require("./CompositeDuration"));
|
|
21
|
-
|
|
22
14
|
var _PhoneNumber = _interopRequireDefault(require("./PhoneNumber"));
|
|
23
|
-
|
|
24
15
|
var _Identifier = _interopRequireDefault(require("./Identifier"));
|
|
25
|
-
|
|
26
16
|
var _QuestionGroup = _interopRequireDefault(require("./observation/QuestionGroup"));
|
|
27
|
-
|
|
28
17
|
var _General = _interopRequireDefault(require("./utility/General"));
|
|
29
|
-
|
|
30
18
|
var _RepeatableQuestionGroup = _interopRequireDefault(require("./observation/RepeatableQuestionGroup"));
|
|
31
|
-
|
|
32
19
|
var _ArrayHelper = _interopRequireDefault(require("./framework/ArrayHelper"));
|
|
33
|
-
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
41
|
-
|
|
42
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
43
|
-
|
|
44
|
-
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; }
|
|
45
|
-
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
22
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
23
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
24
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
25
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
26
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
46
27
|
// Helper function to find media observation by value
|
|
47
28
|
const findMediaObservationByValue = (observations, targetValue) => {
|
|
48
29
|
if (!observations || !Array.isArray(observations)) return null;
|
|
49
30
|
return _lodash.default.find(observations, obs => {
|
|
50
31
|
// Check direct value
|
|
51
|
-
if (obs.getValue && obs.getValue() === targetValue) return true;
|
|
32
|
+
if (obs.getValue && obs.getValue() === targetValue) return true;
|
|
52
33
|
|
|
34
|
+
// Check coded values (for MultipleCodedValues)
|
|
53
35
|
const valueJSON = obs.valueJSON;
|
|
54
|
-
|
|
55
36
|
if (valueJSON && valueJSON.answer && Array.isArray(valueJSON.answer)) {
|
|
56
37
|
return valueJSON.answer.includes(targetValue);
|
|
57
38
|
}
|
|
58
|
-
|
|
59
39
|
return false;
|
|
60
40
|
});
|
|
61
|
-
};
|
|
62
|
-
|
|
41
|
+
};
|
|
63
42
|
|
|
43
|
+
// Helper function to update media value
|
|
64
44
|
const updateMediaValue = (mediaObs, oldVal, newVal) => {
|
|
65
|
-
if (!mediaObs) return false;
|
|
45
|
+
if (!mediaObs) return false;
|
|
66
46
|
|
|
47
|
+
// For coded values, we need to update the array content
|
|
67
48
|
if (mediaObs.valueJSON && mediaObs.valueJSON.answer && Array.isArray(mediaObs.valueJSON.answer)) {
|
|
68
49
|
const answerIndex = mediaObs.valueJSON.answer.indexOf(oldVal);
|
|
69
|
-
|
|
70
50
|
if (answerIndex >= 0) {
|
|
71
51
|
mediaObs.valueJSON.answer[answerIndex] = newVal;
|
|
72
52
|
return true;
|
|
@@ -76,56 +56,45 @@ const updateMediaValue = (mediaObs, oldVal, newVal) => {
|
|
|
76
56
|
mediaObs.setValue(mediaObs.concept.getValueWrapperFor(newVal));
|
|
77
57
|
return true;
|
|
78
58
|
}
|
|
79
|
-
|
|
80
59
|
return false;
|
|
81
|
-
};
|
|
82
|
-
|
|
60
|
+
};
|
|
83
61
|
|
|
62
|
+
// Process each question group observation
|
|
84
63
|
const processQuestionGroupObservations = (observations, oldVal, newVal) => {
|
|
85
64
|
const mediaObs = findMediaObservationByValue(observations, oldVal);
|
|
86
65
|
return mediaObs ? updateMediaValue(mediaObs, oldVal, newVal) : false;
|
|
87
66
|
};
|
|
88
|
-
|
|
89
67
|
class ObservationsHolder {
|
|
90
68
|
constructor(observations) {
|
|
91
69
|
this.observations = observations;
|
|
92
70
|
}
|
|
93
|
-
|
|
94
71
|
findObservation(concept) {
|
|
95
72
|
return _lodash.default.find(this.observations, observation => {
|
|
96
73
|
return observation.concept.uuid === concept.uuid;
|
|
97
74
|
});
|
|
98
75
|
}
|
|
99
|
-
|
|
100
76
|
findQuestionGroupObservation(concept, parentFormElement, questionGroupIndex) {
|
|
101
77
|
const observations = this.findObservation(parentFormElement.concept);
|
|
102
78
|
const groupObservations = observations && observations.getValueWrapper();
|
|
103
|
-
|
|
104
79
|
if (parentFormElement.repeatable) {
|
|
105
80
|
return groupObservations && groupObservations.size() > questionGroupIndex && groupObservations.getGroupObservationAtIndex(questionGroupIndex).getObservation(concept);
|
|
106
81
|
}
|
|
107
|
-
|
|
108
82
|
return groupObservations && groupObservations.getObservation(concept);
|
|
109
83
|
}
|
|
110
|
-
|
|
111
84
|
getObservation(concept) {
|
|
112
85
|
return this.findObservation(concept);
|
|
113
86
|
}
|
|
114
|
-
|
|
115
87
|
findObservationByValue(value) {
|
|
116
88
|
return _lodash.default.find(this.observations, observation => observation.getValue() === value);
|
|
117
89
|
}
|
|
90
|
+
|
|
118
91
|
/*
|
|
119
92
|
Called from the wizard on changes done by the user for primitive fields (including Date)
|
|
120
93
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
94
|
addOrUpdatePrimitiveObs(concept, value, answerSource = _Observation.default.AnswerSource.Manual) {
|
|
124
95
|
let currentObservation = this.findObservation(concept);
|
|
125
96
|
const currentValue = currentObservation && currentObservation.getValueWrapper() || {};
|
|
126
|
-
|
|
127
97
|
this._removeExistingObs(concept);
|
|
128
|
-
|
|
129
98
|
if (!_lodash.default.isEmpty(_lodash.default.toString(value))) {
|
|
130
99
|
if (concept.isIdConcept()) {
|
|
131
100
|
this.observations.push(_Observation.default.create(concept, _Identifier.default.fromObs(_objectSpread({}, currentValue, {
|
|
@@ -135,49 +104,40 @@ class ObservationsHolder {
|
|
|
135
104
|
this.observations.push(_Observation.default.create(concept, new _PrimitiveValue.default(value, concept.datatype, answerSource)));
|
|
136
105
|
}
|
|
137
106
|
}
|
|
138
|
-
}
|
|
139
|
-
|
|
107
|
+
}
|
|
140
108
|
|
|
109
|
+
//private
|
|
141
110
|
_removeExistingObs(concept) {
|
|
142
111
|
const observation = this.getObservation(concept);
|
|
143
|
-
|
|
144
112
|
if (!_lodash.default.isEmpty(observation)) {
|
|
145
113
|
_ArrayHelper.default.remove(this.observations, obs => obs.concept.uuid === observation.concept.uuid);
|
|
146
114
|
}
|
|
147
|
-
}
|
|
148
|
-
|
|
115
|
+
}
|
|
149
116
|
|
|
117
|
+
//private
|
|
150
118
|
addOrUpdateCodedObs(concept, value, isSingleSelect, answerSource = _Observation.default.AnswerSource.Auto) {
|
|
151
119
|
this._removeExistingObs(concept);
|
|
152
|
-
|
|
153
120
|
const getConceptUUID = conceptAnswer => conceptAnswer ? conceptAnswer.concept.uuid : undefined;
|
|
154
|
-
|
|
155
121
|
if (!_lodash.default.isEmpty(value)) {
|
|
156
122
|
const answerUUID = isSingleSelect ? getConceptUUID(concept.getAnswerWithConceptName(value)) : value.map(v => getConceptUUID(concept.getAnswerWithConceptName(v)));
|
|
157
|
-
|
|
158
123
|
const observation = _Observation.default.create(concept, isSingleSelect ? new _SingleCodedValue.default(answerUUID, answerSource) : new _MultipleCodedValues.default(answerUUID, answerSource));
|
|
159
|
-
|
|
160
124
|
this.observations.push(observation);
|
|
161
125
|
}
|
|
162
126
|
}
|
|
127
|
+
|
|
163
128
|
/*
|
|
164
129
|
called during edit of form element by the user and when the page transition takes place
|
|
165
130
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
131
|
removeNonApplicableObs(allFormElements, applicableFormElements) {
|
|
169
132
|
const formElementsIncludingRepeatableElements = [];
|
|
170
|
-
|
|
171
133
|
_lodash.default.forEach(allFormElements, fe => {
|
|
172
134
|
if (fe.concept.isQuestionGroup()) {
|
|
173
135
|
const observations = this.findObservation(fe.concept);
|
|
174
136
|
const questionGroupObs = observations && observations.getValueWrapper();
|
|
175
137
|
const size = questionGroupObs ? questionGroupObs.size() : 1;
|
|
176
|
-
|
|
177
138
|
const childFormElements = _lodash.default.filter(allFormElements, ({
|
|
178
139
|
groupUuid
|
|
179
140
|
}) => groupUuid === fe.uuid);
|
|
180
|
-
|
|
181
141
|
_lodash.default.forEach(childFormElements, cfe => {
|
|
182
142
|
_lodash.default.range(size).forEach(questionGroupIndex => {
|
|
183
143
|
const newFormElement = cfe.clone();
|
|
@@ -185,44 +145,36 @@ class ObservationsHolder {
|
|
|
185
145
|
formElementsIncludingRepeatableElements.push(newFormElement);
|
|
186
146
|
});
|
|
187
147
|
});
|
|
188
|
-
|
|
189
148
|
formElementsIncludingRepeatableElements.push(fe);
|
|
190
149
|
} else if (_lodash.default.isNil(fe.groupUuid)) {
|
|
191
150
|
formElementsIncludingRepeatableElements.push(fe);
|
|
192
151
|
}
|
|
193
152
|
});
|
|
194
|
-
|
|
195
153
|
const inApplicableFormElements = _lodash.default.differenceWith(formElementsIncludingRepeatableElements, applicableFormElements, (a, b) => a.uuid === b.uuid && a.questionGroupIndex === b.questionGroupIndex);
|
|
196
|
-
|
|
197
154
|
applicableFormElements.forEach(fe => {
|
|
198
155
|
if (fe.concept.isCodedConcept() && (!_lodash.default.isEmpty(fe.answersToShow) || !_lodash.default.isEmpty(fe.answersToExclude))) {
|
|
199
156
|
fe.isQuestionGroup() ? this.removeNonApplicableAnswersFromQuestionGroup(fe, fe.isSingleSelect(), allFormElements) : this.removeNonApplicableAnswers(fe, fe.isSingleSelect(), this.getObservation(fe.concept));
|
|
200
157
|
}
|
|
201
158
|
});
|
|
202
159
|
return _lodash.default.flatten(inApplicableFormElements.map(fe => this._removeObs(fe))).filter(obs => !_lodash.default.isEmpty(obs));
|
|
203
|
-
}
|
|
204
|
-
|
|
160
|
+
}
|
|
205
161
|
|
|
162
|
+
//private
|
|
206
163
|
removeNonApplicableAnswersFromQuestionGroup(fe, isSingleSelect) {
|
|
207
164
|
const questionGroup = this.getQuestionGroups(fe);
|
|
208
165
|
const questionGroupObservation = questionGroup && questionGroup.getGroupObservationAtIndex(fe.questionGroupIndex);
|
|
209
166
|
const observation = questionGroupObservation && questionGroupObservation.getObservation(fe.concept);
|
|
210
|
-
|
|
211
167
|
if (!_lodash.default.isEmpty(observation)) {
|
|
212
168
|
questionGroupObservation.removeExistingObs(fe.concept);
|
|
213
169
|
const applicableConceptAnswerUUIDs = fe.getApplicableAnswerConceptUUIDs();
|
|
214
|
-
|
|
215
170
|
const applicableAnswers = _lodash.default.filter(_lodash.default.flatten([observation.getValue()]), value => _lodash.default.includes(applicableConceptAnswerUUIDs, value));
|
|
216
|
-
|
|
217
171
|
const newValue = isSingleSelect ? new _SingleCodedValue.default(_lodash.default.head(applicableAnswers)) : new _MultipleCodedValues.default(applicableAnswers);
|
|
218
|
-
|
|
219
172
|
const newObservation = _Observation.default.create(observation.concept, newValue);
|
|
220
|
-
|
|
221
173
|
questionGroupObservation.addObservation(newObservation);
|
|
222
174
|
}
|
|
223
|
-
}
|
|
224
|
-
|
|
175
|
+
}
|
|
225
176
|
|
|
177
|
+
//private
|
|
226
178
|
_removeObs(formElement) {
|
|
227
179
|
if (formElement.isQuestionGroup()) {
|
|
228
180
|
const questionGroup = this.getQuestionGroups(formElement);
|
|
@@ -232,80 +184,64 @@ class ObservationsHolder {
|
|
|
232
184
|
return _ArrayHelper.default.remove(this.observations, obs => obs.concept.uuid === formElement.concept.uuid);
|
|
233
185
|
}
|
|
234
186
|
}
|
|
235
|
-
|
|
236
187
|
getQuestionGroups(formElement) {
|
|
237
188
|
const parentFormElement = formElement.getParentFormElement();
|
|
238
189
|
const questionGroupObservations = this.getObservation(parentFormElement.concept);
|
|
239
190
|
return questionGroupObservations && questionGroupObservations.getValueWrapper();
|
|
240
|
-
}
|
|
241
|
-
|
|
191
|
+
}
|
|
242
192
|
|
|
193
|
+
//private
|
|
243
194
|
removeNonApplicableAnswers(fe, isSingleSelect, observation) {
|
|
244
195
|
if (!_lodash.default.isEmpty(observation)) {
|
|
245
196
|
_ArrayHelper.default.remove(this.observations, obs => obs.concept.uuid === observation.concept.uuid);
|
|
246
|
-
|
|
247
197
|
const applicableConceptAnswerUUIDs = fe.getApplicableAnswerConceptUUIDs();
|
|
248
|
-
|
|
249
198
|
const applicableAnswers = _lodash.default.filter(_lodash.default.flatten([observation.getValue()]), value => _lodash.default.includes(applicableConceptAnswerUUIDs, value));
|
|
250
|
-
|
|
251
199
|
const newValue = isSingleSelect ? new _SingleCodedValue.default(_lodash.default.head(applicableAnswers)) : new _MultipleCodedValues.default(applicableAnswers);
|
|
252
|
-
|
|
253
200
|
const newObservation = _Observation.default.create(observation.concept, newValue);
|
|
254
|
-
|
|
255
201
|
this.observations.push(newObservation);
|
|
256
202
|
}
|
|
257
203
|
}
|
|
204
|
+
|
|
258
205
|
/*
|
|
259
206
|
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.
|
|
260
207
|
*/
|
|
261
|
-
|
|
262
|
-
|
|
263
208
|
updatePrimitiveCodedObs(applicableFormElements, formElementStatuses) {
|
|
264
209
|
const updateQuestionGroupObs = (parentFormElement, questionGroupIndex, fe, value) => {
|
|
265
210
|
parentFormElement && parentFormElement.repeatable ? this.updateRepeatableGroupQuestion(questionGroupIndex, parentFormElement, fe, value) : this.updateGroupQuestion(parentFormElement, fe, value);
|
|
266
211
|
};
|
|
267
|
-
|
|
268
212
|
applicableFormElements.forEach(fe => {
|
|
269
213
|
const formElementStatus = _lodash.default.find(formElementStatuses, formElementStatus => {
|
|
270
214
|
return fe.uuid === formElementStatus.uuid && (_lodash.default.isNil(fe.questionGroupIndex) || fe.questionGroupIndex === formElementStatus.questionGroupIndex);
|
|
271
215
|
});
|
|
272
|
-
|
|
273
216
|
const {
|
|
274
217
|
value,
|
|
275
218
|
questionGroupIndex,
|
|
276
219
|
initializedWithNullValueOnPurpose
|
|
277
220
|
} = formElementStatus;
|
|
278
|
-
|
|
279
221
|
if (!_lodash.default.isNil(value) || !!initializedWithNullValueOnPurpose) {
|
|
280
222
|
const concept = fe.concept;
|
|
281
|
-
|
|
282
223
|
if (fe.isQuestionGroup()) {
|
|
283
224
|
const parentFormElement = _lodash.default.find(applicableFormElements, ({
|
|
284
225
|
uuid
|
|
285
226
|
}) => fe.groupUuid === uuid);
|
|
286
|
-
|
|
287
227
|
updateQuestionGroupObs(parentFormElement, questionGroupIndex, fe, value);
|
|
288
228
|
} else if (concept.isQuestionGroup() && !_lodash.default.isNil(value) && _lodash.default.isArray(value)) {
|
|
289
229
|
const observation = this.findObservation(concept);
|
|
290
230
|
const questionGroup = observation && observation.getValueWrapper();
|
|
291
231
|
const size = questionGroup ? questionGroup.size() : 0;
|
|
292
|
-
|
|
293
232
|
if (size >= value.length) {
|
|
294
233
|
// Don't populate the values if already done. This will allow users to edit the prepopulated values.
|
|
295
234
|
// This check is added to make sure user can update the group values.
|
|
296
235
|
return;
|
|
297
236
|
}
|
|
298
|
-
|
|
299
237
|
_lodash.default.forEach(value, (questionGroupValue, index) => {
|
|
300
238
|
if (fe.repeatable && size < index + 1) {
|
|
301
239
|
this.updateRepeatableGroupQuestion(index, fe, null, null, 'add');
|
|
302
240
|
}
|
|
303
|
-
|
|
304
241
|
_lodash.default.forEach(questionGroupValue, (answerValue, conceptUUID) => {
|
|
305
242
|
const childFormElement = _lodash.default.find(fe.formElementGroup.getFormElements(), ({
|
|
306
243
|
concept
|
|
307
244
|
}) => concept.uuid === conceptUUID);
|
|
308
|
-
|
|
309
245
|
if (childFormElement.concept.isCodedConcept() && childFormElement.isMultiSelect() && _lodash.default.isArray(answerValue)) {
|
|
310
246
|
_lodash.default.forEach(answerValue, v => updateQuestionGroupObs(fe, index, childFormElement, v));
|
|
311
247
|
} else {
|
|
@@ -319,108 +255,86 @@ class ObservationsHolder {
|
|
|
319
255
|
}
|
|
320
256
|
});
|
|
321
257
|
}
|
|
258
|
+
|
|
322
259
|
/*
|
|
323
260
|
called for direct edit of single select field
|
|
324
261
|
*/
|
|
325
|
-
|
|
326
|
-
|
|
327
262
|
toggleSingleSelectAnswer(concept, answerUUID) {
|
|
328
263
|
return this.toggleCodedAnswer(concept, answerUUID, true);
|
|
329
|
-
}
|
|
330
|
-
|
|
264
|
+
}
|
|
331
265
|
|
|
266
|
+
//private
|
|
332
267
|
toggleCodedAnswer(concept, answerUUID, isSingleSelect) {
|
|
333
268
|
let observation = this.getObservation(concept);
|
|
334
|
-
|
|
335
269
|
if (_lodash.default.isEmpty(observation)) {
|
|
336
270
|
observation = _Observation.default.create(concept, isSingleSelect ? new _SingleCodedValue.default(answerUUID) : new _MultipleCodedValues.default().push(answerUUID));
|
|
337
271
|
this.observations.push(observation);
|
|
338
272
|
return observation;
|
|
339
273
|
} else {
|
|
340
274
|
isSingleSelect ? observation.toggleSingleSelectAnswer(answerUUID) : observation.toggleMultiSelectAnswer(answerUUID);
|
|
341
|
-
|
|
342
275
|
if (observation.hasNoAnswer()) {
|
|
343
276
|
_ArrayHelper.default.remove(this.observations, obs => obs.concept.uuid === observation.concept.uuid);
|
|
344
|
-
|
|
345
277
|
return null;
|
|
346
278
|
}
|
|
347
|
-
|
|
348
279
|
observation.valueJSON.answerSource = _Observation.default.AnswerSource.Manual;
|
|
349
280
|
return observation;
|
|
350
281
|
}
|
|
351
282
|
}
|
|
283
|
+
|
|
352
284
|
/*
|
|
353
285
|
called for direct edit of duration field
|
|
354
286
|
*/
|
|
355
|
-
|
|
356
|
-
|
|
357
287
|
updateCompositeDurationValue(concept, duration) {
|
|
358
288
|
let observation = this.getObservation(concept);
|
|
359
|
-
|
|
360
289
|
if (!_lodash.default.isEmpty(observation)) {
|
|
361
290
|
_ArrayHelper.default.remove(this.observations, obs => obs.concept.uuid === observation.concept.uuid);
|
|
362
|
-
|
|
363
291
|
if (duration.isEmpty) return null;
|
|
364
292
|
}
|
|
365
|
-
|
|
366
293
|
observation = _Observation.default.create(concept, duration);
|
|
367
294
|
this.observations.push(observation);
|
|
368
295
|
return observation;
|
|
369
296
|
}
|
|
297
|
+
|
|
370
298
|
/*
|
|
371
299
|
called for direct edit of phone number field
|
|
372
300
|
*/
|
|
373
|
-
|
|
374
|
-
|
|
375
301
|
updatePhoneNumberValue(concept, phoneNumber, verified = false, skipVerification = false) {
|
|
376
302
|
let observation = this.getObservation(concept);
|
|
377
|
-
|
|
378
303
|
if (!_lodash.default.isEmpty(observation)) {
|
|
379
304
|
_ArrayHelper.default.remove(this.observations, obs => obs.concept.uuid === observation.concept.uuid);
|
|
380
|
-
|
|
381
305
|
if (_lodash.default.isEmpty(phoneNumber)) return null;
|
|
382
306
|
}
|
|
383
|
-
|
|
384
307
|
observation = _Observation.default.create(concept, new _PhoneNumber.default(phoneNumber, verified, skipVerification));
|
|
385
308
|
this.observations.push(observation);
|
|
386
309
|
return observation;
|
|
387
310
|
}
|
|
388
|
-
|
|
389
311
|
updateGroupQuestion(parentFormElement, childFormElement, value, verified = false, skipVerification = false) {
|
|
390
312
|
if (_lodash.default.isUndefined(parentFormElement) || _lodash.default.isNull(parentFormElement)) {
|
|
391
313
|
return;
|
|
392
314
|
}
|
|
393
|
-
|
|
394
315
|
const parentConcept = parentFormElement.concept;
|
|
395
316
|
const parentObservation = this.getObservation(parentConcept);
|
|
396
317
|
const childObservations = _lodash.default.isEmpty(parentObservation) ? new _QuestionGroup.default() : parentObservation.getValueWrapper();
|
|
397
318
|
this.updateChildObservations(childFormElement, childObservations, value, verified, skipVerification);
|
|
398
|
-
|
|
399
319
|
this._removeExistingObs(parentConcept);
|
|
400
|
-
|
|
401
320
|
if (!childObservations.isEmpty()) {
|
|
402
321
|
this.observations.push(_Observation.default.create(parentConcept, childObservations));
|
|
403
322
|
}
|
|
404
|
-
}
|
|
405
|
-
|
|
323
|
+
}
|
|
406
324
|
|
|
325
|
+
//private
|
|
407
326
|
updateChildObservations(childFormElement, childObservations, value, verified = false, skipVerification = false) {
|
|
408
327
|
const childConcept = childFormElement.concept;
|
|
409
|
-
|
|
410
328
|
if (childConcept.isPrimitive()) {
|
|
411
329
|
childObservations.removeExistingObs(childConcept);
|
|
412
|
-
|
|
413
330
|
if (!_lodash.default.isEmpty(_lodash.default.toString(value))) {
|
|
414
331
|
const observation = _Observation.default.create(childConcept, new _PrimitiveValue.default(value, childConcept.datatype));
|
|
415
|
-
|
|
416
332
|
childObservations.addObservation(observation);
|
|
417
333
|
}
|
|
418
334
|
}
|
|
419
|
-
|
|
420
335
|
if (childConcept.isCodedConcept() || childConcept.isMediaConcept() || childConcept.isSubjectConcept()) {
|
|
421
336
|
let observation = childObservations.getObservation(childConcept);
|
|
422
337
|
const isSingleSelect = childFormElement.isSingleSelect();
|
|
423
|
-
|
|
424
338
|
if (_lodash.default.isEmpty(observation)) {
|
|
425
339
|
observation = _Observation.default.create(childConcept, isSingleSelect ? new _SingleCodedValue.default(value) : new _MultipleCodedValues.default().push(value));
|
|
426
340
|
childObservations.addObservation(observation);
|
|
@@ -428,39 +342,30 @@ class ObservationsHolder {
|
|
|
428
342
|
if (!_lodash.default.isNil(value)) {
|
|
429
343
|
isSingleSelect ? observation.toggleSingleSelectAnswer(value) : observation.toggleMultiSelectAnswer(value);
|
|
430
344
|
}
|
|
431
|
-
|
|
432
345
|
if (observation.hasNoAnswer() || _lodash.default.isNil(value)) {
|
|
433
346
|
childObservations.removeExistingObs(childConcept);
|
|
434
347
|
}
|
|
435
348
|
}
|
|
436
349
|
}
|
|
437
|
-
|
|
438
350
|
if (childFormElement.getType() === _Concept.default.dataType.Duration && !(0, _lodash.isNil)(childFormElement.durationOptions)) {
|
|
439
351
|
childObservations.removeExistingObs(childConcept);
|
|
440
|
-
|
|
441
352
|
if (!_lodash.default.isEmpty(value) && !_lodash.default.isEmpty(value.durations)) {
|
|
442
353
|
const observation = _Observation.default.create(childFormElement.concept, _CompositeDuration.default.fromObs(value));
|
|
443
|
-
|
|
444
354
|
childObservations.addObservation(observation);
|
|
445
355
|
}
|
|
446
356
|
}
|
|
447
|
-
|
|
448
357
|
if (childFormElement.getType() === _Concept.default.dataType.PhoneNumber) {
|
|
449
358
|
childObservations.removeExistingObs(childConcept);
|
|
450
|
-
|
|
451
359
|
if (!_lodash.default.isEmpty(value)) {
|
|
452
360
|
const observation = _Observation.default.create(childFormElement.concept, new _PhoneNumber.default(value, verified, skipVerification));
|
|
453
|
-
|
|
454
361
|
childObservations.addObservation(observation);
|
|
455
362
|
}
|
|
456
363
|
}
|
|
457
364
|
}
|
|
458
|
-
|
|
459
365
|
updateRepeatableGroupQuestion(index, parentFormElement, childFormElement, value, action, verified = false, skipVerification = false) {
|
|
460
366
|
const parentConcept = parentFormElement.concept;
|
|
461
367
|
const observations = this.getObservation(parentConcept);
|
|
462
368
|
const repeatableObservations = _lodash.default.isEmpty(observations) ? new _RepeatableQuestionGroup.default() : observations.getValueWrapper();
|
|
463
|
-
|
|
464
369
|
if (action === _RepeatableQuestionGroup.default.actions.add) {
|
|
465
370
|
repeatableObservations.addQuestionGroup();
|
|
466
371
|
return;
|
|
@@ -468,159 +373,147 @@ class ObservationsHolder {
|
|
|
468
373
|
repeatableObservations.removeQuestionGroup(index);
|
|
469
374
|
return;
|
|
470
375
|
}
|
|
471
|
-
|
|
472
376
|
const childObservations = repeatableObservations.getGroupObservationAtIndex(index);
|
|
473
377
|
this.updateChildObservations(childFormElement, childObservations, value, verified, skipVerification);
|
|
474
378
|
repeatableObservations.updateGroupObservationsAtIndex(childObservations, index);
|
|
475
|
-
|
|
476
379
|
this._removeExistingObs(parentConcept);
|
|
477
|
-
|
|
478
380
|
if (!repeatableObservations.isEmpty()) {
|
|
479
381
|
this.observations.push(_Observation.default.create(parentConcept, repeatableObservations));
|
|
480
382
|
}
|
|
481
383
|
}
|
|
482
|
-
|
|
483
384
|
toggleMultiSelectAnswer(concept, answerUUID) {
|
|
484
385
|
return this.toggleCodedAnswer(concept, answerUUID, false);
|
|
485
386
|
}
|
|
486
|
-
|
|
487
387
|
static clone(observations) {
|
|
488
388
|
return _lodash.default.map(observations, o => o.cloneForEdit());
|
|
489
389
|
}
|
|
490
|
-
|
|
491
390
|
static convertObsForSave(observations) {
|
|
492
391
|
observations.forEach(observation => {
|
|
493
392
|
if (observation.valueJSON && typeof observation.valueJSON !== "string") {
|
|
494
393
|
observation.valueJSON = JSON.stringify(observation.valueJSON);
|
|
495
394
|
}
|
|
496
395
|
});
|
|
497
|
-
}
|
|
498
|
-
|
|
396
|
+
}
|
|
499
397
|
|
|
398
|
+
//private
|
|
500
399
|
getObservationReadableValue(concept) {
|
|
501
400
|
let obs = this.getObservation(concept);
|
|
502
401
|
return obs ? obs.getReadableValue() : null;
|
|
503
402
|
}
|
|
504
|
-
|
|
505
403
|
addOrUpdateObservation(concept, value) {
|
|
506
404
|
let observation = this.getObservation(concept);
|
|
507
405
|
let valueWrapper = concept.getValueWrapperFor(value);
|
|
508
|
-
|
|
509
406
|
if (observation) {
|
|
510
407
|
observation.setValue(valueWrapper);
|
|
511
408
|
} else {
|
|
512
409
|
this.observations.push(_Observation.default.create(concept, valueWrapper));
|
|
513
410
|
}
|
|
514
|
-
}
|
|
515
|
-
|
|
411
|
+
}
|
|
516
412
|
|
|
413
|
+
//private
|
|
517
414
|
updateObservationBasedOnValue(oldValue, newValue) {
|
|
518
415
|
// Try to find at top level first
|
|
519
416
|
const observation = this.findObservationByValue(oldValue);
|
|
520
|
-
|
|
521
417
|
if (observation) {
|
|
522
418
|
observation.setValue(observation.concept.getValueWrapperFor(newValue));
|
|
523
419
|
return true;
|
|
524
|
-
}
|
|
525
|
-
|
|
420
|
+
}
|
|
526
421
|
|
|
527
|
-
|
|
422
|
+
// Search in nested structures if not found at top level
|
|
423
|
+
let updated = false;
|
|
528
424
|
|
|
425
|
+
// Iterate through all observations
|
|
529
426
|
_lodash.default.forEach(this.observations, obs => {
|
|
530
427
|
// Skip non-question group observations
|
|
531
428
|
if (obs.concept.datatype !== _Concept.default.dataType.QuestionGroup) return;
|
|
532
429
|
const valueWrapper = obs.getValueWrapper && obs.getValueWrapper();
|
|
533
|
-
if (!valueWrapper) return;
|
|
430
|
+
if (!valueWrapper) return;
|
|
534
431
|
|
|
432
|
+
// Handle RepeatableQuestionGroup
|
|
535
433
|
if (valueWrapper.isRepeatable && valueWrapper.isRepeatable()) {
|
|
536
434
|
const allGroups = valueWrapper.getAllQuestionGroupObservations && valueWrapper.getAllQuestionGroupObservations();
|
|
537
|
-
|
|
538
435
|
if (allGroups && allGroups.length) {
|
|
539
436
|
// Check each group in the repeatable question group
|
|
540
437
|
allGroups.forEach(group => {
|
|
541
438
|
const groupObservations = group.getValue && group.getValue();
|
|
542
|
-
|
|
543
439
|
if (processQuestionGroupObservations(groupObservations, oldValue, newValue)) {
|
|
544
440
|
updated = true;
|
|
545
441
|
}
|
|
546
442
|
});
|
|
547
443
|
}
|
|
548
|
-
}
|
|
444
|
+
}
|
|
445
|
+
// Handle regular QuestionGroup
|
|
549
446
|
else {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
updated = true;
|
|
554
|
-
}
|
|
447
|
+
const groupObservations = valueWrapper.getValue && valueWrapper.getValue();
|
|
448
|
+
if (processQuestionGroupObservations(groupObservations, oldValue, newValue)) {
|
|
449
|
+
updated = true;
|
|
555
450
|
}
|
|
451
|
+
}
|
|
556
452
|
});
|
|
557
|
-
|
|
558
453
|
return updated;
|
|
559
|
-
}
|
|
560
|
-
|
|
454
|
+
}
|
|
561
455
|
|
|
456
|
+
// Helper method to update media value in an observation
|
|
562
457
|
_updateMediaValueInObservation(observation, oldValue, newValue) {
|
|
563
458
|
if (!observation) return false;
|
|
564
459
|
const valueWrapper = observation.getValueWrapper && observation.getValueWrapper();
|
|
565
|
-
if (!valueWrapper) return false;
|
|
460
|
+
if (!valueWrapper) return false;
|
|
566
461
|
|
|
462
|
+
// Handle ImageV2 type
|
|
567
463
|
if (observation.concept.datatype === _Concept.default.dataType.ImageV2) {
|
|
568
464
|
const mediaObjects = JSON.parse(valueWrapper.getValue());
|
|
569
465
|
let updated = false;
|
|
570
|
-
|
|
571
466
|
const newAnswers = _lodash.default.map(mediaObjects, mediaObject => {
|
|
572
467
|
if (mediaObject.uri === oldValue) {
|
|
573
468
|
mediaObject.uri = newValue;
|
|
574
469
|
updated = true;
|
|
575
470
|
}
|
|
576
|
-
|
|
577
471
|
return mediaObject;
|
|
578
472
|
});
|
|
579
|
-
|
|
580
473
|
if (updated) {
|
|
581
474
|
observation.valueJSON = new _PrimitiveValue.default(JSON.stringify(newAnswers), _Concept.default.dataType.ImageV2);
|
|
582
475
|
return true;
|
|
583
476
|
}
|
|
584
|
-
}
|
|
477
|
+
}
|
|
478
|
+
// Handle multiple coded values
|
|
585
479
|
else if (valueWrapper.isMultipleCoded) {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
return true;
|
|
601
|
-
}
|
|
602
|
-
|
|
480
|
+
const answers = valueWrapper.getValue();
|
|
481
|
+
const oldValueIndex = _lodash.default.indexOf(answers, oldValue);
|
|
482
|
+
if (oldValueIndex >= 0) {
|
|
483
|
+
const newAnswers = _lodash.default.reject(answers, answer => answer === oldValue);
|
|
484
|
+
newAnswers.splice(oldValueIndex, 0, newValue);
|
|
485
|
+
observation.valueJSON = new _MultipleCodedValues.default(newAnswers);
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
// Handle single coded value
|
|
490
|
+
else if (valueWrapper.getValue() === oldValue) {
|
|
491
|
+
observation.valueJSON = new _SingleCodedValue.default(newValue);
|
|
492
|
+
return true;
|
|
493
|
+
}
|
|
603
494
|
return false;
|
|
604
|
-
}
|
|
605
|
-
|
|
495
|
+
}
|
|
606
496
|
|
|
497
|
+
// Helper to find and update media in question group
|
|
607
498
|
_updateMediaInQuestionGroup(questionGroup, conceptUUID, oldValue, newValue) {
|
|
608
499
|
if (!questionGroup || !questionGroup.getValue) return false;
|
|
609
500
|
const groupObservations = questionGroup.getValue();
|
|
610
|
-
if (!groupObservations || !Array.isArray(groupObservations)) return false;
|
|
611
|
-
|
|
612
|
-
const mediaObs = _lodash.default.find(groupObservations, obs => obs.concept.uuid === conceptUUID || _Concept.default.dataType.Media.includes(obs.concept.datatype) && obs.getValue && obs.getValue() === oldValue); // Update if found
|
|
501
|
+
if (!groupObservations || !Array.isArray(groupObservations)) return false;
|
|
613
502
|
|
|
503
|
+
// Find media observation either by concept UUID or by value
|
|
504
|
+
const mediaObs = _lodash.default.find(groupObservations, obs => obs.concept.uuid === conceptUUID || _Concept.default.dataType.Media.includes(obs.concept.datatype) && obs.getValue && obs.getValue() === oldValue);
|
|
614
505
|
|
|
506
|
+
// Update if found
|
|
615
507
|
return this._updateMediaValueInObservation(mediaObs, oldValue, newValue);
|
|
616
|
-
}
|
|
617
|
-
|
|
508
|
+
}
|
|
618
509
|
|
|
510
|
+
// Helper to find and update media in repeatable question group
|
|
619
511
|
_updateMediaInRepeatableQuestionGroup(repeatableGroup, conceptUUID, oldValue, newValue) {
|
|
620
512
|
if (!repeatableGroup || !repeatableGroup.getAllQuestionGroupObservations) return false;
|
|
621
513
|
const allGroups = repeatableGroup.getAllQuestionGroupObservations();
|
|
622
|
-
if (!allGroups || !allGroups.length) return false;
|
|
514
|
+
if (!allGroups || !allGroups.length) return false;
|
|
623
515
|
|
|
516
|
+
// Check each group in the repeatable question group
|
|
624
517
|
let updated = false;
|
|
625
518
|
allGroups.forEach(group => {
|
|
626
519
|
if (this._updateMediaInQuestionGroup(group, conceptUUID, oldValue, newValue)) {
|
|
@@ -628,23 +521,24 @@ class ObservationsHolder {
|
|
|
628
521
|
}
|
|
629
522
|
});
|
|
630
523
|
return updated;
|
|
631
|
-
}
|
|
632
|
-
|
|
524
|
+
}
|
|
633
525
|
|
|
526
|
+
// Helper to process a question group (regular or repeatable) and update media within it
|
|
634
527
|
_processQuestionGroupWrapper(wrapper, conceptUUID, oldValue, newValue, sourceName) {
|
|
635
|
-
if (!wrapper) return false;
|
|
528
|
+
if (!wrapper) return false;
|
|
636
529
|
|
|
637
|
-
|
|
530
|
+
// Determine if it's a repeatable question group or regular question group
|
|
531
|
+
const isRepeatable = wrapper.isRepeatable && wrapper.isRepeatable();
|
|
638
532
|
|
|
533
|
+
// Process the appropriate group type
|
|
639
534
|
return isRepeatable ? this._updateMediaInRepeatableQuestionGroup(wrapper, conceptUUID, oldValue, newValue) : this._updateMediaInQuestionGroup(wrapper, conceptUUID, oldValue, newValue);
|
|
640
535
|
}
|
|
641
|
-
|
|
642
536
|
replaceMediaObservation(oldValue, newValue, conceptUUID) {
|
|
643
|
-
console.log(`[INFO] Replacing media: ${oldValue} → ${newValue}`);
|
|
644
|
-
// Try to find direct top-level observation with matching concept UUID
|
|
537
|
+
console.log(`[INFO] Replacing media: ${oldValue} → ${newValue}`);
|
|
645
538
|
|
|
539
|
+
// Since conceptUUID is always provided in practice, optimize for that case first
|
|
540
|
+
// Try to find direct top-level observation with matching concept UUID
|
|
646
541
|
const directObservation = _lodash.default.find(this.observations, obs => obs.concept.uuid === conceptUUID);
|
|
647
|
-
|
|
648
542
|
if (directObservation) {
|
|
649
543
|
// Direct media observation
|
|
650
544
|
if (_Concept.default.dataType.Media.includes(directObservation.concept.datatype)) {
|
|
@@ -652,55 +546,49 @@ class ObservationsHolder {
|
|
|
652
546
|
console.log(`[INFO] Updated media in direct observation`);
|
|
653
547
|
return true;
|
|
654
548
|
}
|
|
655
|
-
}
|
|
549
|
+
}
|
|
550
|
+
// Question Group containing the media
|
|
656
551
|
else if (directObservation.concept.datatype === _Concept.default.dataType.QuestionGroup) {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
return true;
|
|
662
|
-
}
|
|
552
|
+
const valueWrapper = directObservation.getValueWrapper();
|
|
553
|
+
if (this._processQuestionGroupWrapper(valueWrapper, conceptUUID, oldValue, newValue)) {
|
|
554
|
+
console.log(`[INFO] Updated media in question group`);
|
|
555
|
+
return true;
|
|
663
556
|
}
|
|
664
|
-
|
|
665
|
-
|
|
557
|
+
}
|
|
558
|
+
}
|
|
666
559
|
|
|
560
|
+
// Check nested structures (this works both with and without conceptUUID)
|
|
667
561
|
let updated = false;
|
|
668
|
-
|
|
669
562
|
_lodash.default.forEach(this.observations, obs => {
|
|
670
563
|
// Only process question groups
|
|
671
564
|
if (obs.concept.datatype !== _Concept.default.dataType.QuestionGroup) return;
|
|
672
565
|
const valueWrapper = obs.getValueWrapper && obs.getValueWrapper();
|
|
673
566
|
if (!valueWrapper) return;
|
|
674
|
-
|
|
675
567
|
if (this._processQuestionGroupWrapper(valueWrapper, conceptUUID, oldValue, newValue)) {
|
|
676
568
|
updated = true;
|
|
677
569
|
}
|
|
678
570
|
});
|
|
679
|
-
|
|
680
571
|
if (updated) {
|
|
681
572
|
console.log(`[INFO] Updated media in nested structure`);
|
|
682
573
|
return true;
|
|
683
|
-
}
|
|
684
|
-
// This ensures backward compatibility and handles edge cases
|
|
685
|
-
|
|
574
|
+
}
|
|
686
575
|
|
|
576
|
+
// As a fallback, use value-based replacement if we couldn't find it by concept
|
|
577
|
+
// This ensures backward compatibility and handles edge cases
|
|
687
578
|
return this.updateObservationBasedOnValue(oldValue, newValue);
|
|
688
579
|
}
|
|
689
|
-
|
|
690
580
|
toString(I18n) {
|
|
691
581
|
let display = "";
|
|
692
582
|
this.observations.forEach(obs => {
|
|
693
583
|
display += `${I18n.t(obs.concept.name)}: ${obs.getReadableValue()}\n`;
|
|
694
584
|
});
|
|
695
585
|
return display;
|
|
696
|
-
}
|
|
697
|
-
|
|
586
|
+
}
|
|
698
587
|
|
|
588
|
+
// it uses only underlying realm model and not avni model
|
|
699
589
|
static hasAnyAnswer(obsHolder, conceptUuid, answerUuids) {
|
|
700
590
|
return _lodash.default.some(obsHolder.observations, obs => obs.concept.uuid === conceptUuid && obs.valueJSON && _lodash.default.some(answerUuids, ansUuid => obs.valueJSON.includes(ansUuid)));
|
|
701
591
|
}
|
|
702
|
-
|
|
703
592
|
}
|
|
704
|
-
|
|
705
593
|
var _default = ObservationsHolder;
|
|
706
594
|
exports.default = _default;
|