openchs-models 1.10.2 → 1.11.2
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/dist/Concept.js +15 -0
- package/dist/Observation.js +13 -1
- package/dist/ObservationsHolder.js +40 -1
- package/dist/Schema.js +1 -1
- package/dist/application/Form.js +22 -8
- package/dist/application/FormElement.js +11 -1
- package/dist/application/FormElementGroup.js +16 -3
- package/dist/index.js +8 -0
- package/dist/observation/QuestionGroup.js +105 -0
- package/dist/utility/General.js +21 -2
- package/package.json +1 -1
package/dist/Concept.js
CHANGED
|
@@ -29,6 +29,8 @@ var _PhoneNumber = _interopRequireDefault(require("./PhoneNumber"));
|
|
|
29
29
|
|
|
30
30
|
var _Identifier = _interopRequireDefault(require("./Identifier"));
|
|
31
31
|
|
|
32
|
+
var _QuestionGroup = _interopRequireDefault(require("./observation/QuestionGroup"));
|
|
33
|
+
|
|
32
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
35
|
|
|
34
36
|
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; }
|
|
@@ -203,6 +205,10 @@ class Concept {
|
|
|
203
205
|
return _Identifier.default.fromObs(obsValue);
|
|
204
206
|
}
|
|
205
207
|
|
|
208
|
+
if (this.isQuestionGroup()) {
|
|
209
|
+
return _QuestionGroup.default.fromObs(obsValue);
|
|
210
|
+
}
|
|
211
|
+
|
|
206
212
|
return new _PrimitiveValue.default(obsValue, this.datatype);
|
|
207
213
|
}
|
|
208
214
|
|
|
@@ -230,6 +236,14 @@ class Concept {
|
|
|
230
236
|
return this.isType(Concept.dataType.Id);
|
|
231
237
|
}
|
|
232
238
|
|
|
239
|
+
isQuestionGroup() {
|
|
240
|
+
return this.isType(Concept.dataType.QuestionGroup);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
isPrimitive() {
|
|
244
|
+
return [Concept.dataType.Text, Concept.dataType.Time, Concept.dataType.Numeric, Concept.dataType.Video, Concept.dataType.Image, Concept.dataType.Audio, Concept.dataType.Date, Concept.dataType.DateTime, Concept.dataType.Location, Concept.dataType.File].includes(this.datatype);
|
|
245
|
+
}
|
|
246
|
+
|
|
233
247
|
getAnswers() {
|
|
234
248
|
return _lodash.default.sortBy(this.answers, answer => {
|
|
235
249
|
return _lodash.default.indexOf([Concept.StandardConcepts.OtherConceptUUID, Concept.StandardConcepts.NoneConceptUUID], answer.concept.uuid) !== -1 ? 99999 : answer.answerOrder;
|
|
@@ -335,6 +349,7 @@ _defineProperty(Concept, "dataType", {
|
|
|
335
349
|
Subject: "Subject",
|
|
336
350
|
PhoneNumber: "PhoneNumber",
|
|
337
351
|
GroupAffiliation: "GroupAffiliation",
|
|
352
|
+
QuestionGroup: "QuestionGroup",
|
|
338
353
|
File: "File",
|
|
339
354
|
|
|
340
355
|
get Media() {
|
package/dist/Observation.js
CHANGED
|
@@ -78,6 +78,14 @@ class Observation {
|
|
|
78
78
|
return new _Displayable.default(addressLevel.name, addressLevel);
|
|
79
79
|
} else if (observation.concept.isPhoneNumberConcept()) {
|
|
80
80
|
return new _Displayable.default(_lodash.default.toString(valueWrapper.toString()), null);
|
|
81
|
+
} else if (observation.concept.isQuestionGroup()) {
|
|
82
|
+
const groupObservations = valueWrapper.getValue();
|
|
83
|
+
|
|
84
|
+
const groupQuestionValues = _lodash.default.map(groupObservations, obs => ({
|
|
85
|
+
[obs.concept.name]: obs.getReadableValue()
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
return new _Displayable.default(JSON.stringify(groupQuestionValues), null);
|
|
81
89
|
} else {
|
|
82
90
|
const unit = _lodash.default.defaultTo(observation.concept.unit, "");
|
|
83
91
|
|
|
@@ -113,7 +121,7 @@ class Observation {
|
|
|
113
121
|
|
|
114
122
|
if (this.concept.isDurationConcept()) {
|
|
115
123
|
valueParsed = valueParsed.durations;
|
|
116
|
-
} else if (this.concept.isPhoneNumberConcept() || this.concept.isIdConcept()) {
|
|
124
|
+
} else if (this.concept.isPhoneNumberConcept() || this.concept.isIdConcept() || this.concept.isQuestionGroup()) {
|
|
117
125
|
return this.concept.getValueWrapperFor(valueParsed);
|
|
118
126
|
} else {
|
|
119
127
|
valueParsed = valueParsed.answer;
|
|
@@ -164,6 +172,10 @@ class Observation {
|
|
|
164
172
|
return answerConcept.name;
|
|
165
173
|
});
|
|
166
174
|
}
|
|
175
|
+
} else if (this.concept.isQuestionGroup()) {
|
|
176
|
+
return _lodash.default.map(value, obs => ({
|
|
177
|
+
[obs.concept.name]: obs.getReadableValue()
|
|
178
|
+
}));
|
|
167
179
|
}
|
|
168
180
|
|
|
169
181
|
return value;
|
|
@@ -23,6 +23,8 @@ var _PhoneNumber = _interopRequireDefault(require("./PhoneNumber"));
|
|
|
23
23
|
|
|
24
24
|
var _Identifier = _interopRequireDefault(require("./Identifier"));
|
|
25
25
|
|
|
26
|
+
var _QuestionGroup = _interopRequireDefault(require("./observation/QuestionGroup"));
|
|
27
|
+
|
|
26
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
29
|
|
|
28
30
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -59,7 +61,7 @@ class ObservationsHolder {
|
|
|
59
61
|
|
|
60
62
|
_lodash.default.remove(this.observations, obs => obs.concept.uuid === formElement.concept.uuid);
|
|
61
63
|
|
|
62
|
-
if (
|
|
64
|
+
if (formElement.concept.isPrimitive() && (0, _lodash.isNil)(formElement.durationOptions)) {
|
|
63
65
|
this.addOrUpdatePrimitiveObs(formElement.concept, value);
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -235,6 +237,43 @@ class ObservationsHolder {
|
|
|
235
237
|
return observation;
|
|
236
238
|
}
|
|
237
239
|
|
|
240
|
+
updateGroupQuestion(parentConcept, childConcept, value, childFormElement) {
|
|
241
|
+
const parentObservation = this.getObservation(parentConcept);
|
|
242
|
+
const childObservations = _lodash.default.isEmpty(parentObservation) ? new _QuestionGroup.default() : parentObservation.getValueWrapper();
|
|
243
|
+
|
|
244
|
+
if (childConcept.isPrimitive() && _lodash.default.isNil(childFormElement.durationOptions)) {
|
|
245
|
+
childObservations.removeExistingObs(childConcept);
|
|
246
|
+
|
|
247
|
+
if (!_lodash.default.isEmpty(_lodash.default.toString(value))) {
|
|
248
|
+
const observation = _Observation.default.create(childConcept, new _PrimitiveValue.default(value, childConcept.datatype));
|
|
249
|
+
|
|
250
|
+
childObservations.addObservation(observation);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (childConcept.isCodedConcept()) {
|
|
255
|
+
let observation = childObservations.getObservation(childConcept);
|
|
256
|
+
const isSingleSelect = childFormElement.isSingleSelect();
|
|
257
|
+
|
|
258
|
+
if (_lodash.default.isEmpty(observation)) {
|
|
259
|
+
observation = _Observation.default.create(childConcept, isSingleSelect ? new _SingleCodedValue.default(value) : new _MultipleCodedValues.default().push(value));
|
|
260
|
+
childObservations.addObservation(observation);
|
|
261
|
+
} else {
|
|
262
|
+
isSingleSelect ? observation.toggleSingleSelectAnswer(value) : observation.toggleMultiSelectAnswer(value);
|
|
263
|
+
|
|
264
|
+
if (observation.hasNoAnswer()) {
|
|
265
|
+
childObservations.removeExistingObs(childConcept);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
this._removeExistingObs(parentConcept);
|
|
271
|
+
|
|
272
|
+
if (!childObservations.isEmpty()) {
|
|
273
|
+
this.observations.push(_Observation.default.create(parentConcept, childObservations));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
238
277
|
toggleMultiSelectAnswer(concept, answerUUID) {
|
|
239
278
|
return this.toggleCodedAnswer(concept, answerUUID, false);
|
|
240
279
|
}
|
package/dist/Schema.js
CHANGED
|
@@ -168,7 +168,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
168
168
|
var _default = {
|
|
169
169
|
//order is important, should be arranged according to the dependency
|
|
170
170
|
schema: [_LocaleMapping.default, _Settings.default, _Concept.ConceptAnswer, _Concept.default, _EncounterType.default, _Gender.default, _UserDefinedIndividualProperty.default, _AddressLevel.LocationMapping, _AddressLevel.default, _KeyValue.default, _Form.default, _FormMapping.default, _FormElementGroup.default, _FormElement.default, _SubjectType.default, _Individual.default, _ProgramOutcome.default, _Program.default, _ProgramEnrolment.default, _Observation.default, _ProgramEncounter.default, _Encounter.default, _EntitySyncStatus.default, _EntityQueue.default, _ConfigFile.default, _Checklist.default, _ChecklistItem.default, _Format.default, _UserInfo.default, _StringKeyNumericValue.default, _VisitScheduleInterval.default, _VisitScheduleConfig.default, _ProgramConfig.default, _Family.default, _IndividualRelation.default, _IndividualRelationGenderMapping.default, _IndividualRelationshipType.default, _IndividualRelationship.default, _RuleDependency.default, _Rule.default, _ChecklistItemStatus.default, _ChecklistDetail.default, _ChecklistItemDetail.default, _VideoTelemetric.default, _Video.default, _MediaQueue.default, _Point.default, _SyncTelemetry.default, _IdentifierSource.default, _IdentifierAssignment.default, _RuleFailureTelemetry.default, _BeneficiaryModePin.default, _OrganisationConfig.default, _PlatformTranslation.default, _Translation.default, _Groups.default, _MyGroups.default, _GroupPrivileges.default, _Privilege.default, _GroupRole.default, _GroupSubject.default, _DashboardCache.default, _LocationHierarchy.default, _ReportCard.default, _Dashboard.default, _DashboardSectionCardMapping.default, _DraftSubject.default, _StandardReportCardType.default, _ApprovalStatus.default, _EntityApprovalStatus.default, _GroupDashboard.default, _DashboardSection.default, _News.default, _Comment.default, _CommentThread.default, _Extension.default, _SubjectMigration.default],
|
|
171
|
-
schemaVersion:
|
|
171
|
+
schemaVersion: 149,
|
|
172
172
|
migration: function (oldDB, newDB) {
|
|
173
173
|
if (oldDB.schemaVersion < 10) {
|
|
174
174
|
var oldObjects = oldDB.objects("DecisionConfig");
|
package/dist/application/Form.js
CHANGED
|
@@ -21,6 +21,8 @@ var _EntitySyncStatus = _interopRequireDefault(require("../EntitySyncStatus"));
|
|
|
21
21
|
|
|
22
22
|
var _moment = _interopRequireDefault(require("moment"));
|
|
23
23
|
|
|
24
|
+
var _QuestionGroup = _interopRequireDefault(require("../observation/QuestionGroup"));
|
|
25
|
+
|
|
24
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
27
|
|
|
26
28
|
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; }
|
|
@@ -132,11 +134,10 @@ class Form {
|
|
|
132
134
|
orderObservations(observations) {
|
|
133
135
|
const orderedObservations = [];
|
|
134
136
|
|
|
135
|
-
const
|
|
137
|
+
const formElementOrdering = _lodash.default.sortBy(this.formElementGroups, feg => feg.displayOrder).map(feg => _lodash.default.sortBy(feg.getFormElements(), fe => fe.displayOrder));
|
|
136
138
|
|
|
137
|
-
_lodash.default.flatten(
|
|
138
|
-
|
|
139
|
-
if (!_lodash.default.isNil(foundObs)) orderedObservations.push(foundObs);
|
|
139
|
+
_lodash.default.flatten(formElementOrdering).map(formElement => {
|
|
140
|
+
this.addSortedObservations(formElement, observations, orderedObservations);
|
|
140
141
|
});
|
|
141
142
|
|
|
142
143
|
const extraObs = observations.filter(obs => _lodash.default.isNil(orderedObservations.find(oobs => oobs.concept.uuid === obs.concept.uuid)));
|
|
@@ -152,13 +153,12 @@ class Form {
|
|
|
152
153
|
}) => displayOrder);
|
|
153
154
|
|
|
154
155
|
_lodash.default.forEach(orderedFEG, feg => {
|
|
155
|
-
const
|
|
156
|
+
const formElementOrdering = _lodash.default.sortBy(feg.getFormElements(), fe => fe.displayOrder);
|
|
156
157
|
|
|
157
158
|
const fegObs = [];
|
|
158
159
|
|
|
159
|
-
_lodash.default.forEach(
|
|
160
|
-
|
|
161
|
-
if (!_lodash.default.isNil(foundObs)) fegObs.push(foundObs);
|
|
160
|
+
_lodash.default.forEach(formElementOrdering, formElement => {
|
|
161
|
+
this.addSortedObservations(formElement, observations, fegObs);
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
if (!_lodash.default.isEmpty(fegObs)) {
|
|
@@ -180,6 +180,20 @@ class Form {
|
|
|
180
180
|
return sections;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
addSortedObservations(formElement, observations, orderedObservations) {
|
|
184
|
+
const concept = formElement.concept;
|
|
185
|
+
const foundObs = observations.find(obs => obs.concept.uuid === concept.uuid);
|
|
186
|
+
|
|
187
|
+
if (!_lodash.default.isNil(foundObs) && concept.isQuestionGroup()) {
|
|
188
|
+
const clonedObs = foundObs.cloneForEdit();
|
|
189
|
+
const sortedChildObs = this.orderObservations(clonedObs.getValueWrapper().getValue());
|
|
190
|
+
clonedObs.valueJSON = JSON.stringify(new _QuestionGroup.default(sortedChildObs));
|
|
191
|
+
if (!_lodash.default.isEmpty(sortedChildObs)) orderedObservations.push(clonedObs);
|
|
192
|
+
} else {
|
|
193
|
+
if (!_lodash.default.isNil(foundObs)) orderedObservations.push(foundObs);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
183
197
|
getFormElementGroupOrder(groupUUID) {
|
|
184
198
|
const orderedFEG = _lodash.default.sortBy(this.nonVoidedFormElementGroups(), ({
|
|
185
199
|
displayOrder
|
|
@@ -37,6 +37,7 @@ class FormElement {
|
|
|
37
37
|
const formElement = _General.default.assignFields(resource, new FormElement(), ["uuid", "name", "displayOrder", "mandatory", "type", "voided", "rule"], []);
|
|
38
38
|
|
|
39
39
|
formElement.formElementGroup = formElementGroup;
|
|
40
|
+
formElement.groupUuid = _ResourceUtil.default.getUUIDFor(resource, "groupQuestionUUID");
|
|
40
41
|
formElement.concept = concept; //remove orphan keyValues (because KeyValue doesn't have primary key
|
|
41
42
|
|
|
42
43
|
entityService.deleteObjects(resource["uuid"], FormElement.schema.name, "keyValues");
|
|
@@ -196,6 +197,10 @@ class FormElement {
|
|
|
196
197
|
return this.name === elementNameOrUUID || this.uuid === elementNameOrUUID;
|
|
197
198
|
}
|
|
198
199
|
|
|
200
|
+
isQuestionGroup() {
|
|
201
|
+
return !_lodash.default.isNil(this.groupUuid);
|
|
202
|
+
}
|
|
203
|
+
|
|
199
204
|
toJSON() {
|
|
200
205
|
return {
|
|
201
206
|
uuid: this.uuid,
|
|
@@ -204,7 +209,8 @@ class FormElement {
|
|
|
204
209
|
mandatory: this.mandatory,
|
|
205
210
|
keyValues: this.keyValues,
|
|
206
211
|
concept: this.concept,
|
|
207
|
-
formElementGroupUUID: this.formElementGroup.uuid
|
|
212
|
+
formElementGroupUUID: this.formElementGroup.uuid,
|
|
213
|
+
groupUuid: this.groupUuid
|
|
208
214
|
};
|
|
209
215
|
}
|
|
210
216
|
|
|
@@ -278,6 +284,10 @@ _defineProperty(FormElement, "schema", {
|
|
|
278
284
|
rule: {
|
|
279
285
|
type: "string",
|
|
280
286
|
optional: true
|
|
287
|
+
},
|
|
288
|
+
groupUuid: {
|
|
289
|
+
type: "string",
|
|
290
|
+
optional: true
|
|
281
291
|
}
|
|
282
292
|
}
|
|
283
293
|
});
|
|
@@ -17,6 +17,8 @@ var _FormElement = _interopRequireDefault(require("./FormElement"));
|
|
|
17
17
|
|
|
18
18
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
19
19
|
|
|
20
|
+
var _QuestionGroup = _interopRequireDefault(require("../observation/QuestionGroup"));
|
|
21
|
+
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
23
|
|
|
22
24
|
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; }
|
|
@@ -68,13 +70,24 @@ class FormElementGroup {
|
|
|
68
70
|
validate(observationHolder, filteredFormElements) {
|
|
69
71
|
const validationResults = [];
|
|
70
72
|
filteredFormElements.forEach(formElement => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
if (formElement.isQuestionGroup()) {
|
|
74
|
+
const parentFormElement = _lodash.default.find(filteredFormElements, fe => fe.uuid === formElement.groupUuid);
|
|
75
|
+
|
|
76
|
+
const parentObservation = observationHolder.findObservation(parentFormElement.concept);
|
|
77
|
+
const childObservations = _lodash.default.isEmpty(parentObservation) ? new _QuestionGroup.default() : parentObservation.getValueWrapper();
|
|
78
|
+
this.validateFormElement(formElement, childObservations.findObservation(formElement.concept), validationResults);
|
|
79
|
+
} else {
|
|
80
|
+
this.validateFormElement(formElement, observationHolder.findObservation(formElement.concept), validationResults);
|
|
81
|
+
}
|
|
74
82
|
});
|
|
75
83
|
return validationResults;
|
|
76
84
|
}
|
|
77
85
|
|
|
86
|
+
validateFormElement(formElement, observation, validationResults) {
|
|
87
|
+
const validationResult = formElement.validate(_lodash.default.isNil(observation) ? null : observation.getValue());
|
|
88
|
+
validationResults.push(validationResult);
|
|
89
|
+
}
|
|
90
|
+
|
|
78
91
|
get formElementIds() {
|
|
79
92
|
return this.getFormElements().map(formElement => {
|
|
80
93
|
return formElement.uuid;
|
package/dist/index.js
CHANGED
|
@@ -645,6 +645,12 @@ Object.defineProperty(exports, "SubjectMigration", {
|
|
|
645
645
|
return _SubjectMigration.default;
|
|
646
646
|
}
|
|
647
647
|
});
|
|
648
|
+
Object.defineProperty(exports, "QuestionGroup", {
|
|
649
|
+
enumerable: true,
|
|
650
|
+
get: function () {
|
|
651
|
+
return _QuestionGroup.default;
|
|
652
|
+
}
|
|
653
|
+
});
|
|
648
654
|
|
|
649
655
|
var _AbstractEncounter = _interopRequireDefault(require("./AbstractEncounter"));
|
|
650
656
|
|
|
@@ -858,6 +864,8 @@ var _FileFormat = _interopRequireDefault(require("./FileFormat"));
|
|
|
858
864
|
|
|
859
865
|
var _SubjectMigration = _interopRequireDefault(require("./SubjectMigration"));
|
|
860
866
|
|
|
867
|
+
var _QuestionGroup = _interopRequireDefault(require("./observation/QuestionGroup"));
|
|
868
|
+
|
|
861
869
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
862
870
|
|
|
863
871
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
+
|
|
10
|
+
var _Concept = _interopRequireWildcard(require("../Concept"));
|
|
11
|
+
|
|
12
|
+
var _Observation = _interopRequireDefault(require("../Observation"));
|
|
13
|
+
|
|
14
|
+
var _General = _interopRequireDefault(require("../utility/General"));
|
|
15
|
+
|
|
16
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
17
|
+
|
|
18
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
class QuestionGroup {
|
|
23
|
+
constructor(groupObservations = []) {
|
|
24
|
+
this.groupObservations = groupObservations;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get toResource() {
|
|
28
|
+
return _lodash.default.map(this.groupObservations, obs => obs.toResource);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static fromObs({
|
|
32
|
+
groupObservations
|
|
33
|
+
}) {
|
|
34
|
+
const newObs = _lodash.default.map(groupObservations, ({
|
|
35
|
+
concept,
|
|
36
|
+
valueJSON
|
|
37
|
+
}) => {
|
|
38
|
+
const observation = new _Observation.default();
|
|
39
|
+
observation.concept = QuestionGroup.constructConceptModel(concept);
|
|
40
|
+
const value = valueJSON.answer || valueJSON.value;
|
|
41
|
+
observation.valueJSON = observation.concept.getValueWrapperFor(value);
|
|
42
|
+
return observation;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return new QuestionGroup(newObs);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static constructConceptModel(resource) {
|
|
49
|
+
const concept = _Concept.default.fromResource(resource);
|
|
50
|
+
|
|
51
|
+
concept.datatype = resource.datatype;
|
|
52
|
+
|
|
53
|
+
if (!_lodash.default.isNil(resource.answers)) {
|
|
54
|
+
concept.answers = _lodash.default.map(resource.answers, answer => {
|
|
55
|
+
const conceptAnswer = _General.default.assignFields(answer, new _Concept.ConceptAnswer(), ["uuid", "answerOrder", "abnormal", "unique", "voided"]);
|
|
56
|
+
|
|
57
|
+
conceptAnswer.concept = QuestionGroup.constructConceptModel(answer.concept);
|
|
58
|
+
return conceptAnswer;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return concept;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getValue() {
|
|
66
|
+
return this.groupObservations;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
findObservation(concept) {
|
|
70
|
+
return _lodash.default.find(this.groupObservations, observation => {
|
|
71
|
+
return observation.concept.uuid === concept.uuid;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getObservation(concept) {
|
|
76
|
+
return this.findObservation(concept);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
addObservation(observation) {
|
|
80
|
+
this.groupObservations.push(observation);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
removeExistingObs(concept) {
|
|
84
|
+
_lodash.default.remove(this.groupObservations, obs => obs.concept.uuid === concept.uuid);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
getValueForConcept(concept) {
|
|
88
|
+
const observation = this.findObservation(concept);
|
|
89
|
+
return _lodash.default.isNil(observation) ? observation : observation.getReadableValue();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
cloneForEdit() {
|
|
93
|
+
const newObs = _lodash.default.map(this.groupObservations, o => o.cloneForEdit());
|
|
94
|
+
|
|
95
|
+
return new QuestionGroup(newObs);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
isEmpty() {
|
|
99
|
+
return _lodash.default.isEmpty(this.groupObservations);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var _default = QuestionGroup;
|
|
105
|
+
exports.default = _default;
|
package/dist/utility/General.js
CHANGED
|
@@ -15,6 +15,8 @@ var _Observation = _interopRequireDefault(require("../Observation"));
|
|
|
15
15
|
|
|
16
16
|
var _Concept = _interopRequireDefault(require("../Concept"));
|
|
17
17
|
|
|
18
|
+
var _QuestionGroup = _interopRequireDefault(require("../observation/QuestionGroup"));
|
|
19
|
+
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
21
|
|
|
20
22
|
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; }
|
|
@@ -150,8 +152,16 @@ class General {
|
|
|
150
152
|
if (!_lodash.default.isNil(source[observationField])) {
|
|
151
153
|
_lodash.default.toPairs(source[observationField]).forEach(([conceptUUID, value]) => {
|
|
152
154
|
const observation = new _Observation.default();
|
|
153
|
-
|
|
154
|
-
observation.
|
|
155
|
+
const concept = entityService.findByKey("uuid", conceptUUID, _Concept.default.schema.name);
|
|
156
|
+
observation.concept = concept;
|
|
157
|
+
|
|
158
|
+
if (concept.isQuestionGroup()) {
|
|
159
|
+
const groupObservations = this.createQuestionGroupObservations(value, entityService);
|
|
160
|
+
observation.valueJSON = JSON.stringify(new _QuestionGroup.default(groupObservations));
|
|
161
|
+
} else {
|
|
162
|
+
observation.valueJSON = JSON.stringify(observation.concept.getValueWrapperFor(value));
|
|
163
|
+
}
|
|
164
|
+
|
|
155
165
|
observations.push(observation);
|
|
156
166
|
});
|
|
157
167
|
}
|
|
@@ -161,6 +171,15 @@ class General {
|
|
|
161
171
|
return dest;
|
|
162
172
|
}
|
|
163
173
|
|
|
174
|
+
static createQuestionGroupObservations(keyValues, entityService) {
|
|
175
|
+
return _lodash.default.map(_lodash.default.toPairs(keyValues), ([conceptUUID, value]) => {
|
|
176
|
+
const observation = new _Observation.default();
|
|
177
|
+
observation.concept = entityService.findByKey("uuid", conceptUUID, _Concept.default.schema.name);
|
|
178
|
+
observation.valueJSON = observation.concept.getValueWrapperFor(value);
|
|
179
|
+
return observation;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
164
183
|
static pick(from, attributes, listAttributes) {
|
|
165
184
|
const picked = _lodash.default.pick(from, attributes);
|
|
166
185
|
|