Search in sources :

Example 1 with VSPACE_3

use of de.symeda.sormas.ui.utils.CssStyles.VSPACE_3 in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationDataForm method addFields.

@SuppressWarnings("deprecation")
@Override
protected void addFields() {
    TextField immunizationUuuidField = addField(ImmunizationDto.UUID, TextField.class);
    immunizationUuuidField.setReadOnly(true);
    TextField externalIdField = addField(ImmunizationDto.EXTERNAL_ID, TextField.class);
    style(externalIdField, ERROR_COLOR_PRIMARY);
    addField(ImmunizationDto.REPORT_DATE, DateField.class);
    addField(ImmunizationDto.REPORTING_USER, ComboBox.class);
    ComboBox cbDisease = addDiseaseField(ImmunizationDto.DISEASE, false);
    addField(ImmunizationDto.DISEASE_DETAILS, TextField.class);
    ComboBox meansOfImmunizationField = addField(ImmunizationDto.MEANS_OF_IMMUNIZATION, ComboBox.class);
    addField(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS, TextField.class);
    overwriteImmunizationManagementStatus = addCustomField(OVERWRITE_IMMUNIZATION_MANAGEMENT_STATUS, Boolean.class, CheckBox.class);
    overwriteImmunizationManagementStatus.addStyleName(VSPACE_3);
    ComboBox managementStatusField = addField(ImmunizationDto.IMMUNIZATION_MANAGEMENT_STATUS, ComboBox.class);
    managementStatusField.setNullSelectionAllowed(false);
    managementStatusField.setEnabled(false);
    ComboBox immunizationStatusField = addField(ImmunizationDto.IMMUNIZATION_STATUS, ComboBox.class);
    immunizationStatusField.setEnabled(false);
    addField(ImmunizationDto.PREVIOUS_INFECTION, NullableOptionGroup.class);
    addField(ImmunizationDto.LAST_INFECTION_DATE, DateField.class);
    ComboBox country = addInfrastructureField(ImmunizationDto.COUNTRY);
    country.addItems(FacadeProvider.getCountryFacade().getAllActiveAsReference());
    TextArea descriptionField = addField(ImmunizationDto.ADDITIONAL_DETAILS, TextArea.class, new ResizableTextAreaWrapper<>());
    descriptionField.setRows(2);
    descriptionField.setDescription(I18nProperties.getPrefixDescription(ImmunizationDto.I18N_PREFIX, ImmunizationDto.ADDITIONAL_DETAILS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    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);
    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);
    ComboBox facilityType = addField(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);
    MeansOfImmunization meansOfImmunizationValue = (MeansOfImmunization) meansOfImmunizationField.getValue();
    boolean isVaccinationVisibleInitial = shouldShowVaccinationFields(meansOfImmunizationValue);
    Label vaccinationHeadingLabel = new Label(I18nProperties.getString(Strings.headingVaccination));
    vaccinationHeadingLabel.addStyleName(H3);
    getContent().addComponent(vaccinationHeadingLabel, VACCINATION_HEADING_LOC);
    vaccinationHeadingLabel.setVisible(isVaccinationVisibleInitial);
    Field numberOfDosesField = addField(ImmunizationDto.NUMBER_OF_DOSES);
    numberOfDosesField.addValidator(new NumberValidator(I18nProperties.getValidationError(Validations.vaccineDosesFormat), 1, 10, false));
    numberOfDosesField.setVisible(isVaccinationVisibleInitial);
    Field numberOfDosesDetailsField = addField(ImmunizationDto.NUMBER_OF_DOSES_DETAILS);
    numberOfDosesDetailsField.setReadOnly(true);
    numberOfDosesDetailsField.setVisible(isVaccinationVisibleInitial && getValue().getNumberOfDosesDetails() != null);
    VaccinationsField vaccinationsField = addField(ImmunizationDto.VACCINATIONS, VaccinationsField.class);
    FieldHelper.setVisibleWhen(getFieldGroup(), ImmunizationDto.VACCINATIONS, ImmunizationDto.MEANS_OF_IMMUNIZATION, Arrays.asList(MeansOfImmunization.VACCINATION, MeansOfImmunization.VACCINATION_RECOVERY), false);
    cbDisease.addValueChangeListener(e -> vaccinationsField.setDisease((Disease) cbDisease.getValue()));
    Label recoveryHeadingLabel = new Label(I18nProperties.getString(Strings.headingRecovery));
    recoveryHeadingLabel.addStyleName(H3);
    getContent().addComponent(recoveryHeadingLabel, RECOVERY_HEADING_LOC);
    recoveryHeadingLabel.setVisible(shouldShowRecoveryFields(meansOfImmunizationValue));
    DateField positiveTestResultDate = addField(ImmunizationDto.POSITIVE_TEST_RESULT_DATE, DateField.class);
    DateField recoveryDate = addField(ImmunizationDto.RECOVERY_DATE, DateField.class);
    Button linkImmunizationToCaseButton;
    if (relatedCase != null) {
        linkImmunizationToCaseButton = ButtonHelper.createButton(Captions.openLinkedCaseToImmunizationButton, e -> ControllerProvider.getCaseController().navigateToCase(relatedCase.getUuid()), ValoTheme.BUTTON_PRIMARY, FORCE_CAPTION);
    } else {
        linkImmunizationToCaseButton = ButtonHelper.createButton(Captions.linkImmunizationToCaseButton, e -> buildAndOpenSearchSpecificCaseWindow(), ValoTheme.BUTTON_PRIMARY, FORCE_CAPTION);
    }
    getContent().addComponent(linkImmunizationToCaseButton, LINK_IMMUNIZATION_TO_CASE_BTN_LOC);
    linkImmunizationToCaseButton.setVisible(shouldShowRecoveryFields(meansOfImmunizationValue));
    // Set initial visibilities & accesses
    initializeVisibilitiesAndAllowedVisibilities();
    setRequired(true, ImmunizationDto.REPORT_DATE, ImmunizationDto.DISEASE, ImmunizationDto.MEANS_OF_IMMUNIZATION);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(ImmunizationDto.DISEASE_DETAILS), ImmunizationDto.DISEASE, Arrays.asList(Disease.OTHER), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), ImmunizationDto.DISEASE, Arrays.asList(ImmunizationDto.DISEASE_DETAILS), Arrays.asList(Disease.OTHER));
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS), ImmunizationDto.MEANS_OF_IMMUNIZATION, Collections.singletonList(MeansOfImmunization.OTHER), true);
    overwriteImmunizationManagementStatus.addValueChangeListener(valueChangeEvent -> {
        boolean selectedValue = (boolean) valueChangeEvent.getProperty().getValue();
        if (!selectedValue) {
            ImmunizationManagementStatus value = getValue().getImmunizationManagementStatus();
            managementStatusField.setValue(value);
        }
        managementStatusField.setEnabled(selectedValue);
        ignoreMeansOfImmunizationChange = selectedValue;
    });
    meansOfImmunizationField.addValueChangeListener(valueChangeEvent -> {
        MeansOfImmunization meansOfImmunization = (MeansOfImmunization) valueChangeEvent.getProperty().getValue();
        boolean isVaccinationVisible = shouldShowVaccinationFields(meansOfImmunization);
        boolean isRecoveryVisible = shouldShowRecoveryFields(meansOfImmunization);
        if (!ignoreMeansOfImmunizationChange) {
            if (MeansOfImmunization.RECOVERY.equals(meansOfImmunization) || MeansOfImmunization.OTHER.equals(meansOfImmunization)) {
                managementStatusField.setValue(ImmunizationManagementStatus.COMPLETED);
                if (CollectionUtils.isNotEmpty(vaccinationsField.getValue())) {
                    VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingDeleteVaccinations), new Label(I18nProperties.getString(Strings.messageDeleteImmunizationVaccinations)), questionWindow -> {
                        ConfirmationComponent confirmationComponent = new ConfirmationComponent(false) {

                            private static final long serialVersionUID = 1L;

                            @Override
                            protected void onConfirm() {
                                vaccinationsField.clear();
                                previousMeansOfImmunization = meansOfImmunization;
                                if (!isVaccinationVisible) {
                                    numberOfDosesField.setValue(null);
                                }
                                questionWindow.close();
                            }

                            @Override
                            protected void onCancel() {
                                ignoreMeansOfImmunizationChange = true;
                                meansOfImmunizationField.setValue(previousMeansOfImmunization);
                                ignoreMeansOfImmunizationChange = false;
                                questionWindow.close();
                            }
                        };
                        confirmationComponent.getConfirmButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
                        confirmationComponent.getCancelButton().setCaption(I18nProperties.getCaption(Captions.actionCancel));
                        return confirmationComponent;
                    }, null);
                } else {
                    previousMeansOfImmunization = meansOfImmunization;
                }
            } else {
                previousMeansOfImmunization = meansOfImmunization;
            }
        }
        vaccinationHeadingLabel.setVisible(isVaccinationVisible);
        numberOfDosesField.setVisible(isVaccinationVisible);
        numberOfDosesDetailsField.setVisible(isVaccinationVisible && getValue().getNumberOfDosesDetails() != null);
        recoveryHeadingLabel.setVisible(isRecoveryVisible);
        positiveTestResultDate.setVisible(isRecoveryVisible);
        recoveryDate.setVisible(isRecoveryVisible);
    });
    managementStatusField.addValueChangeListener(valueChangeEvent -> {
        ImmunizationManagementStatus managementStatusValue = (ImmunizationManagementStatus) valueChangeEvent.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;
        }
    });
    setReadOnly(true, ImmunizationDto.REPORTING_USER);
    FieldHelper.setVisibleWhen(getFieldGroup(), ImmunizationDto.LAST_INFECTION_DATE, ImmunizationDto.PREVIOUS_INFECTION, Collections.singletonList(YesNoUnknown.YES), true);
    meansOfImmunizationField.addValueChangeListener(e -> {
        if (shouldShowRecoveryFields((MeansOfImmunization) e.getProperty().getValue())) {
            positiveTestResultDate.setVisible(true);
            recoveryDate.setVisible(true);
            linkImmunizationToCaseButton.setVisible(true);
        } else {
            positiveTestResultDate.setVisible(false);
            recoveryDate.setVisible(false);
            linkImmunizationToCaseButton.setVisible(false);
        }
    });
    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 -> {
        if (facilityTypeGroup.getValue() == null) {
            facilityType.clear();
        }
        FieldHelper.updateEnumData(facilityType, facilityTypeGroup.getValue() != null ? FacilityType.getTypes((FacilityTypeGroup) facilityTypeGroup.getValue()) : Arrays.stream(FacilityType.values()).collect(Collectors.toList()));
    });
    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);
    });
    addValueChangeListener(e -> {
        FacilityType facilityTypeValue = getValue().getFacilityType();
        if (facilityTypeValue != null) {
            facilityTypeGroup.setValue(facilityTypeValue.getFacilityTypeGroup());
            facilityCombo.setValue(getValue().getHealthFacility());
            facilityDetails.setValue(getValue().getHealthFacilityDetails());
        }
    });
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) UI(com.vaadin.ui.UI) Window(com.vaadin.ui.Window) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) FORCE_CAPTION(de.symeda.sormas.ui.utils.CssStyles.FORCE_CAPTION) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) ConfirmationComponent(de.symeda.sormas.ui.utils.ConfirmationComponent) ComboBox(com.vaadin.v7.ui.ComboBox) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) Descriptions(de.symeda.sormas.api.i18n.Descriptions) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) VaccinationsField(de.symeda.sormas.ui.vaccination.VaccinationsField) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) SearchSpecificLayout(de.symeda.sormas.ui.SearchSpecificLayout) FacadeProvider(de.symeda.sormas.api.FacadeProvider) Converter(com.vaadin.v7.data.util.converter.Converter) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) CollectionUtils(org.apache.commons.collections.CollectionUtils) SormasUI(de.symeda.sormas.ui.SormasUI) Label(com.vaadin.ui.Label) ERROR_COLOR_PRIMARY(de.symeda.sormas.ui.utils.CssStyles.ERROR_COLOR_PRIMARY) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) CssStyles.style(de.symeda.sormas.ui.utils.CssStyles.style) Validations(de.symeda.sormas.api.i18n.Validations) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ResizableTextAreaWrapper(de.symeda.sormas.ui.utils.ResizableTextAreaWrapper) SOFT_REQUIRED(de.symeda.sormas.ui.utils.CssStyles.SOFT_REQUIRED) Captions(de.symeda.sormas.api.i18n.Captions) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Button(com.vaadin.ui.Button) Disease(de.symeda.sormas.api.Disease) TextArea(com.vaadin.v7.ui.TextArea) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) ImmunizationStatus(de.symeda.sormas.api.immunization.ImmunizationStatus) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) NumberValidator(de.symeda.sormas.ui.utils.NumberValidator) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) Disease(de.symeda.sormas.api.Disease) TextArea(com.vaadin.v7.ui.TextArea) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) VaccinationsField(de.symeda.sormas.ui.vaccination.VaccinationsField) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) VaccinationsField(de.symeda.sormas.ui.vaccination.VaccinationsField) DateField(com.vaadin.v7.ui.DateField) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) NumberValidator(de.symeda.sormas.ui.utils.NumberValidator) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.v7.ui.CheckBox) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) ConfirmationComponent(de.symeda.sormas.ui.utils.ConfirmationComponent) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 2 with VSPACE_3

