openchs-models 1.31.82 → 1.31.84

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.
@@ -52,6 +52,14 @@ class CustomDashboardCache extends _BaseEntity.default {
52
52
  this.that.dashboard = this.fromObject(x);
53
53
  }
54
54
 
55
+ get dashboardFiltersHash() {
56
+ return this.that.dashboardFiltersHash;
57
+ }
58
+
59
+ set dashboardFiltersHash(x) {
60
+ this.that.dashboardFiltersHash = x;
61
+ }
62
+
55
63
  static create(uuid, updatedAt, selectedValuesJSON = '{}', filterApplied) {
56
64
  const customDashboardCache = new CustomDashboardCache();
57
65
  customDashboardCache.uuid = uuid;
@@ -61,17 +69,18 @@ class CustomDashboardCache extends _BaseEntity.default {
61
69
  return customDashboardCache;
62
70
  }
63
71
 
64
- static newInstance(dashboard) {
72
+ static newInstance(dashboard, dashboardFiltersHash) {
65
73
  const customDashboardCache = new CustomDashboardCache();
66
74
  customDashboardCache.uuid = _General.default.randomUUID();
67
75
  customDashboardCache.dashboard = dashboard;
68
- customDashboardCache.reset();
76
+ customDashboardCache.reset(dashboardFiltersHash);
69
77
  return customDashboardCache;
70
78
  }
71
79
 
72
- reset() {
80
+ reset(dashboardFiltersHash) {
73
81
  this.filterApplied = false;
74
82
  this.selectedValuesJSON = JSON.stringify({});
83
+ this.dashboardFiltersHash = dashboardFiltersHash;
75
84
  this.updatedAt = new Date();
76
85
  }
77
86
 
@@ -86,6 +95,7 @@ class CustomDashboardCache extends _BaseEntity.default {
86
95
  customDashboardCache.updatedAt = this.updatedAt;
87
96
  customDashboardCache.selectedValuesJSON = this.selectedValuesJSON;
88
97
  customDashboardCache.filterApplied = this.filterApplied;
98
+ customDashboardCache.dashboardFiltersHash = this.dashboardFiltersHash;
89
99
  return customDashboardCache;
90
100
  }
91
101
 
@@ -99,7 +109,8 @@ _defineProperty(CustomDashboardCache, "schema", {
99
109
  dashboard: "Dashboard",
100
110
  updatedAt: "date",
101
111
  selectedValuesJSON: "string",
102
- filterApplied: "bool"
112
+ filterApplied: "bool",
113
+ dashboardFiltersHash: "string"
103
114
  }
104
115
  });
105
116
 
package/dist/Schema.js CHANGED
@@ -279,7 +279,7 @@ function createRealmConfig() {
279
279
  return doCompact;
280
280
  },
281
281
  //order is important, should be arranged according to the dependency
282
- schemaVersion: 191,
282
+ schemaVersion: 192,
283
283
  onMigration: function (oldDB, newDB) {
284
284
  console.log("[AvniModels.Schema]", `Running migration with old schema version: ${oldDB.schemaVersion} and new schema version: ${newDB.schemaVersion}`);
285
285
  if (oldDB.schemaVersion === VersionWithEmbeddedMigrationProblem) throw new Error(`Update from schema version ${VersionWithEmbeddedMigrationProblem} is not allowed. Please uninstall and install app.`);
package/dist/index.js CHANGED
@@ -795,6 +795,12 @@ Object.defineProperty(exports, "Locations", {
795
795
  return _Locations.default;
796
796
  }
797
797
  });
798
+ Object.defineProperty(exports, "Range", {
799
+ enumerable: true,
800
+ get: function () {
801
+ return _Range.default;
802
+ }
803
+ });
798
804
 
799
805
  var _AbstractEncounter = _interopRequireDefault(require("./AbstractEncounter"));
800
806
 
@@ -1050,6 +1056,8 @@ var _JsonStringify = require("./utility/JsonStringify");
1050
1056
 
1051
1057
  var _Locations = _interopRequireDefault(require("./location/Locations"));
1052
1058
 
1059
+ var _Range = _interopRequireDefault(require("./reports/Range"));
1060
+
1053
1061
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
1054
1062
 
1055
1063
  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; }
@@ -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,
@@ -108,6 +129,23 @@ class GroupSubjectTypeFilter {
108
129
 
109
130
  exports.GroupSubjectTypeFilter = GroupSubjectTypeFilter;
110
131
  const dateFilterTypes = [_CustomFilter.default.type.RegistrationDate, _CustomFilter.default.type.EnrolmentDate, _CustomFilter.default.type.EncounterDate, _CustomFilter.default.type.ProgramEncounterDate];
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() {
@@ -122,22 +160,92 @@ class DashboardFilterConfig {
122
160
  _defineProperty(this, "observationBasedFilter", void 0);
123
161
  }
124
162
 
163
+ toDisplayText() {
164
+ let s = `Type: ${this.type}.`;
165
+
166
+ if (this.widget === _CustomFilter.default.widget.Range) {
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
+
125
177
  getInputDataType() {
126
178
  if (this.isConceptTypeFilter()) {
127
179
  return this.observationBasedFilter.concept.datatype;
128
- } else if (this.isGroupSubjectTypeFilter()) {
129
- return _Concept.default.dataType.Subject;
130
- } else if (dateFilterTypes.includes(this.type)) {
180
+ } else if ([_CustomFilter.default.type.Gender, _CustomFilter.default.type.Address, _CustomFilter.default.type.GroupSubject].includes(this.type)) {
181
+ return DashboardFilterConfig.dataTypes.array;
182
+ } else if (dateFilterTypes.includes(this.type) && this.widget === _CustomFilter.default.widget.Default) {
131
183
  return _Concept.default.dataType.Date;
132
- } else {
133
- return this.type;
184
+ } else if (dateFilterTypes.includes(this.type) && this.widget === _CustomFilter.default.widget.Range) {
185
+ return _Range.default.DateRange;
186
+ } else if (this.type === _CustomFilter.default.type.SubjectType) {
187
+ return DashboardFilterConfig.dataTypes.formMetaData;
188
+ }
189
+
190
+ throw new Error("Unsupported filter type: " + this.type);
191
+ }
192
+
193
+ isDateFilterType() {
194
+ return isDateDataType(this) && this.widget !== _CustomFilter.default.widget.Range;
195
+ }
196
+
197
+ isDateRangeFilterType() {
198
+ return isDateDataType(this) && this.widget === _CustomFilter.default.widget.Range;
199
+ }
200
+
201
+ isDateTimeFilterType() {
202
+ return isDateTimeDataType(this) && this.widget !== _CustomFilter.default.widget.Range;
203
+ }
204
+
205
+ isDateTimeRangeFilterType() {
206
+ return isDateTimeDataType(this) && this.widget === _CustomFilter.default.widget.Range;
207
+ }
208
+
209
+ isTimeFilterType() {
210
+ return isTimeDataType(this) && this.widget !== _CustomFilter.default.widget.Range;
211
+ }
212
+
213
+ isTimeRangeFilterType() {
214
+ return isTimeDataType(this) && this.widget === _CustomFilter.default.widget.Range;
215
+ }
216
+
217
+ isNumericRangeFilterType() {
218
+ return this.isConceptTypeFilter() && this.observationBasedFilter.concept.datatype === _Concept.default.dataType.Numeric && this.widget === _CustomFilter.default.widget.Range;
219
+ }
220
+
221
+ isDateLikeFilterType() {
222
+ return this.isDateFilterType() || this.isDateTimeFilterType() || this.isTimeFilterType();
223
+ }
224
+
225
+ isDateLikeRangeFilterType() {
226
+ return this.isDateRangeFilterType() || this.isDateTimeRangeFilterType() || this.isTimeRangeFilterType();
227
+ }
228
+
229
+ isMultiEntityType() {
230
+ return [_CustomFilter.default.type.Gender, _CustomFilter.default.type.Address, _CustomFilter.default.type.GroupSubject].includes(this.type) || this.isConceptTypeFilter() && this.observationBasedFilter.isMultiEntityType();
231
+ }
232
+
233
+ getEntityType() {
234
+ if (this.isMultiEntityType()) {
235
+ return _lodash.default.isNil(entityTypes[this.type]) ? this.observationBasedFilter.getEntityType() : entityTypes[this.type];
134
236
  }
237
+
238
+ throw new Error("Unsupported filter type: " + this.type);
135
239
  }
136
240
 
137
241
  isConceptTypeFilter() {
138
242
  return this.type === _CustomFilter.default.type.Concept;
139
243
  }
140
244
 
245
+ isNonCodedObservationDataType() {
246
+ return this.isConceptTypeFilter() && this.observationBasedFilter.concept.datatype !== _Concept.default.dataType.Coded;
247
+ }
248
+
141
249
  isGroupSubjectTypeFilter() {
142
250
  return this.type === _CustomFilter.default.type.GroupSubject;
143
251
  }
@@ -199,11 +307,11 @@ class DashboardFilterConfig {
199
307
  validate(filterValue) {
200
308
  const inputDataType = this.getInputDataType();
201
309
 
202
- if ([_Concept.default.dataType.Date, _Concept.default.dataType.DateTime].includes(inputDataType) && this.widget === _CustomFilter.default.widget.Range) {
310
+ if (this.isDateRangeFilterType()) {
203
311
  return _DateTimeUtil.default.validateDateRange(filterValue.minValue, filterValue.maxValue);
204
312
  }
205
313
 
206
- if (_Concept.default.dataType.Time === inputDataType && this.widget === _CustomFilter.default.widget.Range) {
314
+ if (this.isTimeRangeFilterType()) {
207
315
  return _DateTimeUtil.default.validateTimeRange(filterValue.minValue, filterValue.maxValue);
208
316
  }
209
317
 
@@ -222,5 +330,10 @@ class DashboardFilterConfig {
222
330
 
223
331
  }
224
332
 
333
+ _defineProperty(DashboardFilterConfig, "dataTypes", {
334
+ array: "array",
335
+ formMetaData: "formMetaData"
336
+ });
337
+
225
338
  var _default = DashboardFilterConfig;
226
339
  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;
@@ -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.31.82",
4
+ "version": "1.31.84",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",