openchs-models 1.31.64 → 1.31.66

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;
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: 188,
282
+ schemaVersion: 189,
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.`);
@@ -903,6 +901,10 @@ function createRealmConfig() {
903
901
  // newDB.deleteModel("Decision");
904
902
  // newDB.deleteModel("ProgramOutcome");
905
903
  }
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
+ }
906
908
  }
907
909
  };
908
910
  }
@@ -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", {
@@ -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
 
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.64",
4
+ "version": "1.31.66",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",