openchs-models 1.30.34 → 1.30.37

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.
@@ -0,0 +1,16 @@
1
+ name: Add to Product board
2
+
3
+ on:
4
+ issues:
5
+ types:
6
+ - opened
7
+
8
+ jobs:
9
+ add-to-project:
10
+ name: Add all issues created in this repository to the Avni product board
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/add-to-project@v0.5.0
14
+ with:
15
+ project-url: https://github.com/orgs/avniproject/projects/2
16
+ github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
@@ -0,0 +1,18 @@
1
+ name: Automatically add items to project
2
+
3
+ on:
4
+ issues:
5
+ types:
6
+ - opened
7
+
8
+ jobs:
9
+ add-to-project:
10
+ name: Add issue to project
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/add-to-project@v0.5.0
14
+ with:
15
+ # You can target a project in a different organization
16
+ # to the issue
17
+ project-url: https://github.com/orgs/avniproject/projects/2/
18
+ github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
@@ -0,0 +1,21 @@
1
+ name: 'Close cards moved to Done Lane'
2
+
3
+ on:
4
+ project_card:
5
+ types: [created, edited, moved]
6
+
7
+ permissions:
8
+ repository-projects: read
9
+ issues: write
10
+ pull-requests: write
11
+
12
+ jobs:
13
+ action:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: dessant/issue-states@v3
17
+ with:
18
+ github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
19
+ open-issue-columns: ''
20
+ closed-issue-columns: 'Done'
21
+ log-output: false
package/Makefile CHANGED
@@ -15,6 +15,9 @@ release:
15
15
  git pull --tags
16
16
  git pull --rebase
17
17
  @echo "Ensure version changes follow semantic versioning - https://classic.yarnpkg.com/en/docs/dependency-versions#toc-semantic-versioning"
18
+ @echo "\033[1mLatest openchs-models version across branches:"
19
+ npm view openchs-models version
20
+ @echo "\033[0m"
18
21
  yarn version
19
22
  @echo " Now please run \nmake publish"
20
23
 
