openchs-models 1.32.0 → 1.32.2

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.
@@ -7,6 +7,16 @@ exports.default = void 0;
7
7
 
8
8
  var _BaseEntity = _interopRequireDefault(require("./BaseEntity"));
9
9
 
10
+ var _Dashboard = _interopRequireDefault(require("./Dashboard"));
11
+
12
+ var _General = _interopRequireDefault(require("./utility/General"));
13
+
14
+ var _ReportCardResult = _interopRequireDefault(require("./reports/ReportCardResult"));
15
+
16
+ var _NestedReportCardResult = _interopRequireDefault(require("./reports/NestedReportCardResult"));
17
+
18
+ var _lodash = _interopRequireDefault(require("lodash"));
19
+
10
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
21
 
12
22
  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; }
@@ -16,14 +26,6 @@ class CustomDashboardCache extends _BaseEntity.default {
16
26
  super(that);
17
27
  }
18
28
 
19
- get checksum() {
20
- return this.that.checksum;
21
- }
22
-
23
- set checksum(x) {
24
- this.that.checksum = x;
25
- }
26
-
27
29
  get updatedAt() {
28
30
  return this.that.updatedAt;
29
31
  }
@@ -48,84 +50,102 @@ class CustomDashboardCache extends _BaseEntity.default {
48
50
  this.that.filterApplied = x;
49
51
  }
50
52
 