use of de.symeda.sormas.ui.utils.CssStyles.VSPACE_3 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));
    });
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) LayoutUtil.divsCss(de.symeda.sormas.ui.utils.LayoutUtil.divsCss) Date(java.util.Date) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) LayoutUtil.locs(de.symeda.sormas.ui.utils.LayoutUtil.locs) PersonDto(de.symeda.sormas.api.person.PersonDto) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) CssStyles(de.symeda.sormas.ui.utils.CssStyles) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) UserRole(de.symeda.sormas.api.user.UserRole) FORCE_CAPTION(de.symeda.sormas.ui.utils.CssStyles.FORCE_CAPTION) UserProvider(de.symeda.sormas.ui.UserProvider) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) ComboBox(com.vaadin.v7.ui.ComboBox) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Sex(de.symeda.sormas.api.person.Sex) PersonDependentEditForm(de.symeda.sormas.ui.utils.PersonDependentEditForm) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Sets(com.google.common.collect.Sets) TypeOfPlace(de.symeda.sormas.api.event.TypeOfPlace) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) List(java.util.List) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) FacadeProvider(de.symeda.sormas.api.FacadeProvider) DateHelper(de.symeda.sormas.api.utils.DateHelper) Converter(com.vaadin.v7.data.util.converter.Converter) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) CustomizableEnumType(de.symeda.sormas.api.customizableenum.CustomizableEnumType) LayoutUtil.loc(de.symeda.sormas.ui.utils.LayoutUtil.loc) CollectionUtils(org.apache.commons.collections.CollectionUtils) Label(com.vaadin.ui.Label) CountryHelper(de.symeda.sormas.api.CountryHelper) ERROR_COLOR_PRIMARY(de.symeda.sormas.ui.utils.CssStyles.ERROR_COLOR_PRIMARY) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) LocationDto(de.symeda.sormas.api.location.LocationDto) CssStyles.style(de.symeda.sormas.ui.utils.CssStyles.style) Validations(de.symeda.sormas.api.i18n.Validations) Month(java.time.Month) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) SOFT_REQUIRED(de.symeda.sormas.ui.utils.CssStyles.SOFT_REQUIRED) Captions(de.symeda.sormas.api.i18n.Captions) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ItemCaptionMode(com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Button(com.vaadin.ui.Button) Disease(de.symeda.sormas.api.Disease) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) LayoutUtil.fluidColumn(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumn) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) Disease(de.symeda.sormas.api.Disease) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) ComboBox(com.vaadin.v7.ui.ComboBox) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) Label(com.vaadin.ui.Label) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) TypeOfPlace(de.symeda.sormas.api.event.TypeOfPlace) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) CheckBox(com.vaadin.v7.ui.CheckBox) TextField(com.vaadin.v7.ui.TextField) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) List(java.util.List)

