openchs-models 1.33.1 → 1.33.4
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.
- package/.circleci/config.yml +15 -5
- package/.commit-message.txt +21 -0
- package/.nvmrc +1 -1
- package/Makefile +32 -10
- package/REALM_V12_NOTES.md +46 -0
- package/dist/AbstractEncounter.js +4 -105
- package/dist/AddressLevel.js +5 -62
- package/dist/ApprovalStatus.js +4 -17
- package/dist/BaseEntity.js +5 -42
- package/dist/BeneficiaryModePin.js +4 -13
- package/dist/Checklist.js +6 -52
- package/dist/ChecklistDetail.js +4 -22
- package/dist/ChecklistItem.js +16 -96
- package/dist/ChecklistItemDetail.js +4 -43
- package/dist/ChecklistItemStatus.js +6 -35
- package/dist/Comment.js +6 -51
- package/dist/CommentThread.js +4 -26
- package/dist/CompositeDuration.js +1 -18
- package/dist/Concept.js +5 -107
- package/dist/ConceptAnswer.js +4 -21
- package/dist/CustomDashboardCache.js +4 -38
- package/dist/CustomFilter.js +5 -15
- package/dist/Dashboard.js +4 -23
- package/dist/DashboardCache.js +4 -23
- package/dist/DashboardSection.js +4 -24
- package/dist/DashboardSectionCardMapping.js +4 -21
- package/dist/Displayable.js +3 -11
- package/dist/Documentation.js +4 -21
- package/dist/DocumentationItem.js +4 -20
- package/dist/Duration.js +4 -39
- package/dist/Encounter.js +6 -41
- package/dist/EncounterType.js +4 -26
- package/dist/EntityApprovalStatus.js +6 -56
- package/dist/EntityMetaData.js +7 -105
- package/dist/EntityQueue.js +4 -15
- package/dist/EntityRule.js +1 -29
- package/dist/EntitySyncStatus.js +4 -19
- package/dist/Extension.js +4 -18
- package/dist/Family.js +4 -56
- package/dist/FileFormat.js +0 -7
- package/dist/Gender.js +4 -17
- package/dist/GroupDashboard.js +4 -23
- package/dist/GroupPrivileges.js +4 -28
- package/dist/GroupRole.js +4 -34
- package/dist/GroupSubject.js +6 -59
- package/dist/Groups.js +4 -14
- package/dist/Identifier.js +4 -20
- package/dist/IdentifierAssignment.js +6 -45
- package/dist/IdentifierSource.js +4 -15
- package/dist/Individual.js +17 -265
- package/dist/LocaleMapping.js +4 -13
- package/dist/LocationHierarchy.js +4 -25
- package/dist/Media.js +35 -35
- package/dist/MediaQueue.js +4 -26
- package/dist/MigrationsHelper.js +15 -22
- package/dist/MyGroups.js +4 -14
- package/dist/News.js +4 -31
- package/dist/Observation.js +4 -54
- package/dist/ObservationsHolder.js +104 -216
- package/dist/OrganisationConfig.js +4 -19
- package/dist/PersistedObject.js +1 -19
- package/dist/PhoneNumber.js +0 -11
- package/dist/PlatformTranslation.js +4 -17
- package/dist/Privilege.js +5 -22
- package/dist/Program.js +4 -39
- package/dist/ProgramEncounter.js +6 -48
- package/dist/ProgramEnrolment.js +8 -162
- package/dist/ReferenceEntity.js +1 -10
- package/dist/ReportCard.js +5 -60
- package/dist/ResetSync.js +4 -17
- package/dist/Rule.js +4 -28
- package/dist/RuleDependency.js +4 -17
- package/dist/RuleFailureTelemetry.js +4 -36
- package/dist/Schema.js +16 -268
- package/dist/SchemaNames.js +3 -46
- package/dist/Settings.js +4 -53
- package/dist/StandardReportCardType.js +4 -39
- package/dist/SubjectMigration.js +6 -45
- package/dist/SubjectType.js +6 -72
- package/dist/SyncTelemetry.js +4 -40
- package/dist/Translation.js +4 -17
- package/dist/UserInfo.js +4 -33
- package/dist/application/DashboardCacheFilter.js +4 -24
- package/dist/application/Filter.js +3 -16
- package/dist/application/Form.js +6 -93
- package/dist/application/FormElement.js +5 -100
- package/dist/application/FormElementGroup.js +4 -75
- package/dist/application/FormElementStatus.js +1 -11
- package/dist/application/FormMapping.js +6 -44
- package/dist/application/Format.js +4 -20
- package/dist/application/KeyValue.js +4 -19
- package/dist/application/MenuItem.js +4 -35
- package/dist/application/MultiSelectFilter.js +1 -11
- package/dist/application/NullProgramEnrolment.js +0 -8
- package/dist/application/SingleSelectFilter.js +1 -12
- package/dist/application/StaticFormElementGroup.js +0 -11
- package/dist/application/StringKeyNumericValue.js +4 -17
- package/dist/application/ValidationResult.js +6 -20
- package/dist/application/ValidationResults.js +1 -14
- package/dist/application/WorkItem.js +4 -20
- package/dist/application/WorkList.js +1 -24
- package/dist/application/WorkLists.js +1 -13
- package/dist/assignment/UserSubjectAssignment.js +6 -26
- package/dist/draft/DraftEncounter.js +4 -40
- package/dist/draft/DraftSubject.js +4 -46
- package/dist/error/IgnorableSyncError.js +1 -6
- package/dist/error/SyncError.js +1 -6
- package/dist/framework/ArrayHelper.js +3 -11
- package/dist/framework/DefinedObjectSchema.js +4 -12
- package/dist/framework/RealmCollectionHelper.js +1 -9
- package/dist/framework/RealmListProxy.js +1 -10
- package/dist/framework/RealmObjectSchema.js +1 -11
- package/dist/framework/RealmProxy.js +2 -31
- package/dist/framework/RealmResultsProxy.js +3 -37
- package/dist/framework/RealmResultsProxyHandler.js +2 -5
- package/dist/geo/Point.js +4 -17
- package/dist/index.js +2 -137
- package/dist/location/Locations.js +1 -6
- package/dist/observation/MultipleCodedValues.js +1 -21
- package/dist/observation/PrimitiveValue.js +1 -17
- package/dist/observation/QuestionGroup.js +1 -36
- package/dist/observation/RepeatableQuestionGroup.js +4 -27
- package/dist/observation/SingleCodedValue.js +1 -15
- package/dist/program/SubjectProgramEligibility.js +6 -56
- package/dist/relationship/IndividualRelation.js +6 -18
- package/dist/relationship/IndividualRelationGenderMapping.js +4 -22
- package/dist/relationship/IndividualRelationship.js +6 -51
- package/dist/relationship/IndividualRelationshipType.js +4 -24
- package/dist/relationship/IndividualRelative.js +4 -31
- package/dist/reports/DashboardFilter.js +4 -20
- package/dist/reports/DashboardFilterConfig.js +5 -85
- package/dist/reports/NestedReportCardResult.js +5 -35
- package/dist/reports/Range.js +4 -13
- package/dist/reports/ReportCardResult.js +5 -24
- package/dist/service/MetaDataService.js +1 -30
- package/dist/task/Task.js +6 -62
- package/dist/task/TaskStatus.js +4 -21
- package/dist/task/TaskType.js +4 -23
- package/dist/task/TaskUnAssignment.js +6 -30
- package/dist/utility/AgeUtil.js +1 -15
- package/dist/utility/ArrayUtil.js +1 -6
- package/dist/utility/AuditUtil.js +1 -8
- package/dist/utility/DateTimeUtil.js +1 -8
- package/dist/utility/General.js +4 -71
- package/dist/utility/JsonStringify.js +15 -28
- package/dist/utility/MergeUtil.js +1 -10
- package/dist/utility/ResourceUtil.js +1 -7
- package/dist/videos/Video.js +4 -23
- package/dist/videos/VideoTelemetric.js +6 -37
- package/package.json +6 -3
- package/scripts/validateSchemas.js +40 -0
- package/tsconfig.json +1 -1
- package/yarn.lock +0 -6744
package/dist/Individual.js
CHANGED
|
@@ -4,269 +4,190 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _moment = _interopRequireDefault(require("moment"));
|
|
9
|
-
|
|
10
8
|
var _ResourceUtil = _interopRequireDefault(require("./utility/ResourceUtil"));
|
|
11
|
-
|
|
12
9
|
var _AddressLevel = _interopRequireDefault(require("./AddressLevel"));
|
|
13
|
-
|
|
14
10
|
var _Gender = _interopRequireDefault(require("./Gender"));
|
|
15
|
-
|
|
16
11
|
var _General = _interopRequireDefault(require("./utility/General"));
|
|
17
|
-
|
|
18
12
|
var _BaseEntity = _interopRequireDefault(require("./BaseEntity"));
|
|
19
|
-
|
|
20
13
|
var _ProgramEnrolment = _interopRequireDefault(require("./ProgramEnrolment"));
|
|
21
|
-
|
|
22
14
|
var _IndividualRelationship = _interopRequireDefault(require("./relationship/IndividualRelationship"));
|
|
23
|
-
|
|
24
15
|
var _Encounter = _interopRequireDefault(require("./Encounter"));
|
|
25
|
-
|
|
26
16
|
var _Duration = _interopRequireDefault(require("./Duration"));
|
|
27
|
-
|
|
28
17
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
29
|
-
|
|
30
18
|
var _ValidationResult = _interopRequireDefault(require("./application/ValidationResult"));
|
|
31
|
-
|
|
32
19
|
var _ObservationsHolder = _interopRequireDefault(require("./ObservationsHolder"));
|
|
33
|
-
|
|
34
20
|
var _Media = require("./Media");
|
|
35
|
-
|
|
36
21
|
var _Point = _interopRequireDefault(require("./geo/Point"));
|
|
37
|
-
|
|
38
22
|
var _SubjectType = _interopRequireDefault(require("./SubjectType"));
|
|
39
|
-
|
|
40
23
|
var _Observation = _interopRequireDefault(require("./Observation"));
|
|
41
|
-
|
|
42
24
|
var _GroupSubject = _interopRequireDefault(require("./GroupSubject"));
|
|
43
|
-
|
|
44
25
|
var _EntityApprovalStatus = _interopRequireDefault(require("./EntityApprovalStatus"));
|
|
45
|
-
|
|
46
26
|
var _Comment = _interopRequireDefault(require("./Comment"));
|
|
47
|
-
|
|
48
27
|
var _SchemaNames = _interopRequireDefault(require("./SchemaNames"));
|
|
49
|
-
|
|
50
28
|
var _ArrayHelper = _interopRequireDefault(require("./framework/ArrayHelper"));
|
|
51
|
-
|
|
52
29
|
var _MergeUtil = _interopRequireDefault(require("./utility/MergeUtil"));
|
|
53
|
-
|
|
54
30
|
var _AgeUtil = _interopRequireDefault(require("./utility/AgeUtil"));
|
|
55
|
-
|
|
56
31
|
var _AuditUtil = require("./utility/AuditUtil");
|
|
57
|
-
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
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; }
|
|
65
|
-
|
|
32
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
33
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
34
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
35
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
36
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
37
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
66
38
|
const mergeMap = new Map([[_SchemaNames.default.ProgramEnrolment, "enrolments"], [_SchemaNames.default.Encounter, "encounters"], [_SchemaNames.default.IndividualRelationship, "relationships"], [_SchemaNames.default.EntityApprovalStatus, "approvalStatuses"], [_SchemaNames.default.Comment, "comments"]]);
|
|
67
39
|
const ADDRESS_LEVEL_DUMMY_UUID = 'f71b2f45-2c11-427f-aa99-be6161a6b413';
|
|
68
|
-
|
|
69
40
|
class Individual extends _BaseEntity.default {
|
|
70
41
|
constructor(that = null) {
|
|
71
42
|
super(that);
|
|
72
43
|
}
|
|
73
|
-
|
|
74
44
|
get subjectType() {
|
|
75
45
|
return this.toEntity("subjectType", _SubjectType.default);
|
|
76
46
|
}
|
|
77
|
-
|
|
78
47
|
set subjectType(x) {
|
|
79
48
|
this.that.subjectType = this.fromObject(x);
|
|
80
49
|
}
|
|
81
|
-
|
|
82
50
|
get name() {
|
|
83
51
|
return this.that.name;
|
|
84
52
|
}
|
|
85
|
-
|
|
86
53
|
set name(x) {
|
|
87
54
|
this.that.name = x;
|
|
88
55
|
}
|
|
89
|
-
|
|
90
56
|
get firstName() {
|
|
91
57
|
return this.that.firstName;
|
|
92
58
|
}
|
|
93
|
-
|
|
94
59
|
set firstName(x) {
|
|
95
60
|
this.that.firstName = x;
|
|
96
61
|
}
|
|
97
|
-
|
|
98
62
|
get middleName() {
|
|
99
63
|
return this.that.middleName;
|
|
100
64
|
}
|
|
101
|
-
|
|
102
65
|
set middleName(x) {
|
|
103
66
|
this.that.middleName = x;
|
|
104
67
|
}
|
|
105
|
-
|
|
106
68
|
get lastName() {
|
|
107
69
|
return this.that.lastName;
|
|
108
70
|
}
|
|
109
|
-
|
|
110
71
|
set lastName(x) {
|
|
111
72
|
this.that.lastName = x;
|
|
112
73
|
}
|
|
113
|
-
|
|
114
74
|
get profilePicture() {
|
|
115
75
|
return this.that.profilePicture;
|
|
116
76
|
}
|
|
117
|
-
|
|
118
77
|
set profilePicture(x) {
|
|
119
78
|
this.that.profilePicture = x;
|
|
120
79
|
}
|
|
121
|
-
|
|
122
80
|
get dateOfBirth() {
|
|
123
81
|
return this.that.dateOfBirth;
|
|
124
82
|
}
|
|
125
|
-
|
|
126
83
|
set dateOfBirth(x) {
|
|
127
84
|
this.that.dateOfBirth = x;
|
|
128
85
|
}
|
|
129
|
-
|
|
130
86
|
get dateOfBirthVerified() {
|
|
131
87
|
return this.that.dateOfBirthVerified;
|
|
132
88
|
}
|
|
133
|
-
|
|
134
89
|
set dateOfBirthVerified(x) {
|
|
135
90
|
this.that.dateOfBirthVerified = x;
|
|
136
91
|
}
|
|
137
|
-
|
|
138
92
|
get gender() {
|
|
139
93
|
return this.toEntity("gender", _Gender.default);
|
|
140
94
|
}
|
|
141
|
-
|
|
142
95
|
set gender(x) {
|
|
143
96
|
this.that.gender = this.fromObject(x);
|
|
144
97
|
}
|
|
145
|
-
|
|
146
98
|
get registrationDate() {
|
|
147
99
|
return this.that.registrationDate;
|
|
148
100
|
}
|
|
149
|
-
|
|
150
101
|
set registrationDate(x) {
|
|
151
102
|
this.that.registrationDate = x;
|
|
152
103
|
}
|
|
153
|
-
|
|
154
104
|
get lowestAddressLevel() {
|
|
155
105
|
return this.toEntity("lowestAddressLevel", _AddressLevel.default);
|
|
156
106
|
}
|
|
157
|
-
|
|
158
107
|
set lowestAddressLevel(x) {
|
|
159
108
|
this.that.lowestAddressLevel = this.fromObject(x);
|
|
160
109
|
}
|
|
161
|
-
|
|
162
110
|
get enrolments() {
|
|
163
111
|
return this.toEntityList("enrolments", _ProgramEnrolment.default);
|
|
164
112
|
}
|
|
165
|
-
|
|
166
113
|
set enrolments(x) {
|
|
167
114
|
this.that.enrolments = this.fromEntityList(x);
|
|
168
115
|
}
|
|
169
|
-
|
|
170
116
|
get encounters() {
|
|
171
117
|
return this.toEntityList("encounters", _Encounter.default);
|
|
172
118
|
}
|
|
173
|
-
|
|
174
119
|
set encounters(x) {
|
|
175
120
|
this.that.encounters = this.fromEntityList(x);
|
|
176
121
|
}
|
|
177
|
-
|
|
178
122
|
get observations() {
|
|
179
123
|
return this.toEntityList("observations", _Observation.default);
|
|
180
124
|
}
|
|
181
|
-
|
|
182
125
|
set observations(x) {
|
|
183
126
|
this.that.observations = this.fromEntityList(x);
|
|
184
127
|
}
|
|
185
|
-
|
|
186
128
|
get relationships() {
|
|
187
129
|
return this.toEntityList("relationships", _IndividualRelationship.default);
|
|
188
130
|
}
|
|
189
|
-
|
|
190
131
|
set relationships(x) {
|
|
191
132
|
this.that.relationships = this.fromEntityList(x);
|
|
192
133
|
}
|
|
193
|
-
|
|
194
134
|
get groupSubjects() {
|
|
195
135
|
return this.toEntityList("groupSubjects", _GroupSubject.default);
|
|
196
136
|
}
|
|
197
|
-
|
|
198
137
|
set groupSubjects(x) {
|
|
199
138
|
this.that.groupSubjects = this.fromEntityList(x);
|
|
200
139
|
}
|
|
201
|
-
|
|
202
140
|
get registrationLocation() {
|
|
203
141
|
return this.toEntity("registrationLocation", _Point.default);
|
|
204
142
|
}
|
|
205
|
-
|
|
206
143
|
set registrationLocation(x) {
|
|
207
144
|
this.that.registrationLocation = this.fromObject(x);
|
|
208
145
|
}
|
|
209
|
-
|
|
210
146
|
get latestEntityApprovalStatus() {
|
|
211
147
|
return _lodash.default.maxBy(this.approvalStatuses, 'statusDateTime');
|
|
212
148
|
}
|
|
213
|
-
|
|
214
149
|
get comments() {
|
|
215
150
|
return this.toEntityList("comments", _Comment.default);
|
|
216
151
|
}
|
|
217
|
-
|
|
218
152
|
set comments(x) {
|
|
219
153
|
this.that.comments = this.fromEntityList(x);
|
|
220
154
|
}
|
|
221
|
-
|
|
222
155
|
get groups() {
|
|
223
156
|
return this.toEntityList("groups", _GroupSubject.default);
|
|
224
157
|
}
|
|
225
|
-
|
|
226
158
|
set groups(x) {
|
|
227
159
|
this.that.groups = this.fromEntityList(x);
|
|
228
160
|
}
|
|
229
|
-
|
|
230
161
|
get approvalStatuses() {
|
|
231
162
|
return this.toEntityList("approvalStatuses", _EntityApprovalStatus.default);
|
|
232
163
|
}
|
|
233
|
-
|
|
234
164
|
set approvalStatuses(x) {
|
|
235
165
|
this.that.approvalStatuses = this.fromEntityList(x);
|
|
236
166
|
}
|
|
237
|
-
|
|
238
167
|
get createdBy() {
|
|
239
168
|
return this.that.createdBy;
|
|
240
169
|
}
|
|
241
|
-
|
|
242
170
|
set createdBy(x) {
|
|
243
171
|
this.that.createdBy = x;
|
|
244
172
|
}
|
|
245
|
-
|
|
246
173
|
get lastModifiedBy() {
|
|
247
174
|
return this.that.lastModifiedBy;
|
|
248
175
|
}
|
|
249
|
-
|
|
250
176
|
set lastModifiedBy(x) {
|
|
251
177
|
this.that.lastModifiedBy = x;
|
|
252
178
|
}
|
|
253
|
-
|
|
254
179
|
get createdByUUID() {
|
|
255
180
|
return this.that.createdByUUID;
|
|
256
181
|
}
|
|
257
|
-
|
|
258
182
|
set createdByUUID(x) {
|
|
259
183
|
this.that.createdByUUID = x;
|
|
260
184
|
}
|
|
261
|
-
|
|
262
185
|
get lastModifiedByUUID() {
|
|
263
186
|
return this.that.lastModifiedByUUID;
|
|
264
187
|
}
|
|
265
|
-
|
|
266
188
|
set lastModifiedByUUID(x) {
|
|
267
189
|
this.that.lastModifiedByUUID = x;
|
|
268
190
|
}
|
|
269
|
-
|
|
270
191
|
static createEmptyInstance() {
|
|
271
192
|
const individual = new Individual();
|
|
272
193
|
individual.uuid = _General.default.randomUUID();
|
|
@@ -285,7 +206,6 @@ class Individual extends _BaseEntity.default {
|
|
|
285
206
|
individual.comments = [];
|
|
286
207
|
return individual;
|
|
287
208
|
}
|
|
288
|
-
|
|
289
209
|
static getPlaceholderAddressLevel(entityService) {
|
|
290
210
|
return _AddressLevel.default.create({
|
|
291
211
|
uuid: ADDRESS_LEVEL_DUMMY_UUID,
|
|
@@ -299,41 +219,33 @@ class Individual extends _BaseEntity.default {
|
|
|
299
219
|
locationProperties: []
|
|
300
220
|
}, entityService);
|
|
301
221
|
}
|
|
302
|
-
|
|
303
222
|
static createEmptySubjectInstance() {
|
|
304
223
|
const individual = Individual.createEmptyInstance();
|
|
305
224
|
individual.gender = null;
|
|
306
225
|
return individual;
|
|
307
226
|
}
|
|
308
|
-
|
|
309
227
|
get toResource() {
|
|
310
228
|
const resource = _lodash.default.pick(this, ["uuid", "firstName", "middleName", "lastName", "profilePicture", "dateOfBirthVerified", "voided"]);
|
|
311
|
-
|
|
312
229
|
resource.dateOfBirth = this.dateOfBirth ? (0, _moment.default)(this.dateOfBirth).format("YYYY-MM-DD") : null;
|
|
313
230
|
resource.registrationDate = (0, _moment.default)(this.registrationDate).format("YYYY-MM-DD");
|
|
314
231
|
resource["genderUUID"] = this.gender ? this.gender.uuid : null;
|
|
315
232
|
resource["addressLevelUUID"] = this.lowestAddressLevel.uuid;
|
|
316
233
|
resource["subjectTypeUUID"] = this.subjectType.uuid;
|
|
317
|
-
|
|
318
234
|
if (!_lodash.default.isNil(this.registrationLocation)) {
|
|
319
235
|
resource["registrationLocation"] = this.registrationLocation.toResource;
|
|
320
236
|
}
|
|
321
|
-
|
|
322
237
|
resource["observations"] = [];
|
|
323
238
|
this.observations.forEach(obs => {
|
|
324
239
|
resource["observations"].push(obs.toResource);
|
|
325
240
|
});
|
|
326
241
|
return resource;
|
|
327
242
|
}
|
|
328
|
-
|
|
329
243
|
findObservationAcrossAllEnrolments(conceptNameOrUuid) {
|
|
330
244
|
return this.nonVoidedEnrolments().find(enrolment => enrolment.findLatestObservationInEntireEnrolment(conceptNameOrUuid) !== undefined);
|
|
331
245
|
}
|
|
332
|
-
|
|
333
246
|
observationExistsAcrossAllEnrolments(conceptNameOrUuid) {
|
|
334
247
|
return this.nonVoidedEnrolments().find(enrolment => enrolment.findLatestObservationInEntireEnrolment(conceptNameOrUuid) !== undefined);
|
|
335
248
|
}
|
|
336
|
-
|
|
337
249
|
static newInstance(uuid, firstName, lastName, dateOfBirth, dateOfBirthVerified, gender, lowestAddressLevel, subjectType, profilePicture) {
|
|
338
250
|
const individual = new Individual();
|
|
339
251
|
individual.uuid = uuid;
|
|
@@ -348,22 +260,18 @@ class Individual extends _BaseEntity.default {
|
|
|
348
260
|
individual.lowestAddressLevel = this.initLowestAddressLevel(lowestAddressLevel, subjectType, null);
|
|
349
261
|
return individual;
|
|
350
262
|
}
|
|
263
|
+
|
|
351
264
|
/**
|
|
352
265
|
* Init Lowest AddressLevel with Placeholder only if the Individual SubjectType is User
|
|
353
266
|
*/
|
|
354
|
-
|
|
355
|
-
|
|
356
267
|
static initLowestAddressLevel(lowestAddressLevel, subjectType, entityService) {
|
|
357
268
|
return lowestAddressLevel || subjectType && subjectType.isUser() && this.getPlaceholderAddressLevel(entityService);
|
|
358
269
|
}
|
|
359
|
-
|
|
360
270
|
static fromResource(individualResource, entityService) {
|
|
361
271
|
const addressLevel = entityService.findByKey("uuid", _ResourceUtil.default.getUUIDFor(individualResource, "addressUUID"), _AddressLevel.default.schema.name);
|
|
362
272
|
const gender = entityService.findByKey("uuid", _ResourceUtil.default.getUUIDFor(individualResource, "genderUUID"), _Gender.default.schema.name);
|
|
363
273
|
const subjectType = entityService.findByKey("uuid", _ResourceUtil.default.getUUIDFor(individualResource, "subjectTypeUUID"), _SubjectType.default.schema.name);
|
|
364
|
-
|
|
365
274
|
const individual = _General.default.assignFields(individualResource, new Individual(), this.directCopyFields, this.dateFields, ["observations"], entityService);
|
|
366
|
-
|
|
367
275
|
individual.gender = gender;
|
|
368
276
|
individual.lowestAddressLevel = this.initLowestAddressLevel(addressLevel, subjectType, entityService);
|
|
369
277
|
individual.name = individual.nameString;
|
|
@@ -372,42 +280,29 @@ class Individual extends _BaseEntity.default {
|
|
|
372
280
|
(0, _AuditUtil.mapAuditFields)(individual, individualResource);
|
|
373
281
|
return individual;
|
|
374
282
|
}
|
|
375
|
-
|
|
376
283
|
isMale() {
|
|
377
284
|
return this.gender.isMale();
|
|
378
285
|
}
|
|
379
|
-
|
|
380
286
|
isFemale() {
|
|
381
287
|
return this.gender.isFemale();
|
|
382
288
|
}
|
|
383
|
-
|
|
384
289
|
static associateRelationship(child, childEntityClass, childResource, entityService) {
|
|
385
290
|
let individual = _BaseEntity.default.getParentEntity(entityService, childEntityClass, childResource, "individualAUUID", Individual.schema.name);
|
|
386
|
-
|
|
387
291
|
individual = _General.default.pick(individual, ["uuid"], ["enrolments", "encounters", "relationships", "groupSubjects", "comments", "groups"]);
|
|
388
|
-
|
|
389
292
|
_BaseEntity.default.addNewChild(child, individual.relationships);
|
|
390
|
-
|
|
391
293
|
return individual;
|
|
392
294
|
}
|
|
393
|
-
|
|
394
295
|
static associateGroupSubject(child, childEntityClass, childResource, entityService) {
|
|
395
296
|
const getParentByUUID = parentUUIDField => _BaseEntity.default.getParentEntity(entityService, childEntityClass, childResource, parentUUIDField, Individual.schema.name);
|
|
396
|
-
|
|
397
297
|
const copyFieldsForSubject = subject => _General.default.pick(subject, ["uuid", "subjectType"], ["enrolments", "encounters", "relationships", "groupSubjects", "comments", "groups"]);
|
|
398
|
-
|
|
399
298
|
var groupSubject = getParentByUUID("groupSubjectUUID");
|
|
400
299
|
groupSubject = copyFieldsForSubject(groupSubject);
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
300
|
+
_BaseEntity.default.addNewChild(child, groupSubject.groupSubjects);
|
|
301
|
+
//Don't associate voided member subjects if not found in the catchment
|
|
405
302
|
try {
|
|
406
303
|
let memberSubject = getParentByUUID("memberSubjectUUID");
|
|
407
304
|
memberSubject = copyFieldsForSubject(memberSubject);
|
|
408
|
-
|
|
409
305
|
_BaseEntity.default.addNewChild(child, memberSubject.groups);
|
|
410
|
-
|
|
411
306
|
return [groupSubject, memberSubject];
|
|
412
307
|
} catch (e) {
|
|
413
308
|
if (!childResource.voided) {
|
|
@@ -417,83 +312,66 @@ class Individual extends _BaseEntity.default {
|
|
|
417
312
|
}
|
|
418
313
|
}
|
|
419
314
|
}
|
|
420
|
-
|
|
421
315
|
static associateChildToMultipleParents(child, childEntityClass, childResource, entityService) {
|
|
422
316
|
if (childEntityClass === _GroupSubject.default) {
|
|
423
317
|
return Individual.associateGroupSubject(child, childEntityClass, childResource, entityService);
|
|
424
318
|
}
|
|
425
319
|
}
|
|
426
|
-
|
|
427
320
|
static associateChild(child, childEntityClass, childResource, entityService) {
|
|
428
321
|
if (childEntityClass === _IndividualRelationship.default) {
|
|
429
322
|
return Individual.associateRelationship(child, childEntityClass, childResource, entityService);
|
|
430
323
|
}
|
|
431
|
-
|
|
432
324
|
const parentIdField = childEntityClass === _EntityApprovalStatus.default ? "entityUUID" : "individualUUID";
|
|
433
|
-
|
|
434
325
|
let realmIndividual = _BaseEntity.default.getParentEntity(entityService, childEntityClass, childResource, parentIdField, Individual.schema.name);
|
|
435
|
-
|
|
436
326
|
realmIndividual = _General.default.pick(realmIndividual, ["uuid", "latestEntityApprovalStatus"], ["enrolments", "encounters", "relationships", "groupSubjects", "comments", "groups", "approvalStatuses"]);
|
|
437
327
|
if (childEntityClass === _ProgramEnrolment.default) _BaseEntity.default.addNewChild(child, realmIndividual.enrolments);else if (childEntityClass === _Encounter.default) _BaseEntity.default.addNewChild(child, realmIndividual.encounters);else if (childEntityClass === _Comment.default) _BaseEntity.default.addNewChild(child, realmIndividual.comments);else if (childEntityClass === _EntityApprovalStatus.default) {
|
|
438
328
|
_BaseEntity.default.addNewChild(child, realmIndividual.approvalStatuses);
|
|
439
|
-
|
|
440
329
|
realmIndividual.latestEntityApprovalStatus = _lodash.default.maxBy(realmIndividual.approvalStatuses, 'statusDateTime');
|
|
441
330
|
} else throw `${childEntityClass.name} not support by ${realmIndividual.nameString}`;
|
|
442
331
|
return realmIndividual;
|
|
443
332
|
}
|
|
444
|
-
|
|
445
333
|
setFirstName(firstName) {
|
|
446
334
|
this.firstName = firstName;
|
|
447
335
|
this.name = this.nameString;
|
|
448
336
|
}
|
|
449
|
-
|
|
450
337
|
setMiddleName(middleName) {
|
|
451
338
|
this.middleName = middleName;
|
|
452
339
|
this.name = this.nameString;
|
|
453
340
|
}
|
|
454
|
-
|
|
455
341
|
setLastName(lastName) {
|
|
456
342
|
this.lastName = lastName;
|
|
457
343
|
this.name = this.nameString;
|
|
458
344
|
}
|
|
459
|
-
|
|
460
345
|
getAgeAndDateOfBirthDisplay(i18n) {
|
|
461
346
|
if (this.dateOfBirthVerified) return `${_AgeUtil.default.getDisplayAge(this.dateOfBirth, i18n)} (${_General.default.toDisplayDate(this.dateOfBirth)})`;
|
|
462
347
|
return _AgeUtil.default.getDisplayAge(this.dateOfBirth, i18n);
|
|
463
348
|
}
|
|
464
|
-
|
|
465
349
|
getAgeInYears(asOnDate = (0, _moment.default)(), precise = false) {
|
|
466
350
|
return _AgeUtil.default.getAgeInYears(this.dateOfBirth, asOnDate, precise);
|
|
467
351
|
}
|
|
468
|
-
|
|
469
352
|
getAgeInMonths(asOnDate = (0, _moment.default)(), precise = false) {
|
|
470
353
|
return _AgeUtil.default.getAgeInMonths(this.dateOfBirth, asOnDate, precise);
|
|
471
354
|
}
|
|
472
|
-
|
|
473
355
|
getAgeInWeeks(asOnDate = (0, _moment.default)(), precise = false) {
|
|
474
356
|
return _AgeUtil.default.getAgeInWeeks(this.dateOfBirth, asOnDate, precise);
|
|
475
357
|
}
|
|
476
|
-
|
|
477
358
|
getAge(asOnDate = (0, _moment.default)()) {
|
|
478
359
|
if (this.getAgeInYears(asOnDate) > 0) return _Duration.default.inYear(this.getAgeInYears());
|
|
479
360
|
if (this.getAgeInMonths(asOnDate) > 0) return _Duration.default.inMonth(asOnDate.diff(this.dateOfBirth, "months"));
|
|
480
361
|
return _Duration.default.inYear(0);
|
|
481
362
|
}
|
|
482
|
-
|
|
483
363
|
getTranslatedNameString(i18n) {
|
|
484
364
|
return this.isPerson() ? Individual.getFullName(this) : this.subjectType.type === _SubjectType.default.types.User ? `${this.firstName}(${i18n.t('you')})` : this.firstName;
|
|
485
365
|
}
|
|
486
|
-
|
|
487
366
|
get nameString() {
|
|
488
367
|
return this.isPerson() ? Individual.getFullName(this) : this.subjectType.type === _SubjectType.default.types.User ? `${this.firstName}(You)` : this.firstName;
|
|
489
368
|
}
|
|
490
|
-
|
|
491
369
|
static getFullName(obj) {
|
|
492
370
|
let name = `${obj.firstName} ${obj.middleName ? obj.middleName : ''}`.trim();
|
|
493
371
|
return `${name} ${obj.lastName ? obj.lastName : ''}`.trim();
|
|
494
|
-
}
|
|
495
|
-
|
|
372
|
+
}
|
|
496
373
|
|
|
374
|
+
//TODO: this will be fixed later where we specify the option to create a template to display another unique field along with the name
|
|
497
375
|
get nameStringWithUniqueAttribute() {
|
|
498
376
|
if (this.subjectType.name === 'Farmer') {
|
|
499
377
|
const mobileNumber = this.getObservationReadableValue('Mobile Number', null);
|
|
@@ -503,21 +381,17 @@ class Individual extends _BaseEntity.default {
|
|
|
503
381
|
return this.nameString;
|
|
504
382
|
}
|
|
505
383
|
}
|
|
506
|
-
|
|
507
384
|
toSummaryString() {
|
|
508
385
|
return `${this.name}, Age: ${this.getAge().toString()}, ${this.gender.name}`;
|
|
509
386
|
}
|
|
510
|
-
|
|
511
387
|
setDateOfBirth(date) {
|
|
512
388
|
this.dateOfBirth = (0, _moment.default)(date).startOf('day').toDate();
|
|
513
389
|
this.dateOfBirthVerified = true;
|
|
514
390
|
}
|
|
515
|
-
|
|
516
391
|
setAge(age, isInYears) {
|
|
517
392
|
this.dateOfBirth = (0, _moment.default)().subtract(age, isInYears ? "years" : "months").startOf('day').toDate();
|
|
518
393
|
this.dateOfBirthVerified = false;
|
|
519
394
|
}
|
|
520
|
-
|
|
521
395
|
validateDateOfBirth() {
|
|
522
396
|
if (_lodash.default.isNil(this.dateOfBirth)) {
|
|
523
397
|
return _ValidationResult.default.failure(Individual.validationKeys.DOB, "emptyValidationMessage");
|
|
@@ -533,33 +407,25 @@ class Individual extends _BaseEntity.default {
|
|
|
533
407
|
return _ValidationResult.default.successful(Individual.validationKeys.DOB);
|
|
534
408
|
}
|
|
535
409
|
}
|
|
536
|
-
|
|
537
410
|
get isRegistrationBeforeDateOfBirth() {
|
|
538
411
|
if (_lodash.default.isNil(this.dateOfBirth) || _lodash.default.isNil(this.registrationDate)) return false;
|
|
539
412
|
return _General.default.dateAIsAfterB(this.dateOfBirth, this.registrationDate);
|
|
540
413
|
}
|
|
541
|
-
|
|
542
414
|
validateRegistrationDate() {
|
|
543
415
|
const validationResult = this.validateFieldForEmpty(this.registrationDate, Individual.validationKeys.REGISTRATION_DATE);
|
|
544
|
-
|
|
545
416
|
if (validationResult.success && !(0, _moment.default)(this.registrationDate).isValid()) {
|
|
546
417
|
return _ValidationResult.default.failure(Individual.validationKeys.REGISTRATION_DATE, "invalidDateFormat");
|
|
547
418
|
}
|
|
548
|
-
|
|
549
419
|
if (validationResult.success && this.isRegistrationBeforeDateOfBirth) {
|
|
550
420
|
return _ValidationResult.default.failure(Individual.validationKeys.REGISTRATION_DATE, "registrationBeforeDateOfBirth");
|
|
551
421
|
}
|
|
552
|
-
|
|
553
422
|
if (validationResult.success && _General.default.dateIsAfterToday(this.registrationDate)) {
|
|
554
423
|
return _ValidationResult.default.failure(Individual.validationKeys.REGISTRATION_DATE, "registrationDateInFuture");
|
|
555
424
|
}
|
|
556
|
-
|
|
557
425
|
return validationResult;
|
|
558
426
|
}
|
|
559
|
-
|
|
560
427
|
validateName(value, validationKey, validFormat, mandatory = true) {
|
|
561
428
|
const validationResult = new _ValidationResult.default(false, validationKey);
|
|
562
|
-
|
|
563
429
|
if (_lodash.default.isEmpty(value) && !mandatory) {
|
|
564
430
|
return new _ValidationResult.default(true, validationKey, null);
|
|
565
431
|
} else if (_lodash.default.isEmpty(value)) {
|
|
@@ -569,89 +435,68 @@ class Individual extends _BaseEntity.default {
|
|
|
569
435
|
} else {
|
|
570
436
|
return new _ValidationResult.default(true, validationKey, null);
|
|
571
437
|
}
|
|
572
|
-
|
|
573
438
|
return validationResult;
|
|
574
439
|
}
|
|
575
|
-
|
|
576
440
|
validateFirstName() {
|
|
577
441
|
return this.validateName(this.firstName, Individual.validationKeys.FIRST_NAME, this.subjectType.validFirstNameFormat);
|
|
578
442
|
}
|
|
579
|
-
|
|
580
443
|
validateMiddleName() {
|
|
581
444
|
return this.validateName(this.middleName, Individual.validationKeys.MIDDLE_NAME, this.subjectType.validMiddleNameFormat, false);
|
|
582
445
|
}
|
|
583
|
-
|
|
584
446
|
validateLastName() {
|
|
585
447
|
return this.validateName(this.lastName, Individual.validationKeys.LAST_NAME, this.subjectType.validLastNameFormat, !this.subjectType.lastNameOptional);
|
|
586
448
|
}
|
|
587
|
-
|
|
588
449
|
validateRegistrationLocation() {
|
|
589
450
|
return this.validateFieldForNull(this.registrationLocation, Individual.validationKeys.REGISTRATION_LOCATION);
|
|
590
451
|
}
|
|
591
|
-
|
|
592
452
|
validate() {
|
|
593
453
|
const validationResults = [];
|
|
594
|
-
|
|
595
454
|
if (!this.subjectType.allowEmptyLocation) {
|
|
596
455
|
validationResults.push(this.validateAddress());
|
|
597
456
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
457
|
+
validationResults.push(this.validateRegistrationDate());
|
|
458
|
+
//validationResults.push(this.validateRegistrationLocation());
|
|
601
459
|
validationResults.push(this.validateFirstName());
|
|
602
|
-
|
|
603
460
|
if (this.subjectType.isPerson()) {
|
|
604
461
|
if (this.subjectType.allowMiddleName) validationResults.push(this.validateMiddleName());
|
|
605
462
|
validationResults.push(this.validateLastName());
|
|
606
463
|
validationResults.push(this.validateDateOfBirth());
|
|
607
464
|
validationResults.push(this.validateGender());
|
|
608
465
|
}
|
|
609
|
-
|
|
610
466
|
return validationResults;
|
|
611
467
|
}
|
|
612
|
-
|
|
613
468
|
validateAddress() {
|
|
614
469
|
let validateAddressFieldForEmpty = this.validateFieldForEmpty(_lodash.default.isEmpty(this.lowestAddressLevel) ? undefined : this.lowestAddressLevel.name, Individual.validationKeys.LOWEST_ADDRESS_LEVEL);
|
|
615
470
|
return validateAddressFieldForEmpty;
|
|
616
471
|
}
|
|
617
|
-
|
|
618
472
|
validateGender() {
|
|
619
473
|
return this.validateFieldForEmpty(_lodash.default.isEmpty(this.gender) ? undefined : this.gender.name, Individual.validationKeys.GENDER);
|
|
620
474
|
}
|
|
621
|
-
|
|
622
475
|
isGender(gender) {
|
|
623
476
|
return this.gender === gender;
|
|
624
477
|
}
|
|
625
|
-
|
|
626
478
|
staticallyEligiblePrograms(allPrograms) {
|
|
627
479
|
const programs = _lodash.default.slice(allPrograms);
|
|
628
|
-
|
|
629
480
|
_ArrayHelper.default.remove(programs, program => {
|
|
630
481
|
const find = _lodash.default.find(this.nonVoidedEnrolments(), enrolment => {
|
|
631
482
|
return enrolment.program.uuid === program.uuid && enrolment.isActive && !enrolment.program.allowMultipleEnrolments;
|
|
632
483
|
});
|
|
633
|
-
|
|
634
484
|
return find !== undefined;
|
|
635
485
|
});
|
|
636
|
-
|
|
637
486
|
return programs;
|
|
638
487
|
}
|
|
639
|
-
|
|
640
488
|
addEncounter(encounter) {
|
|
641
489
|
if (!_lodash.default.some(this.encounters, it => it.uuid === encounter.uuid)) {
|
|
642
490
|
this.encounters = this.encounters || [];
|
|
643
491
|
this.encounters.push(encounter);
|
|
644
492
|
}
|
|
645
493
|
}
|
|
646
|
-
|
|
647
494
|
nonVoidedEncounters() {
|
|
648
495
|
return _lodash.default.reject(this.encounters, "voided");
|
|
649
496
|
}
|
|
650
|
-
|
|
651
497
|
nonVoidedEnrolments() {
|
|
652
498
|
return this.enrolments.filter(x => !x.voided);
|
|
653
499
|
}
|
|
654
|
-
|
|
655
500
|
cloneForEdit() {
|
|
656
501
|
const individual = new Individual();
|
|
657
502
|
individual.uuid = this.uuid;
|
|
@@ -678,7 +523,6 @@ class Individual extends _BaseEntity.default {
|
|
|
678
523
|
individual.approvalStatuses = this.approvalStatuses;
|
|
679
524
|
return individual;
|
|
680
525
|
}
|
|
681
|
-
|
|
682
526
|
cloneForReference() {
|
|
683
527
|
const individual = new Individual();
|
|
684
528
|
individual.uuid = this.uuid;
|
|
@@ -691,155 +535,122 @@ class Individual extends _BaseEntity.default {
|
|
|
691
535
|
individual.gender = _lodash.default.isNil(this.gender) ? null : this.gender.clone();
|
|
692
536
|
return individual;
|
|
693
537
|
}
|
|
694
|
-
|
|
695
538
|
get hasActiveEnrolment() {
|
|
696
539
|
return _lodash.default.some(this.nonVoidedEnrolments(), enrolment => enrolment.isActive);
|
|
697
540
|
}
|
|
698
|
-
|
|
699
541
|
get firstActiveOrRecentEnrolment() {
|
|
700
542
|
return (0, _lodash.default)(this.nonVoidedEnrolments()).sortBy(["isActive", "enrolmentDateTime"]).last();
|
|
701
543
|
}
|
|
702
|
-
|
|
703
544
|
get hasEnrolments() {
|
|
704
545
|
return this.nonVoidedEnrolments().length;
|
|
705
546
|
}
|
|
706
|
-
|
|
707
547
|
findEnrolment(enrolmentUUID) {
|
|
708
548
|
return _lodash.default.find(this.nonVoidedEnrolments(), enrolment => enrolment.uuid === enrolmentUUID);
|
|
709
549
|
}
|
|
710
|
-
|
|
711
550
|
addEnrolment(programEnrolment) {
|
|
712
551
|
if (!_lodash.default.some(this.enrolments, x => x.uuid === programEnrolment.uuid)) {
|
|
713
552
|
this.enrolments.push(programEnrolment);
|
|
714
553
|
}
|
|
715
554
|
}
|
|
716
|
-
|
|
717
555
|
addRelationship(relationship) {
|
|
718
556
|
if (!_lodash.default.some(this.relationships, x => x.uuid === relationship.uuid)) {
|
|
719
557
|
this.relationships = _lodash.default.isEmpty(this.relationships) ? [] : this.relationships;
|
|
720
558
|
this.relationships.push(relationship);
|
|
721
559
|
}
|
|
722
560
|
}
|
|
723
|
-
|
|
724
561
|
addGroupSubject(groupSubject) {
|
|
725
562
|
if (!_lodash.default.some(this.groupSubjects, x => x.uuid === groupSubject.uuid)) {
|
|
726
563
|
this.groupSubjects = _lodash.default.isEmpty(this.groupSubjects) ? [] : this.groupSubjects;
|
|
727
564
|
this.groupSubjects.push(groupSubject);
|
|
728
565
|
}
|
|
729
566
|
}
|
|
730
|
-
|
|
731
567
|
addGroup(groupSubject) {
|
|
732
568
|
if (!_lodash.default.some(this.groups, x => x.uuid === groupSubject.uuid)) {
|
|
733
569
|
this.groups = _lodash.default.isEmpty(this.groups) ? [] : this.groups;
|
|
734
570
|
this.groups.push(groupSubject);
|
|
735
571
|
}
|
|
736
572
|
}
|
|
737
|
-
|
|
738
573
|
addComment(comment) {
|
|
739
574
|
if (!_lodash.default.some(this.comments, x => x.uuid === comment.uuid)) {
|
|
740
575
|
this.comments = _lodash.default.isEmpty(this.comments) ? [] : this.comments;
|
|
741
576
|
this.comments.push(comment);
|
|
742
577
|
}
|
|
743
578
|
}
|
|
744
|
-
|
|
745
579
|
findObservation(conceptNameOrUuid, parentConceptNameOrUuid) {
|
|
746
580
|
const observations = _lodash.default.isNil(parentConceptNameOrUuid) ? this.observations : this.findGroupedObservation(parentConceptNameOrUuid);
|
|
747
581
|
return _lodash.default.find(observations, observation => {
|
|
748
582
|
return observation.concept.name === conceptNameOrUuid || observation.concept.uuid === conceptNameOrUuid;
|
|
749
583
|
});
|
|
750
584
|
}
|
|
751
|
-
|
|
752
585
|
findGroupedObservation(parentConceptNameOrUuid) {
|
|
753
586
|
const groupedObservations = _lodash.default.find(this.observations, observation => observation.concept.name === parentConceptNameOrUuid || observation.concept.uuid === parentConceptNameOrUuid);
|
|
754
|
-
|
|
755
587
|
return _lodash.default.isEmpty(groupedObservations) ? [] : groupedObservations.getValue();
|
|
756
588
|
}
|
|
757
|
-
|
|
758
589
|
getObservationValue(conceptNameOrUuid, parentConceptNameOrUuid) {
|
|
759
590
|
const observationForConcept = this.findObservation(conceptNameOrUuid, parentConceptNameOrUuid);
|
|
760
591
|
return _lodash.default.isEmpty(observationForConcept) ? observationForConcept : observationForConcept.getValue();
|
|
761
592
|
}
|
|
762
|
-
|
|
763
593
|
getRelationships() {
|
|
764
594
|
return _lodash.default.filter(this.relationships, v => !v.voided);
|
|
765
595
|
}
|
|
766
|
-
|
|
767
596
|
getGroupSubjects() {
|
|
768
597
|
return _lodash.default.filter(this.groupSubjects, g => !g.voided);
|
|
769
598
|
}
|
|
770
|
-
|
|
771
599
|
getGroups() {
|
|
772
600
|
return _lodash.default.filter(this.groups, g => !g.voided);
|
|
773
601
|
}
|
|
774
|
-
|
|
775
602
|
getRelative(relationName, inverse = false) {
|
|
776
603
|
return _lodash.default.head(this.getRelatives(relationName, inverse));
|
|
777
604
|
}
|
|
778
|
-
|
|
779
605
|
getRelatives(relationName, inverse = false) {
|
|
780
606
|
return _lodash.default.filter(this.getRelationships(), relation => {
|
|
781
607
|
return inverse ? relation.relationship.individualAIsToBRelation.name === relationName : relation.relationship.individualBIsToARelation.name === relationName;
|
|
782
608
|
}).map(relation => relation.individualB);
|
|
783
609
|
}
|
|
784
|
-
|
|
785
610
|
getPreviousEnrolment(programName, enrolmentUUID) {
|
|
786
611
|
const chronologicalEnrolments = this.chronologicalEnrolments;
|
|
787
|
-
|
|
788
612
|
let index = _lodash.default.findIndex(chronologicalEnrolments, enrolment => enrolment.uuid === enrolmentUUID);
|
|
789
|
-
|
|
790
613
|
while (index > 0) {
|
|
791
614
|
if (chronologicalEnrolments[--index].program.name === programName) return chronologicalEnrolments[index];
|
|
792
615
|
}
|
|
793
|
-
|
|
794
616
|
return null;
|
|
795
617
|
}
|
|
796
|
-
|
|
797
618
|
get chronologicalEnrolments() {
|
|
798
619
|
return _lodash.default.sortBy(this.nonVoidedEnrolments(), enrolment => enrolment.encounterDateTime);
|
|
799
620
|
}
|
|
800
|
-
|
|
801
621
|
getProfilePicture() {
|
|
802
622
|
return this.profilePicture;
|
|
803
623
|
}
|
|
804
|
-
|
|
805
624
|
updateProfilePicture(newValue) {
|
|
806
625
|
this.profilePicture = newValue;
|
|
807
626
|
}
|
|
808
|
-
|
|
809
627
|
findMediaObservations() {
|
|
810
628
|
return (0, _Media.findMediaObservations)(this.observations);
|
|
811
629
|
}
|
|
812
|
-
|
|
813
630
|
replaceMediaObservation(originalValue, newValue, conceptUUID) {
|
|
814
631
|
new _ObservationsHolder.default(this.observations).replaceMediaObservation(originalValue, newValue, conceptUUID);
|
|
815
632
|
}
|
|
816
|
-
|
|
817
633
|
replaceObservation(originalValue, newValue) {
|
|
818
634
|
new _ObservationsHolder.default(this.observations).updateObservationBasedOnValue(originalValue, newValue);
|
|
819
|
-
}
|
|
820
|
-
|
|
635
|
+
}
|
|
821
636
|
|
|
637
|
+
//TODO use polymorphism to avoid if checks based on this
|
|
822
638
|
isPerson() {
|
|
823
639
|
//TODO this nil check is not required when migration works properly
|
|
824
640
|
return _lodash.default.isNil(this.subjectType) || this.subjectType.isPerson();
|
|
825
641
|
}
|
|
826
|
-
|
|
827
642
|
isHousehold() {
|
|
828
643
|
return this.subjectType.isHousehold();
|
|
829
644
|
}
|
|
830
|
-
|
|
831
645
|
isGroup() {
|
|
832
646
|
return this.subjectType.isGroup();
|
|
833
647
|
}
|
|
834
|
-
|
|
835
648
|
isUniqueName() {
|
|
836
649
|
return !!this.subjectType.uniqueName;
|
|
837
650
|
}
|
|
838
|
-
|
|
839
651
|
get subjectTypeName() {
|
|
840
652
|
return this.subjectType.name;
|
|
841
653
|
}
|
|
842
|
-
|
|
843
654
|
getHeadOfHouseholdGroupSubject() {
|
|
844
655
|
return _lodash.default.find(this.groupSubjects.filter(({
|
|
845
656
|
voided
|
|
@@ -847,96 +658,76 @@ class Individual extends _BaseEntity.default {
|
|
|
847
658
|
groupRole
|
|
848
659
|
}) => groupRole.isHeadOfHousehold);
|
|
849
660
|
}
|
|
850
|
-
|
|
851
661
|
userProfileSubtext1(i18n) {
|
|
852
662
|
return this.isPerson() ? i18n.t(this.gender.name) : "";
|
|
853
663
|
}
|
|
854
|
-
|
|
855
664
|
userProfileSubtext2(i18n) {
|
|
856
665
|
return this.isPerson() ? _AgeUtil.default.getDisplayAge(this.dateOfBirth, i18n) : "";
|
|
857
666
|
}
|
|
858
|
-
|
|
859
667
|
lowestTwoLevelAddress(i18n) {
|
|
860
668
|
if (!_lodash.default.isNil(this.lowestAddressLevel)) {
|
|
861
669
|
let addressText = i18n.t(this.lowestAddressLevel.name);
|
|
862
|
-
|
|
863
670
|
const parentAddress = _lodash.default.get(this.lowestAddressLevel.getParent(), "name");
|
|
864
|
-
|
|
865
671
|
if (!_lodash.default.isNil(parentAddress)) addressText += ', ' + i18n.t(parentAddress);
|
|
866
672
|
return addressText;
|
|
867
673
|
}
|
|
868
|
-
|
|
869
674
|
return '';
|
|
870
675
|
}
|
|
871
|
-
|
|
872
676
|
fullAddress(i18n) {
|
|
873
677
|
let lineage = this.lowestAddressLevel.getLineage();
|
|
874
678
|
return _lodash.default.join(_lodash.default.reverse(lineage).map(x => i18n.t(x.name)), ", ");
|
|
875
|
-
}
|
|
876
|
-
|
|
679
|
+
}
|
|
877
680
|
|
|
681
|
+
//TODO these methods are slightly differece because of differece in UI on search result and my dashboard listing. Not taking the hit right now.
|
|
878
682
|
detail1(i18n) {
|
|
879
683
|
return this.isPerson() ? {
|
|
880
684
|
label: "Age",
|
|
881
685
|
value: _AgeUtil.default.getDisplayAge(this.dateOfBirth, i18n)
|
|
882
686
|
} : {};
|
|
883
687
|
}
|
|
884
|
-
|
|
885
688
|
detail2(i18n) {
|
|
886
689
|
return this.isPerson() ? {
|
|
887
690
|
label: "Gender",
|
|
888
691
|
value: i18n.t(this.gender.name)
|
|
889
692
|
} : {};
|
|
890
693
|
}
|
|
891
|
-
|
|
892
694
|
address(i18n) {
|
|
893
695
|
return {
|
|
894
696
|
label: "Address",
|
|
895
697
|
value: i18n.t(this.lowestAddressLevel.name)
|
|
896
698
|
};
|
|
897
699
|
}
|
|
898
|
-
|
|
899
700
|
_getEncounters(removeCancelledEncounters) {
|
|
900
701
|
return _lodash.default.chain(this.nonVoidedEncounters()).filter(encounter => removeCancelledEncounters ? _lodash.default.isNil(encounter.cancelDateTime) : true).sortBy(encounter => (0, _moment.default)().diff(encounter.encounterDateTime));
|
|
901
702
|
}
|
|
902
|
-
|
|
903
703
|
getEncounters(removeCancelledEncounters) {
|
|
904
704
|
return this._getEncounters(removeCancelledEncounters).value();
|
|
905
705
|
}
|
|
906
|
-
|
|
907
706
|
scheduledEncounters() {
|
|
908
707
|
return _lodash.default.filter(this.getEncounters(true), encounter => !encounter.encounterDateTime && _lodash.default.isNil(encounter.cancelDateTime));
|
|
909
708
|
}
|
|
910
|
-
|
|
911
709
|
everScheduledEncounters() {
|
|
912
710
|
return _lodash.default.filter(this.getEncounters(true), encounter => !_lodash.default.isNil(encounter.earliestVisitDateTime) && _lodash.default.isNil(encounter.cancelDateTime));
|
|
913
711
|
}
|
|
914
|
-
|
|
915
712
|
scheduledEncountersOfType(encounterTypeName) {
|
|
916
713
|
return this.scheduledEncounters().filter(scheduledEncounter => scheduledEncounter.encounterType.name === encounterTypeName);
|
|
917
714
|
}
|
|
918
|
-
|
|
919
715
|
everScheduledEncountersOfType(encounterTypeName) {
|
|
920
716
|
return this.everScheduledEncounters().filter(scheduledEncounter => scheduledEncounter.encounterType.name === encounterTypeName);
|
|
921
717
|
}
|
|
922
|
-
|
|
923
718
|
findObservationInLastEncounter(conceptNameOrUuid, currentEncounter) {
|
|
924
719
|
const lastEncounter = this.findLastEncounterOfType(currentEncounter, _lodash.default.get(currentEncounter, 'encounterType'));
|
|
925
720
|
return lastEncounter ? lastEncounter.findObservation(conceptNameOrUuid) : null;
|
|
926
721
|
}
|
|
927
|
-
|
|
928
722
|
findLastEncounterOfType(currentEncounter, encounterTypes = []) {
|
|
929
723
|
return this.findNthLastEncounterOfType(currentEncounter, encounterTypes, 0);
|
|
930
724
|
}
|
|
931
|
-
|
|
932
725
|
findNthLastEncounterOfType(currentEncounter, encounterTypes = [], n = 0) {
|
|
933
726
|
return _lodash.default.chain(this.getEncounters(false)).filter(enc => enc.encounterDateTime).filter(enc => enc.encounterDateTime < currentEncounter.encounterDateTime).filter(enc => encounterTypes.some(encounterType => encounterType === enc.encounterType.name)).nth(n).value();
|
|
934
727
|
}
|
|
935
|
-
|
|
936
728
|
_findObservationWithDateFromAllEncounters(conceptNameOrUuid, encounters) {
|
|
937
729
|
let observation;
|
|
938
730
|
let encounter;
|
|
939
|
-
|
|
940
731
|
for (let i = 0; i < encounters.length; i++) {
|
|
941
732
|
encounter = encounters[i];
|
|
942
733
|
observation = encounters[i].findObservation(conceptNameOrUuid);
|
|
@@ -945,32 +736,23 @@ class Individual extends _BaseEntity.default {
|
|
|
945
736
|
date: encounter.encounterDateTime
|
|
946
737
|
};
|
|
947
738
|
}
|
|
948
|
-
|
|
949
739
|
return {};
|
|
950
740
|
}
|
|
951
|
-
|
|
952
741
|
_findObservationFromAllEncounters(conceptNameOrUuid, encounters) {
|
|
953
742
|
return this._findObservationWithDateFromAllEncounters(conceptNameOrUuid, encounters).observation;
|
|
954
743
|
}
|
|
955
|
-
|
|
956
744
|
findLatestObservationFromPreviousEncounters(conceptNameOrUuid, currentEncounter) {
|
|
957
745
|
const encounters = _lodash.default.chain(this.getEncounters(false)).filter(enc => enc.encounterDateTime).filter(enc => enc.encounterDateTime < currentEncounter.encounterDateTime).value();
|
|
958
|
-
|
|
959
746
|
return this._findObservationFromAllEncounters(conceptNameOrUuid, encounters);
|
|
960
747
|
}
|
|
961
|
-
|
|
962
748
|
findLatestObservationFromEncounters(conceptNameOrUuid, currentEncounter) {
|
|
963
749
|
const previousEncounters = _lodash.default.chain(this.getEncounters(false)).filter(enc => enc.encounterDateTime).filter(enc => currentEncounter ? enc.encounterDateTime < currentEncounter.encounterDateTime : true).value();
|
|
964
|
-
|
|
965
750
|
const encounters = _lodash.default.chain(currentEncounter).concat(previousEncounters).compact().value();
|
|
966
|
-
|
|
967
751
|
return this._findObservationFromAllEncounters(conceptNameOrUuid, encounters);
|
|
968
752
|
}
|
|
969
|
-
|
|
970
753
|
scheduledEncountersOfType(encounterTypeName) {
|
|
971
754
|
return this.scheduledEncounters().filter(scheduledEncounter => scheduledEncounter.encounterType.name === encounterTypeName);
|
|
972
755
|
}
|
|
973
|
-
|
|
974
756
|
getAllScheduledVisits(currentEncounter) {
|
|
975
757
|
return _lodash.default.defaults(this.scheduledEncounters(), []).filter(encounter => encounter.uuid !== currentEncounter.uuid).map(_lodash.default.identity).map(({
|
|
976
758
|
uuid,
|
|
@@ -986,74 +768,57 @@ class Individual extends _BaseEntity.default {
|
|
|
986
768
|
uuid: uuid
|
|
987
769
|
}));
|
|
988
770
|
}
|
|
989
|
-
|
|
990
771
|
getMobileNo() {
|
|
991
772
|
for (let i = 0; i < this.observations.length; i++) {
|
|
992
773
|
const observation = this.observations[i];
|
|
993
774
|
const mobileNo = observation.getMobileNo();
|
|
994
|
-
|
|
995
775
|
if (mobileNo) {
|
|
996
776
|
return mobileNo;
|
|
997
777
|
}
|
|
998
778
|
}
|
|
999
779
|
}
|
|
1000
|
-
|
|
1001
780
|
getObservationReadableValue(conceptNameOrUuid, parentConceptNameOrUuid) {
|
|
1002
781
|
const observationForConcept = this.findObservation(conceptNameOrUuid, parentConceptNameOrUuid);
|
|
1003
782
|
return _lodash.default.isEmpty(observationForConcept) ? observationForConcept : observationForConcept.getReadableValue();
|
|
1004
783
|
}
|
|
1005
|
-
|
|
1006
784
|
get individual() {
|
|
1007
785
|
return this;
|
|
1008
786
|
}
|
|
1009
|
-
|
|
1010
787
|
getEntityTypeName() {
|
|
1011
788
|
return this.subjectTypeName;
|
|
1012
789
|
}
|
|
1013
|
-
|
|
1014
790
|
getName() {
|
|
1015
791
|
return 'Registration';
|
|
1016
792
|
}
|
|
1017
|
-
|
|
1018
793
|
isRejectedEntity() {
|
|
1019
794
|
return this.latestEntityApprovalStatus && this.latestEntityApprovalStatus.isRejected;
|
|
1020
795
|
}
|
|
1021
|
-
|
|
1022
796
|
getMobileNumber() {
|
|
1023
797
|
const mobileNumberObs = _lodash.default.find(this.observations, obs => obs.concept.isMobileNo());
|
|
1024
|
-
|
|
1025
798
|
if (!_lodash.default.isNil(mobileNumberObs)) {
|
|
1026
799
|
return mobileNumberObs.getReadableValue();
|
|
1027
800
|
}
|
|
1028
801
|
}
|
|
1029
|
-
|
|
1030
802
|
hasProgramEncounterOfType(encounterTypes) {
|
|
1031
803
|
return _lodash.default.some(this.enrolments, enrolment => _lodash.default.some(enrolment.encounters, encounter => _lodash.default.some(encounterTypes, encounterType => encounterType.uuid === encounter.encounterType.uuid)));
|
|
1032
804
|
}
|
|
1033
|
-
|
|
1034
805
|
hasEncounterOfType(encounterTypes) {
|
|
1035
806
|
return _lodash.default.some(this.encounters, encounter => _lodash.default.some(encounterTypes, encounterType => encounterType.uuid === encounter.encounterType.uuid));
|
|
1036
807
|
}
|
|
1037
|
-
|
|
1038
808
|
setLatestEntityApprovalStatus(entityApprovalStatus) {
|
|
1039
809
|
this.that.latestEntityApprovalStatus = this.fromObject(entityApprovalStatus);
|
|
1040
810
|
}
|
|
1041
|
-
|
|
1042
811
|
getMemberEntitiesWithLatestStatus(approvalStatus_status) {
|
|
1043
812
|
let descendants = [];
|
|
1044
813
|
if (!_lodash.default.isNil(this.latestEntityApprovalStatus) && this.latestEntityApprovalStatus.hasStatus(approvalStatus_status)) descendants.push(this);
|
|
1045
|
-
|
|
1046
814
|
_EntityApprovalStatus.default.addMatchingApprovalStatusEntity(this.nonVoidedEncounters(), approvalStatus_status, descendants, "encounterType.uuid");
|
|
1047
|
-
|
|
1048
815
|
_EntityApprovalStatus.default.addMatchingApprovalStatusEntity(this.nonVoidedEnrolments(), approvalStatus_status, descendants, "program.uuid");
|
|
1049
|
-
|
|
1050
816
|
this.nonVoidedEnrolments().forEach(enrolment => {
|
|
1051
817
|
const latestEntity = enrolment.addApprovalDescendantsWithLatestStatus(approvalStatus_status, descendants);
|
|
1052
818
|
if (!_lodash.default.isNil(latestEntity)) descendants.push(latestEntity);
|
|
1053
819
|
});
|
|
1054
820
|
return descendants;
|
|
1055
821
|
}
|
|
1056
|
-
|
|
1057
822
|
toJSON() {
|
|
1058
823
|
return {
|
|
1059
824
|
uuid: this.uuid,
|
|
@@ -1078,21 +843,16 @@ class Individual extends _BaseEntity.default {
|
|
|
1078
843
|
comments: this.comments
|
|
1079
844
|
};
|
|
1080
845
|
}
|
|
1081
|
-
|
|
1082
846
|
getSchemaName() {
|
|
1083
847
|
return _SchemaNames.default.Individual;
|
|
1084
848
|
}
|
|
1085
|
-
|
|
1086
849
|
updateAudit(userInfo, isNew) {
|
|
1087
850
|
(0, _AuditUtil.updateAuditFields)(this, userInfo, isNew);
|
|
1088
851
|
}
|
|
1089
|
-
|
|
1090
852
|
static getAddressLevelDummyUUID() {
|
|
1091
853
|
return ADDRESS_LEVEL_DUMMY_UUID;
|
|
1092
854
|
}
|
|
1093
|
-
|
|
1094
855
|
}
|
|
1095
|
-
|
|
1096
856
|
_defineProperty(Individual, "schema", {
|
|
1097
857
|
name: _SchemaNames.default.Individual,
|
|
1098
858
|
primaryKey: "uuid",
|
|
@@ -1182,7 +942,6 @@ _defineProperty(Individual, "schema", {
|
|
|
1182
942
|
}
|
|
1183
943
|
}, _AuditUtil.AuditFields)
|
|
1184
944
|
});
|
|
1185
|
-
|
|
1186
945
|
_defineProperty(Individual, "validationKeys", {
|
|
1187
946
|
DOB: "DOB",
|
|
1188
947
|
GENDER: "GENDER",
|
|
@@ -1195,7 +954,6 @@ _defineProperty(Individual, "validationKeys", {
|
|
|
1195
954
|
REGISTRATION_LOCATION: "REGISTRATION_LOCATION",
|
|
1196
955
|
NAME: "NAME"
|
|
1197
956
|
});
|
|
1198
|
-
|
|
1199
957
|
_defineProperty(Individual, "nonIndividualValidationKeys", {
|
|
1200
958
|
FIRST_NAME: "FIRST_NAME",
|
|
1201
959
|
REGISTRATION_DATE: "REGISTRATION_DATE",
|
|
@@ -1203,23 +961,17 @@ _defineProperty(Individual, "nonIndividualValidationKeys", {
|
|
|
1203
961
|
REGISTRATION_LOCATION: "REGISTRATION_LOCATION",
|
|
1204
962
|
NAME: "NAME"
|
|
1205
963
|
});
|
|
1206
|
-
|
|
1207
964
|
_defineProperty(Individual, "directCopyFields", ["uuid", "firstName", "middleName", "lastName", "profilePicture", "dateOfBirthVerified", "voided"]);
|
|
1208
|
-
|
|
1209
965
|
_defineProperty(Individual, "dateFields", ["dateOfBirth", "registrationDate"]);
|
|
1210
|
-
|
|
1211
966
|
_defineProperty(Individual, "merge", childEntityName => {
|
|
1212
967
|
return _MergeUtil.default.getMergeFunction(childEntityName, mergeMap);
|
|
1213
968
|
});
|
|
1214
|
-
|
|
1215
969
|
_defineProperty(Individual, "mergeMultipleParents", (childEntityClass, entities) => {
|
|
1216
970
|
if (childEntityClass === _GroupSubject.default.schema.name) {
|
|
1217
971
|
const individual = _lodash.default.head(entities);
|
|
1218
|
-
|
|
1219
972
|
const key = individual.subjectType.group ? 'groupSubjects' : 'groups';
|
|
1220
973
|
return _BaseEntity.default.mergeOn(key)(entities);
|
|
1221
974
|
}
|
|
1222
975
|
});
|
|
1223
|
-
|
|
1224
976
|
var _default = Individual;
|
|
1225
977
|
exports.default = _default;
|