51
- get filterErrorsJSON() {
52
- return this.that.filterErrorsJSON;
53
+ get dashboard() {
54
+ return this.toEntity("dashboard", _Dashboard.default);
55
+ }
56
+
57
+ set dashboard(x) {
58
+ this.that.dashboard = this.fromObject(x);
53
59
  }
54
60
 
55
- set filterErrorsJSON(x) {
56
- this.that.filterErrorsJSON = x;
61
+ get dashboardFiltersHash() {
62
+ return this.that.dashboardFiltersHash;
57
63
  }
58
64
 
59
- get ruleInputJSON() {
60
- return this.that.ruleInputJSON;
65
+ set dashboardFiltersHash(x) {
66
+ this.that.dashboardFiltersHash = x;
61
67
  }
62
68
 
63
- set ruleInputJSON(x) {
64
- this.that.ruleInputJSON = x;
69
+ get reportCardResults() {
70
+ return this.toEntityList("reportCardResults", _ReportCardResult.default);
65
71
  }
66
72
 
67
- get transformedFiltersJSON() {
68
- return this.that.transformedFiltersJSON;
73
+ set reportCardResults(x) {
74
+ this.that.reportCardResults = this.fromEntityList(x);
69
75
  }
70
76
 
71
- set transformedFiltersJSON(x) {
72
- this.that.transformedFiltersJSON = x;
77
+ get nestedReportCardResults() {
78
+ return this.toEntityList("nestedReportCardResults", _NestedReportCardResult.default);
73
79
  }
74
80
 
75
- static create(uuid, checksum, updatedAt, selectedValuesJSON, filterApplied, filterErrorsJSON, ruleInputJSON, transformedFiltersJSON) {
81
+ set nestedReportCardResults(x) {
82
+ this.that.nestedReportCardResults = this.fromEntityList(x);
83
+ }
84
+
85
+ static newInstance(dashboard, dashboardFiltersHash) {
76
86
  const customDashboardCache = new CustomDashboardCache();
77
- customDashboardCache.uuid = uuid;
78
- customDashboardCache.checksum = checksum;
79
- customDashboardCache.updatedAt = updatedAt;
80
- customDashboardCache.selectedValuesJSON = selectedValuesJSON;
81
- customDashboardCache.filterApplied = filterApplied;
82
- customDashboardCache.filterErrorsJSON = filterErrorsJSON;
83
- customDashboardCache.ruleInputJSON = ruleInputJSON;
84
- customDashboardCache.transformedFiltersJSON = transformedFiltersJSON;
87
+ customDashboardCache.uuid = _General.default.randomUUID();
88
+ customDashboardCache.dashboard = dashboard;
89
+ customDashboardCache.reset(dashboardFiltersHash);
85
90
  return customDashboardCache;
86
91
  }
87
92
 
88
- static getSelectedValuesFromState(state) {
89
- const filterCache = {
90
- date: state.date,
91
- applied: false,
92
- selectedLocations: state.selectedLocations,
93
- selectedCustomFilters: state.selectedCustomFilters,
94
- selectedGenders: state.selectedGenders
95
- };
96
- return filterCache;
93
+ reset(dashboardFiltersHash) {
94
+ this.filterApplied = false;
95
+ this.selectedValuesJSON = JSON.stringify({});
96
+ this.dashboardFiltersHash = dashboardFiltersHash;
97
+ this.updatedAt = null;
98
+ this.reportCardResults = [];
99
+ this.nestedReportCardResults = [];
97
100
  }
98
101
 
99
- static createEmptyInstance() {
100
- return new CustomDashboardCache();
102
+ getSelectedValues() {
103
+ return JSON.parse(this.selectedValuesJSON);
101
104
  }
102
105
 
103
- getChecksum() {
104
- return this.checksum;
106
+ getReportCardResult(reportCard) {
107
+ const result = this.reportCardResults.find(reportCardResult => reportCardResult.reportCard === reportCard.uuid && reportCardResult.dashboard === this.dashboard.uuid);
108
+
109
+ if (_lodash.default.isNil(result)) {
110
+ return result;
111
+ } else {
112
+ result.clickable = true;
113
+ result.hasErrorMsg = false;
114
+ return result;
115
+ }
105
116
  }
106
117
 
107
- getSelectedValues() {
108
- return this.selectedValuesJSON && JSON.parse(this.selectedValuesJSON) || {};
118
+ getNestedReportCardResults(reportCard) {
119
+ return this.nestedReportCardResults.filter(nestedReportCardResult => nestedReportCardResult.reportCard === reportCard.uuid && nestedReportCardResult.dashboard === this.dashboard.uuid).map(x => {
120
+ x.clickable = true;
121
+ x.hasErrorMsg = false;
122
+ return x;
123
+ });
109
124
  }
110
125
 
111
- getFilterErrors() {
112
- return this.filterErrorsJSON && JSON.parse(this.filterErrorsJSON) || {};
126
+ clone() {
127
+ const customDashboardCache = new CustomDashboardCache();
128
+ customDashboardCache.uuid = this.uuid;
129
+ customDashboardCache.dashboard = this.dashboard;
130
+ customDashboardCache.updatedAt = this.updatedAt;
131
+ customDashboardCache.selectedValuesJSON = this.selectedValuesJSON;
132
+ customDashboardCache.filterApplied = this.filterApplied;
133
+ customDashboardCache.dashboardFiltersHash = this.dashboardFiltersHash;
134
+ customDashboardCache.reportCardResults = this.reportCardResults;
135
+ customDashboardCache.nestedReportCardResults = this.nestedReportCardResults;
136
+ return customDashboardCache;
113
137
  }
114
138
 
115
- getRuleInput() {
116
- return this.ruleInputJSON && JSON.parse(this.ruleInputJSON) || {
117
- ruleInputArray: null
118
- };
139
+ matchNestedReportCardResult(nestedReportCardResult) {
140
+ return this.nestedReportCardResults.find(x => x.reportCard === nestedReportCardResult.reportCard && x.itemKey === nestedReportCardResult.itemKey && x.dashboard === this.dashboard.uuid);
119
141
  }
120
142
 
121
- getTransformedFilters() {
122
- return this.transformedFiltersJSON && JSON.parse(this.transformedFiltersJSON) || {
123
- date: new Date(),
124
- applied: false,
125
- selectedLocations: [],
126
- selectedCustomFilters: [],
127
- selectedGenders: []
128
- };
143
+ matchReportCardResult(reportCardResult) {
144
+ return this.reportCardResults.find(x => x.reportCard === reportCardResult.reportCard && x.dashboard === this.dashboard.uuid);
145
+ }
146
+
147
+ isCachePopulated() {
148
+ return _lodash.default.isNil(this.updatedAt);
129
149
  }
130
150
 
131
151
  }
@@ -135,16 +155,22 @@ _defineProperty(CustomDashboardCache, "schema", {
135
155
  primaryKey: "uuid",
136
156
  properties: {
137
157
  uuid: "string",
138
- checksum: "string",
139
- updatedAt: "date",
158
+ dashboard: "Dashboard",
159
+ updatedAt: {
160
+ type: "date",
161
+ optional: true
162
+ },
140
163
  selectedValuesJSON: "string",
141
- filterApplied: {
142
- type: "bool",
143
- default: false
164
+ filterApplied: "bool",
165
+ dashboardFiltersHash: "string",
166
+ reportCardResults: {
167
+ type: "list",
168
+ objectType: "ReportCardResult"
144
169
  },
145
- filterErrorsJSON: "string",
146
- ruleInputJSON: "string",
147
- transformedFiltersJSON: "string"
170
+ nestedReportCardResults: {
171
+ type: "list",
172
+ objectType: "NestedReportCardResult"
173
+ }
148
174
  }
149
175
  });
150
176
 
@@ -41,7 +41,9 @@ _defineProperty(CustomFilter, "type", {
41
41
  EncounterDate: "EncounterDate",
42
42
  Address: "Address",
43
43
  Concept: "Concept",
44
- GroupSubject: "GroupSubject"
44
+ GroupSubject: "GroupSubject",
45
+ SubjectType: "SubjectType",
46
+ AsOnDate: "AsOnDate"
45
47
  });
46
48
 
47
49
  _defineProperty(CustomFilter, "scope", {
package/dist/Dashboard.js CHANGED
@@ -36,6 +36,14 @@ class Dashboard extends _BaseEntity.default {
36
36
  this.that.description = x;
37
37
  }
38
38
 
39
+ get filters() {
40
+ return this.toEntityList("filters", _DashboardFilter.default);
41
+ }
42
+
43
+ set filters(x) {
44
+ this.that.filters = this.fromEntityList(x);
45
+ }
46
+
39
47
  static fromResource(resource) {
40
48
  return _General.default.assignFields(resource, new Dashboard(), ["uuid", "name", "description", "voided"]);
41
49
  }
@@ -48,6 +56,14 @@ class Dashboard extends _BaseEntity.default {
48
56
  return dashboard;
49
57
  }
50
58
 
59
+ getFilterOfType(filterType) {
60
+ return this.filters.find(filter => filter.filterConfig.type === filterType);
61
+ }
62
+
63
+ getFilter(filterUUID) {
64
+ return this.filters.find(filter => filter.uuid === filterUUID);
65
+ }
66
+
51
67
  }
52
68
 
53
69
  _defineProperty(Dashboard, "schema", {
package/dist/Duration.js CHANGED
@@ -9,13 +9,16 @@ var _lodash = _interopRequireDefault(require("lodash"));
9
9
 
10
10
  var _moment = _interopRequireDefault(require("moment"));
11
11
 
12
- var _SingleCodedValue = _interopRequireDefault(require("./observation/SingleCodedValue"));
13
-
14
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
13
 
16
14
  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; }
17
15
 
18
16
  class Duration {
17
+ constructor(durationValue, durationUnit) {
18
+ this._durationValue = durationValue;
19
+ this.durationUnit = durationUnit;
20
+ }
21
+
19
22
  static inDay(value) {
20
23
  return new Duration(value, Duration.Day);
21
24
  }
@@ -42,11 +45,6 @@ class Duration {
42
45
  }
43
46
  }
44
47
 
45
- constructor(durationValue, durationUnit) {
46
- this._durationValue = durationValue;
47
- this.durationUnit = durationUnit;
48
- }
49
-
50
48
  get isInYears() {
51
49
  return this.durationUnit === Duration.Year;
52
50
  }
@@ -15,15 +15,29 @@ var _StandardReportCardType = _interopRequireDefault(require("./StandardReportCa
15
15
 
16
16
  var _lodash = _interopRequireDefault(require("lodash"));
17
17
 
18
+ var _SubjectType = _interopRequireDefault(require("./SubjectType"));
19
+
20
+ var _Program = _interopRequireDefault(require("./Program"));
21
+
22
+ var _EncounterType = _interopRequireDefault(require("./EncounterType"));
23
+
24
+ var _Duration = _interopRequireDefault(require("./Duration"));
25
+
26
+ var _NestedReportCardResult = _interopRequireDefault(require("./reports/NestedReportCardResult"));
27
+
18
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
29
 
20
30
  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; }
21
31
 
22
- function throwInvalidIndexError(index, reportCardsLength) {
23
- throw new Error(`Invalid index ${index} specified for reportCard with length ${reportCardsLength}`);
24
- }
25
-
26
32
  class ReportCard extends _BaseEntity.default {
33
+ static newReportCard() {
34
+ const reportCard = new ReportCard();
35
+ reportCard.standardReportCardInputSubjectTypes = [];
36
+ reportCard.standardReportCardInputPrograms = [];
37
+ reportCard.standardReportCardInputEncounterTypes = [];
38
+ return reportCard;
39
+ }
40
+
27
41
  constructor(that = null) {
28
42
  super(that);
29
43
  }
@@ -96,6 +110,39 @@ class ReportCard extends _BaseEntity.default {
96
110
  get textColor() {
97
111
  return _lodash.default.isNil(this.standardReportCardType) ? '#ffffff' : this.standardReportCardType.textColor;
98
112
  }
113
+
114
+ get standardReportCardInputSubjectTypes() {
115
+ return this.toEntityList("standardReportCardInputSubjectTypes", _SubjectType.default);
116
+ }
117
+
118
+ set standardReportCardInputSubjectTypes(x) {
119
+ this.that.standardReportCardInputSubjectTypes = this.fromEntityList(x);
120
+ }
121
+
122
+ get standardReportCardInputPrograms() {
123
+ return this.toEntityList("standardReportCardInputPrograms", _Program.default);
124
+ }
125
+
126
+ set standardReportCardInputPrograms(x) {
127
+ this.that.standardReportCardInputPrograms = this.fromEntityList(x);
128
+ }
129
+
130
+ get standardReportCardInputEncounterTypes() {
131
+ return this.toEntityList("standardReportCardInputEncounterTypes", _EncounterType.default);
132
+ }
133
+
134
+ set standardReportCardInputEncounterTypes(x) {
135
+ this.that.standardReportCardInputEncounterTypes = this.fromEntityList(x);
136
+ }
137
+
138
+ getStandardReportCardInputRecentDuration() {
139
+ const duration = JSON.parse(this.that.standardReportCardInputRecentDurationJSON);
140
+ return new _Duration.default(duration.value, duration.unit);
141
+ }
142
+
143
+ setStandardReportCardInputRecentDurationJSON(x) {
144
+ this.that.standardReportCardInputRecentDurationJSON = x;
145
+ }
99
146
  /**
100
147
  * Helper method used to generate unique key value for Nested Report Cards using UUID and Index of the Report Card.
101
148
  * The Nested Report Card's query responses would be mapped to the corresponding Dashboard Report cards using the UUID and Index.
@@ -122,9 +169,19 @@ class ReportCard extends _BaseEntity.default {
122
169
  }
123
170
 
124
171
  static fromResource(resource, entityService) {
125
- const reportCard = _General.default.assignFields(resource, new ReportCard(), ["uuid", "name", "query", "description", "colour", "voided", "nested", "countOfCards"]);
172
+ const reportCard = _General.default.assignFields(resource, ReportCard.newReportCard(), ["uuid", "name", "query", "description", "colour", "voided", "nested", "countOfCards"]);
126
173
 
127
174
  reportCard.standardReportCardType = entityService.findByKey("uuid", _ResourceUtil.default.getUUIDFor(resource, "standardReportCardUUID"), _StandardReportCardType.default.schema.name);
175
+ resource.standardReportCardInputSubjectTypes.forEach(uuid => {
176
+ reportCard.standardReportCardInputSubjectTypes.push(entityService.findByUUID(uuid, _SubjectType.default.schema.name));
177
+ });
178
+ resource.standardReportCardInputPrograms.forEach(uuid => {
179
+ reportCard.standardReportCardInputPrograms.push(entityService.findByUUID(uuid, _Program.default.schema.name));
180
+ });
181
+ resource.standardReportCardInputEncounterTypes.forEach(uuid => {
182
+ reportCard.standardReportCardInputEncounterTypes.push(entityService.findByUUID(uuid, _EncounterType.default.schema.name));
183
+ });
184
+ reportCard.setStandardReportCardInputRecentDurationJSON(resource.standardReportCardInputRecentDuration);
128
185
  return reportCard;
129
186
  }
130
187
 
@@ -132,6 +189,42 @@ class ReportCard extends _BaseEntity.default {
132
189
  return _lodash.default.isNil(this.standardReportCardType) ? false : this.standardReportCardType.isTaskType();
133
190
  }
134
191
 
192
+ isStandardReportType() {
193
+ return !_lodash.default.isNil(this.standardReportCardType);
194
+ }
195
+
196
+ isSubjectTypeFilterSupported() {
197
+ return this.isStandardReportType() && this.standardReportCardType.isSubjectTypeFilterSupported();
198
+ }
199
+
200
+ isRecentType() {
201
+ return this.isStandardReportType() && this.standardReportCardType.isRecentType();
202
+ }
203
+
204
+ hasInputForSubject() {
205
+ return this.standardReportCardInputSubjectTypes.length > 0;
206
+ }
207
+
208
+ hasInputForEnrolment() {
209
+ return this.standardReportCardInputPrograms.length > 0;
210
+ }
211
+
212
+ hasInputForProgramEncounter() {
213
+ return this.hasInputForEnrolment() && this.standardReportCardInputEncounterTypes.length > 0;
214
+ }
215
+
216
+ hasInputForGeneralEncounter() {
217
+ return this.standardReportCardInputEncounterTypes.length > 0;
218
+ }
219
+
220
+ createNestedErrorResults(primaryValue, secondaryValue) {
221
+ const reportCard = this;
222
+ return Array(this.card.countOfCards).map(index => {
223
+ const itemKey = reportCard.getCardId(index);
224
+ return _NestedReportCardResult.default.create(primaryValue, secondaryValue, false, true, itemKey);
225
+ });
226
+ }
227
+
135
228
  }
136
229
 
137
230
  _defineProperty(ReportCard, "schema", {
@@ -166,8 +259,24 @@ _defineProperty(ReportCard, "schema", {
166
259
  type: "int",
167
260
  default: 1,
168
261
  optional: true
169
- } //Used only by nested ReportCards
170
-
262
+ },
263
+ //Used only by nested ReportCards
264
+ standardReportCardInputSubjectTypes: {
265
+ type: "list",
266
+ objectType: "SubjectType"
267
+ },
268
+ standardReportCardInputPrograms: {
269
+ type: "list",
270
+ objectType: "Program"
271
+ },
272
+ standardReportCardInputEncounterTypes: {
273
+ type: "list",
274
+ objectType: "EncounterType"
275
+ },
276
+ standardReportCardInputRecentDurationJSON: {
277
+ type: "string",
278
+ optional: true
279
+ }
171
280
  }
172
281
  });
173
282
 
package/dist/Schema.js CHANGED
@@ -183,13 +183,17 @@ var _MigrationsHelper = _interopRequireDefault(require("./MigrationsHelper"));
183
183
 
184
184
  var _MetaDataService = _interopRequireDefault(require("./service/MetaDataService"));
185
185
 
186
+ var _ReportCardResult = _interopRequireDefault(require("./reports/ReportCardResult"));
187
+
188
+ var _NestedReportCardResult = _interopRequireDefault(require("./reports/NestedReportCardResult"));
189
+
186
190
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
187
191
 
188
192
  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; }
189
193
 
190
194
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
191
195
 
192
- const entities = [_DashboardFilter.default, _LocaleMapping.default, _Settings.default, _ConceptAnswer.default, _Concept.default, _EncounterType.default, _Gender.default, _AddressLevel.LocationMapping, _AddressLevel.default, _KeyValue.default, _Form.default, _FormMapping.default, _FormElementGroup.default, _FormElement.default, _SubjectType.default, _Individual.default, _Program.default, _ProgramEnrolment.default, _Observation.default, _ProgramEncounter.default, _Encounter.default, _EntitySyncStatus.default, _EntityQueue.default, _Checklist.default, _ChecklistItem.default, _Format.default, _UserInfo.default, _StringKeyNumericValue.default, _Family.default, _IndividualRelation.default, _IndividualRelationGenderMapping.default, _IndividualRelationshipType.default, _IndividualRelationship.default, _RuleDependency.default, _Rule.default, _ChecklistItemStatus.default, _ChecklistDetail.default, _ChecklistItemDetail.default, _VideoTelemetric.default, _Video.default, _MediaQueue.default, _Point.default, _SyncTelemetry.default, _IdentifierSource.default, _IdentifierAssignment.default, _RuleFailureTelemetry.default, _BeneficiaryModePin.default, _OrganisationConfig.default, _PlatformTranslation.default, _Translation.default, _Groups.default, _MyGroups.default, _GroupPrivileges.default, _Privilege.default, _GroupRole.default, _GroupSubject.default, _DashboardCache.default, _CustomDashboardCache.default, _LocationHierarchy.default, _ReportCard.default, _Dashboard.default, _DashboardSectionCardMapping.default, _DraftSubject.default, _StandardReportCardType.default, _ApprovalStatus.default, _EntityApprovalStatus.default, _GroupDashboard.default, _DashboardSection.default, _News.default, _Comment.default, _CommentThread.default, _Extension.default, _SubjectMigration.default, _ResetSync.default, _Documentation.default, _DocumentationItem.default, _TaskType.default, _TaskStatus.default, _Task.default, _TaskUnAssignment.default, _DraftEncounter.default, _SubjectProgramEligibility.default, _MenuItem.default, _UserSubjectAssignment.default];
196
+ const entities = [_ReportCardResult.default, _NestedReportCardResult.default, _DashboardFilter.default, _LocaleMapping.default, _Settings.default, _ConceptAnswer.default, _Concept.default, _EncounterType.default, _Gender.default, _AddressLevel.LocationMapping, _AddressLevel.default, _KeyValue.default, _Form.default, _FormMapping.default, _FormElementGroup.default, _FormElement.default, _SubjectType.default, _Individual.default, _Program.default, _ProgramEnrolment.default, _Observation.default, _ProgramEncounter.default, _Encounter.default, _EntitySyncStatus.default, _EntityQueue.default, _Checklist.default, _ChecklistItem.default, _Format.default, _UserInfo.default, _StringKeyNumericValue.default, _Family.default, _IndividualRelation.default, _IndividualRelationGenderMapping.default, _IndividualRelationshipType.default, _IndividualRelationship.default, _RuleDependency.default, _Rule.default, _ChecklistItemStatus.default, _ChecklistDetail.default, _ChecklistItemDetail.default, _VideoTelemetric.default, _Video.default, _MediaQueue.default, _Point.default, _SyncTelemetry.default, _IdentifierSource.default, _IdentifierAssignment.default, _RuleFailureTelemetry.default, _BeneficiaryModePin.default, _OrganisationConfig.default, _PlatformTranslation.default, _Translation.default, _Groups.default, _MyGroups.default, _GroupPrivileges.default, _Privilege.default, _GroupRole.default, _GroupSubject.default, _DashboardCache.default, _CustomDashboardCache.default, _LocationHierarchy.default, _ReportCard.default, _Dashboard.default, _DashboardSectionCardMapping.default, _DraftSubject.default, _StandardReportCardType.default, _ApprovalStatus.default, _EntityApprovalStatus.default, _GroupDashboard.default, _DashboardSection.default, _News.default, _Comment.default, _CommentThread.default, _Extension.default, _SubjectMigration.default, _ResetSync.default, _Documentation.default, _DocumentationItem.default, _TaskType.default, _TaskStatus.default, _Task.default, _TaskUnAssignment.default, _DraftEncounter.default, _SubjectProgramEligibility.default, _MenuItem.default, _UserSubjectAssignment.default];
193
197
 
194
198
  function migrateObjectTypeFieldToEmbedded(newDB, oldDB, schemaName, field, creatorFn) {
195
199
  console.log(`schema: ${schemaName}, field: ${field}`);
@@ -279,7 +283,7 @@ function createRealmConfig() {
279
283
  return doCompact;
280
284
  },
281
285
  //order is important, should be arranged according to the dependency
282
- schemaVersion: 190,
286
+ schemaVersion: 196,
283
287
  onMigration: function (oldDB, newDB) {
284
288
  console.log("[AvniModels.Schema]", `Running migration with old schema version: ${oldDB.schemaVersion} and new schema version: ${newDB.schemaVersion}`);
285
289
  if (oldDB.schemaVersion === VersionWithEmbeddedMigrationProblem) throw new Error(`Update from schema version ${VersionWithEmbeddedMigrationProblem} is not allowed. Please uninstall and install app.`);
@@ -913,6 +917,10 @@ function createRealmConfig() {
913
917
  if (oldDB.schemaVersion < 190) {// PlaceHolder for SubjectType.User changes, so that people with previous version of client
914
918
  // are not able to use fastSync of version 190 and above
915
919
  }
920
+
921
+ if (oldDB.schemaVersion < 191) {
922
+ newDB.delete(newDB.objects("CustomDashboardCache"));
923
+ }
916
924
  }
917
925
  };
918
926
  }
@@ -15,6 +15,8 @@ var _ApprovalStatus = _interopRequireDefault(require("./ApprovalStatus"));
15
15
 
16
16
  var _lodash = _interopRequireDefault(require("lodash"));
17
17
 
18
+ var _Duration = _interopRequireDefault(require("./Duration"));
19
+
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
21
 
20
22
  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; }
@@ -81,7 +83,7 @@ class StandardReportCardType extends _BaseEntity.default {
81
83
  }
82
84
 
83
85
  defaultTypes() {
84
- return [StandardReportCardType.type.ScheduledVisits, StandardReportCardType.type.OverdueVisits, StandardReportCardType.type.LatestRegistrations, StandardReportCardType.type.LatestEnrolments, StandardReportCardType.type.LatestVisits, StandardReportCardType.type.Total];
86
+ return [StandardReportCardType.type.ScheduledVisits, StandardReportCardType.type.OverdueVisits, StandardReportCardType.type.RecentRegistrations, StandardReportCardType.type.RecentEnrolments, StandardReportCardType.type.RecentVisits, StandardReportCardType.type.Total];
85
87
  }
86
88
 
87
89
  isApprovalType() {
@@ -118,6 +120,14 @@ class StandardReportCardType extends _BaseEntity.default {
118
120
  return typeToStatusMap[this.name];
119
121
  }
120
122
 
123
+ isSubjectTypeFilterSupported() {
124
+ return [StandardReportCardType.type.ScheduledVisits, StandardReportCardType.type.OverdueVisits, StandardReportCardType.type.RecentRegistrations, StandardReportCardType.type.RecentEnrolments, StandardReportCardType.type.RecentVisits, StandardReportCardType.type.Total].includes(this.name);
125
+ }
126
+
127
+ isRecentType() {
128
+ return [StandardReportCardType.type.RecentRegistrations, StandardReportCardType.type.RecentEnrolments, StandardReportCardType.type.RecentVisits].includes(this.name);
129
+ }
130
+
121
131
  }
122
132
 
123
133
  _defineProperty(StandardReportCardType, "schema", {
@@ -143,9 +153,9 @@ _defineProperty(StandardReportCardType, "type", {
143
153
  Rejected: "Rejected",
144
154
  ScheduledVisits: "Scheduled visits",
145
155
  OverdueVisits: "Overdue visits",
146
- LatestRegistrations: "Last 24 hours registrations",
147
- LatestEnrolments: "Last 24 hours enrolments",
148
- LatestVisits: "Last 24 hours visits",
156
+ RecentRegistrations: "Recent registrations",
157
+ RecentEnrolments: "Recent enrolments",
158
+ RecentVisits: "Recent visits",
149
159
  Total: "Total",
150
160
  Comments: "Comments",
151
161
  CallTasks: "Call tasks",
@@ -153,6 +163,8 @@ _defineProperty(StandardReportCardType, "type", {
153
163
  DueChecklist: "Due checklist"
154
164
  });
155
165
 
166
+ _defineProperty(StandardReportCardType, "recentCardDurationUnits", [_Duration.default.Day, _Duration.default.Week, _Duration.default.Month]);
167
+
156
168
  const typeToStatusMap = {
157
169
  [StandardReportCardType.type.PendingApproval]: _ApprovalStatus.default.statuses.Pending,
158
170
  [StandardReportCardType.type.Approved]: _ApprovalStatus.default.statuses.Approved,
@@ -226,7 +226,11 @@ class FormElementGroup extends _BaseEntity.default {
226
226
  }
227
227
 
228
228
  nonVoidedFormElements() {
229
- return _lodash.default.filter(this.formElements, formElement => !formElement.voided);
229
+ return _lodash.default.filter(this.formElements, formElement => {
230
+ let parentFormElement;
231
+ if (!_lodash.default.isNil(formElement.groupUuid)) parentFormElement = _lodash.default.find(this.formElements, fe => fe.uuid === formElement.groupUuid);
232
+ return !formElement.voided && (_lodash.default.isNil(parentFormElement) || !parentFormElement.voided);
233
+ });
230
234
  }
231
235
 
232
236
  getFormElements() {
package/dist/index.js CHANGED
@@ -789,6 +789,30 @@ Object.defineProperty(exports, "JSONStringify", {
789
789
  return _JsonStringify.JSONStringify;
790
790
  }
791
791
  });
792
+ Object.defineProperty(exports, "Locations", {
793
+ enumerable: true,
794
+ get: function () {
795
+ return _Locations.default;
796
+ }
797
+ });
798
+ Object.defineProperty(exports, "Range", {
799
+ enumerable: true,
800
+ get: function () {
801
+ return _Range.default;
802
+ }
803
+ });
804
+ Object.defineProperty(exports, "ReportCardResult", {
805
+ enumerable: true,
806
+ get: function () {
807
+ return _ReportCardResult.default;
808
+ }
809
+ });
810
+ Object.defineProperty(exports, "NestedReportCardResult", {
811
+ enumerable: true,
812
+ get: function () {
813
+ return _NestedReportCardResult.default;
814
+ }
815
+ });
792
816
 
793
817
  var _AbstractEncounter = _interopRequireDefault(require("./AbstractEncounter"));
794
818
 
@@ -1042,6 +1066,14 @@ var _DashboardCacheFilter = _interopRequireDefault(require("./application/Dashbo
1042
1066
 
1043
1067
  var _JsonStringify = require("./utility/JsonStringify");
1044
1068
 
1069
+ var _Locations = _interopRequireDefault(require("./location/Locations"));
1070
+
1071
+ var _Range = _interopRequireDefault(require("./reports/Range"));
1072
+
1073
+ var _ReportCardResult = _interopRequireDefault(require("./reports/ReportCardResult"));
1074
+
1075
+ var _NestedReportCardResult = _interopRequireDefault(require("./reports/NestedReportCardResult"));
1076
+
1045
1077
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
1046
1078
 
1047
1079
  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,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _lodash = _interopRequireDefault(require("lodash"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ // AddressLevel = Location
13
+ class Locations {
14
+ static getUniqueLevels(locations) {
15
+ return _lodash.default.uniq(locations.map(x => x.level));
16
+ }
17
+
18
+ }
19
+
20
+ var _default = Locations;
21
+ exports.default = _default;
@@ -13,11 +13,23 @@ var _lodash = _interopRequireDefault(require("lodash"));
13
13
 
14
14
  var _DateTimeUtil = _interopRequireDefault(require("../utility/DateTimeUtil"));
15
15
 
16
+ var _Range = _interopRequireDefault(require("./Range"));
17
+
18
+ var _Gender = _interopRequireDefault(require("../Gender"));
19
+
20
+ var _AddressLevel = _interopRequireDefault(require("../AddressLevel"));
21
+
22
+ var _Individual = _interopRequireDefault(require("../Individual"));
23
+
16
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
25
 
18
26
  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; }
19
27
 
20
28
  const widgetConceptDataTypes = [_Concept.default.dataType.Date, _Concept.default.dataType.DateTime, _Concept.default.dataType.Time, _Concept.default.dataType.Numeric];
29
+ const conceptEntityTypes = {
30
+ [_Concept.default.dataType.Coded]: _Concept.default.schema.name,
31
+ [_Concept.default.dataType.Location]: _AddressLevel.default.schema.name
32
+ };
21
33
 
22
34
  class ObservationBasedFilter {
23
35
  constructor() {
@@ -42,6 +54,15 @@ class ObservationBasedFilter {
42
54
  return !_lodash.default.isNil(concept) && (!_lodash.default.isEmpty(programs) || !_lodash.default.isEmpty(encounterTypes) || this.scope === _CustomFilter.default.scope.Registration);
43
55
  }
44
56
 
57
+ isMultiEntityType() {
58
+ return [_Concept.default.dataType.Coded, _Concept.default.dataType.Location].includes(this.concept.datatype);
59
+ }
60
+
61
+ getEntityType() {
62
+ if (this.isMultiEntityType()) return conceptEntityTypes[this.concept.datatype];
63
+ throw new Error("Unsupported concept data type for getting entity type: " + this.concept.datatype);
64
+ }
65
+
45
66
  toServerRequest() {
46
67
  return {
47
68
  scope: this.scope,
@@ -107,10 +128,29 @@ class GroupSubjectTypeFilter {
107
128
  }
108
129
 
109
130
  exports.GroupSubjectTypeFilter = GroupSubjectTypeFilter;
110
- const dateFilterTypes = [_CustomFilter.default.type.RegistrationDate, _CustomFilter.default.type.EnrolmentDate, _CustomFilter.default.type.EncounterDate, _CustomFilter.default.type.ProgramEncounterDate];
131
+ const dateFilterTypes = [_CustomFilter.default.type.RegistrationDate, _CustomFilter.default.type.EnrolmentDate, _CustomFilter.default.type.EncounterDate, _CustomFilter.default.type.ProgramEncounterDate, _CustomFilter.default.type.AsOnDate];
132
+ const entityTypes = {
133
+ [_CustomFilter.default.type.Gender]: _Gender.default.schema.name,
134
+ [_CustomFilter.default.type.Address]: _AddressLevel.default.schema.name,
135
+ [_CustomFilter.default.type.GroupSubject]: _Individual.default.schema.name
136
+ };
137
+
138
+ function isDateDataType(dashboardFilterConfig) {
139
+ return dateFilterTypes.includes(dashboardFilterConfig.type) || dashboardFilterConfig.isConceptTypeFilter() && dashboardFilterConfig.observationBasedFilter.concept.datatype === _Concept.default.dataType.Date;
140
+ }
141
+
142
+ function isDateTimeDataType(dashboardFilterConfig) {
143
+ return dashboardFilterConfig.isConceptTypeFilter() && dashboardFilterConfig.observationBasedFilter.concept.datatype === _Concept.default.dataType.DateTime;
144
+ }
145
+
146
+ function isTimeDataType(dashboardFilterConfig) {
147
+ return dashboardFilterConfig.isConceptTypeFilter() && dashboardFilterConfig.observationBasedFilter.concept.datatype === _Concept.default.dataType.Time;
148
+ }
111
149
 
112
150
  class DashboardFilterConfig {
113
151
  constructor() {
152
+ _defineProperty(this, "subjectType", void 0);
153
+
114
154
  _defineProperty(this, "type", void 0);
115
155
 
116
156
  _defineProperty(this, "widget", void 0);
@@ -120,26 +160,108 @@ class DashboardFilterConfig {
120
160
  _defineProperty(this, "observationBasedFilter", void 0);
121
161
  }
122
162
 
163
+ toDisplayText() {
164
+ let s = `Type: ${this.type}.`;
165
+
166
+ if (this.isRangeWidget()) {
167
+ s += ` Widget: ${this.widget}.`;
168
+ }
169
+
170
+ if (this.isConceptTypeFilter()) {
171
+ s += ` Concept: ${this.observationBasedFilter.concept.name}. DataType: ${this.observationBasedFilter.concept.datatype}.`;
172
+ }
173
+
174
+ return s;
175
+ }
176
+
177
+ isRangeWidget() {
178
+ return this.widget === _CustomFilter.default.widget.Range;
179
+ }
180
+
123
181
  getInputDataType() {
124
182
  if (this.isConceptTypeFilter()) {
125
183
  return this.observationBasedFilter.concept.datatype;
126
- } else if (this.isGroupSubjectTypeFilter()) {
127
- return _Concept.default.dataType.Subject;
128
- } else if (dateFilterTypes.includes(this.type)) {
184
+ } else if ([_CustomFilter.default.type.Gender, _CustomFilter.default.type.Address, _CustomFilter.default.type.GroupSubject].includes(this.type)) {
185
+ return DashboardFilterConfig.dataTypes.array;
186
+ } else if (dateFilterTypes.includes(this.type) && !this.isRangeWidget()) {
129
187
  return _Concept.default.dataType.Date;
130
- } else {
131
- return this.type;
188
+ } else if (dateFilterTypes.includes(this.type) && this.isRangeWidget()) {
189
+ return _Range.default.DateRange;
190
+ } else if (this.type === _CustomFilter.default.type.SubjectType) {
191
+ return DashboardFilterConfig.dataTypes.formMetaData;
192
+ }
193
+
194
+ throw new Error("Unsupported filter type: " + this.type);
195
+ }
196
+
197
+ isDateFilterType() {
198
+ return isDateDataType(this) && !this.isRangeWidget();
199
+ }
200
+
201
+ isDateRangeFilterType() {
202
+ return isDateDataType(this) && this.isRangeWidget();
203
+ }
204
+
205
+ isDateTimeFilterType() {
206
+ return isDateTimeDataType(this) && !this.isRangeWidget();
207
+ }
208
+
209
+ isDateTimeRangeFilterType() {
210
+ return isDateTimeDataType(this) && this.isRangeWidget();
211
+ }
212
+
213
+ isTimeFilterType() {
214
+ return isTimeDataType(this) && !this.isRangeWidget();
215
+ }
216
+
217
+ isTimeRangeFilterType() {
218
+ return isTimeDataType(this) && this.isRangeWidget();
219
+ }
220
+
221
+ isNumericRangeFilterType() {
222
+ return this.isConceptTypeFilter() && this.observationBasedFilter.concept.datatype === _Concept.default.dataType.Numeric && this.isRangeWidget();
223
+ }
224
+
225
+ isDateLikeFilterType() {
226
+ return this.isDateFilterType() || this.isDateTimeFilterType() || this.isTimeFilterType();
227
+ }
228
+
229
+ isDateLikeRangeFilterType() {
230
+ return this.isDateRangeFilterType() || this.isDateTimeRangeFilterType() || this.isTimeRangeFilterType();
231
+ }
232
+
233
+ isMultiEntityType() {
234
+ return [_CustomFilter.default.type.Gender, _CustomFilter.default.type.Address, _CustomFilter.default.type.GroupSubject].includes(this.type) || this.isConceptTypeFilter() && this.observationBasedFilter.isMultiEntityType();
235
+ }
236
+
237
+ getEntityType() {
238
+ if (this.isMultiEntityType()) {
239
+ return _lodash.default.isNil(entityTypes[this.type]) ? this.observationBasedFilter.getEntityType() : entityTypes[this.type];
132
240
  }
241
+
242
+ throw new Error("Unsupported filter type: " + this.type);
133
243
  }
134
244
 
135
245
  isConceptTypeFilter() {
136
246
  return this.type === _CustomFilter.default.type.Concept;
137
247
  }
138
248
 
249
+ isNonCodedObservationDataType() {
250
+ return this.isConceptTypeFilter() && this.observationBasedFilter.concept.datatype !== _Concept.default.dataType.Coded;
251
+ }
252
+
139
253
  isGroupSubjectTypeFilter() {
140
254
  return this.type === _CustomFilter.default.type.GroupSubject;
141
255
  }
142
256
 
257
+ requiresSpecificSubjectType() {
258
+ return ![_CustomFilter.default.type.SubjectType, _CustomFilter.default.type.AsOnDate].includes(this.type);
259
+ }
260
+
261
+ isAsOnDateFilter() {
262
+ return this.type === _CustomFilter.default.type.AsOnDate;
263
+ }
264
+
143
265
  isValid() {
144
266
  const valid = !_lodash.default.isNil(this.type);
145
267
  if (!valid) return valid;
@@ -149,6 +271,7 @@ class DashboardFilterConfig {
149
271
  toServerRequest() {
150
272
  const request = {
151
273
  type: this.type,
274
+ subjectTypeUUID: this.subjectType && this.subjectType.uuid,
152
275
  widget: this.widget
153
276
  };
154
277
  if (this.isConceptTypeFilter()) request.observationBasedFilter = this.observationBasedFilter.toServerRequest();else if (this.isGroupSubjectTypeFilter()) request.groupSubjectTypeFilter = this.groupSubjectTypeFilter.toServerRequest();
@@ -175,6 +298,12 @@ class DashboardFilterConfig {
175
298
  return [RegistrationDate, EnrolmentDate, ProgramEncounterDate, EncounterDate].includes(this.type) || this.isConceptTypeFilter() && this.observationBasedFilter.isWidgetRequired();
176
299
  }
177
300
 
301
+ setSubjectType(subjectType) {
302
+ if (_lodash.default.get(subjectType, "uuid") !== _lodash.default.get(this.subjectType, "uuid")) {
303
+ this.subjectType = subjectType;
304
+ }
305
+ }
306
+
178
307
  willObservationBeInScopeOfProgramEnrolment() {
179
308
  return this.isConceptTypeFilter() && this.observationBasedFilter.willObservationBeInScopeOfProgramEnrolment();
180
309
  }
@@ -184,13 +313,11 @@ class DashboardFilterConfig {
184
313
  }
185
314
 
186
315
  validate(filterValue) {
187
- const inputDataType = this.getInputDataType();
188
-
189
- if ([_Concept.default.dataType.Date, _Concept.default.dataType.DateTime].includes(inputDataType) && this.widget === _CustomFilter.default.widget.Range) {
316
+ if (this.isDateRangeFilterType()) {
190
317
  return _DateTimeUtil.default.validateDateRange(filterValue.minValue, filterValue.maxValue);
191
318
  }
192
319
 
193
- if (_Concept.default.dataType.Time === inputDataType && this.widget === _CustomFilter.default.widget.Range) {
320
+ if (this.isTimeRangeFilterType()) {
194
321
  return _DateTimeUtil.default.validateTimeRange(filterValue.minValue, filterValue.maxValue);
195
322
  }
196
323
 
@@ -200,6 +327,7 @@ class DashboardFilterConfig {
200
327
  clone() {
201
328
  const clone = new DashboardFilterConfig();
202
329
  clone.type = this.type;
330
+ clone.subjectType = this.subjectType;
203
331
  clone.widget = this.widget;
204
332
  clone.groupSubjectTypeFilter = this.groupSubjectTypeFilter;
205
333
  clone.observationBasedFilter = this.observationBasedFilter;
@@ -208,5 +336,10 @@ class DashboardFilterConfig {
208
336
 
209
337
  }
210
338
 
339
+ _defineProperty(DashboardFilterConfig, "dataTypes", {
340
+ array: "array",
341
+ formMetaData: "formMetaData"
342
+ });
343
+
211
344
  var _default = DashboardFilterConfig;
212
345
  exports.default = _default;
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _lodash = _interopRequireDefault(require("lodash"));
9
+
10
+ var _BaseEntity = _interopRequireDefault(require("../BaseEntity"));
11
+
12
+ var _General = _interopRequireDefault(require("../utility/General"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ 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; }
17
+
18
+ class NestedReportCardResult extends _BaseEntity.default {
19
+ // transient state
20
+ constructor(that) {
21
+ super(that);
22
+
23
+ _defineProperty(this, "clickable", void 0);
24
+
25
+ _defineProperty(this, "hasErrorMsg", void 0);
26
+ }
27
+
28
+ static create(primaryValue, secondaryValue, clickable, hasErrorMsg, itemKey) {
29
+ const nestedReportCardResult = new NestedReportCardResult();
30
+ nestedReportCardResult.uuid = _General.default.randomUUID();
31
+ nestedReportCardResult.primaryValue = _lodash.default.toString(primaryValue);
32
+ nestedReportCardResult.secondaryValue = _lodash.default.toString(secondaryValue);
33
+ nestedReportCardResult.clickable = clickable;
34
+ nestedReportCardResult.hasErrorMsg = hasErrorMsg;
35
+ nestedReportCardResult.itemKey = itemKey;
36
+ return nestedReportCardResult;
37
+ }
38
+
39
+ get dashboard() {
40
+ return this.that.dashboard;
41
+ }
42
+
43
+ set dashboard(x) {
44
+ this.that.dashboard = x;
45
+ }
46
+
47
+ get reportCard() {
48
+ return this.that.reportCard;
49
+ }
50
+
51
+ set reportCard(x) {
52
+ this.that.reportCard = x;
53
+ }
54
+
55
+ get primaryValue() {
56
+ return this.that.primaryValue;
57
+ }
58
+
59
+ set primaryValue(x) {
60
+ this.that.primaryValue = x;
61
+ }
62
+
63
+ get secondaryValue() {
64
+ return this.that.secondaryValue;
65
+ }
66
+
67
+ set secondaryValue(x) {
68
+ this.that.secondaryValue = x;
69
+ }
70
+
71
+ get itemKey() {
72
+ return this.that.itemKey;
73
+ }
74
+
75
+ set itemKey(x) {
76
+ this.that.itemKey = x;
77
+ }
78
+
79
+ get cardName() {
80
+ return this.that.cardName;
81
+ }
82
+
83
+ set cardName(x) {
84
+ this.that.cardName = x;
85
+ }
86
+
87
+ get cardColor() {
88
+ return this.that.cardColor;
89
+ }
90
+
91
+ set cardColor(x) {
92
+ this.that.cardColor = x;
93
+ }
94
+
95
+ get textColor() {
96
+ return this.that.textColor;
97
+ }
98
+
99
+ set textColor(x) {
100
+ this.that.textColor = x;
101
+ }
102
+
103
+ get reportCardUUID() {
104
+ return this.that.reportCardUUID;
105
+ }
106
+
107
+ set reportCardUUID(x) {
108
+ this.that.reportCardUUID = x;
109
+ }
110
+
111
+ static fromQueryResult(ruleResult, reportCard, index) {
112
+ const nestedReportCardResult = NestedReportCardResult.create(ruleResult.primaryValue, ruleResult.secondaryValue, _lodash.default.isFunction(ruleResult.lineListFunction), ruleResult.hasErrorMsg, reportCard.getCardId(index));
113
+
114
+ if (ruleResult.hasErrorMsg) {
115
+ return nestedReportCardResult;
116
+ }
117
+
118
+ nestedReportCardResult.cardName = ruleResult.cardName;
119
+ nestedReportCardResult.cardColor = _lodash.default.isNil(ruleResult.cardColor) ? reportCard.colour : ruleResult.cardColor;
120
+ nestedReportCardResult.textColor = ruleResult.textColor;
121
+ nestedReportCardResult.reportCardUUID = reportCard.uuid;
122
+ return nestedReportCardResult;
123
+ }
124
+
125
+ }
126
+
127
+ _defineProperty(NestedReportCardResult, "schema", {
128
+ name: "NestedReportCardResult",
129
+ embedded: true,
130
+ properties: {
131
+ uuid: "string",
132
+ dashboard: "string",
133
+ reportCard: "string",
134
+ primaryValue: "string",
135
+ secondaryValue: "string",
136
+ itemKey: "string",
137
+ cardName: "string",
138
+ cardColor: "string",
139
+ textColor: "string",
140
+ reportCardUUID: "string"
141
+ }
142
+ });
143
+
144
+ var _default = NestedReportCardResult;
145
+ exports.default = _default;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _lodash = _interopRequireDefault(require("lodash"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ 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; }
13
+
14
+ class Range {
15
+ constructor(minValue, maxValue) {
16
+ _defineProperty(this, "minValue", void 0);
17
+
18
+ _defineProperty(this, "maxValue", void 0);
19
+
20
+ this.minValue = minValue;
21
+ this.maxValue = maxValue;
22
+ }
23
+
24
+ static empty() {
25
+ return new Range(null, null);
26
+ }
27
+
28
+ isEmpty() {
29
+ return _lodash.default.isNil(this.minValue) || _lodash.default.isNil(this.maxValue);
30
+ }
31
+
32
+ }
33
+
34
+ _defineProperty(Range, "DateRange", "DateRange");
35
+
36
+ var _default = Range;
37
+ exports.default = _default;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _lodash = _interopRequireDefault(require("lodash"));
9
+
10
+ var _BaseEntity = _interopRequireDefault(require("../BaseEntity"));
11
+
12
+ var _General = _interopRequireDefault(require("../utility/General"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ 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; }
17
+
18
+ class ReportCardResult extends _BaseEntity.default {
19
+ // transient state
20
+ constructor(that) {
21
+ super(that);
22
+
23
+ _defineProperty(this, "clickable", void 0);
24
+
25
+ _defineProperty(this, "hasErrorMsg", void 0);
26
+ }
27
+
28
+ get primaryValue() {
29
+ return this.that.primaryValue;
30
+ }
31
+
32
+ set primaryValue(x) {
33
+ this.that.primaryValue = x;
34
+ }
35
+
36
+ get secondaryValue() {
37
+ return this.that.secondaryValue;
38
+ }
39
+
40
+ set secondaryValue(x) {
41
+ this.that.secondaryValue = x;
42
+ }
43
+
44
+ get dashboard() {
45
+ return this.that.dashboard;
46
+ }
47
+
48
+ set dashboard(x) {
49
+ this.that.dashboard = x;
50
+ }
51
+
52
+ get reportCard() {
53
+ return this.that.reportCard;
54
+ }
55
+
56
+ set reportCard(x) {
57
+ this.that.reportCard = x;
58
+ }
59
+
60
+ static create(primaryValue, secondaryValue, clickable, hasErrorMsg = false) {
61
+ const reportCardResult = new ReportCardResult();
62
+ reportCardResult.uuid = _General.default.randomUUID();
63
+ reportCardResult.primaryValue = _lodash.default.toString(primaryValue);
64
+ reportCardResult.secondaryValue = _lodash.default.toString(secondaryValue);
65
+ reportCardResult.clickable = clickable;
66
+ reportCardResult.hasErrorMsg = hasErrorMsg;
67
+ return reportCardResult;
68
+ }
69
+
70
+ static fromQueryResult(result) {
71
+ return ReportCardResult.create(result.primaryValue, result.secondaryValue, _lodash.default.isFunction(result.lineListFunction), result.hasErrorMsg);
72
+ }
73
+
74
+ get lineListFunction() {
75
+ return _lodash.default.noop;
76
+ }
77
+
78
+ }
79
+
80
+ _defineProperty(ReportCardResult, "schema", {
81
+ name: "ReportCardResult",
82
+ embedded: true,
83
+ properties: {
84
+ uuid: "string",
85
+ dashboard: "string",
86
+ reportCard: "string",
87
+ primaryValue: "string",
88
+ secondaryValue: "string"
89
+ }
90
+ });
91
+
92
+ var _default = ReportCardResult;
93
+ exports.default = _default;
@@ -99,6 +99,10 @@ class MetaDataService {
99
99
  return _lodash.default.filter(formMappings, formMapping => formMapping.formType === _Form.default.formTypes.ProgramEncounter || formMapping.formType === _Form.default.formTypes.ProgramEncounterCancellation);
100
100
  }
101
101
 
102
+ static getProgramEncounterFormMappingsForFormType(formMappings, formType) {
103
+ return _lodash.default.filter(formMappings, formMapping => formMapping.formType === formType);
104
+ }
105
+
102
106
  static getProgramsForSubjectType(allPrograms, subjectType, formMappings) {
103
107
  if (_lodash.default.isNil(subjectType)) return allPrograms;
104
108
 
@@ -116,9 +120,9 @@ class MetaDataService {
116
120
  }
117
121
 
118
122
  static getEncounterTypesForPrograms(allEncounterTypes, programs, formMappings) {
119
- const programEncounterTypeMappings = MetaDataService.getProgramEncounterFormMappings(formMappings);
123
+ const programEncounterTypeMappings = MetaDataService.getProgramEncounterFormMappingsForFormType(formMappings, _Form.default.formTypes.ProgramEncounter);
120
124
 
121
- const encounterTypeMappingsForPrograms = _lodash.default.intersectionWith(programEncounterTypeMappings, programs, (etMapping, program) => etMapping.programUUID === program.uuid);
125
+ const encounterTypeMappingsForPrograms = _lodash.default.filter(programEncounterTypeMappings, formMapping => _lodash.default.some(programs, program => formMapping.programUUID === program.uuid));
122
126
 
123
127
  return encounterTypeMappingsForPrograms.map(x => _lodash.default.find(allEncounterTypes, et => et.uuid === x.encounterTypeUUID));
124
128
  }
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.32.00",
4
+ "version": "1.32.2",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",