Example 3 with VSPACE_3

use of de.symeda.sormas.ui.utils.CssStyles.VSPACE_3 in project SORMAS-Project by hzi-braunschweig.

the class BulkCaseDataForm method addFields.

@SuppressWarnings("deprecation")
@Override
protected void addFields() {
    if (!initialized) {
        return;
    }
    diseaseCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkDisease));
    getContent().addComponent(diseaseCheckBox, DISEASE_CHECKBOX);
    ComboBox disease = addDiseaseField(CaseDataDto.DISEASE, false);
    disease.setEnabled(false);
    addField(CaseDataDto.DISEASE_DETAILS, TextField.class);
    addField(CaseDataDto.PLAGUE_TYPE, NullableOptionGroup.class);
    addField(CaseDataDto.DENGUE_FEVER_TYPE, NullableOptionGroup.class);
    addField(CaseDataDto.RABIES_TYPE, NullableOptionGroup.class);
    if (isVisibleAllowed(CaseDataDto.DISEASE_DETAILS)) {
        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));
    }
    if (isVisibleAllowed(CaseDataDto.PLAGUE_TYPE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.PLAGUE_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.PLAGUE), true);
    }
    if (isVisibleAllowed(CaseDataDto.DENGUE_FEVER_TYPE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.DENGUE_FEVER_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.DENGUE), true);
    }
    if (isVisibleAllowed(CaseDataDto.RABIES_TYPE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.RABIES_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.RABIES), true);
    }
    classificationCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkCaseClassification));
    getContent().addComponent(classificationCheckBox, CLASSIFICATION_CHECKBOX);
    investigationStatusCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkInvestigationStatus));
    getContent().addComponent(investigationStatusCheckBox, INVESTIGATION_STATUS_CHECKBOX);
    outcomeCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkCaseOutcome));
    getContent().addComponent(outcomeCheckBox, OUTCOME_CHECKBOX);
    NullableOptionGroup caseClassification = addField(CaseBulkEditData.CASE_CLASSIFICATION, NullableOptionGroup.class);
    caseClassification.setEnabled(false);
    if (!isConfiguredServer(CountryHelper.COUNTRY_CODE_GERMANY)) {
        caseClassification.removeItem(CaseClassification.CONFIRMED_NO_SYMPTOMS);
        caseClassification.removeItem(CaseClassification.CONFIRMED_UNKNOWN_SYMPTOMS);
    }
    NullableOptionGroup investigationStatus = addField(CaseBulkEditData.INVESTIGATION_STATUS, NullableOptionGroup.class);
    investigationStatus.setEnabled(false);
    NullableOptionGroup outcome = addField(CaseBulkEditData.OUTCOME, NullableOptionGroup.class);
    outcome.setEnabled(false);
    if (singleSelectedDistrict != null) {
        surveillanceOfficerCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkSurveillanceOfficer));
        getContent().addComponent(surveillanceOfficerCheckBox, SURVEILLANCE_OFFICER_CHECKBOX);
        ComboBox surveillanceOfficer = addField(CaseBulkEditData.SURVEILLANCE_OFFICER, ComboBox.class);
        surveillanceOfficer.setEnabled(false);
        FieldHelper.addSoftRequiredStyleWhen(getFieldGroup(), surveillanceOfficerCheckBox, Arrays.asList(CaseBulkEditData.SURVEILLANCE_OFFICER), Arrays.asList(true), null);
        List<UserReferenceDto> assignableSurveillanceOfficers = FacadeProvider.getUserFacade().getUserRefsByDistrict(singleSelectedDistrict, false, UserRole.SURVEILLANCE_OFFICER);
        FieldHelper.updateItems(surveillanceOfficer, assignableSurveillanceOfficers);
        surveillanceOfficerCheckBox.addValueChangeListener(e -> {
            surveillanceOfficer.setEnabled((boolean) e.getProperty().getValue());
        });
    }
    healthFacilityCheckbox = new CheckBox(I18nProperties.getCaption(Captions.bulkFacility));
    getContent().addComponent(healthFacilityCheckbox, HEALTH_FACILITY_CHECKBOX);
    ComboBox region = addInfrastructureField(CaseBulkEditData.REGION);
    region.setEnabled(false);
    ComboBox district = addInfrastructureField(CaseBulkEditData.DISTRICT);
    district.setEnabled(false);
    ComboBox community = addInfrastructureField(CaseBulkEditData.COMMUNITY);
    community.setNullSelectionAllowed(true);
    community.setEnabled(false);
    facilityOrHome = new OptionGroup(I18nProperties.getCaption(Captions.casePlaceOfStay), TypeOfPlace.FOR_CASES);
    addCustomField(facilityOrHome, FACILITY_OR_HOME_LOC, I18nProperties.getCaption(Captions.casePlaceOfStay));
    facilityOrHome.setId("facilityOrHome");
    facilityOrHome.setEnabled(false);
    CssStyles.style(facilityOrHome, ValoTheme.OPTIONGROUP_HORIZONTAL);
    healthFacilityDetails = addField(CaseDataDto.HEALTH_FACILITY_DETAILS, TextField.class);
    healthFacilityDetails.setVisible(false);
    facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
    facilityTypeGroup.setId("typeGroup");
    addCustomField(facilityTypeGroup, TYPE_GROUP_LOC, I18nProperties.getCaption(Captions.Facility_typeGroup));
    facilityTypeGroup.addItems(FacilityTypeGroup.getAccomodationGroups());
    facilityTypeGroup.setEnabled(false);
    facilityType = addField(CaseDataDto.FACILITY_TYPE, ComboBox.class);
    facilityType.setEnabled(false);
    ComboBox facility = addInfrastructureField(CaseBulkEditData.HEALTH_FACILITY);
    facility.setImmediate(true);
    facility.setEnabled(false);
    region.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(district, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
    });
    healthFacilityDetails.addValueChangeListener(e -> {
        updateFacilityFields(facility, healthFacilityDetails);
    });
    district.addValueChangeListener(e -> {
        FieldHelper.removeItems(facility);
        FieldHelper.removeItems(community);
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(community, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
        if (districtDto != null && facilityType.getValue() != null) {
            FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(districtDto, (FacilityType) facilityType.getValue(), true, false));
        }
    });
    community.addValueChangeListener(e -> {
        FieldHelper.removeItems(facility);
        CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
        if (facilityType.getValue() != null) {
            FieldHelper.updateItems(facility, communityDto != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(communityDto, (FacilityType) facilityType.getValue(), true, false) : district.getValue() != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) district.getValue(), (FacilityType) facilityType.getValue(), true, false) : null);
        }
    });
    facilityTypeGroup.addValueChangeListener(e -> {
        FieldHelper.removeItems(facility);
        FieldHelper.updateEnumData(facilityType, FacilityType.getAccommodationTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
    });
    // default value
    facilityTypeGroup.setValue(FacilityTypeGroup.MEDICAL_FACILITY);
    facilityType.addValueChangeListener(e -> {
        FieldHelper.removeItems(facility);
        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));
            }
        }
    });
    warningLayout = VaadinUiUtil.createWarningComponent(I18nProperties.getString(Strings.pseudonymizedCasesSelectedWarning));
    facilityOrHome.addValueChangeListener(e -> {
        FieldHelper.removeItems(facility);
        if (TypeOfPlace.FACILITY.equals(facilityOrHome.getValue())) {
            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((DistrictReferenceDto) district.getValue(), (CommunityReferenceDto) community.getValue(), facility);
            }
            this.getContent().removeComponent(warningLayout);
            healthFacilityDetails.setVisible(false);
        } else {
            long pseudonymizedCount = selectedCases.stream().filter(caze -> caze.isPseudonymized()).count();
            if (pseudonymizedCount > 0) {
                this.getContent().addComponent(warningLayout, WARNING_LAYOUT);
                healthFacilityDetails.setVisible(true);
            }
            FacilityReferenceDto noFacilityRef = FacadeProvider.getFacilityFacade().getByUuid(FacilityDto.NONE_FACILITY_UUID).toReference();
            facility.addItem(noFacilityRef);
            facility.setValue(noFacilityRef);
        }
    });
    facility.addValueChangeListener(e -> {
        updateFacilityFields(facility, healthFacilityDetails);
    });
    // default
    facilityType.setValue(FacilityType.HOSPITAL);
    region.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    if (FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled()) {
        shareWithReportingToolCheckbox = new CheckBox(I18nProperties.getCaption(Captions.bulkCaseShareWithReportingTool));
        shareWithReportingToolCheckbox.addStyleName(VSPACE_3);
        getContent().addComponent(shareWithReportingToolCheckbox, SHARE_CHECKBOX);
        CheckBox dontShareCheckbox = addField(CaseBulkEditData.DONT_SHARE_WITH_REPORTING_TOOL, CheckBox.class);
        CaseFormHelper.addDontShareWithReportingTool(getContent(), () -> dontShareCheckbox, DONT_SHARE_WARNING_LOC, Strings.messageBulkDontShareWithReportingToolWarning);
        dontShareCheckbox.setEnabled(false);
        FieldHelper.setEnabledWhen(shareWithReportingToolCheckbox, Collections.singletonList(Boolean.TRUE), Collections.singletonList(dontShareCheckbox), true);
    }
    FieldHelper.setRequiredWhen(getFieldGroup(), diseaseCheckBox, Arrays.asList(CaseBulkEditData.DISEASE), Arrays.asList(true));
    FieldHelper.setRequiredWhen(getFieldGroup(), classificationCheckBox, Arrays.asList(CaseBulkEditData.CASE_CLASSIFICATION), Arrays.asList(true));
    FieldHelper.setRequiredWhen(getFieldGroup(), investigationStatusCheckBox, Arrays.asList(CaseBulkEditData.INVESTIGATION_STATUS), Arrays.asList(true));
    FieldHelper.setRequiredWhen(getFieldGroup(), outcomeCheckBox, Arrays.asList(CaseBulkEditData.OUTCOME), Arrays.asList(true));
    FieldHelper.setRequiredWhen(getFieldGroup(), healthFacilityCheckbox, Arrays.asList(CaseBulkEditData.REGION, CaseBulkEditData.DISTRICT, CaseBulkEditData.HEALTH_FACILITY), Arrays.asList(true));
    FieldHelper.setRequiredWhen(healthFacilityCheckbox, Arrays.asList(facilityTypeGroup, facilityType, facilityOrHome), Arrays.asList(true), false, null);
    FieldHelper.setVisibleWhen(facilityOrHome, Arrays.asList(facilityTypeGroup, facilityType, facility), Collections.singletonList(TypeOfPlace.FACILITY), false);
    FieldHelper.setRequiredWhen(facilityOrHome, Arrays.asList(facilityTypeGroup, facilityType, facility), Collections.singletonList(TypeOfPlace.FACILITY), false, null);
    diseaseCheckBox.addValueChangeListener(e -> {
        disease.setEnabled((boolean) e.getProperty().getValue());
    });
    classificationCheckBox.addValueChangeListener(e -> {
        caseClassification.setEnabled((boolean) e.getProperty().getValue());
    });
    investigationStatusCheckBox.addValueChangeListener(e -> {
        investigationStatus.setEnabled((boolean) e.getProperty().getValue());
    });
    outcomeCheckBox.addValueChangeListener(e -> {
        outcome.setEnabled((boolean) e.getProperty().getValue());
    });
    healthFacilityCheckbox.addValueChangeListener(e -> {
        region.setEnabled((boolean) e.getProperty().getValue());
        district.setEnabled((boolean) e.getProperty().getValue());
        community.setEnabled((boolean) e.getProperty().getValue());
        facilityTypeGroup.setEnabled((boolean) e.getProperty().getValue());
        facilityOrHome.setEnabled((boolean) e.getProperty().getValue());
        facilityOrHome.setRequired((boolean) e.getProperty().getValue());
        healthFacilityDetails.setEnabled((boolean) e.getProperty().getValue());
        facilityType.setEnabled((boolean) e.getProperty().getValue());
        facility.setEnabled((boolean) e.getProperty().getValue());
        if ((boolean) e.getProperty().getValue()) {
            FieldHelper.addSoftRequiredStyle(community);
        } else {
            FieldHelper.removeSoftRequiredStyle(community);
        }
    });
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) LayoutUtil.fluidRowLocsCss(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocsCss) AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) Arrays(java.util.Arrays) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) CheckBox(com.vaadin.v7.ui.CheckBox) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) LayoutUtil.locs(de.symeda.sormas.ui.utils.LayoutUtil.locs) OptionGroup(com.vaadin.v7.ui.OptionGroup) CssStyles(de.symeda.sormas.ui.utils.CssStyles) VSPACE_4(de.symeda.sormas.ui.utils.CssStyles.VSPACE_4) CountryHelper(de.symeda.sormas.api.CountryHelper) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) UserRole(de.symeda.sormas.api.user.UserRole) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) ComboBox(com.vaadin.v7.ui.ComboBox) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Collection(java.util.Collection) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Captions(de.symeda.sormas.api.i18n.Captions) TypeOfPlace(de.symeda.sormas.api.event.TypeOfPlace) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) List(java.util.List) CaseBulkEditData(de.symeda.sormas.api.caze.CaseBulkEditData) Disease(de.symeda.sormas.api.Disease) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) HorizontalLayout(com.vaadin.ui.HorizontalLayout) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) LayoutUtil.fluidColumn(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumn) TextField(com.vaadin.v7.ui.TextField) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ComboBox(com.vaadin.v7.ui.ComboBox) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) OptionGroup(com.vaadin.v7.ui.OptionGroup) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) CheckBox(com.vaadin.v7.ui.CheckBox) TextField(com.vaadin.v7.ui.TextField) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 4 with VSPACE_3