@@ -167,7 +167,9 @@ const refData = (clazz, {
167
167
  translated,
168
168
  parent,
169
169
  syncWeight,
170
- resUrl
170
+ resUrl,
171
+ syncPushRequired = true,
172
+ syncPullRequired = true
171
173
  } = {}) => ({
172
174
  schemaName: clazz.schema.name,
173
175
  entityName: clazz.schema.name,
@@ -178,7 +180,9 @@ const refData = (clazz, {
178
180
  resourceSearchFilterURL: filter,
179
181
  parent: parent,
180
182
  syncWeight: syncWeight,
181
- resourceUrl: resUrl
183
+ resourceUrl: resUrl,
184
+ syncPushRequired,
185
+ syncPullRequired
182
186
  });
183
187
 
184
188
  const refDataNameTranslated = (clazz, attrs = {}) => refData(clazz, _objectSpread({}, attrs, {
@@ -186,39 +190,8 @@ const refDataNameTranslated = (clazz, attrs = {}) => refData(clazz, _objectSprea
186
190
  }));
187
191
 
188
192
  const txData = (clazz, {
189
- res,
190
- resUrl,
191
- parent,
192
- apiVersion,
193
- syncWeight,
194
- privilegeParam,
195
- privilegeEntity,
196
- privilegeName,
197
- queryParam,
198
- hasMoreThanOneAssociation,
199
- apiQueryParams
200
- } = {}) => ({
201
- schemaName: clazz.schema.name,
202
- entityName: clazz.schema.name,
203
- entityClass: clazz,
204
- resourceName: res || _lodash.default.camelCase(clazz.schema.name),
205
- resourceUrl: resUrl,
206
- type: "tx",
207
- nameTranslated: false,
208
- parent: parent,
209
- apiVersion,
210
- syncWeight: syncWeight,
211
- privilegeParam,
212
- privilegeEntity,
213
- privilegeName,
214
- queryParam,
215
- hasMoreThanOneAssociation: !!hasMoreThanOneAssociation,
216
- apiQueryParams
217
- });
218
-
219
- const virtualTxData = (clazz, {
220
- res,
221
193
  entityName,
194
+ res,
222
195
  resUrl,
223
196
  parent,
224
197
  apiVersion,
@@ -229,14 +202,16 @@ const virtualTxData = (clazz, {
229
202
  queryParam,
230
203
  hasMoreThanOneAssociation,
231
204
  apiQueryParams,
232
- apiQueryParamKey
205
+ apiQueryParamKey,
206
+ syncPushRequired = true,
207
+ syncPullRequired = true
233
208
  } = {}) => ({
234
209
  schemaName: clazz.schema.name,
235
- entityName: entityName,
210
+ entityName: entityName || clazz.schema.name,
236
211
  entityClass: clazz,
237
212
  resourceName: res || _lodash.default.camelCase(clazz.schema.name),
238
213
  resourceUrl: resUrl,
239
- type: "virtualTx",
214
+ type: "tx",
240
215
  nameTranslated: false,
241
216
  parent: parent,
242
217
  apiVersion,
@@ -247,7 +222,9 @@ const virtualTxData = (clazz, {
247
222
  queryParam,
248
223
  hasMoreThanOneAssociation: !!hasMoreThanOneAssociation,
249
224
  apiQueryParams,
250
- apiQueryParamKey
225
+ apiQueryParamKey,
226
+ syncPushRequired,
227
+ syncPullRequired
251
228
  });
252
229
 
253
230
  const checklistDetail = refData(_ChecklistDetail.default, {
@@ -409,11 +386,13 @@ const groupSubject = txData(_GroupSubject.default, {
409
386
  const videoTelemetric = txData(_VideoTelemetric.default, {
410
387
  res: "videotelemetric",
411
388
  parent: video,
412
- syncWeight: 0
389
+ syncWeight: 0,
390
+ syncPullRequired: false
413
391
  });
414
392
  const syncTelemetry = txData(_SyncTelemetry.default, {
415
393
  resUrl: "syncTelemetry",
416
- syncWeight: 1
394
+ syncWeight: 1,
395
+ syncPullRequired: false
417
396
  });
418
397
  const userInfo = txData(_UserInfo.default, {
419
398
  resUrl: "me",
@@ -425,7 +404,8 @@ const identifierAssignment = txData(_IdentifierAssignment.default, {
425
404
  });
426
405
  const ruleFailureTelemetry = txData(_RuleFailureTelemetry.default, {
427
406
  resUrl: "ruleFailureTelemetry",
428
- syncWeight: 0
407
+ syncWeight: 0,
408
+ syncPullRequired: false
429
409
  });
430
410
  const groups = refData(_Groups.default, {
431
411
  res: "groups",
@@ -495,7 +475,7 @@ const EntityApprovalStatusMetaData = txData(_EntityApprovalStatus.default, {
495
475
  entityName: "EntityApprovalStatus"
496
476
  });
497
477
  exports.EntityApprovalStatusMetaData = EntityApprovalStatusMetaData;
498
- const subjectEntityApprovalStatus = virtualTxData(_EntityApprovalStatus.default, {
478
+ const subjectEntityApprovalStatus = txData(_EntityApprovalStatus.default, {
499
479
  res: "entityApprovalStatus",
500
480
  resUrl: "entityApprovalStatus",
501
481
  entityName: 'SubjectEntityApprovalStatus',
@@ -507,9 +487,10 @@ const subjectEntityApprovalStatus = virtualTxData(_EntityApprovalStatus.default,
507
487
  privilegeEntity: _Privilege.default.privilegeEntityType.subject,
508
488
  privilegeName: _Privilege.default.privilegeName.viewSubject,
509
489
  parent: individual,
510
- syncWeight: 2
490
+ syncWeight: 2,
491
+ syncPushRequired: false
511
492
  });
512
- const encounterEntityApprovalStatus = virtualTxData(_EntityApprovalStatus.default, {
493
+ const encounterEntityApprovalStatus = txData(_EntityApprovalStatus.default, {
513
494
  res: "entityApprovalStatus",
514
495
  resUrl: "entityApprovalStatus",
515
496
  entityName: 'EncounterEntityApprovalStatus',
@@ -521,9 +502,10 @@ const encounterEntityApprovalStatus = virtualTxData(_EntityApprovalStatus.defaul
521
502
  privilegeEntity: _Privilege.default.privilegeEntityType.encounter,
522
503
  privilegeName: _Privilege.default.privilegeName.viewVisit,
523
504
  parent: encounter,
524
- syncWeight: 2
505
+ syncWeight: 2,
506
+ syncPushRequired: false
525
507
  });
526
- const programEncounterEntityApprovalStatus = virtualTxData(_EntityApprovalStatus.default, {
508
+ const programEncounterEntityApprovalStatus = txData(_EntityApprovalStatus.default, {
527
509
  res: "entityApprovalStatus",
528
510
  resUrl: "entityApprovalStatus",
529
511
  entityName: 'ProgramEncounterEntityApprovalStatus',
@@ -535,9 +517,10 @@ const programEncounterEntityApprovalStatus = virtualTxData(_EntityApprovalStatus
535
517
  privilegeEntity: _Privilege.default.privilegeEntityType.encounter,
536
518
  privilegeName: _Privilege.default.privilegeName.viewVisit,
537
519
  parent: programEncounter,
538
- syncWeight: 2
520
+ syncWeight: 2,
521
+ syncPushRequired: false
539
522
  });
540
- const programEnrolmentEntityApprovalStatus = virtualTxData(_EntityApprovalStatus.default, {
523
+ const programEnrolmentEntityApprovalStatus = txData(_EntityApprovalStatus.default, {
541
524
  res: "entityApprovalStatus",
542
525
  resUrl: "entityApprovalStatus",
543
526
  entityName: 'ProgramEnrolmentEntityApprovalStatus',
@@ -549,9 +532,10 @@ const programEnrolmentEntityApprovalStatus = virtualTxData(_EntityApprovalStatus
549
532
  privilegeEntity: _Privilege.default.privilegeEntityType.enrolment,
550
533
  privilegeName: _Privilege.default.privilegeName.viewEnrolmentDetails,
551
534
  parent: programEnrolment,
552
- syncWeight: 2
535
+ syncWeight: 2,
536
+ syncPushRequired: false
553
537
  });
554
- const checklistItemEntityApprovalStatus = virtualTxData(_EntityApprovalStatus.default, {
538
+ const checklistItemEntityApprovalStatus = txData(_EntityApprovalStatus.default, {
555
539
  res: "entityApprovalStatus",
556
540
  resUrl: "entityApprovalStatus",
557
541
  entityName: 'ChecklistItemEntityApprovalStatus',
@@ -563,7 +547,13 @@ const checklistItemEntityApprovalStatus = virtualTxData(_EntityApprovalStatus.de
563
547
  privilegeEntity: _Privilege.default.privilegeEntityType.checklist,
564
548
  privilegeName: _Privilege.default.privilegeName.viewChecklist,
565
549
  parent: checklistItem,
566
- syncWeight: 2
550
+ syncWeight: 2,
551
+ syncPushRequired: false
552
+ });
553
+ const entityApprovalStatus = txData(_EntityApprovalStatus.default, {
554
+ res: 'entityApprovalStatus',
555
+ syncWeight: 1,
556
+ syncPullRequired: false
567
557
  });
568
558
  const news = txData(_News.default, {
569
559
  syncWeight: 0
@@ -645,7 +635,7 @@ class EntityMetaData {
645
635
 
646
636
  //order is important. last entity in each (tx and ref) with be executed first. parent should be synced before the child.
647
637
  static model() {
648
- return [groupDashboard, approvalStatus, dashboardSectionCardMapping, dashboardSection, dashboardFilter, dashboard, reportCard, standardReportCardType, menuItem, locationHierarchy, video, checklistItemDetail, checklistDetail, rule, ruleDependency, individualRelationshipType, individualRelationGenderMapping, individualRelation, programConfig, formMapping, formElement, formElementGroup, form, documentationItem, documentation, identifierSource, organisationConfig, platformTranslation, translation, locationMapping, addressLevel, taskStatus, taskType, encounterType, program, programOutcome, gender, groupRole, subjectType, conceptAnswer, concept, myGroups, groupPrivileges, groups, privilege, resetSync, subjectMigration, userSubjectAssignment, task, taskUnAssigment, subjectProgramEligibility, news, videoTelemetric, groupSubject, comment, commentThread, subjectEntityApprovalStatus, encounterEntityApprovalStatus, programEncounterEntityApprovalStatus, programEnrolmentEntityApprovalStatus, checklistItemEntityApprovalStatus, individualRelationship, checklistItem, checklist, encounter, identifierAssignment, programEncounter, programEnrolment, individual, extension, userInfo, syncTelemetry, ruleFailureTelemetry];
638
+ return [groupDashboard, approvalStatus, dashboardSectionCardMapping, dashboardSection, dashboardFilter, dashboard, reportCard, standardReportCardType, menuItem, locationHierarchy, video, checklistItemDetail, checklistDetail, rule, ruleDependency, individualRelationshipType, individualRelationGenderMapping, individualRelation, programConfig, formMapping, formElement, formElementGroup, form, documentationItem, documentation, identifierSource, organisationConfig, platformTranslation, translation, locationMapping, addressLevel, taskStatus, taskType, encounterType, program, programOutcome, gender, groupRole, subjectType, conceptAnswer, concept, myGroups, groupPrivileges, groups, privilege, resetSync, subjectMigration, userSubjectAssignment, task, taskUnAssigment, subjectProgramEligibility, news, videoTelemetric, groupSubject, comment, commentThread, entityApprovalStatus, subjectEntityApprovalStatus, encounterEntityApprovalStatus, programEncounterEntityApprovalStatus, programEnrolmentEntityApprovalStatus, checklistItemEntityApprovalStatus, individualRelationship, checklistItem, checklist, encounter, identifierAssignment, programEncounter, programEnrolment, individual, extension, userInfo, syncTelemetry, ruleFailureTelemetry];
649
639
  }
650
640
 
651
641
  static entitiesLoadedFromServer() {
@@ -657,8 +647,11 @@ class EntityMetaData {
657
647
  }
658
648
 
659
649
  static findByNameIn(entityName, modelCollection) {
660
- return _lodash.default.find(modelCollection, //TODO check if this works
661
- entityMetadata => entityMetadata.entityName === entityName);
650
+ return _lodash.default.find(modelCollection, entityMetadata => entityMetadata.entityName === entityName);
651
+ }
652
+
653
+ static getEntitiesToBePulled() {
654
+ return _lodash.default.filter(EntityMetaData.model(), entityMetadata => entityMetadata.syncPullRequired);
662
655
  }
663
656
 
664
657
  static allModels() {
@@ -51,6 +51,8 @@ var _ArrayHelper = _interopRequireDefault(require("./framework/ArrayHelper"));
51
51
 
52
52
  var _MergeUtil = _interopRequireDefault(require("./utility/MergeUtil"));
53
53
 
54
+ var _AgeUtil = _interopRequireDefault(require("./utility/AgeUtil"));
55
+
54
56
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
55
57
 
56
58
  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; }
@@ -403,23 +405,21 @@ class Individual extends _BaseEntity.default {
403
405
  this.name = this.nameString;
404
406
  }
405
407
 
406
- getDisplayAge(i18n) {
407
- //Keeping date of birth to be always entered and displayed as per the current date. It would be perhaps more error prone for users to put themselves in the past and enter age as of that date
408
- const ageInYears = this.getAgeInYears();
408
+ getAgeAndDateOfBirthDisplay(i18n) {
409
+ if (this.dateOfBirthVerified) return `${_AgeUtil.default.getDisplayAge(this.dateOfBirth, i18n)} (${_General.default.toDisplayDate(this.dateOfBirth)})`;
410
+ return _AgeUtil.default.getDisplayAge(this.dateOfBirth, i18n);
411
+ }
409
412
 
410
- if (ageInYears < 1) {
411
- let ageInWeeks = (0, _moment.default)().diff(this.dateOfBirth, "weeks");
412
- return ageInWeeks === 0 ? _Duration.default.inDay((0, _moment.default)().diff(this.dateOfBirth, "days")).toString(i18n) : _Duration.default.inWeek(ageInWeeks).toString(i18n);
413
- } else if (ageInYears < 2) {
414
- return _Duration.default.inMonth((0, _moment.default)().diff(this.dateOfBirth, "months")).toString(i18n);
415
- } else {
416
- return _Duration.default.inYear(ageInYears).toString(i18n);
417
- }
413
+ getAgeInYears(asOnDate = (0, _moment.default)(), precise = false) {
414
+ return _AgeUtil.default.getAgeInYears(this.dateOfBirth, asOnDate, precise);
418
415
  }
419
416
 
420
- getAgeAndDateOfBirthDisplay(i18n) {
421
- if (this.dateOfBirthVerified) return `${this.getDisplayAge(i18n)} (${_General.default.toDisplayDate(this.dateOfBirth)})`;
422
- return this.getDisplayAge(i18n);
417
+ getAgeInMonths(asOnDate = (0, _moment.default)(), precise = false) {
418
+ return _AgeUtil.default.getAgeInMonths(this.dateOfBirth, asOnDate, precise);
419
+ }
420
+
421
+ getAgeInWeeks(asOnDate = (0, _moment.default)(), precise = false) {
422
+ return _AgeUtil.default.getAgeInWeeks(this.dateOfBirth, asOnDate, precise);
423
423
  }
424
424
 
425
425
  getAge(asOnDate = (0, _moment.default)()) {
@@ -448,22 +448,6 @@ class Individual extends _BaseEntity.default {
448
448
  }
449
449
  }
450
450
 
451
- getAgeIn(unit) {
452
- return (asOnDate = (0, _moment.default)(), precise = false) => (0, _moment.default)(asOnDate).diff(this.dateOfBirth, unit, precise);
453
- }
454
-
455
- getAgeInMonths(asOnDate = (0, _moment.default)(), precise = false) {
456
- return this.getAgeIn("months")(asOnDate, precise);
457
- }
458
-
459
- getAgeInWeeks(asOnDate, precise) {
460
- return this.getAgeIn("weeks")(asOnDate, precise);
461
- }
462
-
463
- getAgeInYears(asOnDate = (0, _moment.default)(), precise = false) {
464
- return this.getAgeIn("years")(asOnDate, precise);
465
- }
466
-
467
451
  toSummaryString() {
468
452
  return `${this.name}, Age: ${this.getAge().toString()}, ${this.gender.name}`;
469
453
  }
@@ -818,7 +802,15 @@ class Individual extends _BaseEntity.default {
818
802
  }
819
803
 
820
804
  userProfileSubtext2(i18n) {
821
- return this.isPerson() ? this.getDisplayAge(i18n) : "";
805
+ return this.isPerson() ? _AgeUtil.default.getDisplayAge(this.dateOfBirth, i18n) : "";
806
+ }
807
+
808
+ subjectAddressText(i18n) {
809
+ const parentAddress = _lodash.default.get(this, 'lowestAddressLevel.locationMappings[0].parent.name');
810
+
811
+ let addressText = i18n.t(this.lowestAddressLevel.name);
812
+ if (!_lodash.default.isNil(parentAddress)) addressText += ', ' + i18n.t(parentAddress);
813
+ return addressText;
822
814
  }
823
815
 
824
816
  subjectAddressText(i18n) {
@@ -833,7 +825,7 @@ class Individual extends _BaseEntity.default {
833
825
  detail1(i18n) {
834
826
  return this.isPerson() ? {
835
827
  label: "Age",
836
- value: this.getDisplayAge(i18n)
828
+ value: _AgeUtil.default.getDisplayAge(this.dateOfBirth, i18n)
837
829
  } : {};
838
830
  }
839
831
 
package/dist/Privilege.js CHANGED
@@ -89,6 +89,37 @@ _defineProperty(Privilege, "privilegeName", {
89
89
  approveChecklistItem: "Approve ChecklistItem"
90
90
  });
91
91
 
92
+ _defineProperty(Privilege, "PrivilegeType", {
93
+ ViewSubject: "ViewSubject",
94
+ RegisterSubject: "RegisterSubject",
95
+ EditSubject: "EditSubject",
96
+ VoidSubject: "VoidSubject",
97
+ EnrolSubject: "EnrolSubject",
98
+ ViewEnrolmentDetails: "ViewEnrolmentDetails",
99
+ EditEnrolmentDetails: "EditEnrolmentDetails",
100
+ ExitEnrolment: "ExitEnrolment",
101
+ ViewVisit: "ViewVisit",
102
+ ScheduleVisit: "ScheduleVisit",
103
+ PerformVisit: "PerformVisit",
104
+ EditVisit: "EditVisit",
105
+ CancelVisit: "CancelVisit",
106
+ VoidVisit: "VoidVisit",
107
+ ViewChecklist: "ViewChecklist",
108
+ EditChecklist: "EditChecklist",
109
+ AddMember: "AddMember",
110
+ EditMember: "EditMember",
111
+ RemoveMember: "RemoveMember",
112
+ ApproveSubject: "ApproveSubject",
113
+ RejectSubject: "RejectSubject",
114
+ ApproveEnrolment: "ApproveEnrolment",
115
+ RejectEnrolment: "RejectEnrolment",
116
+ ApproveEncounter: "ApproveEncounter",
117
+ RejectEncounter: "RejectEncounter",
118
+ ApproveChecklistitem: "ApproveChecklistitem",
119
+ RejectChecklistitem: "RejectChecklistitem",
120
+ UploadMetadataAndData: "UploadMetadataAndData"
121
+ });
122
+
92
123
  _defineProperty(Privilege, "privilegeEntityType", {
93
124
  subject: "Subject",
94
125
  enrolment: "Enrolment",
package/dist/Schema.js CHANGED
@@ -200,7 +200,7 @@ const entities = [_DashboardFilter.default, _LocaleMapping.default, _Settings.de
200
200
  function createRealmConfig() {
201
201
  return {
202
202
  //order is important, should be arranged according to the dependency
203
- schemaVersion: 177,
203
+ schemaVersion: 178,
204
204
  migration: function (oldDB, newDB) {
205
205
  console.log("[AvniModels.Schema]", `Running migration with old schema version: ${oldDB.schemaVersion} and new schema version: ${newDB.schemaVersion}`);
206
206
 
@@ -761,6 +761,12 @@ function createRealmConfig() {
761
761
  }
762
762
  });
763
763
  }
764
+
765
+ if (oldDB.schemaVersion < 178) {
766
+ const pushOnlyEntities = oldDB.objects(_EntitySyncStatus.default.schema.name).filtered("entityName = 'EntityApprovalStatus' OR entityName = 'SyncTelemetry' OR entityName = 'VideoTelemetric' OR entityName = 'RuleFailureTelemetry'");
767
+
768
+ _lodash.default.forEach(pushOnlyEntities, pushOnlyEntity => newDB.delete(pushOnlyEntity));
769
+ }
764
770
  }
765
771
  };
766
772
  }
package/dist/index.js CHANGED
@@ -801,6 +801,12 @@ Object.defineProperty(exports, "CustomDashboardCache", {
801
801
  return _CustomDashboardCache.default;
802
802
  }
803
803
  });
804
+ Object.defineProperty(exports, "AgeUtil", {
805
+ enumerable: true,
806
+ get: function () {
807
+ return _AgeUtil.default;
808
+ }
809
+ });
804
810
 
805
811
  var _AbstractEncounter = _interopRequireDefault(require("./AbstractEncounter"));
806
812
 
@@ -1060,6 +1066,8 @@ var _DateTimeUtil = _interopRequireDefault(require("./utility/DateTimeUtil"));
1060
1066
 
1061
1067
  var _CustomDashboardCache = _interopRequireDefault(require("./CustomDashboardCache"));
1062
1068
 
1069
+ var _AgeUtil = _interopRequireDefault(require("./utility/AgeUtil"));
1070
+
1063
1071
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
1064
1072
 
1065
1073
  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; }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _Duration = _interopRequireDefault(require("../Duration"));
9
+
10
+ var _moment = _interopRequireDefault(require("moment"));
11
+
12
+ var _lodash = _interopRequireDefault(require("lodash"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ class AgeUtil {
17
+ static getDisplayAge(dateOfBirth, i18n) {
18
+ //Keeping date of birth to be always entered and displayed as per the current date. It would be perhaps more error prone for users to put themselves in the past and enter age as of that date
19
+ const ageInYears = this.getAgeInYears(dateOfBirth);
20
+
21
+ if (ageInYears < 1) {
22
+ let ageInWeeks = this.getAgeInWeeks(dateOfBirth);
23
+ return ageInWeeks === 0 ? _Duration.default.inDay((0, _moment.default)().diff(dateOfBirth, "days")).toString(i18n) : _Duration.default.inWeek(ageInWeeks).toString(i18n);
24
+ } else if (ageInYears < 2) {
25
+ return _Duration.default.inMonth(this.getAgeInMonths(dateOfBirth)).toString(i18n);
26
+ } else if (ageInYears < 6) {
27
+ let ageInMonths = this.getAgeInMonths(dateOfBirth);
28
+
29
+ let noOfYears = _lodash.default.toInteger(ageInMonths / 12);
30
+
31
+ let noOfMonths = ageInMonths % 12;
32
+ let durationInYears = `${_Duration.default.inYear(noOfYears).toString(i18n)}`;
33
+ if (noOfMonths > 0) return `${durationInYears} ${_Duration.default.inMonth(noOfMonths).toString(i18n)}`;
34
+ return durationInYears;
35
+ } else {
36
+ return _Duration.default.inYear(ageInYears).toString(i18n);
37
+ }
38
+ }
39
+
40
+ static getAgeInYears(dateOfBirth, asOnDate = (0, _moment.default)(), precise = false) {
41
+ return this.getAgeIn(dateOfBirth, "years")(asOnDate, precise);
42
+ }
43
+
44
+ static getAgeInMonths(dateOfBirth, asOnDate = (0, _moment.default)(), precise = false) {
45
+ return this.getAgeIn(dateOfBirth, "months")(asOnDate, precise);
46
+ }
47
+
48
+ static getAgeInWeeks(dateOfBirth, asOnDate, precise) {
49
+ return this.getAgeIn(dateOfBirth, "weeks")(asOnDate, precise);
50
+ }
51
+
52
+ static getAgeIn(dateOfBirth, unit) {
53
+ return (asOnDate = (0, _moment.default)(), precise = false) => (0, _moment.default)(asOnDate).diff(dateOfBirth, unit, precise);
54
+ }
55
+
56
+ }
57
+
58
+ var _default = AgeUtil;
59
+ exports.default = _default;
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.30.34",
4
+ "version": "1.30.37",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",