diff --git a/src/Individual.js b/src/Individual.js index 6d15b18..0b05e08 100644 --- a/src/Individual.js +++ b/src/Individual.js @@ -32,6 +32,8 @@ const mergeMap = new Map([ [SchemaNames.Comment, "comments"] ]); +const ADDRESS_LEVEL_DUMMY_UUID = 'f71b2f45-2c11-427f-aa99-be6161a6b413'; + class Individual extends BaseEntity { static schema = { name: SchemaNames.Individual, @@ -298,8 +300,15 @@ class Individual extends BaseEntity { individual.groupSubjects = []; individual.groups = []; individual.approvalStatuses = []; - individual.lowestAddressLevel = AddressLevel.create({ - uuid: "", + individual.lowestAddressLevel = this.getPlaceholderAddressLevel(); + individual.voided = false; + individual.comments = []; + return individual; + } + + static getPlaceholderAddressLevel(entityService) { + return AddressLevel.create({ + uuid: ADDRESS_LEVEL_DUMMY_UUID, title: "", level: 0, typeString: "", @@ -308,10 +317,7 @@ class Individual extends BaseEntity { parentUuid: "", typeUuid: "", locationProperties: [] - }); - individual.voided = false; - individual.comments = []; - return individual; + }, entityService); } static createEmptySubjectInstance() { @@ -381,10 +387,17 @@ class Individual extends BaseEntity { individual.dateOfBirth = dateOfBirth; individual.dateOfBirthVerified = dateOfBirthVerified; individual.gender = gender; - individual.lowestAddressLevel = lowestAddressLevel; + individual.lowestAddressLevel = this.initLowestAddressLevel(lowestAddressLevel, subjectType, null); return individual; } + /** + * Init Lowest AddressLevel with Placeholder only if the Individual SubjectType is User + */ + static initLowestAddressLevel(lowestAddressLevel, subjectType, entityService) { + return lowestAddressLevel || (subjectType && subjectType.isUser() && this.getPlaceholderAddressLevel(entityService)); + } + static directCopyFields = ["uuid", "firstName", "middleName", "lastName", "profilePicture", "dateOfBirthVerified", "voided"]; static dateFields = ["dateOfBirth", "registrationDate"]; @@ -413,7 +426,7 @@ class Individual extends BaseEntity { entityService ); individual.gender = gender; - individual.lowestAddressLevel = addressLevel; + individual.lowestAddressLevel = this.initLowestAddressLevel(addressLevel, subjectType, entityService); individual.name = individual.nameString; if (!_.isNil(individualResource.registrationLocation)) individual.registrationLocation = Point.fromResource(individualResource.registrationLocation); diff --git a/src/Schema.js b/src/Schema.js index 271aed7..d319806 100644 --- a/src/Schema.js +++ b/src/Schema.js @@ -87,7 +87,6 @@ import CustomDashboardCache from './CustomDashboardCache'; import DefinedObjectSchema from "./framework/DefinedObjectSchema"; import MigrationsHelper from "./MigrationsHelper"; import MetaDataService from "./service/MetaDataService"; -import moment from "moment"; const entities = [ DashboardFilter, @@ -253,7 +252,7 @@ function createRealmConfig() { return doCompact; }, //order is important, should be arranged according to the dependency - schemaVersion: 188, + schemaVersion: 189, onMigration: function (oldDB, newDB) { console.log("[AvniModels.Schema]", `Running migration with old schema version: ${oldDB.schemaVersion} and new schema version: ${newDB.schemaVersion}`); if (oldDB.schemaVersion === VersionWithEmbeddedMigrationProblem) @@ -904,6 +903,10 @@ function createRealmConfig() { // newDB.deleteModel("Decision"); // newDB.deleteModel("ProgramOutcome"); } + if (oldDB.schemaVersion < 189) { + // PlaceHolder for SubjectType.User changes, so that people with previous version of client + // are not able to use fastSync of version 189 and above + } }, }; } diff --git a/src/SubjectType.js b/src/SubjectType.js index 71d0940..eb1362d 100644 --- a/src/SubjectType.js +++ b/src/SubjectType.js @@ -204,6 +204,7 @@ class SubjectType extends ReferenceEntity { Individual: 'Individual', Group: 'Group', Household: 'Household', + User: 'User' }; static settingKeys = { @@ -285,6 +286,10 @@ class SubjectType extends ReferenceEntity { return this.type === SubjectType.types.Individual; } + isUser() { + return this.type === SubjectType.types.User; + } + registerIcon() { return this.isPerson() ? "account-plus" : "plus-box"; } diff --git a/src/utility/General.js b/src/utility/General.js index 0ebdd0d..a74a8f8 100644 --- a/src/utility/General.js +++ b/src/utility/General.js @@ -150,6 +150,9 @@ class General { } static assignObsFields(source, dest, observationFields = [], entityService) { + if(!entityService) { + return dest; + } observationFields.forEach((observationField) => { const observations = []; if (!_.isNil(source[observationField])) {