openchs-models 1.31.69 → 1.31.71

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.
@@ -242,24 +242,6 @@ class AddressLevel extends _BaseEntity.default {
242
242
  return appendLineage(this, []);
243
243
  }
244
244
 
245
- findObservation(conceptNameOrUuid, parentConceptNameOrUuid) {
246
- const observations = _lodash.default.isNil(parentConceptNameOrUuid) ? this.locationProperties : this.findGroupedObservation(parentConceptNameOrUuid);
247
- return _lodash.default.find(observations, observation => {
248
- return observation.concept.name === conceptNameOrUuid || observation.concept.uuid === conceptNameOrUuid;
249
- });
250
- }
251
-
252
- findGroupedObservation(parentConceptNameOrUuid) {
253
- const groupedObservations = _lodash.default.find(this.locationProperties, observation => observation.concept.name === parentConceptNameOrUuid || observation.concept.uuid === parentConceptNameOrUuid);
254
-
255
- return _lodash.default.isEmpty(groupedObservations) ? [] : groupedObservations.getValue();
256
- }
257
-
258
- getObservationReadableValue(conceptNameOrUuid, parentConceptNameOrUuid) {
259
- const observationForConcept = this.findObservation(conceptNameOrUuid, parentConceptNameOrUuid);
260
- return _lodash.default.isEmpty(observationForConcept) ? observationForConcept : observationForConcept.getReadableValue();
261
- }
262
-
263
245
  }
264
246
 
