use of de.symeda.sormas.ui.utils.ApproximateAgeValidator in project SORMAS-Project by hzi-braunschweig.
the class PersonEditForm method addFields.
@Override
protected void addFields() {
personInformationHeadingLabel = new Label(I18nProperties.getString(Strings.headingPersonInformation));
personInformationHeadingLabel.addStyleName(H3);
getContent().addComponent(personInformationHeadingLabel, PERSON_INFORMATION_HEADING_LOC);
addField(PersonDto.UUID).setReadOnly(true);
firstNameField = addField(PersonDto.FIRST_NAME, TextField.class);
lastNameField = addField(PersonDto.LAST_NAME, TextField.class);
addFields(PersonDto.SALUTATION, PersonDto.OTHER_SALUTATION);
FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.OTHER_SALUTATION, PersonDto.SALUTATION, Salutation.OTHER, true);
ComboBox sex = addField(PersonDto.SEX, ComboBox.class);
addField(PersonDto.BIRTH_NAME, TextField.class);
addField(PersonDto.NICKNAME, TextField.class);
addField(PersonDto.MOTHERS_MAIDEN_NAME, TextField.class);
addFields(PersonDto.MOTHERS_NAME, PersonDto.FATHERS_NAME);
addFields(PersonDto.NAMES_OF_GUARDIANS);
ComboBox presentCondition = addField(PersonDto.PRESENT_CONDITION, ComboBox.class);
birthDateDay = addField(PersonDto.BIRTH_DATE_DD, ComboBox.class);
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateDay.setNullSelectionAllowed(true);
birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
birthDateDay.setCaption("");
ComboBox birthDateMonth = addField(PersonDto.BIRTH_DATE_MM, ComboBox.class);
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateMonth.setNullSelectionAllowed(true);
birthDateMonth.addItems(DateHelper.getMonthsInYear());
birthDateMonth.setPageLength(12);
birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
birthDateMonth.setCaption("");
setItemCaptionsForMonths(birthDateMonth);
ComboBox birthDateYear = addField(PersonDto.BIRTH_DATE_YYYY, ComboBox.class);
birthDateYear.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE));
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateYear.setNullSelectionAllowed(true);
birthDateYear.addItems(DateHelper.getYearsToNow());
birthDateYear.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
birthDateYear.setInputPrompt(I18nProperties.getString(Strings.year));
birthDateDay.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) birthDateMonth.getValue(), (Integer) e));
birthDateMonth.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) e, (Integer) birthDateDay.getValue()));
birthDateYear.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) e, (Integer) birthDateMonth.getValue(), (Integer) birthDateDay.getValue()));
DateField deathDate = addField(PersonDto.DEATH_DATE, DateField.class);
TextField approximateAgeField = addField(PersonDto.APPROXIMATE_AGE, TextField.class);
approximateAgeField.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, approximateAgeField.getCaption()));
ComboBox approximateAgeTypeField = addField(PersonDto.APPROXIMATE_AGE_TYPE, ComboBox.class);
addField(PersonDto.APPROXIMATE_AGE_REFERENCE_DATE, DateField.class);
approximateAgeField.addValidator(new ApproximateAgeValidator(approximateAgeField, approximateAgeTypeField, I18nProperties.getValidationError(Validations.softApproximateAgeTooHigh)));
TextField tfGestationAgeAtBirth = addField(PersonDto.GESTATION_AGE_AT_BIRTH, TextField.class);
tfGestationAgeAtBirth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfGestationAgeAtBirth.getCaption()));
TextField tfBirthWeight = addField(PersonDto.BIRTH_WEIGHT, TextField.class);
tfBirthWeight.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfBirthWeight.getCaption()));
AbstractSelect deathPlaceType = addField(PersonDto.DEATH_PLACE_TYPE, ComboBox.class);
deathPlaceType.setNullSelectionAllowed(true);
TextField deathPlaceDesc = addField(PersonDto.DEATH_PLACE_DESCRIPTION, TextField.class);
DateField burialDate = addField(PersonDto.BURIAL_DATE, DateField.class);
TextField burialPlaceDesc = addField(PersonDto.BURIAL_PLACE_DESCRIPTION, TextField.class);
ComboBox burialConductor = addField(PersonDto.BURIAL_CONDUCTOR, ComboBox.class);
addressForm = addField(PersonDto.ADDRESS, LocationEditForm.class);
addressForm.setCaption(null);
addField(PersonDto.ADDRESSES, LocationsField.class).setCaption(null);
PersonContactDetailsField personContactDetailsField = addField(PersonDto.PERSON_CONTACT_DETAILS, PersonContactDetailsField.class);
personContactDetailsField.setThisPerson(getValue());
personContactDetailsField.setCaption(null);
personContactDetailsField.setPseudonymized(isPseudonymized);
addFields(PersonDto.OCCUPATION_TYPE, PersonDto.OCCUPATION_DETAILS, PersonDto.ARMED_FORCES_RELATION_TYPE, PersonDto.EDUCATION_TYPE, PersonDto.EDUCATION_DETAILS);
List<CountryReferenceDto> countries = FacadeProvider.getCountryFacade().getAllActiveAsReference();
addInfrastructureField(PersonDto.BIRTH_COUNTRY).addItems(countries);
addInfrastructureField(PersonDto.CITIZENSHIP).addItems(countries);
addFields(PersonDto.PASSPORT_NUMBER, PersonDto.NATIONAL_HEALTH_ID);
Field externalId = addField(PersonDto.EXTERNAL_ID);
if (FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled()) {
externalId.setEnabled(false);
}
TextField externalTokenField = addField(PersonDto.EXTERNAL_TOKEN);
Label externalTokenWarningLabel = new Label(I18nProperties.getString(Strings.messagePersonExternalTokenWarning));
externalTokenWarningLabel.addStyleNames(VSPACE_3, LABEL_WHITE_SPACE_NORMAL);
getContent().addComponent(externalTokenWarningLabel, EXTERNAL_TOKEN_WARNING_LOC);
addField(PersonDto.INTERNAL_TOKEN);
addField(PersonDto.HAS_COVID_APP).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
addField(PersonDto.COVID_CODE_DELIVERED).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
if (personContext != PersonContext.CASE) {
setVisible(false, PersonDto.HAS_COVID_APP, PersonDto.COVID_CODE_DELIVERED);
}
ComboBox cbPlaceOfBirthRegion = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_REGION);
ComboBox cbPlaceOfBirthDistrict = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_DISTRICT);
ComboBox cbPlaceOfBirthCommunity = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_COMMUNITY);
ComboBox placeOfBirthFacilityType = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_TYPE);
FieldHelper.removeItems(placeOfBirthFacilityType);
placeOfBirthFacilityType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
placeOfBirthFacilityType.addItems(FacilityType.getPlaceOfBirthTypes());
cbPlaceOfBirthFacility = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_FACILITY);
TextField tfPlaceOfBirthFacilityDetails = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_DETAILS, TextField.class);
causeOfDeathField = addField(PersonDto.CAUSE_OF_DEATH, ComboBox.class);
causeOfDeathDiseaseField = addDiseaseField(PersonDto.CAUSE_OF_DEATH_DISEASE, true);
causeOfDeathDetailsField = addField(PersonDto.CAUSE_OF_DEATH_DETAILS, TextField.class);
// Set requirements that don't need visibility changes and read only status
setReadOnly(true, PersonDto.APPROXIMATE_AGE_REFERENCE_DATE);
setRequired(true, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX);
setVisible(false, PersonDto.OCCUPATION_DETAILS, PersonDto.DEATH_DATE, PersonDto.DEATH_PLACE_TYPE, PersonDto.DEATH_PLACE_DESCRIPTION, PersonDto.BURIAL_DATE, PersonDto.BURIAL_PLACE_DESCRIPTION, PersonDto.BURIAL_CONDUCTOR, PersonDto.CAUSE_OF_DEATH, PersonDto.CAUSE_OF_DEATH_DETAILS, PersonDto.CAUSE_OF_DEATH_DISEASE);
FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.EDUCATION_DETAILS, PersonDto.EDUCATION_TYPE, Arrays.asList(EducationType.OTHER), true);
FieldHelper.addSoftRequiredStyle(presentCondition, sex, deathDate, deathPlaceDesc, deathPlaceType, causeOfDeathField, causeOfDeathDiseaseField, causeOfDeathDetailsField, burialDate, burialPlaceDesc, burialConductor);
// Set initial visibilities
initializeVisibilitiesAndAllowedVisibilities();
initializeAccessAndAllowedAccesses();
if (!getField(PersonDto.OCCUPATION_TYPE).isVisible() && !getField(PersonDto.ARMED_FORCES_RELATION_TYPE).isVisible() && !getField(PersonDto.EDUCATION_TYPE).isVisible())
occupationHeader.setVisible(false);
if (!getField(PersonDto.ADDRESS).isVisible())
addressHeader.setVisible(false);
if (!getField(PersonDto.ADDRESSES).isVisible())
addressesHeader.setVisible(false);
// Add listeners
FieldHelper.setRequiredWhenNotNull(getFieldGroup(), PersonDto.APPROXIMATE_AGE, PersonDto.APPROXIMATE_AGE_TYPE);
addFieldListeners(PersonDto.APPROXIMATE_AGE, e -> {
@SuppressWarnings("unchecked") Field<ApproximateAgeType> ageTypeField = (Field<ApproximateAgeType>) getField(PersonDto.APPROXIMATE_AGE_TYPE);
if (!ageTypeField.isReadOnly()) {
if (e.getProperty().getValue() == null) {
ageTypeField.clear();
} else {
if (ageTypeField.isEmpty()) {
ageTypeField.setValue(ApproximateAgeType.YEARS);
}
}
}
});
addFieldListeners(PersonDto.BIRTH_DATE_DD, e -> {
updateApproximateAge();
updateReadyOnlyApproximateAge();
});
addFieldListeners(PersonDto.BIRTH_DATE_MM, e -> {
updateApproximateAge();
updateReadyOnlyApproximateAge();
});
addFieldListeners(PersonDto.BIRTH_DATE_YYYY, e -> {
updateApproximateAge();
updateReadyOnlyApproximateAge();
});
addFieldListeners(PersonDto.DEATH_DATE, e -> updateApproximateAge());
addFieldListeners(PersonDto.OCCUPATION_TYPE, e -> {
updateOccupationFieldCaptions();
toggleOccupationMetaFields();
});
addListenersToInfrastructureFields(cbPlaceOfBirthRegion, cbPlaceOfBirthDistrict, cbPlaceOfBirthCommunity, placeOfBirthFacilityType, cbPlaceOfBirthFacility, tfPlaceOfBirthFacilityDetails, true);
cbPlaceOfBirthRegion.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
this.presentConditionChangeListener = new PresentConditionChangeListener();
addFieldListeners(PersonDto.PRESENT_CONDITION, presentConditionChangeListener);
causeOfDeathField.addValueChangeListener(e -> {
boolean causeOfDeathVisible = presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != PresentCondition.UNKNOWN && presentCondition.getValue() != null;
toggleCauseOfDeathFields(causeOfDeathVisible);
});
causeOfDeathDiseaseField.addValueChangeListener(e -> {
boolean causeOfDeathVisible = presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != PresentCondition.UNKNOWN && presentCondition.getValue() != null;
toggleCauseOfDeathFields(causeOfDeathVisible);
});
addValueChangeListener(e -> fillDeathAndBurialFields(deathPlaceType, deathPlaceDesc, burialPlaceDesc));
deathDate.addValidator(new DateComparisonValidator(deathDate, this::calcBirthDateValue, false, false, I18nProperties.getValidationError(Validations.afterDate, deathDate.getCaption(), birthDateYear.getCaption())));
deathDate.addValidator(new DateComparisonValidator(deathDate, burialDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, deathDate.getCaption(), burialDate.getCaption())));
deathDate.addValueChangeListener(value -> {
deathDate.setValidationVisible(!deathDate.isValid());
burialDate.setValidationVisible(!burialDate.isValid());
});
burialDate.addValidator(new DateComparisonValidator(burialDate, this::calcBirthDateValue, false, false, I18nProperties.getValidationError(Validations.afterDate, burialDate.getCaption(), birthDateYear.getCaption())));
burialDate.addValidator(new DateComparisonValidator(burialDate, deathDate, false, false, I18nProperties.getValidationError(Validations.afterDate, burialDate.getCaption(), deathDate.getCaption())));
burialDate.addValueChangeListener(b -> {
deathDate.setValidationVisible(!deathDate.isValid());
burialDate.setValidationVisible(!burialDate.isValid());
});
// Update the list of days according to the selected month and year
birthDateYear.addValueChangeListener(e -> {
updateListOfDays((Integer) e.getProperty().getValue(), (Integer) birthDateMonth.getValue());
birthDateMonth.markAsDirty();
birthDateDay.markAsDirty();
deathDate.setValidationVisible(!deathDate.isValid());
burialDate.setValidationVisible(!burialDate.isValid());
});
birthDateMonth.addValueChangeListener(e -> {
updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
birthDateYear.markAsDirty();
birthDateDay.markAsDirty();
deathDate.setValidationVisible(!deathDate.isValid());
burialDate.setValidationVisible(!burialDate.isValid());
});
birthDateDay.addValueChangeListener(e -> {
birthDateYear.markAsDirty();
birthDateMonth.markAsDirty();
deathDate.setValidationVisible(!deathDate.isValid());
burialDate.setValidationVisible(!burialDate.isValid());
});
addValueChangeListener((e) -> {
ValidationUtils.initComponentErrorValidator(externalTokenField, getValue().getExternalToken(), Validations.duplicateExternalToken, externalTokenWarningLabel, (externalToken) -> FacadeProvider.getPersonFacade().doesExternalTokenExist(externalToken, getValue().getUuid()));
personContactDetailsField.setThisPerson((PersonDto) e.getProperty().getValue());
});
Label generalCommentLabel = new Label(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS));
generalCommentLabel.addStyleName(H3);
getContent().addComponent(generalCommentLabel, GENERAL_COMMENT_LOC);
TextArea additionalDetails = addField(PersonDto.ADDITIONAL_DETAILS, TextArea.class, new ResizableTextAreaWrapper<>(false));
additionalDetails.setRows(6);
additionalDetails.setDescription(I18nProperties.getPrefixDescription(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
CssStyles.style(additionalDetails, CssStyles.CAPTION_HIDDEN);
}
Aggregations