openchs-models 1.33.22 → 1.33.23
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.
|
@@ -183,6 +183,8 @@ class FormElement extends _BaseEntity.default {
|
|
|
183
183
|
failure.messageKey = "invalidTimeFormat";
|
|
184
184
|
} else if (this.concept.datatype === _Concept.default.dataType.Date && !(0, _moment.default)(value, 'YYYY-MM-DD').isValid() && (!this.mandatory && !_lodash.default.isNil(value) || this.mandatory)) {
|
|
185
185
|
failure.messageKey = "invalidDateFormat";
|
|
186
|
+
} else if (this.concept.datatype === _Concept.default.dataType.Date && !_lodash.default.isNil(value) && (0, _moment.default)(value, 'YYYY-MM-DD').isValid() && !this.isDateWithinValidRange(value)) {
|
|
187
|
+
failure.messageKey = "invalidDate";
|
|
186
188
|
} else if (this.mandatory && this.concept.datatype === _Concept.default.dataType.Duration && _lodash.default.some(_lodash.default.map(value.durations, "durationValue"), durationValue => _lodash.default.isEmpty(durationValue))) {
|
|
187
189
|
failure.messageKey = "emptyValidationMessage";
|
|
188
190
|
} else if (this.concept.datatype === _Concept.default.dataType.PhoneNumber && !_lodash.default.isEmpty(value) && !/^[0-9]{10}$/.test(value)) {
|
|
@@ -192,6 +194,13 @@ class FormElement extends _BaseEntity.default {
|
|
|
192
194
|
}
|
|
193
195
|
return failure;
|
|
194
196
|
}
|
|
197
|
+
isDateWithinValidRange(date) {
|
|
198
|
+
if (!date) return true;
|
|
199
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
200
|
+
const currentDate = new Date();
|
|
201
|
+
const yearDifference = Math.abs(currentDate.getFullYear() - dateObj.getFullYear());
|
|
202
|
+
return yearDifference <= 2000;
|
|
203
|
+
}
|
|
195
204
|
getAnswers() {
|
|
196
205
|
const allAnswers = this.concept.getAnswers();
|
|
197
206
|
if (!_lodash.default.isEmpty(this.answersToShow)) {
|