openchs-models 1.22.1 → 1.22.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.
- package/dist/Individual.js +11 -5
- package/package.json +1 -1
package/dist/Individual.js
CHANGED
|
@@ -182,7 +182,7 @@ class Individual extends _BaseEntity.default {
|
|
|
182
182
|
|
|
183
183
|
individual.gender = gender;
|
|
184
184
|
individual.lowestAddressLevel = addressLevel;
|
|
185
|
-
individual.name = `${individual.firstName} ${individual.lastName}`;
|
|
185
|
+
individual.name = `${individual.firstName} ${individual.middleName ? individual.middleName : ''} ${individual.lastName}`;
|
|
186
186
|
if (!_lodash.default.isNil(individualResource.registrationLocation)) individual.registrationLocation = _Point.default.fromResource(individualResource.registrationLocation);
|
|
187
187
|
individual.subjectType = subjectType;
|
|
188
188
|
return individual;
|
|
@@ -256,6 +256,11 @@ class Individual extends _BaseEntity.default {
|
|
|
256
256
|
this.name = this.nameString;
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
+
setMiddleName(middleName) {
|
|
260
|
+
this.middleName = middleName;
|
|
261
|
+
this.name = this.nameString;
|
|
262
|
+
}
|
|
263
|
+
|
|
259
264
|
setLastName(lastName) {
|
|
260
265
|
this.lastName = lastName;
|
|
261
266
|
this.name = this.nameString;
|
|
@@ -287,7 +292,7 @@ class Individual extends _BaseEntity.default {
|
|
|
287
292
|
}
|
|
288
293
|
|
|
289
294
|
get nameString() {
|
|
290
|
-
return this.isPerson() ? `${this.firstName} ${this.lastName}` : this.firstName;
|
|
295
|
+
return this.isPerson() ? `${this.firstName} ${this.middleName ? this.middleName : ''} ${this.lastName}` : this.firstName;
|
|
291
296
|
} //TODO: this will be fixed later where we specify the option to create a template to display another unique field along with the name
|
|
292
297
|
|
|
293
298
|
|
|
@@ -370,10 +375,10 @@ class Individual extends _BaseEntity.default {
|
|
|
370
375
|
return validationResult;
|
|
371
376
|
}
|
|
372
377
|
|
|
373
|
-
validateName(value, validationKey, validFormat) {
|
|
378
|
+
validateName(value, validationKey, validFormat, mandatory = true) {
|
|
374
379
|
const failure = new _ValidationResult.default(false, validationKey);
|
|
375
380
|
|
|
376
|
-
if (_lodash.default.isEmpty(value)) {
|
|
381
|
+
if (_lodash.default.isEmpty(value) && mandatory) {
|
|
377
382
|
failure.messageKey = "emptyValidationMessage";
|
|
378
383
|
} else if (!_lodash.default.isEmpty(validFormat) && !validFormat.valid(value)) {
|
|
379
384
|
failure.messageKey = validFormat.descriptionKey;
|
|
@@ -389,7 +394,7 @@ class Individual extends _BaseEntity.default {
|
|
|
389
394
|
}
|
|
390
395
|
|
|
391
396
|
validateMiddleName() {
|
|
392
|
-
return this.validateName(this.middleName, Individual.validationKeys.MIDDLE_NAME, this.subjectType.validMiddleNameFormat);
|
|
397
|
+
if (this.subjectType.allowMiddleName) return this.validateName(this.middleName, Individual.validationKeys.MIDDLE_NAME, this.subjectType.validMiddleNameFormat, false);
|
|
393
398
|
}
|
|
394
399
|
|
|
395
400
|
validateLastName() {
|
|
@@ -412,6 +417,7 @@ class Individual extends _BaseEntity.default {
|
|
|
412
417
|
validationResults.push(this.validateFirstName());
|
|
413
418
|
|
|
414
419
|
if (this.subjectType.isPerson()) {
|
|
420
|
+
validationResults.push(this.validateMiddleName());
|
|
415
421
|
validationResults.push(this.validateLastName());
|
|
416
422
|
validationResults.push(this.validateDateOfBirth());
|
|
417
423
|
validationResults.push(this.validateGender());
|