use of de.symeda.sormas.ui.utils.CssStyles.VSPACE_3 in project SORMAS-Project by hzi-braunschweig.

the class TravelEntryCreateForm method addFields.

@Override
protected void addFields() {
    addField(TravelEntryDto.REPORT_DATE, DateField.class);
    TextField externalIdField = addField(TravelEntryDto.EXTERNAL_ID, TextField.class);
    style(externalIdField, ERROR_COLOR_PRIMARY);
    ComboBox diseaseField = addDiseaseField(TravelEntryDto.DISEASE, false, true);
    ComboBox diseaseVariantField = addField(TravelEntryDto.DISEASE_VARIANT, ComboBox.class);
    diseaseVariantField.setNullSelectionAllowed(true);
    diseaseVariantField.setVisible(false);
    addField(TravelEntryDto.DISEASE_DETAILS, TextField.class);
    TextField diseaseVariantDetailsField = addField(TravelEntryDto.DISEASE_VARIANT_DETAILS, TextField.class);
    diseaseVariantDetailsField.setVisible(false);
    Label jurisdictionHeadingLabel = new Label(I18nProperties.getString(Strings.headingResponsibleJurisdiction));
    jurisdictionHeadingLabel.addStyleName(H3);
    getContent().addComponent(jurisdictionHeadingLabel, RESPONSIBLE_JURISDICTION_HEADING_LOC);
    responsibleRegion = addInfrastructureField(TravelEntryDto.RESPONSIBLE_REGION);
    responsibleRegion.setRequired(true);
    responsibleDistrict = addInfrastructureField(TravelEntryDto.RESPONSIBLE_DISTRICT);
    responsibleDistrict.setRequired(true);
    responsibleCommunity = addInfrastructureField(TravelEntryDto.RESPONSIBLE_COMMUNITY);
    responsibleCommunity.setNullSelectionAllowed(true);
    responsibleCommunity.addStyleName(SOFT_REQUIRED);
    InfrastructureFieldsHelper.initInfrastructureFields(responsibleRegion, responsibleDistrict, responsibleCommunity);
    CheckBox differentPointOfEntryJurisdiction = addCustomField(DIFFERENT_POINT_OF_ENTRY_JURISDICTION, Boolean.class, CheckBox.class);
    differentPointOfEntryJurisdiction.addStyleName(VSPACE_3);
    Label placeOfStayHeadingLabel = new Label(I18nProperties.getCaption(Captions.travelEntryPointOfEntry));
    placeOfStayHeadingLabel.addStyleName(H3);
    getContent().addComponent(placeOfStayHeadingLabel, POINT_OF_ENTRY_HEADING_LOC);
    ComboBox regionCombo = addInfrastructureField(TravelEntryDto.REGION);
    districtCombo = addInfrastructureField(TravelEntryDto.DISTRICT);
    cbPointOfEntry = addInfrastructureField(TravelEntryDto.POINT_OF_ENTRY);
    cbPointOfEntry.setImmediate(true);
    TextField tfPointOfEntryDetails = addField(TravelEntryDto.POINT_OF_ENTRY_DETAILS, TextField.class);
    tfPointOfEntryDetails.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())));
    regionCombo.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    regionCombo.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(districtCombo, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
    });
    districtCombo.addValueChangeListener(e -> {
        if (differentPointOfEntryJurisdiction.getValue()) {
            DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
            getPointsOfEntryForDistrict(districtDto);
        }
    });
    differentPointOfEntryJurisdiction.addValueChangeListener(v -> {
        if (differentPointOfEntryJurisdiction.getValue()) {
            cbPointOfEntry.removeAllItems();
        } else {
            getPointsOfEntryForDistrict((DistrictReferenceDto) responsibleDistrict.getValue());
        }
    });
    // Set initial visibilities & accesses
    initializeVisibilitiesAndAllowedVisibilities();
    setRequired(true, TravelEntryDto.REPORT_DATE, TravelEntryDto.POINT_OF_ENTRY, TravelEntryDto.DISEASE);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(TravelEntryDto.DISEASE_DETAILS), TravelEntryDto.DISEASE, Collections.singletonList(Disease.OTHER), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), TravelEntryDto.DISEASE, Collections.singletonList(TravelEntryDto.DISEASE_DETAILS), Collections.singletonList(Disease.OTHER));
    cbPointOfEntry.addValueChangeListener(e -> updatePointOfEntryFields(cbPointOfEntry, tfPointOfEntryDetails));
    FieldHelper.setVisibleWhen(differentPointOfEntryJurisdiction, Arrays.asList(regionCombo, districtCombo), Collections.singletonList(Boolean.TRUE), true);
    FieldHelper.setRequiredWhen(differentPointOfEntryJurisdiction, Arrays.asList(regionCombo, districtCombo), Collections.singletonList(Boolean.TRUE), false, null);
    responsibleDistrict.addValueChangeListener(e -> {
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        getPointsOfEntryForDistrict(districtDto);
    });
    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(TravelEntryDto.DISEASE_VARIANT) && CollectionUtils.isNotEmpty(diseaseVariants));
    });
    diseaseVariantField.addValueChangeListener(e -> {
        DiseaseVariant diseaseVariant = (DiseaseVariant) e.getProperty().getValue();
        diseaseVariantDetailsField.setVisible(diseaseVariant != null && diseaseVariant.matchPropertyValue(DiseaseVariant.HAS_DETAILS, true));
    });
    addValueChangeListener(e -> {
        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);
        }
    });
}
Also used : H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DeaContentEntry(de.symeda.sormas.api.travelentry.DeaContentEntry) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) StringUtils(org.apache.commons.lang3.StringUtils) PersonDto(de.symeda.sormas.api.person.PersonDto) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) UserRole(de.symeda.sormas.api.user.UserRole) FORCE_CAPTION(de.symeda.sormas.ui.utils.CssStyles.FORCE_CAPTION) UserProvider(de.symeda.sormas.ui.UserProvider) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ComboBox(com.vaadin.v7.ui.ComboBox) Sex(de.symeda.sormas.api.person.Sex) PersonDependentEditForm(de.symeda.sormas.ui.utils.PersonDependentEditForm) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) List(java.util.List) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) FacadeProvider(de.symeda.sormas.api.FacadeProvider) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) DateHelper(de.symeda.sormas.api.utils.DateHelper) Converter(com.vaadin.v7.data.util.converter.Converter) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) CustomizableEnumType(de.symeda.sormas.api.customizableenum.CustomizableEnumType) LayoutUtil.loc(de.symeda.sormas.ui.utils.LayoutUtil.loc) CollectionUtils(org.apache.commons.collections.CollectionUtils) Label(com.vaadin.ui.Label) CountryHelper(de.symeda.sormas.api.CountryHelper) ERROR_COLOR_PRIMARY(de.symeda.sormas.ui.utils.CssStyles.ERROR_COLOR_PRIMARY) DEAFormBuilder(de.symeda.sormas.ui.travelentry.DEAFormBuilder) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) CssStyles.style(de.symeda.sormas.ui.utils.CssStyles.style) Validations(de.symeda.sormas.api.i18n.Validations) Month(java.time.Month) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) SOFT_REQUIRED(de.symeda.sormas.ui.utils.CssStyles.SOFT_REQUIRED) Captions(de.symeda.sormas.api.i18n.Captions) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Button(com.vaadin.ui.Button) LayoutUtil(de.symeda.sormas.ui.utils.LayoutUtil) Disease(de.symeda.sormas.api.Disease) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) Disease(de.symeda.sormas.api.Disease) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.v7.ui.CheckBox) TextField(com.vaadin.v7.ui.TextField) List(java.util.List)

