From cac36ce63b414a2b3a9c8a43e84d3ad520984889 Mon Sep 17 00:00:00 2001 From: Joy A Date: Wed, 7 Feb 2024 16:04:16 +0530 Subject: [PATCH 1/8] avniproject/avni-client#1289 | Filter embedded objects while returning entities loaded from server --- src/EntityMetaData.js | 12 +++++++++++- test/EntitiesMetaDataTest.js | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/EntityMetaData.js b/src/EntityMetaData.js index 53e51511..63e3d9e2 100644 --- a/src/EntityMetaData.js +++ b/src/EntityMetaData.js @@ -69,6 +69,12 @@ import SubjectProgramEligibility from "./program/SubjectProgramEligibility"; import MenuItem from "./application/MenuItem"; import UserSubjectAssignment from "./assignment/UserSubjectAssignment"; import DashboardFilter from "./reports/DashboardFilter"; +import KeyValue from "./application/KeyValue"; +import Observation from "./Observation"; +import Format from "./application/Format"; +import StringKeyNumericValue from "./application/StringKeyNumericValue"; +import ChecklistItemStatus from "./ChecklistItemStatus"; +import Point from "./geo/Point"; const refData = (clazz, { res, @@ -502,7 +508,11 @@ class EntityMetaData { } static entitiesLoadedFromServer() { - return _.differenceBy(EntityMappingConfig.getInstance().getEntities(), [Settings, LocaleMapping], "schema.name"); + return _.differenceBy(EntityMappingConfig.getInstance().getEntities(), [Settings, LocaleMapping].concat(EntityMetaData.embeddedEntities()), "schema.name"); + } + + static embeddedEntities() { + return [KeyValue, Observation, Format, StringKeyNumericValue, ChecklistItemStatus, Point]; } static findByName(entityName) { diff --git a/test/EntitiesMetaDataTest.js b/test/EntitiesMetaDataTest.js index 0959d7e3..90c540ed 100644 --- a/test/EntitiesMetaDataTest.js +++ b/test/EntitiesMetaDataTest.js @@ -7,6 +7,7 @@ describe('EntitiesMetaDataTest', () => { it('entitiesLoadedFromServer', () => { var entitiesLoadedFromServer = EntityMetaData.entitiesLoadedFromServer(); assert.notIncludeMembers(entitiesLoadedFromServer, [Settings, Individual]); + assert.notIncludeMembers(entitiesLoadedFromServer, EntityMetaData.embeddedEntities()); }); describe('model', function () { From 3fd4cbd3b12d9c27ee3751b338775d6b97c412a4 Mon Sep 17 00:00:00 2001 From: Joy A Date: Wed, 7 Feb 2024 16:06:37 +0530 Subject: [PATCH 2/8] v1.31.30 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d57a700a..d0db779d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "openchs-models", "description": "OpenCHS data model to be used by front end clients", - "version": "1.31.29", + "version": "1.31.30", "private": false, "repository": { "type": "git", From 9dcd9211d4fb24c44baf2136f6ad6f437b870246 Mon Sep 17 00:00:00 2001 From: himeshr Date: Fri, 9 Feb 2024 17:05:48 +0530 Subject: [PATCH 3/8] avniproject/avni-client#1291 | Avoid cloning Concept during Observation.cloneForEdit() --- src/Observation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Observation.js b/src/Observation.js index 201acb98..48208b0a 100644 --- a/src/Observation.js +++ b/src/Observation.js @@ -162,7 +162,7 @@ class Observation extends PersistedObject { } cloneForEdit() { - return clone(this.concept.cloneForReference(), this.getValueWrapper().cloneForEdit()); + return clone(this.concept, this.getValueWrapper().cloneForEdit()); } shallowClone() { From a42ec2d56afbc735ae4881bff8b3bc041b03edf7 Mon Sep 17 00:00:00 2001 From: himeshr Date: Fri, 9 Feb 2024 17:08:37 +0530 Subject: [PATCH 4/8] avniproject/avni-client#1291 | Correct logic to initialize EmbeddedKeyValues used within Concept and FormElement --- src/Concept.js | 21 +++++++++------------ src/application/FormElement.js | 4 ++-- src/application/KeyValue.js | 2 +- src/framework/RealmProxy.js | 7 +++++++ 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Concept.js b/src/Concept.js index 3160dda3..366c57aa 100644 --- a/src/Concept.js +++ b/src/Concept.js @@ -167,8 +167,8 @@ export default class Concept extends BaseEntity { concept.unit = conceptResource.unit; concept.voided = conceptResource.voided || false; //This change should be independently deployable irrespective of server //remove orphan keyValues (because KeyValue doesn't have primary key - entityService && - entityService.deleteObjects(conceptResource["uuid"], Concept.schema.name, "keyValues"); + // entityService && + // entityService.deleteObjects(conceptResource["uuid"], Concept.schema.name, "keyValues"); concept.keyValues = _.map(conceptResource.keyValues, KeyValue.fromResource); return concept; } @@ -200,20 +200,17 @@ export default class Concept extends BaseEntity { concept.name = name; concept.datatype = dataType; concept.uuid = uuid; - concept.keyValues = keyValues; + concept.keyValues = _.map(keyValues, KeyValue.fromResource); return concept; } + /** + * This should never be cloned and used for reference as this is metadata which is not to be modified during transactional data operations + * + * @returns {Concept} + */ cloneForReference() { - const concept = Concept.create(this.name, this.datatype, this.keyValues); - concept.uuid = this.uuid; - concept.unit = this.unit; - concept.lowAbsolute = this.lowAbsolute; - concept.lowNormal = this.lowNormal; - concept.hiNormal = this.hiNormal; - concept.hiAbsolute = this.hiAbsolute; - concept.answers = this.answers || []; - return concept; + return this; } _valuePresent(value) { diff --git a/src/application/FormElement.js b/src/application/FormElement.js index 47789d16..5aea8858 100644 --- a/src/application/FormElement.js +++ b/src/application/FormElement.js @@ -156,7 +156,7 @@ class FormElement extends BaseEntity { formElement.concept = concept; //remove orphan keyValues (because KeyValue doesn't have primary key - entityService.deleteObjects(resource["uuid"], FormElement.schema.name, "keyValues"); + // entityService.deleteObjects(resource["uuid"], FormElement.schema.name, "keyValues"); formElement.keyValues = _.map(resource.keyValues, KeyValue.fromResource); formElement.validFormat = Format.fromResource(resource["validFormat"]); return formElement; @@ -432,7 +432,7 @@ class FormElement extends BaseEntity { formElement.name = this.name; formElement.displayOrder = this.displayOrder; formElement.mandatory = this.mandatory; - formElement.keyValues = this.keyValues; + formElement.keyValues = _.map(this.keyValues, KeyValue.fromResource); formElement.concept = this.concept; formElement.type = this.type; formElement.formElementGroup = this.formElementGroup; diff --git a/src/application/KeyValue.js b/src/application/KeyValue.js index 1c87728d..5c3ddeaa 100644 --- a/src/application/KeyValue.js +++ b/src/application/KeyValue.js @@ -18,7 +18,7 @@ class KeyValue extends PersistedObject { static fromResource(resource) { const keyValue = new KeyValue(); keyValue.key = resource.key; - keyValue.value = JSON.stringify(resource.value); + keyValue.value = typeof (resource.value) !== "string" ? JSON.stringify(resource.value): resource.value; return keyValue; } diff --git a/src/framework/RealmProxy.js b/src/framework/RealmProxy.js index 6268ba3f..1b1be712 100644 --- a/src/framework/RealmProxy.js +++ b/src/framework/RealmProxy.js @@ -44,6 +44,13 @@ class RealmProxy { return this.realmDb.close(); } + /** + * + * @param schemaName + * @param properties + * @param updateMode , all === true, modified , never === false + * @returns {*} + */ create(schemaName, properties, updateMode = "never") { const underlyingObject = _.isNil(properties.that) ? properties : properties.that; const entityClass = this.entityMappingConfig.getEntityClass(schemaName); From 9192025d772244032d8cf5ea341f3d38b2d012c3 Mon Sep 17 00:00:00 2001 From: himeshr Date: Fri, 9 Feb 2024 17:09:08 +0530 Subject: [PATCH 5/8] v1.31.31 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d0db779d..acdf64a2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "openchs-models", "description": "OpenCHS data model to be used by front end clients", - "version": "1.31.30", + "version": "1.31.31", "private": false, "repository": { "type": "git", From f237bde44378a19ba2efde1b62c5ec0ecb73e9b6 Mon Sep 17 00:00:00 2001 From: himeshr Date: Fri, 9 Feb 2024 17:21:04 +0530 Subject: [PATCH 6/8] avniproject/avni-client#1291 | Remove commented out lines related to deletion of embeddedObjects --- src/Concept.js | 3 --- src/application/FormElement.js | 2 -- 2 files changed, 5 deletions(-) diff --git a/src/Concept.js b/src/Concept.js index 366c57aa..f7691137 100644 --- a/src/Concept.js +++ b/src/Concept.js @@ -166,9 +166,6 @@ export default class Concept extends BaseEntity { concept.hiNormal = conceptResource.highNormal; concept.unit = conceptResource.unit; concept.voided = conceptResource.voided || false; //This change should be independently deployable irrespective of server - //remove orphan keyValues (because KeyValue doesn't have primary key - // entityService && - // entityService.deleteObjects(conceptResource["uuid"], Concept.schema.name, "keyValues"); concept.keyValues = _.map(conceptResource.keyValues, KeyValue.fromResource); return concept; } diff --git a/src/application/FormElement.js b/src/application/FormElement.js index 5aea8858..a11dbaa9 100644 --- a/src/application/FormElement.js +++ b/src/application/FormElement.js @@ -155,8 +155,6 @@ class FormElement extends BaseEntity { ); formElement.concept = concept; - //remove orphan keyValues (because KeyValue doesn't have primary key - // entityService.deleteObjects(resource["uuid"], FormElement.schema.name, "keyValues"); formElement.keyValues = _.map(resource.keyValues, KeyValue.fromResource); formElement.validFormat = Format.fromResource(resource["validFormat"]); return formElement; From 2031c9453598d12f437c4d1918b3eda8d703dd47 Mon Sep 17 00:00:00 2001 From: himeshr Date: Mon, 12 Feb 2024 14:31:02 +0530 Subject: [PATCH 7/8] avniproject/avni-client#1295 | Use entity.schema.embedded check to figure out embedded entities to avoid coding miss when creating new Embedded objects --- src/EntityMetaData.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/EntityMetaData.js b/src/EntityMetaData.js index 63e3d9e2..099496e8 100644 --- a/src/EntityMetaData.js +++ b/src/EntityMetaData.js @@ -69,12 +69,6 @@ import SubjectProgramEligibility from "./program/SubjectProgramEligibility"; import MenuItem from "./application/MenuItem"; import UserSubjectAssignment from "./assignment/UserSubjectAssignment"; import DashboardFilter from "./reports/DashboardFilter"; -import KeyValue from "./application/KeyValue"; -import Observation from "./Observation"; -import Format from "./application/Format"; -import StringKeyNumericValue from "./application/StringKeyNumericValue"; -import ChecklistItemStatus from "./ChecklistItemStatus"; -import Point from "./geo/Point"; const refData = (clazz, { res, @@ -512,7 +506,7 @@ class EntityMetaData { } static embeddedEntities() { - return [KeyValue, Observation, Format, StringKeyNumericValue, ChecklistItemStatus, Point]; + return _.filter(EntityMappingConfig.getInstance().getEntities(), entity => entity.schema.embedded); } static findByName(entityName) { From 79c793d1145a3d7411d376f87eb6c54f1e8474ca Mon Sep 17 00:00:00 2001 From: himeshr Date: Mon, 12 Feb 2024 15:09:58 +0530 Subject: [PATCH 8/8] v1.31.32 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index acdf64a2..c90befb7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "openchs-models", "description": "OpenCHS data model to be used by front end clients", - "version": "1.31.31", + "version": "1.31.32", "private": false, "repository": { "type": "git",