openchs-models 1.31.72 → 1.31.74

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,6 +242,24 @@ 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
+
245
263
  }
246
264
 
247
265
  _defineProperty(AddressLevel, "schema", {
@@ -64,6 +64,7 @@ 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';
67
68
 
68
69
  class Individual extends _BaseEntity.default {
69
70
  constructor(that = null) {
@@ -279,8 +280,15 @@ class Individual extends _BaseEntity.default {
279
280
  individual.groupSubjects = [];
280
281
  individual.groups = [];
281
282
  individual.approvalStatuses = [];
282
- individual.lowestAddressLevel = _AddressLevel.default.create({
283
- uuid: "",
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,
284
292
  title: "",
285
293
  level: 0,
286
294
  typeString: "",
@@ -289,10 +297,7 @@ class Individual extends _BaseEntity.default {
289
297
  parentUuid: "",
290
298
  typeUuid: "",
291
299
  locationProperties: []
292
- });
293
- individual.voided = false;
294
- individual.comments = [];
295
- return individual;
300
+ }, entityService);
296
301
  }
297
302
 
298
303
  static createEmptySubjectInstance() {
@@ -340,9 +345,17 @@ class Individual extends _BaseEntity.default {
340
345
  individual.dateOfBirth = dateOfBirth;
341
346
  individual.dateOfBirthVerified = dateOfBirthVerified;
342
347
  individual.gender = gender;
343
- individual.lowestAddressLevel = lowestAddressLevel;
348
+ individual.lowestAddressLevel = this.initLowestAddressLevel(lowestAddressLevel, subjectType, null);
344
349
  return individual;
345
350
  }
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
+ }
346
359
 
347
360
  static fromResource(individualResource, entityService) {
348
361
  const addressLevel = entityService.findByKey("uuid", _ResourceUtil.default.getUUIDFor(individualResource, "addressUUID"), _AddressLevel.default.schema.name);
@@ -352,7 +365,7 @@ class Individual extends _BaseEntity.default {
352
365
  const individual = _General.default.assignFields(individualResource, new Individual(), this.directCopyFields, this.dateFields, ["observations"], entityService);
353
366
 
354
367
  individual.gender = gender;
355
- individual.lowestAddressLevel = addressLevel;
368
+ individual.lowestAddressLevel = this.initLowestAddressLevel(addressLevel, subjectType, entityService);
356
369
  individual.name = individual.nameString;
357
370
  if (!_lodash.default.isNil(individualResource.registrationLocation)) individual.registrationLocation = _Point.default.fromResource(individualResource.registrationLocation);
358
371
  individual.subjectType = subjectType;
@@ -467,8 +480,12 @@ class Individual extends _BaseEntity.default {
467
480
  return _Duration.default.inYear(0);
468
481
  }
469
482
 
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
+
470
487
  get nameString() {
471
- return this.isPerson() ? Individual.getFullName(this) : this.firstName;
488
+ return this.isPerson() ? Individual.getFullName(this) : this.subjectType.type === _SubjectType.default.types.User ? `${this.firstName}(You)` : this.firstName;
472
489
  }
473
490
 
474
491
  static getFullName(obj) {
@@ -59,7 +59,7 @@ class ObservationsHolder {
59
59
  const groupObservations = observations && observations.getValueWrapper();
60
60
 
61
61
  if (parentFormElement.repeatable) {
62
- return groupObservations && groupObservations.getGroupObservationAtIndex(questionGroupIndex).getObservation(concept);
62
+ return groupObservations && groupObservations.size() > questionGroupIndex && groupObservations.getGroupObservationAtIndex(questionGroupIndex).getObservation(concept);
63
63
  }
64
64
 
65
65
  return groupObservations && groupObservations.getObservation(concept);
package/dist/Schema.js CHANGED
@@ -183,8 +183,6 @@ var _MigrationsHelper = _interopRequireDefault(require("./MigrationsHelper"));
183
183
 
184
184
  var _MetaDataService = _interopRequireDefault(require("./service/MetaDataService"));
185
185
 
186
- var _moment = _interopRequireDefault(require("moment"));
187
-
188
186
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
189
187
 
190
188
  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; }
@@ -281,7 +279,7 @@ function createRealmConfig() {
281
279
  return doCompact;
282
280
  },
283
281
  //order is important, should be arranged according to the dependency
284
- schemaVersion: 189,
282
+ schemaVersion: 190,
285
283
  onMigration: function (oldDB, newDB) {
286
284
  console.log("[AvniModels.Schema]", `Running migration with old schema version: ${oldDB.schemaVersion} and new schema version: ${newDB.schemaVersion}`);
287
285
  if (oldDB.schemaVersion === VersionWithEmbeddedMigrationProblem) throw new Error(`Update from schema version ${VersionWithEmbeddedMigrationProblem} is not allowed. Please uninstall and install app.`);
@@ -911,6 +909,10 @@ function createRealmConfig() {
911
909
  }
912
910
  });
913
911
  }
912
+
913
+ if (oldDB.schemaVersion < 190) {// PlaceHolder for SubjectType.User changes, so that people with previous version of client
914
+ // are not able to use fastSync of version 190 and above
915
+ }
914
916
  }
915
917
  };
916
918
  }
@@ -260,6 +260,10 @@ 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
+
263
267
  registerIcon() {
264
268
  return this.isPerson() ? "account-plus" : "plus-box";
265
269
  }
@@ -376,7 +380,8 @@ _defineProperty(SubjectType, "types", {
376
380
  Person: 'Person',
377
381
  Individual: 'Individual',
378
382
  Group: 'Group',
379
- Household: 'Household'
383
+ Household: 'Household',
384
+ User: 'User'
380
385
  });
381
386
 
382
387
  _defineProperty(SubjectType, "settingKeys", {
@@ -227,6 +227,32 @@ 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;
230
256
  }
231
257
 
232
258
  sectionWiseOrderedObservations(observations) {
@@ -31,6 +31,8 @@ var _BaseEntity = _interopRequireDefault(require("../BaseEntity"));
31
31
 
32
32
  var _SchemaNames = _interopRequireDefault(require("../SchemaNames"));
33
33
 
34
+ var _RepeatableQuestionGroup = _interopRequireDefault(require("../observation/RepeatableQuestionGroup"));
35
+
34
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
37
 
36
38
  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; }
@@ -149,8 +151,18 @@ class FormElement extends _BaseEntity.default {
149
151
  return formElement;
150
152
  }
151
153
 
154
+ newFormElement() {
155
+ return new FormElement();
156
+ }
157
+
152
158
  getType() {
153
- return this.concept.datatype === _Concept.default.dataType.Coded ? this.type : this.concept.datatype;
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
+ }
154
166
  }
155
167
 
156
168
  isMultiSelect() {
@@ -223,7 +235,7 @@ class FormElement extends _BaseEntity.default {
223
235
  }
224
236
  } else if (this.concept.datatype === _Concept.default.dataType.Time && !(0, _moment.default)(value, 'HH:mm').isValid() && (!this.mandatory && !_lodash.default.isNil(value) || this.mandatory)) {
225
237
  failure.messageKey = "invalidTimeFormat";
226
- } else if (this.concept.datatype === _Concept.default.dataType.Date && !(0, _moment.default)(value).isValid() && (!this.mandatory && !_lodash.default.isNil(value) || this.mandatory)) {
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)) {
227
239
  failure.messageKey = "invalidDateFormat";
228
240
  } 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))) {
229
241
  failure.messageKey = "emptyValidationMessage";
@@ -286,6 +298,11 @@ class FormElement extends _BaseEntity.default {
286
298
  return _lodash.default.isNil(repeatable) ? false : repeatable.getValue();
287
299
  }
288
300
 
301
+ get disableManualActions() {
302
+ const disableManualActions = this.recordByKey("disableManualActions");
303
+ return _lodash.default.isNil(disableManualActions) ? false : disableManualActions.getValue();
304
+ }
305
+
289
306
  get datePickerMode() {
290
307
  const datePickerMode = this.recordByKey("datePickerMode");
291
308
  return _lodash.default.isNil(datePickerMode) ? null : datePickerMode.getValue();
@@ -386,8 +403,12 @@ class FormElement extends _BaseEntity.default {
386
403
  return _lodash.default.find(this.formElementGroup.getFormElements(), fe => fe.uuid === this.groupUuid);
387
404
  }
388
405
 
406
+ isRepeatableQuestionGroup() {
407
+ return this.concept.isQuestionGroup() && this.repeatable;
408
+ }
409
+
389
410
  clone() {
390
- const formElement = new FormElement();
411
+ const formElement = this.newFormElement();
391
412
  formElement.uuid = this.uuid;
392
413
  formElement.name = this.name;
393
414
  formElement.displayOrder = this.displayOrder;
package/dist/index.js CHANGED
@@ -783,6 +783,12 @@ 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
+ });
786
792
 
787
793
  var _AbstractEncounter = _interopRequireDefault(require("./AbstractEncounter"));
788
794
 
@@ -1034,6 +1040,8 @@ var _AgeUtil = _interopRequireDefault(require("./utility/AgeUtil"));
1034
1040
 
1035
1041
  var _DashboardCacheFilter = _interopRequireDefault(require("./application/DashboardCacheFilter"));
1036
1042
 
1043
+ var _JsonStringify = require("./utility/JsonStringify");
1044
+
1037
1045
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
1038
1046
 
1039
1047
  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,6 +88,8 @@ class RepeatableQuestionGroup {
88
88
 
89
89
  }
90
90
 
91
+ _defineProperty(RepeatableQuestionGroup, "TypeName", "RepeatableQuestionGroup");
92
+
91
93
  _defineProperty(RepeatableQuestionGroup, "actions", {
92
94
  add: 'add',
93
95
  remove: 'remove'
@@ -150,6 +150,10 @@ class General {
150
150
  }
151
151
 
152
152
  static assignObsFields(source, dest, observationFields = [], entityService) {
153
+ if (!entityService) {
154
+ return dest;
155
+ }
156
+
153
157
  observationFields.forEach(observationField => {
154
158
  const observations = [];
155
159
 
@@ -0,0 +1,107 @@
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;
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.72",
4
+ "version": "1.31.74",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",