openchs-models 1.33.37 → 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.
package/dist/Concept.js CHANGED
@@ -231,10 +231,10 @@ class Concept extends _BaseEntity.default {
231
231
  return this.isType(Concept.dataType.Encounter);
232
232
  }
233
233
  isMediaConcept() {
234
- return _lodash.default.includes(Concept.dataType.Media, this.datatype);
234
+ return _lodash.default.includes([Concept.dataType.Image, Concept.dataType.ImageV2, Concept.dataType.Video, Concept.dataType.File], this.datatype);
235
235
  }
236
236
  isMediaSelectConcept() {
237
- return _lodash.default.includes(Concept.dataType.Media, this.datatype);
237
+ return _lodash.default.includes([Concept.dataType.Image, Concept.dataType.ImageV2, Concept.dataType.Video, Concept.dataType.File], this.datatype);
238
238
  }
239
239
  isSelectConcept() {
240
240
  return this.isCodedConcept() || this.isSubjectConcept() || this.isEncounterConcept() || this.isMediaSelectConcept();
@@ -32,8 +32,29 @@ class CustomCardConfig extends _BaseEntity.default {
32
32
  set dataRule(x) {
33
33
  this.that.dataRule = x;
34
34
  }
35
+ get translations() {
36
+ return this.that.translations;
37
+ }
38
+ set translations(x) {
39
+ this.that.translations = x;
40
+ }
41
+ getTranslations() {
42
+ if (!this.translations) {
43
+ return {};
44
+ }
45
+ try {
46
+ const parsed = JSON.parse(this.translations);
47
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
48
+ } catch (e) {
49
+ return {};
50
+ }
51
+ }
35
52
  static fromResource(resource) {
36
- return _General.default.assignFields(resource, new CustomCardConfig(), ["uuid", "name", "htmlFileS3Key", "dataRule", "voided"]);
53
+ const config = _General.default.assignFields(resource, new CustomCardConfig(), ["uuid", "name", "htmlFileS3Key", "dataRule", "voided"]);
54
+ if (resource && "translations" in resource) {
55
+ config.translations = resource.translations && typeof resource.translations === 'object' ? JSON.stringify(resource.translations) : null;
56
+ }
57
+ return config;
37
58
  }
38
59
  }
39
60
  _defineProperty(CustomCardConfig, "schema", {
@@ -47,6 +68,10 @@ _defineProperty(CustomCardConfig, "schema", {
47
68
  type: "string",
48
69
  optional: true
49
70
  },
71
+ translations: {
72
+ type: "string",
73
+ optional: true
74
+ },
50
75
  voided: {
51
76
  type: "bool",
52
77
  default: false
@@ -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
- if (fe.concept.isCodedConcept() && (!_lodash.default.isEmpty(fe.answersToShow) || !_lodash.default.isEmpty(fe.answersToExclude))) {
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
  */
package/dist/Privilege.js CHANGED
@@ -77,10 +77,7 @@ _defineProperty(Privilege, "privilegeName", {
77
77
  approveEnrolment: "Approve Enrolment",
78
78
  approveEncounter: "Approve Encounter",
79
79
  approveChecklistItem: "Approve ChecklistItem",
80
- viewEditEntitiesOnDataEntryApp: 'View Or Edit Entities On DataEntry App',
81
- shareSubject: "Share subject",
82
- shareEnrolment: "Share enrolment",
83
- shareEncounter: "Share encounter"
80
+ viewEditEntitiesOnDataEntryApp: 'View Or Edit Entities On DataEntry App'
84
81
  });
85
82
  _defineProperty(Privilege, "PrivilegeType", {
86
83
  AddMember: "AddMember",
@@ -142,10 +139,7 @@ _defineProperty(Privilege, "PrivilegeType", {
142
139
  DownloadBundle: "DownloadBundle",
143
140
  EditTaskType: "EditTaskType",
144
141
  ViewEditEntitiesOnDataEntryApp: "ViewEditEntitiesOnDataEntryApp",
145
- DeleteOrganisationConfiguration: "DeleteOrganisationConfiguration",
146
- ShareSubject: "ShareSubject",
147
- ShareEnrolment: "ShareEnrolment",
148
- ShareEncounter: "ShareEncounter"
142
+ DeleteOrganisationConfiguration: "DeleteOrganisationConfiguration"
149
143
  });
150
144
  _defineProperty(Privilege, "privilegeEntityType", {
151
145
  subject: "Subject",
package/dist/Schema.js CHANGED
@@ -181,7 +181,7 @@ function createRealmConfig() {
181
181
  return doCompact;
182
182
  },
183
183
  //order is important, should be arranged according to the dependency
184
- schemaVersion: 209,
184
+ schemaVersion: 210,
185
185
  onMigration: function (oldDB, newDB) {
186
186
  console.log("[AvniModels.Schema]", `Running migration with old schema version: ${oldDB.schemaVersion} and new schema version: ${newDB.schemaVersion}`);
187
187
  if (oldDB.schemaVersion === VersionWithEmbeddedMigrationProblem) throw new Error(`Update from schema version ${VersionWithEmbeddedMigrationProblem} is not allowed. Please uninstall and install app.`);
@@ -802,6 +802,16 @@ function createRealmConfig() {
802
802
  }
803
803
  });
804
804
  }
805
+ if (oldDB.schemaVersion < 210) {
806
+ _lodash.default.forEach(newDB.objects(_EntitySyncStatus.default.schema.name), ess => {
807
+ if (ess.entityName === 'CustomCardConfig') {
808
+ ess.loadedSince = _EntitySyncStatus.default.REALLY_OLD_DATE;
809
+ }
810
+ });
811
+ _lodash.default.forEach(newDB.objects("CustomCardConfig"), config => {
812
+ config.translations = null;
813
+ });
814
+ }
805
815
  }
806
816
  };
807
817
  }
@@ -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
  }
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.33.37",
4
+ "version": "1.33.39",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",