265
247
  _defineProperty(AddressLevel, "schema", {
@@ -64,7 +64,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
64
64
  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; }
65
65
 
66
66
  const mergeMap = new Map([[_SchemaNames.default.ProgramEnrolment, "enrolments"], [_SchemaNames.default.Encounter, "encounters"], [_SchemaNames.default.IndividualRelationship, "relationships"], [_SchemaNames.default.EntityApprovalStatus, "approvalStatuses"], [_SchemaNames.default.Comment, "comments"]]);
67
- const ADDRESS_LEVEL_DUMMY_UUID = 'f71b2f45-2c11-427f-aa99-be6161a6b413';
68
67
 
69
68
  class Individual extends _BaseEntity.default {
70
69
  constructor(that = null) {
@@ -280,15 +279,8 @@ class Individual extends _BaseEntity.default {
280
279
  individual.groupSubjects = [];
281
280
  individual.groups = [];
282
281
  individual.approvalStatuses = [];
283
- individual.lowestAddressLevel = this.getPlaceholderAddressLevel();
284
- individual.voided = false;
285
- individual.comments = [];
286
- return individual;
287
- }
288
-
289
- static getPlaceholderAddressLevel(entityService) {
290
- return _AddressLevel.default.create({
291
- uuid: ADDRESS_LEVEL_DUMMY_UUID,
282
+ individual.lowestAddressLevel = _AddressLevel.default.create({
283
+ uuid: "",
292
284
  title: "",
293
285
  level: 0,
294
286
  typeString: "",
@@ -297,7 +289,10 @@ class Individual extends _BaseEntity.default {
297
289
  parentUuid: "",
298
290
  typeUuid: "",
299
291
  locationProperties: []
300
- }, entityService);
292
+ });
293
+ individual.voided = false;
294
+ individual.comments = [];
295
+ return individual;
301
296
  }
302
297
 
303
298
  static createEmptySubjectInstance() {
@@ -345,17 +340,9 @@ class Individual extends _BaseEntity.default {
345
340
  individual.dateOfBirth = dateOfBirth;
346
341
  individual.dateOfBirthVerified = dateOfBirthVerified;
347
342
  individual.gender = gender;
348
- individual.lowestAddressLevel = this.initLowestAddressLevel(lowestAddressLevel, subjectType, null);
343
+ individual.lowestAddressLevel = lowestAddressLevel;
349
344
  return individual;
350
345
  }
351
- /**
352
- * Init Lowest AddressLevel with Placeholder only if the Individual SubjectType is User
353
- */
354
-
355
-
356
- static initLowestAddressLevel(lowestAddressLevel, subjectType, entityService) {
357
- return lowestAddressLevel || subjectType && subjectType.isUser() && this.getPlaceholderAddressLevel(entityService);
358
- }
359
346
 
360
347
  static fromResource(individualResource, entityService) {
361
348
  const addressLevel = entityService.findByKey("uuid", _ResourceUtil.default.getUUIDFor(individualResource, "addressUUID"), _AddressLevel.default.schema.name);
@@ -365,7 +352,7 @@ class Individual extends _BaseEntity.default {
365
352
  const individual = _General.default.assignFields(individualResource, new Individual(), this.directCopyFields, this.dateFields, ["observations"], entityService);
366
353
 
367
354
  individual.gender = gender;
368
- individual.lowestAddressLevel = this.initLowestAddressLevel(addressLevel, subjectType, entityService);
355
+ individual.lowestAddressLevel = addressLevel;
369
356
  individual.name = individual.nameString;
370
357
  if (!_lodash.default.isNil(individualResource.registrationLocation)) individual.registrationLocation = _Point.default.fromResource(individualResource.registrationLocation);
371
358
  individual.subjectType = subjectType;
@@ -480,12 +467,8 @@ class Individual extends _BaseEntity.default {
480
467
  return _Duration.default.inYear(0);
481
468
  }
482
469
 
483
- getTranslatedNameString(i18n) {
484
- return this.isPerson() ? Individual.getFullName(this) : this.subjectType.type === _SubjectType.default.types.User ? `${this.firstName}(${i18n.t('you')})` : this.firstName;
485
- }
486
-
487
470
  get nameString() {
488
- return this.isPerson() ? Individual.getFullName(this) : this.subjectType.type === _SubjectType.default.types.User ? `${this.firstName}(You)` : this.firstName;
471
+ return this.isPerson() ? Individual.getFullName(this) : this.firstName;
489
472
  }
490
473
 
491
474
  static getFullName(obj) {
@@ -84,8 +84,10 @@ class Observation extends _PersistedObject.default {
84
84
  return new _Displayable.default(valueWrapper.asDisplayTime(), null);
85
85
  } else if (valueWrapper.isSingleCoded) {
86
86
  if (observation.concept.datatype === _Concept.default.dataType.Subject) {
87
- const subject = subjectService.findByUUID(valueWrapper.getValue());
88
- return [new _Displayable.default(subject.nameStringWithUniqueAttribute, subject)];
87
+ const uuid = valueWrapper.getValue();
88
+ const subject = subjectService.findByUUID(uuid);
89
+ const displayName = subject && subject.nameStringWithUniqueAttribute || uuid;
90
+ return [new _Displayable.default(displayName, subject)];
89
91
  } else if (observation.concept.datatype === _Concept.default.dataType.Encounter) {
90
92
  const encounter = encounterService.findByUUID(valueWrapper.getValue());
91
93
  const identifier = observation.concept.recordValueByKey(_Concept.default.keys.encounterIdentifier);
@@ -59,7 +59,7 @@ class ObservationsHolder {
59
59
  const groupObservations = observations && observations.getValueWrapper();
60
60
 
61
61
  if (parentFormElement.repeatable) {
62
- return groupObservations && groupObservations.size() > questionGroupIndex && groupObservations.getGroupObservationAtIndex(questionGroupIndex).getObservation(concept);
62
+ return groupObservations && groupObservations.getGroupObservationAtIndex(questionGroupIndex).getObservation(concept);
63
63
  }
64
64
 
65
65
  return groupObservations && groupObservations.getObservation(concept);
package/dist/Schema.js CHANGED
@@ -183,6 +183,8 @@ var _MigrationsHelper = _interopRequireDefault(require("./MigrationsHelper"));
183
183
 
184
184
  var _MetaDataService = _interopRequireDefault(require("./service/MetaDataService"));
185
185
 
186
+ var _moment = _interopRequireDefault(require("moment"));
187
+
186
188
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
187
189
 
188
190
  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; }
@@ -279,7 +281,7 @@ function createRealmConfig() {
279
281
  return doCompact;
280
282
  },
281
283
  //order is important, should be arranged according to the dependency
282
- schemaVersion: 189,
284
+ schemaVersion: 188,
283
285
  onMigration: function (oldDB, newDB) {
284
286
  console.log("[AvniModels.Schema]", `Running migration with old schema version: ${oldDB.schemaVersion} and new schema version: ${newDB.schemaVersion}`);
285
287
  if (oldDB.schemaVersion === VersionWithEmbeddedMigrationProblem) throw new Error(`Update from schema version ${VersionWithEmbeddedMigrationProblem} is not allowed. Please uninstall and install app.`);
@@ -901,10 +903,6 @@ function createRealmConfig() {
901
903
  // newDB.deleteModel("Decision");
902
904
  // newDB.deleteModel("ProgramOutcome");
903
905
  }
904
-
905
- if (oldDB.schemaVersion < 189) {// PlaceHolder for SubjectType.User changes, so that people with previous version of client
906
- // are not able to use fastSync of version 189 and above
907
- }
908
906
  }
909
907
  };
910
908
  }
@@ -260,10 +260,6 @@ class SubjectType extends _ReferenceEntity.default {
260
260
  return this.type === SubjectType.types.Individual;
261
261
  }
262
262
 
263
- isUser() {
264
- return this.type === SubjectType.types.User;
265
- }
266
-
267
263
  registerIcon() {
268
264
  return this.isPerson() ? "account-plus" : "plus-box";
269
265
  }
@@ -380,8 +376,7 @@ _defineProperty(SubjectType, "types", {
380
376
  Person: 'Person',
381
377
  Individual: 'Individual',
382
378
  Group: 'Group',
383
- Household: 'Household',
384
- User: 'User'
379
+ Household: 'Household'
385
380
  });
386
381
 
387
382
  _defineProperty(SubjectType, "settingKeys", {
@@ -227,32 +227,6 @@ class Form extends _BaseEntity.default {
227
227
 
228
228
  const extraObs = observations.filter(obs => _lodash.default.isNil(orderedObservations.find(oobs => oobs.concept.uuid === obs.concept.uuid)));
229
229
  return orderedObservations.concat(extraObs);
230
- } //TODO add tests
231
-
232
-
233
- orderObservationsPerFEG(observations) {
234
- const orderedObservations = [];
235
-
236
- const formElementOrdering = _lodash.default.sortBy(this.formElementGroups, feg => feg.displayOrder).map(feg => {
237
- let fegOrderedObservations = [];
238
- const returnValue = {};
239
- returnValue.uuid = feg.uuid;
240
- returnValue.feg = feg;
241
- returnValue.sortedObservationsArray = fegOrderedObservations;
242
- this.orderObservationsWithinAFEG(feg.getFormElements(), observations, fegOrderedObservations);
243
- orderedObservations.concat(fegOrderedObservations);
244
- return returnValue;
245
- });
246
-
247
- return formElementOrdering;
248
- }
249
-
250
- orderObservationsWithinAFEG(formElements, observations, orderedObservations) {
251
- _lodash.default.sortBy(formElements, fe => fe.displayOrder).forEach(formElement => this.addSortedObservations(formElement, observations, orderedObservations));
252
-
253
- const extraObs = observations.filter(obs => _lodash.default.isNil(orderedObservations.find(oobs => oobs.concept.uuid === obs.concept.uuid)));
254
- orderedObservations.concat(extraObs);
255
- return extraObs;
256
230
  }
257
231
 
258
232
  sectionWiseOrderedObservations(observations) {
@@ -31,8 +31,6 @@ var _BaseEntity = _interopRequireDefault(require("../BaseEntity"));
31
31
 
32
32
  var _SchemaNames = _interopRequireDefault(require("../SchemaNames"));
33
33
 
34
- var _RepeatableQuestionGroup = _interopRequireDefault(require("../observation/RepeatableQuestionGroup"));
35
-
36
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
35
 
38
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; }
@@ -151,18 +149,8 @@ class FormElement extends _BaseEntity.default {
151
149
  return formElement;
152
150
  }
153
151
 
154
- newFormElement() {
155
- return new FormElement();
156
- }
157
-
158
152
  getType() {
159
- if (this.concept.datatype === _Concept.default.dataType.Coded) {
160
- return this.type;
161
- } else if (this.concept.datatype === _Concept.default.dataType.QuestionGroup && this.repeatable) {
162
- return _RepeatableQuestionGroup.default.TypeName;
163
- } else {
164
- return this.concept.datatype;
165
- }
153
+ return this.concept.datatype === _Concept.default.dataType.Coded ? this.type : this.concept.datatype;
166
154
  }
167
155
 
168
156
  isMultiSelect() {
@@ -235,7 +223,7 @@ class FormElement extends _BaseEntity.default {
235
223
  }
236
224
  } else if (this.concept.datatype === _Concept.default.dataType.Time && !(0, _moment.default)(value, 'HH:mm').isValid() && (!this.mandatory && !_lodash.default.isNil(value) || this.mandatory)) {
237
225
  failure.messageKey = "invalidTimeFormat";
238
- } else if (this.concept.datatype === _Concept.default.dataType.Date && !(0, _moment.default)(value, 'YYYY-MM-DD').isValid() && (!this.mandatory && !_lodash.default.isNil(value) || this.mandatory)) {
226
+ } else if (this.concept.datatype === _Concept.default.dataType.Date && !(0, _moment.default)(value).isValid() && (!this.mandatory && !_lodash.default.isNil(value) || this.mandatory)) {
239
227
  failure.messageKey = "invalidDateFormat";
240
228
  } else if (this.mandatory && this.concept.datatype === _Concept.default.dataType.Duration && _lodash.default.some(_lodash.default.map(value.durations, "durationValue"), durationValue => _lodash.default.isEmpty(durationValue))) {
241
229
  failure.messageKey = "emptyValidationMessage";
@@ -298,11 +286,6 @@ class FormElement extends _BaseEntity.default {
298
286
  return _lodash.default.isNil(repeatable) ? false : repeatable.getValue();
299
287
  }
300
288
 
301
- get disableManualActions() {
302
- const disableManualActions = this.recordByKey("disableManualActions");
303
- return _lodash.default.isNil(disableManualActions) ? false : disableManualActions.getValue();
304
- }
305
-
306
289
  get datePickerMode() {
307
290
  const datePickerMode = this.recordByKey("datePickerMode");
308
291
  return _lodash.default.isNil(datePickerMode) ? null : datePickerMode.getValue();
@@ -403,12 +386,8 @@ class FormElement extends _BaseEntity.default {
403
386
  return _lodash.default.find(this.formElementGroup.getFormElements(), fe => fe.uuid === this.groupUuid);
404
387
  }
405
388
 
406
- isRepeatableQuestionGroup() {
407
- return this.concept.isQuestionGroup() && this.repeatable;
408
- }
409
-
410
389
  clone() {
411
- const formElement = this.newFormElement();
390
+ const formElement = new FormElement();
412
391
  formElement.uuid = this.uuid;
413
392
  formElement.name = this.name;
414
393
  formElement.displayOrder = this.displayOrder;
package/dist/index.js CHANGED
@@ -783,12 +783,6 @@ Object.defineProperty(exports, "DashboardCacheFilter", {
783
783
  return _DashboardCacheFilter.default;
784
784
  }
785
785
  });
786
- Object.defineProperty(exports, "JSONStringify", {
787
- enumerable: true,
788
- get: function () {
789
- return _JsonStringify.JSONStringify;
790
- }
791
- });
792
786
 
793
787
  var _AbstractEncounter = _interopRequireDefault(require("./AbstractEncounter"));
794
788
 
@@ -1040,8 +1034,6 @@ var _AgeUtil = _interopRequireDefault(require("./utility/AgeUtil"));
1040
1034
 
1041
1035
  var _DashboardCacheFilter = _interopRequireDefault(require("./application/DashboardCacheFilter"));
1042
1036
 
1043
- var _JsonStringify = require("./utility/JsonStringify");
1044
-
1045
1037
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
1046
1038
 
1047
1039
  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; }
@@ -88,8 +88,6 @@ class RepeatableQuestionGroup {
88
88
 
89
89
  }
90
90
 
91
- _defineProperty(RepeatableQuestionGroup, "TypeName", "RepeatableQuestionGroup");
92
-
93
91
  _defineProperty(RepeatableQuestionGroup, "actions", {
94
92
  add: 'add',
95
93
  remove: 'remove'
@@ -150,10 +150,6 @@ class General {
150
150
  }
151
151
 
152
152
  static assignObsFields(source, dest, observationFields = [], entityService) {
153
- if (!entityService) {
154
- return dest;
155
- }
156
-
157
153
  observationFields.forEach(observationField => {
158
154
  const observations = [];
159
155
 
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.31.69",
4
+ "version": "1.31.71",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,107 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.JSONStringify = void 0;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- //initial code from : https://javascript.plainenglish.io/create-your-own-implementation-of-json-stringify-simiplied-version-8ab6746cdd1
13
- const isArray = function (value) {
14
- return Array.isArray(value) && typeof value === 'object';
15
- };
16
-
17
- const isObject = function (value) {
18
- return typeof value === 'object' && value !== null && !Array.isArray(value);
19
- };
20
-
21
- const isString = function (value) {
22
- return typeof value === 'string';
23
- };
24
-
25
- const isBoolean = function (value) {
26
- return typeof value === 'boolean';
27
- };
28
-
29
- const isNumber = function (value) {
30
- return typeof value === 'number';
31
- }; // Common check for number, string and boolean value
32
-
33
-
34
- const restOfDataTypes = function (value) {
35
- return isNumber(value) || isString(value) || isBoolean(value);
36
- }; // This function will be used to remove extra comma from the arrays and object
37
-
38
-
39
- const removeComma = function (str) {
40
- const tempArr = str.split('');
41
- tempArr.pop();
42
- return tempArr.join('');
43
- };
44
-
45
- const duckCheckNativeRealmCollection = function (obj) {
46
- return typeof obj === "object" && !_lodash.default.isNil(_lodash.default.get(obj, "removeAllListeners")) && !_lodash.default.isNil(_lodash.default.get(obj, "snapshot"));
47
- };
48
-
49
- function duckCheckForError(obj) {
50
- return obj.stack && obj.message;
51
- }
52
-
53
- const JSONStringifyInternal = function (obj, depth, objectMap, arrayWidth, objectKey) {
54
- if (depth === 0) return "BELOW_DEPTH"; // Boolean and Number behave in a same way and String we need to add extra quotes
55
-
56
- if (restOfDataTypes(obj)) {
57
- const passQuotes = isString(obj) ? `"` : '';
58
- return `${passQuotes}${obj}${passQuotes}`;
59
- } // Recursive function call for Arrays to handle nested arrays
60
-
61
-
62
- if (isArray(obj)) {
63
- let arrStr = '';
64
- obj.forEach((eachValue, index) => {
65
- if (index === arrayWidth) arrStr += "....";
66
- if (index >= arrayWidth) return;
67
- arrStr += JSONStringifyInternal(eachValue, depth - 1, objectMap, arrayWidth);
68
- arrStr += ',';
69
- });
70
- return `[` + removeComma(arrStr) + `]`;
71
- }
72
-
73
- if (duckCheckNativeRealmCollection(obj, objectKey)) {
74
- return "<realm-collection>";
75
- } // Recursive function call for Object to handle nested Object
76
-
77
-
78
- if (isObject(obj) && _lodash.default.isNil(objectMap.get(obj))) {
79
- objectMap.set(obj, true);
80
- let objStr = '';
81
- const objKeys = Object.keys(obj);
82
- objKeys.forEach(eachKey => {
83
- const eachValue = obj[eachKey];
84
- objStr += `"${eachKey}":${JSONStringifyInternal(eachValue, depth - 1, objectMap, arrayWidth, eachKey)},`;
85
- });
86
-
87
- if (duckCheckForError(obj)) {
88
- objStr += `message:${obj.message},`;
89
- objStr += `stack:${obj.stack},`;
90
- }
91
-
92
- return `{` + removeComma(objStr) + `}`;
93
- } else if (!_lodash.default.isNil(objectMap.get(obj))) {
94
- return "<object_repeated>";
95
- } else {
96
- return obj;
97
- }
98
- }; // This class is not meant for production purposes, it is to be used for developer assistance like logging.
99
- // It supports recursive object structure, native realm collection, restricting array width (number of elements that can be stringified), and object tree depth
100
-
101
-
102
- const JSONStringify = function (obj, objectTreeDepth = 3, arrayWidth = 4) {
103
- const objectMap = new Map();
104
- return JSONStringifyInternal(obj, objectTreeDepth, objectMap, arrayWidth);
105
- };
106
-
107
- exports.JSONStringify = JSONStringify;