use of com.vaadin.v7.data.validator.EmailValidator in project SORMAS-Project by hzi-braunschweig.
the class LocationEditForm method addFields.
@SuppressWarnings("deprecation")
@Override
protected void addFields() {
addressType = addField(LocationDto.ADDRESS_TYPE, ComboBox.class);
addressType.setVisible(false);
final PersonAddressType[] personAddressTypeValues = PersonAddressType.getValues(FacadeProvider.getConfigFacade().getCountryCode());
if (!isConfiguredServer("ch")) {
addressType.removeAllItems();
addressType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
addressType.addItems(personAddressTypeValues);
}
TextField addressTypeDetails = addField(LocationDto.ADDRESS_TYPE_DETAILS, TextField.class);
addressTypeDetails.setVisible(false);
FieldHelper.setVisibleWhen(getFieldGroup(), LocationDto.ADDRESS_TYPE_DETAILS, addressType, Arrays.stream(personAddressTypeValues).filter(pat -> !pat.equals(PersonAddressType.HOME)).collect(Collectors.toList()), true);
FieldHelper.setRequiredWhen(getFieldGroup(), addressType, Arrays.asList(LocationDto.ADDRESS_TYPE_DETAILS), Arrays.asList(PersonAddressType.OTHER_ADDRESS));
facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
;
facilityTypeGroup.setId("typeGroup");
facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
facilityTypeGroup.addItems(FacilityTypeGroup.values());
getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
facilityType = addField(LocationDto.FACILITY_TYPE);
facility = addInfrastructureField(LocationDto.FACILITY);
facility.setImmediate(true);
facilityDetails = addField(LocationDto.FACILITY_DETAILS, TextField.class);
facilityDetails.setVisible(false);
addressType.addValueChangeListener(e -> {
FacilityTypeGroup oldGroup = (FacilityTypeGroup) facilityTypeGroup.getValue();
FacilityType oldType = (FacilityType) facilityType.getValue();
FacilityReferenceDto oldFacility = (FacilityReferenceDto) facility.getValue();
String oldDetails = facilityDetails.getValue();
if (PersonAddressType.HOME.equals(addressType.getValue())) {
facilityTypeGroup.removeAllItems();
facilityTypeGroup.addItems(FacilityTypeGroup.getAccomodationGroups());
setOldFacilityValuesIfPossible(oldGroup, oldType, oldFacility, oldDetails);
} else {
facilityTypeGroup.removeAllItems();
facilityTypeGroup.addItems(FacilityTypeGroup.values());
setOldFacilityValuesIfPossible(oldGroup, oldType, oldFacility, oldDetails);
}
});
TextField streetField = addField(LocationDto.STREET, TextField.class);
TextField houseNumberField = addField(LocationDto.HOUSE_NUMBER, TextField.class);
TextField additionalInformationField = addField(LocationDto.ADDITIONAL_INFORMATION, TextField.class);
addField(LocationDto.DETAILS, TextField.class);
TextField cityField = addField(LocationDto.CITY, TextField.class);
TextField postalCodeField = addField(LocationDto.POSTAL_CODE, TextField.class);
ComboBox areaType = addField(LocationDto.AREA_TYPE, ComboBox.class);
areaType.setDescription(I18nProperties.getDescription(getPropertyI18nPrefix() + "." + LocationDto.AREA_TYPE));
contactPersonFirstName = addField(LocationDto.CONTACT_PERSON_FIRST_NAME, TextField.class);
contactPersonLastName = addField(LocationDto.CONTACT_PERSON_LAST_NAME, TextField.class);
contactPersonPhone = addField(LocationDto.CONTACT_PERSON_PHONE, TextField.class);
contactPersonPhone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, contactPersonPhone.getCaption())));
contactPersonEmail = addField(LocationDto.CONTACT_PERSON_EMAIL, TextField.class);
contactPersonEmail.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, contactPersonEmail.getCaption())));
final AccessibleTextField tfLatitude = addField(LocationDto.LATITUDE, AccessibleTextField.class);
final AccessibleTextField tfLongitude = addField(LocationDto.LONGITUDE, AccessibleTextField.class);
final AccessibleTextField tfAccuracy = addField(LocationDto.LAT_LON_ACCURACY, AccessibleTextField.class);
final StringToAngularLocationConverter stringToAngularLocationConverter = new StringToAngularLocationConverter();
tfLatitude.setConverter(stringToAngularLocationConverter);
tfLongitude.setConverter(stringToAngularLocationConverter);
tfAccuracy.setConverter(stringToAngularLocationConverter);
continent = addInfrastructureField(LocationDto.CONTINENT);
subcontinent = addInfrastructureField(LocationDto.SUB_CONTINENT);
country = addInfrastructureField(LocationDto.COUNTRY);
ComboBox region = addInfrastructureField(LocationDto.REGION);
ComboBox district = addInfrastructureField(LocationDto.DISTRICT);
ComboBox community = addInfrastructureField(LocationDto.COMMUNITY);
continent.setVisible(false);
subcontinent.setVisible(false);
initializeVisibilitiesAndAllowedVisibilities();
initializeAccessAndAllowedAccesses();
if (!isEditableAllowed(LocationDto.COMMUNITY)) {
setEnabled(false, LocationDto.COUNTRY, LocationDto.REGION, LocationDto.DISTRICT);
}
ValueChangeListener continentValueListener = e -> {
if (continent.isVisible()) {
ContinentReferenceDto continentReferenceDto = (ContinentReferenceDto) e.getProperty().getValue();
if (subcontinent.getValue() == null) {
FieldHelper.updateItems(country, continentReferenceDto != null ? FacadeProvider.getCountryFacade().getAllActiveByContinent(continentReferenceDto.getUuid()) : FacadeProvider.getCountryFacade().getAllActiveAsReference());
country.setValue(null);
}
subcontinent.setValue(null);
FieldHelper.updateItems(subcontinent, continentReferenceDto != null ? FacadeProvider.getSubcontinentFacade().getAllActiveByContinent(continentReferenceDto.getUuid()) : FacadeProvider.getSubcontinentFacade().getAllActiveAsReference());
}
};
ValueChangeListener subContinentValueListener = e -> {
if (subcontinent.isVisible()) {
SubcontinentReferenceDto subcontinentReferenceDto = (SubcontinentReferenceDto) e.getProperty().getValue();
if (subcontinentReferenceDto != null) {
continent.removeValueChangeListener(continentValueListener);
continent.setValue(FacadeProvider.getContinentFacade().getBySubcontinent(subcontinentReferenceDto));
continent.addValueChangeListener(continentValueListener);
}
country.setValue(null);
ContinentReferenceDto continentValue = (ContinentReferenceDto) continent.getValue();
FieldHelper.updateItems(country, subcontinentReferenceDto != null ? FacadeProvider.getCountryFacade().getAllActiveBySubcontinent(subcontinentReferenceDto.getUuid()) : continentValue == null ? FacadeProvider.getCountryFacade().getAllActiveAsReference() : FacadeProvider.getCountryFacade().getAllActiveByContinent(continentValue.getUuid()));
}
};
continent.addValueChangeListener(continentValueListener);
subcontinent.addValueChangeListener(subContinentValueListener);
skipCountryValueChange = false;
country.addValueChangeListener(e -> {
if (!skipCountryValueChange) {
CountryReferenceDto countryDto = (CountryReferenceDto) e.getProperty().getValue();
if (countryDto != null) {
final ContinentReferenceDto countryContinent = FacadeProvider.getContinentFacade().getByCountry(countryDto);
final SubcontinentReferenceDto countrySubcontinent = FacadeProvider.getSubcontinentFacade().getByCountry(countryDto);
if (countryContinent != null) {
continent.removeValueChangeListener(continentValueListener);
if (continent.isVisible()) {
skipCountryValueChange = true;
FieldHelper.updateItems(country, FacadeProvider.getCountryFacade().getAllActiveByContinent(countryContinent.getUuid()));
skipCountryValueChange = false;
}
continent.setValue(countryContinent);
continent.addValueChangeListener(continentValueListener);
}
if (countrySubcontinent != null) {
subcontinent.removeValueChangeListener(subContinentValueListener);
if (subcontinent.isVisible()) {
skipCountryValueChange = true;
if (countryContinent != null) {
FieldHelper.updateItems(subcontinent, FacadeProvider.getSubcontinentFacade().getAllActiveByContinent(countryContinent.getUuid()));
}
FieldHelper.updateItems(country, FacadeProvider.getCountryFacade().getAllActiveBySubcontinent(countrySubcontinent.getUuid()));
skipCountryValueChange = false;
}
subcontinent.setValue(countrySubcontinent);
subcontinent.addValueChangeListener(subContinentValueListener);
}
}
}
});
region.addValueChangeListener(e -> {
RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(district, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
});
district.addValueChangeListener(e -> {
DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(community, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
if (districtDto == null) {
FieldHelper.removeItems(facility);
// Add a visual indictator reminding the user to select a district
facility.setComponentError(new ErrorMessage() {
@Override
public ErrorLevel getErrorLevel() {
return ErrorLevel.INFO;
}
@Override
public String getFormattedHtmlMessage() {
return I18nProperties.getString(Strings.infoFacilityNeedsDistrict);
}
});
} else if (facilityType.getValue() != null) {
facility.setComponentError(null);
facility.markAsDirty();
FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(districtDto, (FacilityType) facilityType.getValue(), true, false));
}
});
community.addValueChangeListener(e -> {
CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
if (facilityType.getValue() != null) {
FieldHelper.updateItems(facility, communityDto != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(communityDto, (FacilityType) facilityType.getValue(), true, true) : district.getValue() != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) district.getValue(), (FacilityType) facilityType.getValue(), true, false) : null);
}
});
skipFacilityTypeUpdate = false;
facilityTypeGroup.addValueChangeListener(e -> {
if (!skipFacilityTypeUpdate) {
FieldHelper.removeItems(facility);
FieldHelper.updateEnumData(facilityType, FacilityType.getTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
facilityType.setRequired(facilityTypeGroup.getValue() != null);
}
});
facilityType.addValueChangeListener(e -> {
FieldHelper.removeItems(facility);
facility.setComponentError(null);
facility.markAsDirty();
if (facilityType.getValue() != null && facilityTypeGroup.getValue() == null) {
facilityTypeGroup.setValue(((FacilityType) facilityType.getValue()).getFacilityTypeGroup());
}
if (facilityType.getValue() != null && district.getValue() != null) {
if (community.getValue() != null) {
FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType((CommunityReferenceDto) community.getValue(), (FacilityType) facilityType.getValue(), true, false));
} else {
FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) district.getValue(), (FacilityType) facilityType.getValue(), true, false));
}
} else if (facilityType.getValue() != null && district.getValue() == null) {
// Add a visual indictator reminding the user to select a district
facility.setComponentError(new ErrorMessage() {
@Override
public ErrorLevel getErrorLevel() {
return ErrorLevel.INFO;
}
@Override
public String getFormattedHtmlMessage() {
return I18nProperties.getString(Strings.infoFacilityNeedsDistrict);
}
});
}
// Only show contactperson-details if at least a faciltytype has been set
if (facilityType.getValue() != null) {
setFacilityContactPersonFieldsVisible(true, true);
} else {
setFacilityContactPersonFieldsVisible(false, true);
}
});
facility.addValueChangeListener(e -> {
if (facility.getValue() != null) {
boolean visibleAndRequired = areFacilityDetailsRequired();
facilityDetails.setVisible(visibleAndRequired);
facilityDetails.setRequired(visibleAndRequired);
if (!visibleAndRequired) {
facilityDetails.clear();
} else {
String facilityDetailsValue = getValue() != null ? getValue().getFacilityDetails() : null;
facilityDetails.setValue(facilityDetailsValue);
}
} else {
facilityDetails.setVisible(false);
facilityDetails.setRequired(false);
facilityDetails.clear();
}
// value because of this field dependencies to other fields and the way updateEnumValues works
if (facility.isAttached() && !disableFacilityAddressCheck) {
if (facility.getValue() != null) {
FacilityDto facilityDto = FacadeProvider.getFacilityFacade().getByUuid(((FacilityReferenceDto) getField(LocationDto.FACILITY).getValue()).getUuid());
// Only if the facility's address is set
if (StringUtils.isNotEmpty(facilityDto.getCity()) || StringUtils.isNotEmpty(facilityDto.getPostalCode()) || StringUtils.isNotEmpty(facilityDto.getStreet()) || StringUtils.isNotEmpty(facilityDto.getHouseNumber()) || StringUtils.isNotEmpty(facilityDto.getAdditionalInformation()) || facilityDto.getAreaType() != null || facilityDto.getLatitude() != null || facilityDto.getLongitude() != null || (StringUtils.isNotEmpty(facilityDto.getContactPersonFirstName()) && StringUtils.isNotEmpty(facilityDto.getContactPersonLastName()))) {
// Show a confirmation popup if the location's address is already set and different from the facility one
if ((StringUtils.isNotEmpty(cityField.getValue()) && !cityField.getValue().equals(facilityDto.getCity())) || (StringUtils.isNotEmpty(postalCodeField.getValue()) && !postalCodeField.getValue().equals(facilityDto.getPostalCode())) || (StringUtils.isNotEmpty(streetField.getValue()) && !streetField.getValue().equals(facilityDto.getStreet())) || (StringUtils.isNotEmpty(houseNumberField.getValue()) && !houseNumberField.getValue().equals(facilityDto.getHouseNumber())) || (StringUtils.isNotEmpty(additionalInformationField.getValue()) && !additionalInformationField.getValue().equals(facilityDto.getAdditionalInformation())) || (areaType.getValue() != null && areaType.getValue() != facilityDto.getAreaType()) || (StringUtils.isNotEmpty(contactPersonFirstName.getValue()) && StringUtils.isNotEmpty(contactPersonLastName.getValue())) || (tfLatitude.getConvertedValue() != null && Double.compare((Double) tfLatitude.getConvertedValue(), facilityDto.getLatitude()) != 0) || (tfLongitude.getConvertedValue() != null && Double.compare((Double) tfLongitude.getConvertedValue(), facilityDto.getLongitude()) != 0)) {
VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingLocation), new Label(I18nProperties.getString(Strings.confirmationLocationFacilityAddressOverride)), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), 640, confirmationEvent -> {
if (confirmationEvent) {
overrideLocationDetailsWithFacilityOnes(facilityDto);
}
});
} else {
overrideLocationDetailsWithFacilityOnes(facilityDto);
}
}
}
}
});
final List<ContinentReferenceDto> continents = FacadeProvider.getContinentFacade().getAllActiveAsReference();
if (continents.isEmpty()) {
continent.setVisible(false);
continent.clear();
} else {
continent.addItems(continents);
}
final List<SubcontinentReferenceDto> subcontinents = FacadeProvider.getSubcontinentFacade().getAllActiveAsReference();
if (subcontinents.isEmpty()) {
subcontinent.setVisible(false);
subcontinent.clear();
} else {
subcontinent.addItems(subcontinents);
}
country.addItems(FacadeProvider.getCountryFacade().getAllActiveAsReference());
updateRegionCombo(region, country);
country.addValueChangeListener(e -> {
updateRegionCombo(region, country);
region.setValue(null);
});
Stream.of(LocationDto.LATITUDE, LocationDto.LONGITUDE).<Field<?>>map(this::getField).forEach(f -> f.addValueChangeListener(e -> this.updateLeafletMapContent()));
// Set initial visiblity of facility-contactperson-details (should only be visible if at least a facilityType has been selected)
setFacilityContactPersonFieldsVisible(facilityType.getValue() != null, true);
}
use of com.vaadin.v7.data.validator.EmailValidator in project SORMAS-Project by hzi-braunschweig.
the class CaseCreateForm method addFields.
@Override
protected void addFields() {
NullableOptionGroup ogCaseOrigin = addField(CaseDataDto.CASE_ORIGIN, NullableOptionGroup.class);
ogCaseOrigin.setRequired(true);
TextField epidField = addField(CaseDataDto.EPID_NUMBER, TextField.class);
epidField.setInvalidCommitted(true);
style(epidField, ERROR_COLOR_PRIMARY);
if (!FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled()) {
TextField externalIdField = addField(CaseDataDto.EXTERNAL_ID, TextField.class);
style(externalIdField, ERROR_COLOR_PRIMARY);
} else {
CheckBox dontShareCheckbox = addField(CaseDataDto.DONT_SHARE_WITH_REPORTING_TOOL, CheckBox.class);
CaseFormHelper.addDontShareWithReportingTool(getContent(), () -> dontShareCheckbox, DONT_SHARE_WARNING_LOC);
}
addField(CaseDataDto.REPORT_DATE, DateField.class);
ComboBox diseaseField = addDiseaseField(CaseDataDto.DISEASE, false, true);
ComboBox diseaseVariantField = addField(CaseDataDto.DISEASE_VARIANT, ComboBox.class);
diseaseVariantDetailsField = addField(CaseDataDto.DISEASE_VARIANT_DETAILS, TextField.class);
diseaseVariantDetailsField.setVisible(false);
diseaseVariantField.setNullSelectionAllowed(true);
diseaseVariantField.setVisible(false);
addField(CaseDataDto.DISEASE_DETAILS, TextField.class);
NullableOptionGroup plagueType = addField(CaseDataDto.PLAGUE_TYPE, NullableOptionGroup.class);
addField(CaseDataDto.DENGUE_FEVER_TYPE, NullableOptionGroup.class);
addField(CaseDataDto.RABIES_TYPE, NullableOptionGroup.class);
addCustomField(PersonDto.FIRST_NAME, String.class, TextField.class);
addCustomField(PersonDto.LAST_NAME, String.class, TextField.class);
if (showPersonSearchButton) {
searchPersonButton = createPersonSearchButton(PERSON_SEARCH_LOC);
getContent().addComponent(searchPersonButton, PERSON_SEARCH_LOC);
}
TextField nationalHealthIdField = addCustomField(PersonDto.NATIONAL_HEALTH_ID, String.class, TextField.class);
TextField passportNumberField = addCustomField(PersonDto.PASSPORT_NUMBER, String.class, TextField.class);
if (CountryHelper.isCountry(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY)) {
nationalHealthIdField.setVisible(false);
}
if (CountryHelper.isInCountries(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY, CountryHelper.COUNTRY_CODE_FRANCE)) {
passportNumberField.setVisible(false);
}
birthDateDay = addCustomField(PersonDto.BIRTH_DATE_DD, Integer.class, ComboBox.class);
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateDay.setNullSelectionAllowed(true);
birthDateDay.addStyleName(FORCE_CAPTION);
birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
ComboBox birthDateMonth = addCustomField(PersonDto.BIRTH_DATE_MM, Integer.class, ComboBox.class);
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateMonth.setNullSelectionAllowed(true);
birthDateMonth.addItems(DateHelper.getMonthsInYear());
birthDateMonth.setPageLength(12);
birthDateMonth.addStyleName(FORCE_CAPTION);
birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
setItemCaptionsForMonths(birthDateMonth);
ComboBox birthDateYear = addCustomField(PersonDto.BIRTH_DATE_YYYY, Integer.class, 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()));
// 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();
});
birthDateMonth.addValueChangeListener(e -> {
updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
birthDateYear.markAsDirty();
birthDateDay.markAsDirty();
});
birthDateDay.addValueChangeListener(e -> {
birthDateYear.markAsDirty();
birthDateMonth.markAsDirty();
});
ComboBox sex = addCustomField(PersonDto.SEX, Sex.class, ComboBox.class);
sex.setCaption(I18nProperties.getCaption(Captions.Person_sex));
ComboBox presentCondition = addCustomField(PersonDto.PRESENT_CONDITION, PresentCondition.class, ComboBox.class);
presentCondition.setCaption(I18nProperties.getCaption(Captions.Person_presentCondition));
addCustomField(SymptomsDto.ONSET_DATE, Date.class, DateField.class, I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ONSET_DATE));
TextField phone = addCustomField(PersonDto.PHONE, String.class, TextField.class);
phone.setCaption(I18nProperties.getCaption(Captions.Person_phone));
TextField email = addCustomField(PersonDto.EMAIL_ADDRESS, String.class, TextField.class);
email.setCaption(I18nProperties.getCaption(Captions.Person_emailAddress));
phone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, phone.getCaption())));
email.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, email.getCaption())));
differentPlaceOfStayJurisdiction = addCustomField(DIFFERENT_PLACE_OF_STAY_JURISDICTION, Boolean.class, CheckBox.class);
differentPlaceOfStayJurisdiction.addStyleName(VSPACE_3);
Label placeOfStayHeadingLabel = new Label(I18nProperties.getCaption(Captions.casePlaceOfStay));
placeOfStayHeadingLabel.addStyleName(H3);
getContent().addComponent(placeOfStayHeadingLabel, PLACE_OF_STAY_HEADING_LOC);
ComboBox region = addInfrastructureField(CaseDataDto.REGION);
districtCombo = addInfrastructureField(CaseDataDto.DISTRICT);
communityCombo = addInfrastructureField(CaseDataDto.COMMUNITY);
communityCombo.setNullSelectionAllowed(true);
// jurisdictionfields
Label jurisdictionHeadingLabel = new Label(I18nProperties.getString(Strings.headingCaseResponsibleJurisidction));
jurisdictionHeadingLabel.addStyleName(H3);
getContent().addComponent(jurisdictionHeadingLabel, RESPONSIBLE_JURISDICTION_HEADING_LOC);
ComboBox responsibleRegion = addInfrastructureField(CaseDataDto.RESPONSIBLE_REGION);
responsibleRegion.setRequired(true);
responsibleDistrictCombo = addInfrastructureField(CaseDataDto.RESPONSIBLE_DISTRICT);
responsibleDistrictCombo.setRequired(true);
responsibleCommunityCombo = addInfrastructureField(CaseDataDto.RESPONSIBLE_COMMUNITY);
responsibleCommunityCombo.setNullSelectionAllowed(true);
responsibleCommunityCombo.addStyleName(SOFT_REQUIRED);
InfrastructureFieldsHelper.initInfrastructureFields(responsibleRegion, responsibleDistrictCombo, responsibleCommunityCombo);
differentPointOfEntryJurisdiction = addCustomField(DIFFERENT_POINT_OF_ENTRY_JURISDICTION, Boolean.class, CheckBox.class);
differentPointOfEntryJurisdiction.addStyleName(VSPACE_3);
ComboBox pointOfEntryRegionCombo = addCustomField(POINT_OF_ENTRY_REGION, RegionReferenceDto.class, ComboBox.class);
pointOfEntryDistrictCombo = addCustomField(POINT_OF_ENTRY_DISTRICT, DistrictReferenceDto.class, ComboBox.class);
InfrastructureFieldsHelper.initInfrastructureFields(pointOfEntryRegionCombo, pointOfEntryDistrictCombo, null);
pointOfEntryDistrictCombo.addValueChangeListener(e -> updatePOEs());
if (showHomeAddressForm) {
addHomeAddressForm();
}
FieldHelper.setVisibleWhen(differentPlaceOfStayJurisdiction, Arrays.asList(region, districtCombo, communityCombo), Collections.singletonList(Boolean.TRUE), true);
FieldHelper.setVisibleWhen(differentPointOfEntryJurisdiction, Arrays.asList(pointOfEntryRegionCombo, pointOfEntryDistrictCombo), Collections.singletonList(Boolean.TRUE), true);
FieldHelper.setRequiredWhen(differentPlaceOfStayJurisdiction, Arrays.asList(region, districtCombo), Collections.singletonList(Boolean.TRUE), false, null);
ogCaseOrigin.addValueChangeListener(e -> {
boolean pointOfEntryRegionDistrictVisible = CaseOrigin.POINT_OF_ENTRY.equals(ogCaseOrigin.getValue()) && Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue());
pointOfEntryRegionCombo.setVisible(pointOfEntryRegionDistrictVisible);
pointOfEntryDistrictCombo.setVisible(pointOfEntryRegionDistrictVisible);
});
facilityOrHome = addCustomField(FACILITY_OR_HOME_LOC, TypeOfPlace.class, NullableOptionGroup.class, I18nProperties.getCaption(Captions.casePlaceOfStay));
facilityOrHome.removeAllItems();
for (TypeOfPlace place : TypeOfPlace.FOR_CASES) {
facilityOrHome.addItem(place);
facilityOrHome.setItemCaption(place, I18nProperties.getEnumCaption(place));
}
facilityOrHome.setItemCaptionMode(ItemCaptionMode.EXPLICIT);
facilityOrHome.setId("facilityOrHome");
facilityOrHome.setWidth(100, Unit.PERCENTAGE);
CssStyles.style(facilityOrHome, ValoTheme.OPTIONGROUP_HORIZONTAL);
facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
facilityTypeGroup.setId("typeGroup");
facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
facilityTypeGroup.addItems(FacilityTypeGroup.getAccomodationGroups());
getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
facilityType = ComboBoxHelper.createComboBoxV7();
facilityType.setId("type");
facilityType.setCaption(I18nProperties.getCaption(Captions.facilityType));
facilityType.setWidth(100, Unit.PERCENTAGE);
getContent().addComponent(facilityType, CaseDataDto.FACILITY_TYPE);
facilityCombo = addInfrastructureField(CaseDataDto.HEALTH_FACILITY);
facilityCombo.setImmediate(true);
TextField facilityDetails = addField(CaseDataDto.HEALTH_FACILITY_DETAILS, TextField.class);
facilityDetails.setVisible(false);
ComboBox cbPointOfEntry = addInfrastructureField(CaseDataDto.POINT_OF_ENTRY);
cbPointOfEntry.setImmediate(true);
TextField tfPointOfEntryDetails = addField(CaseDataDto.POINT_OF_ENTRY_DETAILS, TextField.class);
tfPointOfEntryDetails.setVisible(false);
if (convertedTravelEntry != null) {
differentPointOfEntryJurisdiction.setValue(true);
RegionReferenceDto regionReferenceDto = convertedTravelEntry.getPointOfEntryRegion() != null ? convertedTravelEntry.getPointOfEntryRegion() : convertedTravelEntry.getResponsibleRegion();
pointOfEntryRegionCombo.setValue(regionReferenceDto);
DistrictReferenceDto districtReferenceDto = convertedTravelEntry.getPointOfEntryDistrict() != null ? convertedTravelEntry.getPointOfEntryDistrict() : convertedTravelEntry.getResponsibleDistrict();
pointOfEntryDistrictCombo.setValue(districtReferenceDto);
differentPointOfEntryJurisdiction.setReadOnly(true);
pointOfEntryRegionCombo.setReadOnly(true);
pointOfEntryDistrictCombo.setReadOnly(true);
updatePOEs();
cbPointOfEntry.setReadOnly(true);
tfPointOfEntryDetails.setReadOnly(true);
ogCaseOrigin.setReadOnly(true);
}
region.addValueChangeListener(e -> {
RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(districtCombo, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
});
districtCombo.addValueChangeListener(e -> {
FieldHelper.removeItems(communityCombo);
DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(communityCombo, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
updateFacility();
if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
updatePOEs();
}
});
communityCombo.addValueChangeListener(e -> {
updateFacility();
});
facilityOrHome.addValueChangeListener(e -> {
FieldHelper.removeItems(facilityCombo);
if (TypeOfPlace.FACILITY.equals(facilityOrHome.getValue()) || ((facilityOrHome.getValue() instanceof java.util.Set) && TypeOfPlace.FACILITY.equals(facilityOrHome.getNullableValue()))) {
if (facilityTypeGroup.getValue() == null) {
facilityTypeGroup.setValue(FacilityTypeGroup.MEDICAL_FACILITY);
}
if (facilityType.getValue() == null && FacilityTypeGroup.MEDICAL_FACILITY.equals(facilityTypeGroup.getValue())) {
facilityType.setValue(FacilityType.HOSPITAL);
}
if (facilityType.getValue() != null) {
updateFacility();
}
if (CaseOrigin.IN_COUNTRY.equals(ogCaseOrigin.getValue())) {
facilityCombo.setRequired(true);
}
updateFacilityFields(facilityCombo, facilityDetails);
} else if (TypeOfPlace.HOME.equals(facilityOrHome.getValue()) || ((facilityOrHome.getValue() instanceof java.util.Set) && TypeOfPlace.HOME.equals(facilityOrHome.getNullableValue()))) {
setNoneFacility();
} else {
facilityCombo.removeAllItems();
facilityCombo.setValue(null);
updateFacilityFields(facilityCombo, facilityDetails);
}
});
facilityTypeGroup.addValueChangeListener(e -> {
FieldHelper.removeItems(facilityCombo);
FieldHelper.updateEnumData(facilityType, FacilityType.getAccommodationTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
});
facilityType.addValueChangeListener(e -> updateFacility());
region.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
JurisdictionLevel userJurisdictionLevel = UserRole.getJurisdictionLevel(UserProvider.getCurrent().getUserRoles());
if (userJurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY) {
region.setReadOnly(true);
responsibleRegion.setReadOnly(true);
districtCombo.setReadOnly(true);
responsibleDistrictCombo.setReadOnly(true);
communityCombo.setReadOnly(true);
responsibleCommunityCombo.setReadOnly(true);
differentPlaceOfStayJurisdiction.setVisible(false);
differentPlaceOfStayJurisdiction.setEnabled(false);
facilityOrHome.setImmediate(true);
// [FACILITY]
facilityOrHome.setValue(Sets.newHashSet(TypeOfPlace.FACILITY));
facilityOrHome.setReadOnly(true);
facilityTypeGroup.setValue(FacilityTypeGroup.MEDICAL_FACILITY);
facilityTypeGroup.setReadOnly(true);
facilityType.setValue(FacilityType.HOSPITAL);
facilityType.setReadOnly(true);
facilityCombo.setValue(UserProvider.getCurrent().getUser().getHealthFacility());
facilityCombo.setReadOnly(true);
}
if (!UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
ogCaseOrigin.addValueChangeListener(ev -> {
if (ev.getProperty().getValue() == CaseOrigin.IN_COUNTRY) {
setVisible(false, CaseDataDto.POINT_OF_ENTRY, CaseDataDto.POINT_OF_ENTRY_DETAILS);
differentPointOfEntryJurisdiction.setVisible(false);
setRequired(true, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE, CaseDataDto.HEALTH_FACILITY);
setRequired(false, CaseDataDto.POINT_OF_ENTRY);
updateFacilityFields(facilityCombo, facilityDetails);
} else {
setVisible(true, CaseDataDto.POINT_OF_ENTRY);
differentPointOfEntryJurisdiction.setVisible(true);
setRequired(true, CaseDataDto.POINT_OF_ENTRY);
if (userJurisdictionLevel != JurisdictionLevel.HEALTH_FACILITY) {
facilityOrHome.clear();
setRequired(false, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE, CaseDataDto.HEALTH_FACILITY);
}
updatePointOfEntryFields(cbPointOfEntry, tfPointOfEntryDetails);
}
});
}
// jurisdiction field valuechangelisteners
responsibleDistrictCombo.addValueChangeListener(e -> {
Boolean differentPlaceOfStay = differentPlaceOfStayJurisdiction.getValue();
if (!Boolean.TRUE.equals(differentPlaceOfStay)) {
updateFacility();
if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
updatePOEs();
}
}
});
responsibleCommunityCombo.addValueChangeListener((e) -> {
Boolean differentPlaceOfStay = differentPlaceOfStayJurisdiction.getValue();
if (differentPlaceOfStay == null || Boolean.FALSE.equals(differentPlaceOfStay)) {
updateFacility();
}
});
differentPlaceOfStayJurisdiction.addValueChangeListener(e -> {
updateFacility();
if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
updatePOEs();
}
});
// Set initial visibilities & accesses
initializeVisibilitiesAndAllowedVisibilities();
setRequired(true, CaseDataDto.REPORT_DATE, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, CaseDataDto.DISEASE, PersonDto.SEX, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE);
FieldHelper.addSoftRequiredStyle(plagueType, communityCombo, facilityDetails);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.DISEASE_DETAILS), CaseDataDto.DISEASE, Arrays.asList(Disease.OTHER), true);
FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.DISEASE, Arrays.asList(CaseDataDto.DISEASE_DETAILS), Arrays.asList(Disease.OTHER));
FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.CASE_ORIGIN, Arrays.asList(CaseDataDto.HEALTH_FACILITY), Arrays.asList(CaseOrigin.IN_COUNTRY));
FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.CASE_ORIGIN, Arrays.asList(CaseDataDto.POINT_OF_ENTRY), Arrays.asList(CaseOrigin.POINT_OF_ENTRY));
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.PLAGUE_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.PLAGUE), true);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.DENGUE_FEVER_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.DENGUE), true);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.RABIES_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.RABIES), true);
FieldHelper.setVisibleWhen(facilityOrHome, Arrays.asList(facilityTypeGroup, facilityType, facilityCombo), Collections.singletonList(TypeOfPlace.FACILITY), false);
FieldHelper.setRequiredWhen(facilityOrHome, Arrays.asList(facilityTypeGroup, facilityType, facilityCombo), Collections.singletonList(TypeOfPlace.FACILITY), false, null);
facilityCombo.addValueChangeListener(e -> {
updateFacilityFields(facilityCombo, facilityDetails);
this.getValue().setFacilityType((FacilityType) facilityType.getValue());
});
cbPointOfEntry.addValueChangeListener(e -> {
updatePointOfEntryFields(cbPointOfEntry, tfPointOfEntryDetails);
});
addValueChangeListener(e -> {
if (UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
setVisible(false, CaseDataDto.CASE_ORIGIN, CaseDataDto.DISEASE, CaseDataDto.COMMUNITY, CaseDataDto.HEALTH_FACILITY);
setVisible(true, CaseDataDto.POINT_OF_ENTRY);
}
});
diseaseField.addValueChangeListener((ValueChangeListener) valueChangeEvent -> {
Disease disease = (Disease) valueChangeEvent.getProperty().getValue();
List<DiseaseVariant> diseaseVariants = FacadeProvider.getCustomizableEnumFacade().getEnumValues(CustomizableEnumType.DISEASE_VARIANT, disease);
FieldHelper.updateItems(diseaseVariantField, diseaseVariants);
diseaseVariantField.setVisible(disease != null && isVisibleAllowed(CaseDataDto.DISEASE_VARIANT) && CollectionUtils.isNotEmpty(diseaseVariants));
});
diseaseVariantField.addValueChangeListener(e -> {
DiseaseVariant diseaseVariant = (DiseaseVariant) e.getProperty().getValue();
diseaseVariantDetailsField.setVisible(diseaseVariant != null && diseaseVariant.matchPropertyValue(DiseaseVariant.HAS_DETAILS, true));
});
}
use of com.vaadin.v7.data.validator.EmailValidator in project SORMAS-Project by hzi-braunschweig.
the class UserSettingsForm method addFields.
@Override
protected void addFields() {
ComboBox cbLanguage = addField(UserDto.LANGUAGE, ComboBox.class);
CssStyles.style(cbLanguage, CssStyles.COMBO_BOX_WITH_FLAG_ICON);
ControllerProvider.getUserController().setFlagIcons(cbLanguage);
String authenticationProvider = FacadeProvider.getConfigFacade().getAuthenticationProvider();
if (AuthProvider.KEYCLOAK.equals(authenticationProvider)) {
emailTf = addField(UserDto.USER_EMAIL, TextField.class);
emailTf.setCaption(I18nProperties.getCaption(Captions.User_userEmail));
emailTf.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, emailTf.getCaption())));
}
}
use of com.vaadin.v7.data.validator.EmailValidator in project SORMAS-Project by hzi-braunschweig.
the class FacilityEditForm method addFields.
@Override
protected void addFields() {
addField(FacilityDto.NAME, TextField.class);
typeGroup = ComboBoxHelper.createComboBoxV7();
typeGroup.setId("typeGroup");
typeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
typeGroup.addItems(FacilityTypeGroup.values());
typeGroup.setWidth(100, Unit.PERCENTAGE);
typeGroup.setEnabled(create);
getContent().addComponent(typeGroup, TYPE_GROUP_LOC);
ComboBox type = addField(FacilityDto.TYPE);
type.removeAllItems();
type.setEnabled(create);
ComboBox region = addInfrastructureField(FacilityDto.REGION);
ComboBox district = addInfrastructureField(FacilityDto.DISTRICT);
ComboBox community = addInfrastructureField(FacilityDto.COMMUNITY);
addField(FacilityDto.CITY, TextField.class);
addField(FacilityDto.POSTAL_CODE, TextField.class);
addField(FacilityDto.STREET, TextField.class);
addField(FacilityDto.HOUSE_NUMBER, TextField.class);
addField(FacilityDto.ADDITIONAL_INFORMATION, TextField.class);
addField(FacilityDto.AREA_TYPE, ComboBox.class);
addField(FacilityDto.CONTACT_PERSON_FIRST_NAME, TextField.class);
addField(FacilityDto.CONTACT_PERSON_LAST_NAME, TextField.class);
TextField contactPersonPhone = addField(FacilityDto.CONTACT_PERSON_PHONE, TextField.class);
contactPersonPhone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, contactPersonPhone.getCaption())));
TextField contactPersonEmail = addField(FacilityDto.CONTACT_PERSON_EMAIL, TextField.class);
contactPersonEmail.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, contactPersonEmail.getCaption())));
AccessibleTextField latitude = addField(FacilityDto.LATITUDE, AccessibleTextField.class);
latitude.setConverter(new StringToAngularLocationConverter());
latitude.setConversionError(I18nProperties.getValidationError(Validations.onlyGeoCoordinatesAllowed, latitude.getCaption()));
AccessibleTextField longitude = addField(FacilityDto.LONGITUDE, AccessibleTextField.class);
longitude.setConverter(new StringToAngularLocationConverter());
longitude.setConversionError(I18nProperties.getValidationError(Validations.onlyGeoCoordinatesAllowed, longitude.getCaption()));
addField(RegionDto.EXTERNAL_ID, TextField.class);
setRequired(true, FacilityDto.NAME, TYPE_GROUP_LOC, FacilityDto.TYPE, FacilityDto.REGION, FacilityDto.DISTRICT);
typeGroup.addValueChangeListener(e -> FieldHelper.updateEnumData(type, FacilityType.getTypes((FacilityTypeGroup) typeGroup.getValue())));
type.addValueChangeListener(e -> {
boolean notLab = !FacilityType.LABORATORY.equals(type.getValue());
region.setRequired(notLab);
district.setRequired(notLab);
if (!create) {
// Disable editing of region, etc. so case references stay correct
region.setEnabled(false);
district.setEnabled(false);
community.setEnabled(false);
}
});
region.addValueChangeListener(e -> {
RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(district, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
});
district.addValueChangeListener(e -> {
FieldHelper.removeItems(community);
DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(community, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
});
community.addValueChangeListener(e -> {
@SuppressWarnings("unused") CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
});
region.addItems(FacadeProvider.getRegionFacade().getAllActiveAsReference());
}
use of com.vaadin.v7.data.validator.EmailValidator in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationCreationForm method addFields.
@SuppressWarnings("deprecation")
@Override
protected void addFields() {
addField(ImmunizationDto.REPORT_DATE, DateField.class);
TextField externalIdField = addField(ImmunizationDto.EXTERNAL_ID, TextField.class);
style(externalIdField, ERROR_COLOR_PRIMARY);
addDiseaseField(ImmunizationDto.DISEASE, false, true);
addField(ImmunizationDto.DISEASE_DETAILS, TextField.class);
ComboBox meansOfImmunizationField = addField(ImmunizationDto.MEANS_OF_IMMUNIZATION, ComboBox.class);
addField(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS, TextField.class);
CheckBox overwriteImmunizationManagementStatus = addCustomField(OVERWRITE_IMMUNIZATION_MANAGEMENT_STATUS, Boolean.class, CheckBox.class);
overwriteImmunizationManagementStatus.addStyleName(VSPACE_3);
ComboBox managementStatusField = addCustomField(ImmunizationDto.IMMUNIZATION_MANAGEMENT_STATUS, ImmunizationManagementStatus.class, ComboBox.class);
managementStatusField.setValue(ImmunizationManagementStatus.SCHEDULED);
managementStatusField.setEnabled(false);
managementStatusField.setNullSelectionAllowed(false);
ComboBox immunizationStatusField = addCustomField(ImmunizationDto.IMMUNIZATION_STATUS, ImmunizationStatus.class, ComboBox.class);
immunizationStatusField.setValue(ImmunizationStatus.PENDING);
immunizationStatusField.setEnabled(false);
Label jurisdictionHeadingLabel = new Label(I18nProperties.getString(Strings.headingResponsibleJurisdiction));
jurisdictionHeadingLabel.addStyleName(H3);
getContent().addComponent(jurisdictionHeadingLabel, RESPONSIBLE_JURISDICTION_HEADING_LOC);
ComboBox responsibleRegion = addInfrastructureField(ImmunizationDto.RESPONSIBLE_REGION);
responsibleRegion.setRequired(true);
ComboBox responsibleDistrictCombo = addInfrastructureField(ImmunizationDto.RESPONSIBLE_DISTRICT);
responsibleDistrictCombo.setRequired(true);
ComboBox responsibleCommunityCombo = addInfrastructureField(ImmunizationDto.RESPONSIBLE_COMMUNITY);
responsibleCommunityCombo.setNullSelectionAllowed(true);
responsibleCommunityCombo.addStyleName(SOFT_REQUIRED);
InfrastructureFieldsHelper.initInfrastructureFields(responsibleRegion, responsibleDistrictCombo, responsibleCommunityCombo);
ComboBox facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
facilityTypeGroup.setId("typeGroup");
facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
facilityTypeGroup.addItems(FacilityTypeGroup.getAccomodationGroups());
getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
ComboBox facilityType = ComboBoxHelper.createComboBoxV7();
facilityType.setId("type");
facilityType.setCaption(I18nProperties.getCaption(Captions.facilityType));
facilityType.setWidth(100, Unit.PERCENTAGE);
getContent().addComponent(facilityType, ImmunizationDto.FACILITY_TYPE);
ComboBox facilityCombo = addInfrastructureField(ImmunizationDto.HEALTH_FACILITY);
facilityCombo.setImmediate(true);
TextField facilityDetails = addField(ImmunizationDto.HEALTH_FACILITY_DETAILS, TextField.class);
facilityDetails.setVisible(false);
DateField startDate = addField(ImmunizationDto.START_DATE, DateField.class);
DateField endDate = addDateField(ImmunizationDto.END_DATE, DateField.class, -1);
DateComparisonValidator.addStartEndValidators(startDate, endDate);
DateField validFrom = addDateField(ImmunizationDto.VALID_FROM, DateField.class, -1);
DateField validUntil = addDateField(ImmunizationDto.VALID_UNTIL, DateField.class, -1);
DateComparisonValidator.addStartEndValidators(validFrom, validUntil);
Field numberOfDosesField = addField(ImmunizationDto.NUMBER_OF_DOSES);
numberOfDosesField.addValidator(new NumberValidator(I18nProperties.getValidationError(Validations.vaccineDosesFormat), 1, 10, false));
numberOfDosesField.setVisible(false);
addCustomField(PersonDto.FIRST_NAME, String.class, TextField.class);
addCustomField(PersonDto.LAST_NAME, String.class, TextField.class);
Button searchPersonButton = createPersonSearchButton(PERSON_SEARCH_LOC);
getContent().addComponent(searchPersonButton, PERSON_SEARCH_LOC);
TextField nationalHealthIdField = addCustomField(PersonDto.NATIONAL_HEALTH_ID, String.class, TextField.class);
TextField passportNumberField = addCustomField(PersonDto.PASSPORT_NUMBER, String.class, TextField.class);
if (CountryHelper.isCountry(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY)) {
nationalHealthIdField.setVisible(false);
}
if (CountryHelper.isInCountries(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY, CountryHelper.COUNTRY_CODE_FRANCE)) {
passportNumberField.setVisible(false);
}
birthDateDay = addCustomField(PersonDto.BIRTH_DATE_DD, Integer.class, ComboBox.class);
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateDay.setNullSelectionAllowed(true);
birthDateDay.addStyleName(FORCE_CAPTION);
birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
ComboBox birthDateMonth = addCustomField(PersonDto.BIRTH_DATE_MM, Integer.class, ComboBox.class);
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateMonth.setNullSelectionAllowed(true);
birthDateMonth.addItems(DateHelper.getMonthsInYear());
birthDateMonth.setPageLength(12);
birthDateMonth.addStyleName(FORCE_CAPTION);
birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
setItemCaptionsForMonths(birthDateMonth);
ComboBox birthDateYear = addCustomField(PersonDto.BIRTH_DATE_YYYY, Integer.class, 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(AbstractSelect.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()));
// 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();
});
birthDateMonth.addValueChangeListener(e -> {
updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
birthDateYear.markAsDirty();
birthDateDay.markAsDirty();
});
birthDateDay.addValueChangeListener(e -> {
birthDateYear.markAsDirty();
birthDateMonth.markAsDirty();
});
ComboBox sex = addCustomField(PersonDto.SEX, Sex.class, ComboBox.class);
sex.setCaption(I18nProperties.getCaption(Captions.Person_sex));
ComboBox presentCondition = addCustomField(PersonDto.PRESENT_CONDITION, PresentCondition.class, ComboBox.class);
presentCondition.setCaption(I18nProperties.getCaption(Captions.Person_presentCondition));
TextField phone = addCustomField(PersonDto.PHONE, String.class, TextField.class);
phone.setCaption(I18nProperties.getCaption(Captions.Person_phone));
TextField email = addCustomField(PersonDto.EMAIL_ADDRESS, String.class, TextField.class);
email.setCaption(I18nProperties.getCaption(Captions.Person_emailAddress));
phone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, phone.getCaption())));
email.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, email.getCaption())));
// Set initial visibilities & accesses
initializeVisibilitiesAndAllowedVisibilities();
setRequired(true, ImmunizationDto.REPORT_DATE, ImmunizationDto.MEANS_OF_IMMUNIZATION);
FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(ImmunizationDto.DISEASE_DETAILS), ImmunizationDto.DISEASE, Collections.singletonList(Disease.OTHER), true);
FieldHelper.setRequiredWhen(getFieldGroup(), ImmunizationDto.DISEASE, Collections.singletonList(ImmunizationDto.DISEASE_DETAILS), Collections.singletonList(Disease.OTHER));
FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS), ImmunizationDto.MEANS_OF_IMMUNIZATION, Collections.singletonList(MeansOfImmunization.OTHER), true);
overwriteImmunizationManagementStatus.addValueChangeListener(e -> {
boolean selectedValue = (boolean) e.getProperty().getValue();
if (!selectedValue) {
managementStatusField.setValue(ImmunizationManagementStatus.SCHEDULED);
}
managementStatusField.setEnabled(selectedValue);
});
meansOfImmunizationField.addValueChangeListener(e -> {
MeansOfImmunization meansOfImmunization = (MeansOfImmunization) e.getProperty().getValue();
if (MeansOfImmunization.RECOVERY.equals(meansOfImmunization) || MeansOfImmunization.OTHER.equals(meansOfImmunization)) {
managementStatusField.setValue(ImmunizationManagementStatus.COMPLETED);
} else {
managementStatusField.setValue(ImmunizationManagementStatus.SCHEDULED);
}
boolean isVaccinationVisible = MeansOfImmunization.VACCINATION.equals(meansOfImmunization) || MeansOfImmunization.VACCINATION_RECOVERY.equals(meansOfImmunization);
numberOfDosesField.setVisible(isVaccinationVisible);
if (!isVaccinationVisible) {
numberOfDosesField.setValue(null);
}
});
managementStatusField.addValueChangeListener(e -> {
ImmunizationManagementStatus managementStatusValue = (ImmunizationManagementStatus) e.getProperty().getValue();
switch(managementStatusValue) {
case SCHEDULED:
case ONGOING:
immunizationStatusField.setValue(ImmunizationStatus.PENDING);
break;
case COMPLETED:
immunizationStatusField.setValue(ImmunizationStatus.ACQUIRED);
break;
case CANCELED:
immunizationStatusField.setValue(ImmunizationStatus.NOT_ACQUIRED);
break;
default:
break;
}
});
responsibleDistrictCombo.addValueChangeListener(e -> {
FieldHelper.removeItems(facilityCombo);
DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
if (districtDto != null && facilityType.getValue() != null) {
FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(districtDto, (FacilityType) facilityType.getValue(), true, false));
}
});
responsibleCommunityCombo.addValueChangeListener(e -> {
FieldHelper.removeItems(facilityCombo);
CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
if (facilityType.getValue() != null) {
FieldHelper.updateItems(facilityCombo, communityDto != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(communityDto, (FacilityType) facilityType.getValue(), true, false) : responsibleDistrictCombo.getValue() != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) responsibleDistrictCombo.getValue(), (FacilityType) facilityType.getValue(), true, false) : null);
}
});
facilityTypeGroup.addValueChangeListener(e -> {
FieldHelper.removeItems(facilityCombo);
FieldHelper.updateEnumData(facilityType, FacilityType.getAccommodationTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
});
facilityType.addValueChangeListener(e -> {
FieldHelper.removeItems(facilityCombo);
if (facilityType.getValue() != null && responsibleDistrictCombo.getValue() != null) {
if (responsibleCommunityCombo.getValue() != null) {
FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType((CommunityReferenceDto) responsibleCommunityCombo.getValue(), (FacilityType) facilityType.getValue(), true, false));
} else {
FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) responsibleDistrictCombo.getValue(), (FacilityType) facilityType.getValue(), true, false));
}
}
});
facilityCombo.addValueChangeListener(e -> {
updateFacilityFields(facilityCombo, facilityDetails);
this.getValue().setFacilityType((FacilityType) facilityType.getValue());
});
addValueChangeListener(e -> {
if (disease != null) {
setVisible(false, ImmunizationDto.DISEASE, ImmunizationDto.DISEASE_DETAILS);
setReadOnly(false, ImmunizationDto.DISEASE, ImmunizationDto.DISEASE_DETAILS);
} else {
setRequired(true, ImmunizationDto.DISEASE);
}
if (personDto != null) {
setVisible(false, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX, PersonDto.NATIONAL_HEALTH_ID, PersonDto.PASSPORT_NUMBER, PersonDto.BIRTH_DATE_DD, PersonDto.BIRTH_DATE_MM, PersonDto.BIRTH_DATE_YYYY, PersonDto.PRESENT_CONDITION, PersonDto.PHONE, PersonDto.EMAIL_ADDRESS);
setReadOnly(false, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX, PersonDto.NATIONAL_HEALTH_ID, PersonDto.PASSPORT_NUMBER, PersonDto.BIRTH_DATE_DD, PersonDto.BIRTH_DATE_MM, PersonDto.BIRTH_DATE_YYYY, PersonDto.PRESENT_CONDITION, PersonDto.PHONE, PersonDto.EMAIL_ADDRESS);
searchPersonButton.setVisible(false);
} else {
setRequired(true, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX);
}
});
}
Aggregations