openchs-models 1.31.57 → 1.31.58

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.
@@ -412,19 +412,6 @@ class AbstractEncounter extends _BaseEntity.default {
412
412
  this.that.latestEntityApprovalStatus = this.fromObject(entityApprovalStatus);
413
413
  }
414
414
 
415
- updateAudit(userInfo, isNew, isGettingFilled) {
416
- (0, _AuditUtil.updateAuditFields)(this, userInfo, isNew);
417
-
418
- if (_lodash.default.isNil(this.filledByUUID) && isGettingFilled) {
419
- this.filledByUUID = userInfo.userUUID;
420
- this.filledBy = userInfo.name;
421
- }
422
- }
423
-
424
- isFilled() {
425
- return !_lodash.default.isNil(this.encounterDateTime);
426
- }
427
-
428
415
  }
429
416
 
430
417
  _defineProperty(AbstractEncounter, "fieldKeys", {
@@ -261,7 +261,7 @@ _defineProperty(AddressLevel, "schema", {
261
261
  },
262
262
  locationProperties: {
263
263
  type: "list",
264
- objectType: "Observation"
264
+ objectType: "EmbeddedObservation"
265
265
  },
266
266
  titleLineage: {
267
267
  type: "string",
@@ -362,7 +362,7 @@ _defineProperty(ChecklistItem, "schema", {
362
362
  },
363
363
  observations: {
364
364
  type: "list",
365
- objectType: "Observation"
365
+ objectType: "EmbeddedObservation"
366
366
  },
367
367
  checklist: "Checklist",
368
368
  approvalStatuses: {
package/dist/Encounter.js CHANGED
@@ -132,10 +132,10 @@ _defineProperty(Encounter, "schema", {
132
132
  individual: _SchemaNames.default.Individual,
133
133
  observations: {
134
134
  type: "list",
135
- objectType: "Observation"
135
+ objectType: "EmbeddedObservation"
136
136
  },
137
137
  encounterLocation: {
138
- type: _SchemaNames.default.Point,
138
+ type: _SchemaNames.default.EmbeddedPoint,
139
139
  optional: true
140
140
  },
141
141
  name: {
@@ -156,10 +156,10 @@ _defineProperty(Encounter, "schema", {
156
156
  },
157
157
  cancelObservations: {
158
158
  type: "list",
159
- objectType: "Observation"
159
+ objectType: "EmbeddedObservation"
160
160
  },
161
161
  cancelLocation: {
162
- type: _SchemaNames.default.Point,
162
+ type: _SchemaNames.default.EmbeddedPoint,
163
163
  optional: true
164
164
  },
165
165
  voided: {
package/dist/Family.js CHANGED
@@ -226,7 +226,7 @@ _defineProperty(Family, "schema", {
226
226
  },
227
227
  observations: {
228
228
  type: "list",
229
- objectType: "Observation"
229
+ objectType: "EmbeddedObservation"
230
230
  }
231
231
  }
232
232
  });
@@ -1066,10 +1066,6 @@ class Individual extends _BaseEntity.default {
1066
1066
  return _SchemaNames.default.Individual;
1067
1067
  }
1068
1068
 
1069
- updateAudit(userInfo, isNew) {
1070
- (0, _AuditUtil.updateAuditFields)(this, userInfo, isNew);
1071
- }
1072
-
1073
1069
  }
1074
1070
 
1075
1071
  _defineProperty(Individual, "schema", {
@@ -1120,7 +1116,7 @@ _defineProperty(Individual, "schema", {
1120
1116
  },
1121
1117
  observations: {
1122
1118
  type: "list",
1123
- objectType: "Observation"
1119
+ objectType: "EmbeddedObservation"
1124
1120
  },
1125
1121
  relationships: {
1126
1122
  type: "list",
@@ -1131,7 +1127,7 @@ _defineProperty(Individual, "schema", {
1131
1127
  objectType: "GroupSubject"
1132
1128
  },
1133
1129
  registrationLocation: {
1134
- type: _SchemaNames.default.Point,
1130
+ type: _SchemaNames.default.EmbeddedPoint,
1135
1131
  optional: true
1136
1132
  },
1137
1133
  comments: {
@@ -261,7 +261,8 @@ class Observation extends _PersistedObject.default {
261
261
  }
262
262
 
263
263
  _defineProperty(Observation, "schema", {
264
- name: "Observation",
264
+ name: "EmbeddedObservation",
265
+ embedded: true,
265
266
  properties: {
266
267
  concept: "Concept",
267
268
  valueJSON: "string"
@@ -194,7 +194,7 @@ _defineProperty(ProgramEncounter, "schema", {
194
194
  programEnrolment: _SchemaNames.default.ProgramEnrolment,
195
195
  observations: {
196
196
  type: "list",
197
- objectType: "Observation"
197
+ objectType: "EmbeddedObservation"
198
198
  },
199
199
  cancelDateTime: {
200
200
  type: "date",
@@ -202,14 +202,14 @@ _defineProperty(ProgramEncounter, "schema", {
202
202
  },
203
203
  cancelObservations: {
204
204
  type: "list",
205
- objectType: "Observation"
205
+ objectType: "EmbeddedObservation"
206
206
  },
207
207
  encounterLocation: {
208
- type: _SchemaNames.default.Point,
208
+ type: _SchemaNames.default.EmbeddedPoint,
209
209
  optional: true
210
210
  },
211
211
  cancelLocation: {
212
- type: _SchemaNames.default.Point,
212
+ type: _SchemaNames.default.EmbeddedPoint,
213
213
  optional: true
214
214
  },
215
215
  voided: {
@@ -646,10 +646,6 @@ class ProgramEnrolment extends _BaseEntity.default {
646
646
  return _SchemaNames.default.ProgramEnrolment;
647
647
  }
648
648
 
649
- updateAudit(userInfo, isNew) {
650
- (0, _AuditUtil.updateAuditFields)(this, userInfo, isNew);
651
- }
652
-
653
649
  }
654
650
 
655
651
  _defineProperty(ProgramEnrolment, "schema", {
@@ -661,7 +657,7 @@ _defineProperty(ProgramEnrolment, "schema", {
661
657
  enrolmentDateTime: "date",
662
658
  observations: {
663
659
  type: "list",
664
- objectType: "Observation"
660
+ objectType: "EmbeddedObservation"
665
661
  },
666
662
  programExitDateTime: {
667
663
  type: "date",
@@ -669,7 +665,7 @@ _defineProperty(ProgramEnrolment, "schema", {
669
665
  },
670
666
  programExitObservations: {
671
667
  type: "list",
672
- objectType: "Observation"
668
+ objectType: "EmbeddedObservation"
673
669
  },
674
670
  encounters: {
675
671
  type: "list",
@@ -681,11 +677,11 @@ _defineProperty(ProgramEnrolment, "schema", {
681
677
  },
682
678
  individual: "Individual",
683
679
  enrolmentLocation: {
684
- type: _SchemaNames.default.Point,
680
+ type: _SchemaNames.default.EmbeddedPoint,
685
681
  optional: true
686
682
  },
687
683
  exitLocation: {
688
- type: _SchemaNames.default.Point,
684
+ type: _SchemaNames.default.EmbeddedPoint,
689
685
  optional: true
690
686
  },
691
687
  voided: {
package/dist/Schema.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.createTransactionDataMapForEmbeddedFields = createTransactionDataMapForEmbeddedFields;
6
7
  exports.default = void 0;
7
8
 
8
9
  var _Settings = _interopRequireDefault(require("./Settings"));
@@ -271,7 +272,100 @@ function migrateEmbeddedObjects(oldDB, newDB) {
271
272
  newDB.deleteModel("StringKeyNumericValue");
272
273
  }
273
274
 
274
- const VersionWithEmbeddedMigrationProblem = 185;
275
+ function flush(db) {
276
+ db.commitTransaction();
277
+ db.beginTransaction();
278
+ }
279
+
280
+ function shouldFlush(numberOfRecords) {
281
+ const batchSize = 100;
282
+ return numberOfRecords % batchSize === batchSize - 1;
283
+ }
284
+
285
+ function createTransactionDataMapForEmbeddedFields() {
286
+ const map = new Map();
287
+
288
+ _MetaDataService.default.forEachPointField((fieldName, schemaName) => {
289
+ if (map.has(schemaName)) {
290
+ map.get(schemaName).push({
291
+ fieldName,
292
+ fieldType: "Point"
293
+ });
294
+ } else {
295
+ map.set(schemaName, [{
296
+ fieldName,
297
+ fieldType: "Point"
298
+ }]);
299
+ }
300
+ });
301
+
302
+ _MetaDataService.default.forEachObservationField((fieldName, schemaName) => {
303
+ if (map.has(schemaName)) {
304
+ map.get(schemaName).push({
305
+ fieldName,
306
+ fieldType: "Obs"
307
+ });
308
+ } else {
309
+ map.set(schemaName, [{
310
+ fieldName,
311
+ fieldType: "Obs"
312
+ }]);
313
+ }
314
+ });
315
+
316
+ return map;
317
+ }
318
+
319
+ function migrateAllEmbeddedForTxnData(oldDB, newDB) {
320
+ const startTime = new Date();
321
+ flush(newDB);
322
+ const map = createTransactionDataMapForEmbeddedFields();
323
+ let recordCounter = 0;
324
+ const conceptMap = new Map();
325
+ map.forEach((fields, schemaName) => {
326
+ console.log(`schema: ${schemaName}, fields: ${fields.length}`);
327
+ newDB.objects(schemaName).forEach(newDbParentEntity => {
328
+ if (shouldFlush(recordCounter)) {
329
+ flush(newDB);
330
+ }
331
+
332
+ fields.forEach(field => {
333
+ const oldEntity = oldDB.objects(schemaName).filtered(`uuid = "${newDbParentEntity.uuid}"`)[0];
334
+ const oldValue = oldEntity[field.fieldName];
335
+
336
+ if (!_lodash.default.isNil(oldValue)) {
337
+ if (field.fieldType === "Point") newDbParentEntity[field.fieldName] = {
338
+ x: oldValue.x,
339
+ y: oldValue.y
340
+ };else {
341
+ const newObsList = [];
342
+ oldValue.forEach(oldItemValue => {
343
+ let newConcept = conceptMap.get(oldItemValue.concept.uuid);
344
+
345
+ if (_lodash.default.isNil(newConcept)) {
346
+ newConcept = newDB.objects("Concept").filtered(`uuid = "${oldItemValue.concept.uuid}"`)[0];
347
+ conceptMap.set(oldItemValue.concept.uuid, newConcept);
348
+ }
349
+
350
+ newObsList.push({
351
+ concept: newConcept,
352
+ valueJSON: oldItemValue.valueJSON
353
+ });
354
+ });
355
+ newDbParentEntity[field.fieldName] = newObsList;
356
+ }
357
+ }
358
+ });
359
+ recordCounter++;
360
+ });
361
+ });
362
+ flush(newDB);
363
+ newDB.deleteModel("Point");
364
+ newDB.deleteModel("Observation");
365
+ const endTime = new Date();
366
+ const diff = (0, _moment.default)(endTime).diff(startTime, "seconds", true);
367
+ console.log("Total Time Taken", diff, "seconds");
368
+ }
275
369
 
276
370
  function createRealmConfig() {
277
371
  return {
@@ -284,14 +378,6 @@ function createRealmConfig() {
284
378
  schemaVersion: 188,
285
379
  onMigration: function (oldDB, newDB) {
286
380
  console.log("[AvniModels.Schema]", `Running migration with old schema version: ${oldDB.schemaVersion} and new schema version: ${newDB.schemaVersion}`);
287
- if (oldDB.schemaVersion === VersionWithEmbeddedMigrationProblem) throw new Error(`Update from schema version ${VersionWithEmbeddedMigrationProblem} is not allowed. Please uninstall and install app.`);
288
-
289
- if (oldDB.schemaVersion < 10) {
290
- const oldObjects = oldDB.objects("DecisionConfig");
291
- oldObjects.forEach(decisionConfig => {
292
- newDB.create(ConfigFile.schema.name, ConfigFile.create(decisionConfig.fileName, decisionConfig.decisionCode), true);
293
- });
294
- }
295
381
 
296
382
  if (oldDB.schemaVersion < 17) {
297
383
  const oldObjects = oldDB.objects("AddressLevel");
@@ -895,7 +981,8 @@ function createRealmConfig() {
895
981
  migrateEmbeddedObjects(oldDB, newDB);
896
982
  }
897
983
 
898
- if (oldDB.schemaVersion < VersionWithEmbeddedMigrationProblem) {// removed migration code. keeping the version number in case this number is required for any checks later
984
+ if (oldDB.schemaVersion < 185) {
985
+ migrateAllEmbeddedForTxnData(oldDB, newDB);
899
986
  }
900
987
 
901
988
  if (oldDB.schemaVersion < 186) {// newDB.deleteModel("UserDefinedIndividualProperty");
@@ -91,7 +91,7 @@ _defineProperty(SchemaNames, "Concept", "Concept");
91
91
 
92
92
  _defineProperty(SchemaNames, "EntityApprovalStatus", "EntityApprovalStatus");
93
93
 
94
- _defineProperty(SchemaNames, "Point", "Point");
94
+ _defineProperty(SchemaNames, "EmbeddedPoint", "EmbeddedPoint");
95
95
 
96
96
  var _default = SchemaNames;
97
97
  exports.default = _default;
@@ -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() {
@@ -387,7 +399,7 @@ class FormElement extends _BaseEntity.default {
387
399
  }
388
400
 
389
401
  clone() {
390
- const formElement = new FormElement();
402
+ const formElement = this.newFormElement();
391
403
  formElement.uuid = this.uuid;
392
404
  formElement.name = this.name;
393
405
  formElement.displayOrder = this.displayOrder;
@@ -170,10 +170,10 @@ _defineProperty(DraftEncounter, "schema", {
170
170
  individual: "Individual",
171
171
  observations: {
172
172
  type: "list",
173
- objectType: "Observation"
173
+ objectType: "EmbeddedObservation"
174
174
  },
175
175
  encounterLocation: {
176
- type: _SchemaNames.default.Point,
176
+ type: _SchemaNames.default.EmbeddedPoint,
177
177
  optional: true
178
178
  },
179
179
  name: {
@@ -194,10 +194,10 @@ _defineProperty(DraftEncounter, "schema", {
194
194
  },
195
195
  cancelObservations: {
196
196
  type: "list",
197
- objectType: "Observation"
197
+ objectType: "EmbeddedObservation"
198
198
  },
199
199
  cancelLocation: {
200
- type: _SchemaNames.default.Point,
200
+ type: _SchemaNames.default.EmbeddedPoint,
201
201
  optional: true
202
202
  },
203
203
  voided: {
@@ -211,10 +211,10 @@ _defineProperty(DraftSubject, "schema", {
211
211
  lowestAddressLevel: "AddressLevel",
212
212
  observations: {
213
213
  type: "list",
214
- objectType: "Observation"
214
+ objectType: "EmbeddedObservation"
215
215
  },
216
216
  registrationLocation: {
217
- type: _SchemaNames.default.Point,
217
+ type: _SchemaNames.default.EmbeddedPoint,
218
218
  optional: true
219
219
  },
220
220
  updatedOn: "date",
package/dist/geo/Point.js CHANGED
@@ -57,7 +57,8 @@ class Point extends _PersistedObject.default {
57
57
  }
58
58
 
59
59
  _defineProperty(Point, "schema", {
60
- name: "Point",
60
+ name: "EmbeddedPoint",
61
+ embedded: true,
61
62
  properties: {
62
63
  x: "double",
63
64
  y: "double"
@@ -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'
@@ -221,7 +221,7 @@ _defineProperty(SubjectProgramEligibility, "schema", {
221
221
  },
222
222
  observations: {
223
223
  type: "list",
224
- objectType: "Observation"
224
+ objectType: "EmbeddedObservation"
225
225
  },
226
226
  voided: {
227
227
  type: "bool",
@@ -207,7 +207,7 @@ _defineProperty(IndividualRelationship, "schema", {
207
207
  },
208
208
  exitObservations: {
209
209
  type: "list",
210
- objectType: "Observation"
210
+ objectType: "EmbeddedObservation"
211
211
  },
212
212
  voided: {
213
213
  type: "bool",
package/dist/task/Task.js CHANGED
@@ -230,7 +230,7 @@ _defineProperty(Task, "schema", {
230
230
  },
231
231
  metadata: {
232
232
  type: "list",
233
- objectType: "Observation"
233
+ objectType: "EmbeddedObservation"
234
234
  },
235
235
  subject: {
236
236
  type: 'Individual',
@@ -238,7 +238,7 @@ _defineProperty(Task, "schema", {
238
238
  },
239
239
  observations: {
240
240
  type: "list",
241
- objectType: "Observation"
241
+ objectType: "EmbeddedObservation"
242
242
  },
243
243
  voided: {
244
244
  type: 'bool',
@@ -3,14 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.updateAuditFields = updateAuditFields;
7
- exports.mapAuditFields = mapAuditFields;
8
- exports.AuditFields = void 0;
6
+ exports.mapAuditFields = exports.AuditFields = void 0;
9
7
 
10
8
  var _ResourceUtil = _interopRequireDefault(require("./ResourceUtil"));
11
9
 
12
- var _lodash = _interopRequireDefault(require("lodash"));
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
11
 
16
12
  const AuditFields = {
@@ -33,23 +29,11 @@ const AuditFields = {
33
29
  };
34
30
  exports.AuditFields = AuditFields;
35
31
 
36
- function updateAuditFields(entity, userInfo, isNew = false) {
37
- // old entities may have createdByUUID as null if never synced after audit release
38
- // isNew must be passed by callers to specify that it is indeed a create scenario
39
- if (_lodash.default.isNil(entity.createdByUUID) && isNew) {
40
- entity.createdByUUID = userInfo.userUUID;
41
- entity.createdBy = userInfo.name;
42
- }
43
-
44
- if (_lodash.default.isNil(entity.lastModifiedByUUID)) {
45
- entity.lastModifiedByUUID = userInfo.userUUID;
46
- entity.lastModifiedBy = userInfo.name;
47
- }
48
- }
49
-
50
- function mapAuditFields(txnEntity, txnResource) {
32
+ const mapAuditFields = function (txnEntity, txnResource) {
51
33
  txnEntity.createdBy = _ResourceUtil.default.getFieldValue(txnResource, "createdBy");
52
34
  txnEntity.createdByUUID = _ResourceUtil.default.getFieldValue(txnResource, "createdByUUID");
53
35
  txnEntity.lastModifiedBy = _ResourceUtil.default.getFieldValue(txnResource, "lastModifiedBy");
54
36
  txnEntity.lastModifiedByUUID = _ResourceUtil.default.getFieldValue(txnResource, "lastModifiedByUUID");
55
- }
37
+ };
38
+
39
+ exports.mapAuditFields = mapAuditFields;
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.57",
4
+ "version": "1.31.58",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",