Example 5 with VSPACE_3

use of de.symeda.sormas.ui.utils.CssStyles.VSPACE_3 in project SORMAS-Project by hzi-braunschweig.

the class TravelEntryDataForm method addFields.

@Override
protected void addFields() {
    Label travelEntryDataHeadingLabel = new Label(I18nProperties.getString(Strings.headingTravelEntryData));
    travelEntryDataHeadingLabel.addStyleName(H3);
    getContent().addComponent(travelEntryDataHeadingLabel, TRAVEL_ENTRY_HEADING_LOC);
    addField(TravelEntryDto.REPORT_DATE, DateField.class);
    addFields(TravelEntryDto.UUID, TravelEntryDto.REPORTING_USER);
    TextField externalIdField = addField(TravelEntryDto.EXTERNAL_ID, TextField.class);
    style(externalIdField, ERROR_COLOR_PRIMARY);
    ComboBox diseaseField = addDiseaseField(TravelEntryDto.DISEASE, false);
    ComboBox diseaseVariantField = addField(TravelEntryDto.DISEASE_VARIANT, ComboBox.class);
    diseaseVariantField.setNullSelectionAllowed(true);
    diseaseVariantField.setVisible(false);
    addField(TravelEntryDto.DISEASE_DETAILS, TextField.class);
    TextField diseaseVariantDetailsField = addField(TravelEntryDto.DISEASE_VARIANT_DETAILS, TextField.class);
    diseaseVariantDetailsField.setVisible(false);
    addField(TravelEntryDto.RECOVERED).addStyleNames(CssStyles.FORCE_CAPTION_CHECKBOX);
    addField(TravelEntryDto.VACCINATED).addStyleNames(CssStyles.FORCE_CAPTION_CHECKBOX);
    addField(TravelEntryDto.TESTED_NEGATIVE).addStyleNames(CssStyles.FORCE_CAPTION_CHECKBOX);
    Label jurisdictionHeadingLabel = new Label(I18nProperties.getString(Strings.headingResponsibleJurisdiction));
    jurisdictionHeadingLabel.addStyleName(H3);
    getContent().addComponent(jurisdictionHeadingLabel, RESPONSIBLE_JURISDICTION_HEADING_LOC);
    responsibleRegion = addInfrastructureField(TravelEntryDto.RESPONSIBLE_REGION);
    responsibleRegion.setRequired(true);
    responsibleDistrict = addInfrastructureField(TravelEntryDto.RESPONSIBLE_DISTRICT);
    responsibleDistrict.setRequired(true);
    responsibleCommunity = addInfrastructureField(TravelEntryDto.RESPONSIBLE_COMMUNITY);
    responsibleCommunity.setNullSelectionAllowed(true);
    responsibleCommunity.addStyleName(SOFT_REQUIRED);
    InfrastructureFieldsHelper.initInfrastructureFields(responsibleRegion, responsibleDistrict, responsibleCommunity);
    differentPointOfEntryJurisdiction = addCustomField(DIFFERENT_POINT_OF_ENTRY_JURISDICTION, Boolean.class, CheckBox.class);
    differentPointOfEntryJurisdiction.addStyleName(VSPACE_3);
    Label pointOfEntryHeadingLabel = new Label(I18nProperties.getCaption(Captions.travelEntryPointOfEntry));
    pointOfEntryHeadingLabel.addStyleName(H3);
    getContent().addComponent(pointOfEntryHeadingLabel, POINT_OF_ENTRY_HEADING_LOC);
    ComboBox regionCombo = addInfrastructureField(TravelEntryDto.REGION);
    districtCombo = addInfrastructureField(TravelEntryDto.DISTRICT);
    differentPointOfEntryJurisdiction.addValueChangeListener(e -> {
        if (!ignoreDifferentPointOfEntryJurisdiction) {
            if (differentPointOfEntryJurisdiction.booleanValue()) {
                districtCombo.setValue(null);
            }
            cbPointOfEntry.setValue(null);
            updatePointsOfEntry();
        }
    });
    cbPointOfEntry = addInfrastructureField(TravelEntryDto.POINT_OF_ENTRY);
    cbPointOfEntry.setImmediate(true);
    TextField tfPointOfEntryDetails = addField(TravelEntryDto.POINT_OF_ENTRY_DETAILS, TextField.class);
    tfPointOfEntryDetails.setVisible(false);
    regionCombo.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    regionCombo.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(districtCombo, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
    });
    districtCombo.addValueChangeListener(e -> {
        if (differentPointOfEntryJurisdiction.booleanValue()) {
            updatePointsOfEntry();
        }
    });
    quarantine = addField(TravelEntryDto.QUARANTINE);
    quarantine.addValueChangeListener(e -> onQuarantineValueChange());
    quarantineFrom = addField(TravelEntryDto.QUARANTINE_FROM, DateField.class);
    quarantineTo = addDateField(TravelEntryDto.QUARANTINE_TO, DateField.class, -1);
    quarantineFrom.addValidator(new DateComparisonValidator(quarantineFrom, quarantineTo, true, false, I18nProperties.getValidationError(Validations.beforeDate, quarantineFrom.getCaption(), quarantineTo.getCaption())));
    quarantineTo.addValidator(new DateComparisonValidator(quarantineTo, quarantineFrom, false, false, I18nProperties.getValidationError(Validations.afterDate, quarantineTo.getCaption(), quarantineFrom.getCaption())));
    quarantineOrderedVerbally = addField(TravelEntryDto.QUARANTINE_ORDERED_VERBALLY, CheckBox.class);
    CssStyles.style(quarantineOrderedVerbally, CssStyles.FORCE_CAPTION);
    addField(TravelEntryDto.QUARANTINE_ORDERED_VERBALLY_DATE, DateField.class);
    quarantineOrderedOfficialDocument = addField(TravelEntryDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT, CheckBox.class);
    CssStyles.style(quarantineOrderedOfficialDocument, CssStyles.FORCE_CAPTION);
    addField(TravelEntryDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT_DATE, DateField.class);
    CheckBox quarantineOfficialOrderSent = addField(TravelEntryDto.QUARANTINE_OFFICIAL_ORDER_SENT, CheckBox.class);
    CssStyles.style(quarantineOfficialOrderSent, FORCE_CAPTION);
    addField(TravelEntryDto.QUARANTINE_OFFICIAL_ORDER_SENT_DATE, DateField.class);
    FieldHelper.setVisibleWhen(getFieldGroup(), TravelEntryDto.QUARANTINE_OFFICIAL_ORDER_SENT, TravelEntryDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT, Collections.singletonList(Boolean.TRUE), true);
    quarantineExtended = addField(TravelEntryDto.QUARANTINE_EXTENDED, CheckBox.class);
    quarantineExtended.setEnabled(false);
    quarantineExtended.setVisible(false);
    CssStyles.style(quarantineExtended, CssStyles.FORCE_CAPTION);
    quarantineReduced = addField(TravelEntryDto.QUARANTINE_REDUCED, CheckBox.class);
    quarantineReduced.setEnabled(false);
    quarantineReduced.setVisible(false);
    CssStyles.style(quarantineReduced, CssStyles.FORCE_CAPTION);
    TextField quarantineHelpNeeded = addField(TravelEntryDto.QUARANTINE_HELP_NEEDED, TextField.class);
    quarantineHelpNeeded.setInputPrompt(I18nProperties.getString(Strings.pleaseSpecify));
    TextField quarantineTypeDetails = addField(TravelEntryDto.QUARANTINE_TYPE_DETAILS, TextField.class);
    quarantineTypeDetails.setInputPrompt(I18nProperties.getString(Strings.pleaseSpecify));
    addField(TravelEntryDto.QUARANTINE_HOME_POSSIBLE, NullableOptionGroup.class);
    addField(TravelEntryDto.QUARANTINE_HOME_POSSIBLE_COMMENT, TextField.class);
    addField(TravelEntryDto.QUARANTINE_HOME_SUPPLY_ENSURED, NullableOptionGroup.class);
    addField(TravelEntryDto.QUARANTINE_HOME_SUPPLY_ENSURED_COMMENT, TextField.class);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(TravelEntryDto.QUARANTINE_FROM, TravelEntryDto.QUARANTINE_TO, TravelEntryDto.QUARANTINE_HELP_NEEDED), TravelEntryDto.QUARANTINE, QuarantineType.QUARANTINE_IN_EFFECT, true);
    if (isConfiguredServer(CountryHelper.COUNTRY_CODE_GERMANY) || isConfiguredServer(CountryHelper.COUNTRY_CODE_SWITZERLAND)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(TravelEntryDto.QUARANTINE_ORDERED_VERBALLY, TravelEntryDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT), TravelEntryDto.QUARANTINE, QuarantineType.QUARANTINE_IN_EFFECT, true);
    }
    FieldHelper.setVisibleWhen(getFieldGroup(), TravelEntryDto.QUARANTINE_HOME_POSSIBLE_COMMENT, TravelEntryDto.QUARANTINE_HOME_POSSIBLE, Arrays.asList(YesNoUnknown.NO), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), TravelEntryDto.QUARANTINE_HOME_SUPPLY_ENSURED, TravelEntryDto.QUARANTINE_HOME_POSSIBLE, Arrays.asList(YesNoUnknown.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), TravelEntryDto.QUARANTINE_HOME_SUPPLY_ENSURED_COMMENT, TravelEntryDto.QUARANTINE_HOME_SUPPLY_ENSURED, Arrays.asList(YesNoUnknown.NO), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), TravelEntryDto.QUARANTINE_TYPE_DETAILS, TravelEntryDto.QUARANTINE, Arrays.asList(QuarantineType.OTHER), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), TravelEntryDto.QUARANTINE_ORDERED_VERBALLY_DATE, TravelEntryDto.QUARANTINE_ORDERED_VERBALLY, Arrays.asList(Boolean.TRUE), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), TravelEntryDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT_DATE, TravelEntryDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT, Arrays.asList(Boolean.TRUE), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), TravelEntryDto.QUARANTINE_OFFICIAL_ORDER_SENT_DATE, TravelEntryDto.QUARANTINE_OFFICIAL_ORDER_SENT, Collections.singletonList(Boolean.TRUE), true);
    // Set initial visibilities & accesses
    initializeVisibilitiesAndAllowedVisibilities();
    setRequired(true, TravelEntryDto.REPORT_DATE, TravelEntryDto.POINT_OF_ENTRY, TravelEntryDto.DISEASE);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(TravelEntryDto.DISEASE_DETAILS), TravelEntryDto.DISEASE, Collections.singletonList(Disease.OTHER), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), TravelEntryDto.DISEASE, Collections.singletonList(TravelEntryDto.DISEASE_DETAILS), Collections.singletonList(Disease.OTHER));
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(TravelEntryDto.RECOVERED, TravelEntryDto.VACCINATED, TravelEntryDto.TESTED_NEGATIVE), TravelEntryDto.DISEASE, Disease.DISEASE_LIST, true);
    cbPointOfEntry.addValueChangeListener(e -> updatePointOfEntryFields(cbPointOfEntry, tfPointOfEntryDetails));
    FieldHelper.setVisibleWhen(differentPointOfEntryJurisdiction, Arrays.asList(regionCombo, districtCombo), Collections.singletonList(Boolean.TRUE), true);
    FieldHelper.setRequiredWhen(differentPointOfEntryJurisdiction, Arrays.asList(regionCombo, districtCombo), Collections.singletonList(Boolean.TRUE), false, null);
    setReadOnly(true, TravelEntryDto.UUID, TravelEntryDto.REPORTING_USER);
    responsibleDistrict.addValueChangeListener(e -> {
        if (!differentPointOfEntryJurisdiction.booleanValue()) {
            updatePointsOfEntry();
        }
    });
    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(TravelEntryDto.DISEASE_VARIANT) && CollectionUtils.isNotEmpty(diseaseVariants));
    });
    diseaseVariantField.addValueChangeListener(e -> {
        DiseaseVariant diseaseVariant = (DiseaseVariant) e.getProperty().getValue();
        diseaseVariantDetailsField.setVisible(diseaseVariant != null && diseaseVariant.matchPropertyValue(DiseaseVariant.HAS_DETAILS, true));
    });
}
Also used : FeatureType(de.symeda.sormas.api.feature.FeatureType) AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DeaContentEntry(de.symeda.sormas.api.travelentry.DeaContentEntry) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) CssStyles(de.symeda.sormas.ui.utils.CssStyles) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) UserRole(de.symeda.sormas.api.user.UserRole) FORCE_CAPTION(de.symeda.sormas.ui.utils.CssStyles.FORCE_CAPTION) UserProvider(de.symeda.sormas.ui.UserProvider) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ComboBox(com.vaadin.v7.ui.ComboBox) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) List(java.util.List) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) FacadeProvider(de.symeda.sormas.api.FacadeProvider) Converter(com.vaadin.v7.data.util.converter.Converter) CustomizableEnumType(de.symeda.sormas.api.customizableenum.CustomizableEnumType) QuarantineType(de.symeda.sormas.api.contact.QuarantineType) LayoutUtil.loc(de.symeda.sormas.ui.utils.LayoutUtil.loc) CollectionUtils(org.apache.commons.collections.CollectionUtils) Label(com.vaadin.ui.Label) CountryHelper(de.symeda.sormas.api.CountryHelper) ERROR_COLOR_PRIMARY(de.symeda.sormas.ui.utils.CssStyles.ERROR_COLOR_PRIMARY) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) CssStyles.style(de.symeda.sormas.ui.utils.CssStyles.style) Validations(de.symeda.sormas.api.i18n.Validations) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) SOFT_REQUIRED(de.symeda.sormas.ui.utils.CssStyles.SOFT_REQUIRED) Captions(de.symeda.sormas.api.i18n.Captions) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) Disease(de.symeda.sormas.api.Disease) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Disease(de.symeda.sormas.api.Disease) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) ComboBox(com.vaadin.v7.ui.ComboBox) CheckBox(com.vaadin.v7.ui.CheckBox) Label(com.vaadin.ui.Label) TextField(com.vaadin.v7.ui.TextField) List(java.util.List) DateField(com.vaadin.v7.ui.DateField) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator)

Aggregations

ComboBox (com.vaadin.v7.ui.ComboBox)10 TextField (com.vaadin.v7.ui.TextField)10 Disease (de.symeda.sormas.api.Disease)10 FacadeProvider (de.symeda.sormas.api.FacadeProvider)10 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)10 VSPACE_3 (de.symeda.sormas.ui.utils.CssStyles.VSPACE_3)10 FieldHelper (de.symeda.sormas.ui.utils.FieldHelper)10 LayoutUtil.fluidRowLocs (de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs)10 Arrays (java.util.Arrays)10 Label (com.vaadin.ui.Label)9 CheckBox (com.vaadin.v7.ui.CheckBox)9 DateField (com.vaadin.v7.ui.DateField)9 Captions (de.symeda.sormas.api.i18n.Captions)9 Strings (de.symeda.sormas.api.i18n.Strings)9 Validations (de.symeda.sormas.api.i18n.Validations)9 FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)9 H3 (de.symeda.sormas.ui.utils.CssStyles.H3)9 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)9 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)8 UiFieldAccessCheckers (de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers)8