Search in sources :

Example 1 with LocationEditForm

use of de.symeda.sormas.ui.location.LocationEditForm in project SORMAS-Project by hzi-braunschweig.

the class CaseCreateForm method addHomeAddressForm.

private void addHomeAddressForm() {
    enterHomeAddressNow = new CheckBox(I18nProperties.getCaption(Captions.caseDataEnterHomeAddressNow));
    enterHomeAddressNow.addStyleName(VSPACE_3);
    getContent().addComponent(enterHomeAddressNow, ENTER_HOME_ADDRESS_NOW);
    Label addressHeader = new Label(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.ADDRESS));
    addressHeader.addStyleName(H3);
    getContent().addComponent(addressHeader, HOME_ADDRESS_HEADER);
    addressHeader.setVisible(false);
    homeAddressForm = new LocationEditForm(FieldVisibilityCheckers.withCountry(FacadeProvider.getConfigFacade().getCountryLocale()), UiFieldAccessCheckers.getNoop());
    homeAddressForm.setValue(new LocationDto());
    homeAddressForm.setCaption(null);
    homeAddressForm.setWidthFull();
    homeAddressForm.setDisableFacilityAddressCheck(true);
    getContent().addComponent(homeAddressForm, HOME_ADDRESS_LOC);
    homeAddressForm.setVisible(false);
    enterHomeAddressNow.addValueChangeListener(e -> {
        boolean isChecked = (boolean) e.getProperty().getValue();
        addressHeader.setVisible(isChecked);
        homeAddressForm.setVisible(isChecked);
        homeAddressForm.clear();
        homeAddressForm.setFacilityFieldsVisible(isChecked, true);
    });
}
Also used : CheckBox(com.vaadin.v7.ui.CheckBox) Label(com.vaadin.ui.Label) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) LocationDto(de.symeda.sormas.api.location.LocationDto)

Example 2 with LocationEditForm

use of de.symeda.sormas.ui.location.LocationEditForm in project SORMAS-Project by hzi-braunschweig.

the class LocationsField method editEntry.

@Override
protected void editEntry(LocationDto entry, boolean create, Consumer<LocationDto> commitCallback) {
    LocationEditForm editForm = new LocationEditForm(fieldVisibilityCheckers, fieldAccessCheckers);
    editForm.showAddressType();
    editForm.setValue(entry);
    final CommitDiscardWrapperComponent<LocationEditForm> editView = new CommitDiscardWrapperComponent<>(editForm, true, editForm.getFieldGroup());
    editView.getCommitButton().setCaption(I18nProperties.getString(Strings.done));
    Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getCaption(LocationDto.I18N_PREFIX));
    editView.addCommitListener(() -> {
        if (!editForm.getFieldGroup().isModified()) {
            commitCallback.accept(editForm.getValue());
        }
    });
    if (!isEmpty(entry)) {
        editView.addDeleteListener(() -> {
            popupWindow.close();
            LocationsField.this.removeEntry(entry);
        }, I18nProperties.getCaption(LocationDto.I18N_PREFIX));
    }
}
Also used : Window(com.vaadin.ui.Window) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm)

Example 3 with LocationEditForm

use of de.symeda.sormas.ui.location.LocationEditForm in project SORMAS-Project by hzi-braunschweig.

the class EventDataForm method addFields.

@Override
protected void addFields() {
    if (isCreateForm == null) {
        return;
    }
    Label eventDataHeadingLabel = new Label(I18nProperties.getString(Strings.headingEventData));
    eventDataHeadingLabel.addStyleName(H3);
    getContent().addComponent(eventDataHeadingLabel, EVENT_DATA_HEADING_LOC);
    Label informationSourceHeadingLabel = new Label(I18nProperties.getString(Strings.headingInformationSource));
    informationSourceHeadingLabel.addStyleName(H3);
    getContent().addComponent(informationSourceHeadingLabel, INFORMATION_SOURCE_HEADING_LOC);
    Label locationHeadingLabel = new Label(I18nProperties.getString(Strings.headingLocation));
    locationHeadingLabel.addStyleName(H3);
    getContent().addComponent(locationHeadingLabel, LOCATION_HEADING_LOC);
    addField(EventDto.UUID, TextField.class);
    ComboBox diseaseField = addDiseaseField(EventDto.DISEASE, false, isCreateForm);
    addField(EventDto.DISEASE_DETAILS, TextField.class);
    ComboBox diseaseVariantField = addField(EventDto.DISEASE_VARIANT, ComboBox.class);
    diseaseVariantField.setNullSelectionAllowed(true);
    addFields(EventDto.EXTERNAL_ID);
    TextField diseaseVariantDetailsField = addField(EventDto.DISEASE_VARIANT_DETAILS, TextField.class);
    diseaseVariantDetailsField.setVisible(false);
    TextField externalTokenField = addField(EventDto.EXTERNAL_TOKEN);
    Label externalTokenWarningLabel = new Label(I18nProperties.getString(Strings.messageEventExternalTokenWarning));
    externalTokenWarningLabel.addStyleNames(VSPACE_3, LABEL_WHITE_SPACE_NORMAL);
    getContent().addComponent(externalTokenWarningLabel, EXTERNAL_TOKEN_WARNING_LOC);
    addField(EventDto.INTERNAL_TOKEN);
    DateTimeField startDate = addField(EventDto.START_DATE, DateTimeField.class);
    CheckBox multiDayCheckbox = addField(EventDto.MULTI_DAY_EVENT, CheckBox.class);
    DateTimeField endDate = addField(EventDto.END_DATE, DateTimeField.class);
    initEventDateValidation(startDate, endDate, multiDayCheckbox);
    addField(EventDto.EVENT_STATUS, NullableOptionGroup.class);
    addField(EventDto.RISK_LEVEL);
    ComboBox specificRiskField = addField(EventDto.SPECIFIC_RISK, ComboBox.class);
    specificRiskField.setNullSelectionAllowed(true);
    addField(EventDto.EVENT_MANAGEMENT_STATUS, NullableOptionGroup.class);
    addField(EventDto.EVENT_IDENTIFICATION_SOURCE, NullableOptionGroup.class);
    addField(EventDto.EVENT_INVESTIGATION_STATUS, NullableOptionGroup.class);
    addField(EventDto.EVENT_INVESTIGATION_START_DATE, DateField.class);
    addField(EventDto.EVENT_INVESTIGATION_END_DATE, DateField.class);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(EventDto.EVENT_INVESTIGATION_START_DATE, EventDto.EVENT_INVESTIGATION_END_DATE), EventDto.EVENT_INVESTIGATION_STATUS, Arrays.asList(EventInvestigationStatus.ONGOING, EventInvestigationStatus.DONE, EventInvestigationStatus.DISCARDED), true);
    TextField title = addField(EventDto.EVENT_TITLE, TextField.class);
    title.addStyleName(CssStyles.SOFT_REQUIRED);
    TextArea descriptionField = addField(EventDto.EVENT_DESC, TextArea.class, new ResizableTextAreaWrapper<>());
    descriptionField.setRows(2);
    descriptionField.setDescription(I18nProperties.getPrefixDescription(EventDto.I18N_PREFIX, EventDto.EVENT_DESC, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    addField(EventDto.DISEASE_TRANSMISSION_MODE, ComboBox.class);
    addField(EventDto.NOSOCOMIAL, NullableOptionGroup.class);
    addFields(EventDto.HUMAN_TRANSMISSION_MODE, EventDto.INFECTION_PATH_CERTAINTY);
    addFields(EventDto.PARENTERAL_TRANSMISSION_MODE, EventDto.MEDICALLY_ASSOCIATED_TRANSMISSION_MODE);
    final NullableOptionGroup epidemiologicalEvidence = addField(EventDto.EPIDEMIOLOGICAL_EVIDENCE, NullableOptionGroup.class);
    final NullableOptionGroup laboratoryDiagnosticEvidence = addField(EventDto.LABORATORY_DIAGNOSTIC_EVIDENCE, NullableOptionGroup.class);
    epidemiologicalEvidenceCheckBoxTree = new EpidemiologicalEvidenceCheckBoxTree(Arrays.stream(EpidemiologicalEvidenceDetail.values()).map(epidemiologicalEvidenceDetail -> epidemiologicalEvidenceDetailToCheckBoxElement(epidemiologicalEvidenceDetail)).collect(Collectors.toList()));
    getContent().addComponent(epidemiologicalEvidenceCheckBoxTree, EventDto.EPIDEMIOLOGICAL_EVIDENCE_DETAILS);
    epidemiologicalEvidenceCheckBoxTree.setVisible(false);
    laboratoryDiagnosticEvidenceCheckBoxTree = new LaboratoryDiagnosticEvidenceCheckBoxTree(Arrays.stream(LaboratoryDiagnosticEvidenceDetail.values()).map(laboratoryDiagnosticEvidenceDetail -> laboratoryDiagnosticEvidenceDetailToCheckBoxElement(laboratoryDiagnosticEvidenceDetail)).collect(Collectors.toList()));
    getContent().addComponent(laboratoryDiagnosticEvidenceCheckBoxTree, EventDto.LABORATORY_DIAGNOSTIC_EVIDENCE_DETAILS);
    laboratoryDiagnosticEvidenceCheckBoxTree.setVisible(false);
    DateField evolutionDateField = addField(EventDto.EVOLUTION_DATE, DateField.class);
    TextField evolutionCommentField = addField(EventDto.EVOLUTION_COMMENT, TextField.class);
    Field<?> statusField = getField(EventDto.EVENT_STATUS);
    statusField.addValueChangeListener(e -> {
        if (statusField.getValue() == null) {
            return;
        }
        EventStatus eventStatus = (EventStatus) statusField.getValue();
        // The status will be used to modify the caption of the field
        // However we don't want to have somthing like "Dropped evolution date"
        // So let's ignore the DROPPED status and use the Event entity caption instead
        String statusCaption;
        if (eventStatus == EventStatus.DROPPED) {
            statusCaption = I18nProperties.getCaption(EVENT_ENTITY);
        } else {
            statusCaption = I18nProperties.getEnumCaption(eventStatus);
        }
        evolutionDateField.setCaption(String.format(I18nProperties.getCaption(EVOLUTION_DATE_WITH_STATUS), statusCaption));
        evolutionCommentField.setCaption(String.format(I18nProperties.getCaption(EVOLUTION_COMMENT_WITH_STATUS), statusCaption));
    });
    FieldHelper.setVisibleWhenSourceNotNull(getFieldGroup(), Collections.singletonList(EventDto.EVOLUTION_COMMENT), EventDto.EVOLUTION_DATE, true);
    ComboBox typeOfPlace = addField(EventDto.TYPE_OF_PLACE, ComboBox.class);
    typeOfPlace.setNullSelectionAllowed(true);
    addField(EventDto.TYPE_OF_PLACE_TEXT, TextField.class);
    addField(EventDto.WORK_ENVIRONMENT);
    ComboBox meansOfTransport = addField(EventDto.MEANS_OF_TRANSPORT);
    TextField connectionNumber = addField(EventDto.CONNECTION_NUMBER);
    DateField travelDate = addField(EventDto.TRAVEL_DATE);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(EventDto.MEANS_OF_TRANSPORT), EventDto.TYPE_OF_PLACE, Collections.singletonList(TypeOfPlace.MEANS_OF_TRANSPORT), true);
    TextField meansOfTransportDetails = addField(EventDto.MEANS_OF_TRANSPORT_DETAILS);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(EventDto.MEANS_OF_TRANSPORT_DETAILS), EventDto.MEANS_OF_TRANSPORT, Collections.singletonList(MeansOfTransport.OTHER), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(EventDto.CONNECTION_NUMBER, EventDto.TRAVEL_DATE), EventDto.TYPE_OF_PLACE, Collections.singletonList(TypeOfPlace.MEANS_OF_TRANSPORT), true);
    getField(EventDto.MEANS_OF_TRANSPORT).addValueChangeListener(e -> {
        if (e.getProperty().getValue() == MeansOfTransport.PLANE) {
            getField(EventDto.CONNECTION_NUMBER).setCaption(I18nProperties.getCaption(Captions.exposureFlightNumber));
        } else {
            getField(EventDto.CONNECTION_NUMBER).setCaption(I18nProperties.getPrefixCaption(EventDto.I18N_PREFIX, EventDto.CONNECTION_NUMBER));
        }
    });
    DateField reportDate = addField(EventDto.REPORT_DATE_TIME, DateField.class);
    addField(EventDto.REPORTING_USER, ComboBox.class);
    addField(EventDto.TRANSREGIONAL_OUTBREAK, NullableOptionGroup.class);
    ComboBox srcType = addField(EventDto.SRC_TYPE);
    TextField srcFirstName = addField(EventDto.SRC_FIRST_NAME, TextField.class);
    TextField srcLastName = addField(EventDto.SRC_LAST_NAME, TextField.class);
    TextField srcTelNo = addField(EventDto.SRC_TEL_NO, TextField.class);
    addField(EventDto.SRC_EMAIL, TextField.class);
    TextField srcMediaWebsite = addField(EventDto.SRC_MEDIA_WEBSITE, TextField.class);
    TextField srcMediaName = addField(EventDto.SRC_MEDIA_NAME, TextField.class);
    TextArea srcMediaDetails = addField(EventDto.SRC_MEDIA_DETAILS, TextArea.class);
    srcMediaDetails.setRows(4);
    ComboBox srcInstitutionalPartnerType = addField(EventDto.SRC_INSTITUTIONAL_PARTNER_TYPE);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(EventDto.SRC_INSTITUTIONAL_PARTNER_TYPE), EventDto.SRC_TYPE, Collections.singletonList(EventSourceType.INSTITUTIONAL_PARTNER), true);
    TextField srcInstitutionalPartnerTypeDetails = addField(EventDto.SRC_INSTITUTIONAL_PARTNER_TYPE_DETAILS);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(EventDto.SRC_INSTITUTIONAL_PARTNER_TYPE_DETAILS), EventDto.SRC_INSTITUTIONAL_PARTNER_TYPE, Collections.singletonList(InstitutionalPartnerType.OTHER), true);
    addField(EventDto.EVENT_LOCATION, new LocationEditForm(fieldVisibilityCheckers, createFieldAccessCheckers(isPseudonymized, false))).setCaption(null);
    locationForm = (LocationEditForm) getFieldGroup().getField(EventDto.EVENT_LOCATION);
    locationForm.setDistrictRequiredOnDefaultCountry(true);
    ComboBox regionField = (ComboBox) locationForm.getFieldGroup().getField(LocationDto.REGION);
    ComboBox districtField = (ComboBox) locationForm.getFieldGroup().getField(LocationDto.DISTRICT);
    ComboBox responsibleUserField = addField(EventDto.RESPONSIBLE_USER, ComboBox.class);
    responsibleUserField.setNullSelectionAllowed(true);
    if (isCreateForm) {
        locationForm.hideValidationUntilNextCommit();
    }
    setReadOnly(true, EventDto.UUID, EventDto.REPORTING_USER);
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.WORK_ENVIRONMENT, locationForm.getFacilityTypeGroup(), Collections.singletonList(FacilityTypeGroup.WORKING_PLACE), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(EventDto.DISEASE_DETAILS), EventDto.DISEASE, Collections.singletonList(Disease.OTHER), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), EventDto.DISEASE, Collections.singletonList(EventDto.DISEASE_DETAILS), Collections.singletonList(Disease.OTHER));
    // Customizable enum fields visibilities
    diseaseVariantField.setVisible(false);
    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 && CollectionUtils.isNotEmpty(diseaseVariants));
        List<SpecificRisk> specificRiskValues = FacadeProvider.getCustomizableEnumFacade().getEnumValues(CustomizableEnumType.SPECIFIC_EVENT_RISK, disease);
        FieldHelper.updateItems(specificRiskField, specificRiskValues);
        specificRiskField.setVisible(isVisibleAllowed(EventDto.SPECIFIC_RISK) && CollectionUtils.isNotEmpty(specificRiskValues));
    });
    diseaseVariantField.addValueChangeListener(e -> {
        DiseaseVariant diseaseVariant = (DiseaseVariant) e.getProperty().getValue();
        diseaseVariantDetailsField.setVisible(diseaseVariant != null && diseaseVariant.matchPropertyValue(DiseaseVariant.HAS_DETAILS, true));
    });
    setRequired(true, EventDto.EVENT_STATUS, EventDto.UUID, EventDto.EVENT_TITLE, EventDto.REPORT_DATE_TIME, EventDto.REPORTING_USER);
    reportDate.addValidator(new DateComparisonValidator(reportDate, startDate, false, false, I18nProperties.getValidationError(Validations.afterDate, reportDate.getCaption(), startDate.getCaption())));
    startDate.addValidator(new DateComparisonValidator(startDate, reportDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, startDate.getCaption(), reportDate.getCaption())));
    FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.END_DATE, EventDto.MULTI_DAY_EVENT, Collections.singletonList(true), true);
    FieldHelper.setCaptionWhen(multiDayCheckbox, startDate, false, I18nProperties.getCaption(Captions.singleDayEventDate), I18nProperties.getCaption(Captions.Event_startDate));
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(EventDto.NOSOCOMIAL, EventDto.TRANSREGIONAL_OUTBREAK, EventDto.DISEASE_TRANSMISSION_MODE), EventDto.EVENT_STATUS, Collections.singletonList(EventStatus.CLUSTER), true);
    if (isVisibleAllowed(EventDto.INFECTION_PATH_CERTAINTY)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.INFECTION_PATH_CERTAINTY, EventDto.NOSOCOMIAL, Collections.singletonList(YesNoUnknown.YES), true);
    }
    if (isVisibleAllowed(EventDto.HUMAN_TRANSMISSION_MODE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.HUMAN_TRANSMISSION_MODE, EventDto.DISEASE_TRANSMISSION_MODE, Collections.singletonList(DiseaseTransmissionMode.HUMAN_TO_HUMAN), true);
    }
    if (isVisibleAllowed(EventDto.PARENTERAL_TRANSMISSION_MODE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.PARENTERAL_TRANSMISSION_MODE, EventDto.HUMAN_TRANSMISSION_MODE, Collections.singletonList(HumanTransmissionMode.PARENTERAL), true);
    }
    if (isVisibleAllowed(EventDto.MEDICALLY_ASSOCIATED_TRANSMISSION_MODE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.MEDICALLY_ASSOCIATED_TRANSMISSION_MODE, EventDto.PARENTERAL_TRANSMISSION_MODE, Collections.singletonList(ParenteralTransmissionMode.MEDICALLY_ASSOCIATED), true);
    }
    if (isVisibleAllowed(EventDto.EPIDEMIOLOGICAL_EVIDENCE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.EPIDEMIOLOGICAL_EVIDENCE, EventDto.DISEASE_TRANSMISSION_MODE, Collections.singletonList(DiseaseTransmissionMode.HUMAN_TO_HUMAN), true);
        epidemiologicalEvidence.addValueChangeListener(valueChangeEvent -> {
            if (((NullableOptionGroup) valueChangeEvent.getProperty()).getNullableValue() == YesNoUnknown.YES) {
                epidemiologicalEvidenceCheckBoxTree.setVisible(true);
            } else {
                epidemiologicalEvidenceCheckBoxTree.clearCheckBoxTree();
                epidemiologicalEvidenceCheckBoxTree.setVisible(false);
            }
        });
    }
    if (isVisibleAllowed(EventDto.LABORATORY_DIAGNOSTIC_EVIDENCE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.LABORATORY_DIAGNOSTIC_EVIDENCE, EventDto.DISEASE_TRANSMISSION_MODE, Collections.singletonList(DiseaseTransmissionMode.HUMAN_TO_HUMAN), true);
        laboratoryDiagnosticEvidence.addValueChangeListener(valueChangeEvent -> {
            if (((NullableOptionGroup) valueChangeEvent.getProperty()).getNullableValue() == YesNoUnknown.YES) {
                laboratoryDiagnosticEvidenceCheckBoxTree.setVisible(true);
            } else {
                laboratoryDiagnosticEvidenceCheckBoxTree.clearCheckBoxTree();
                laboratoryDiagnosticEvidenceCheckBoxTree.setVisible(false);
            }
        });
    }
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(EventDto.SRC_FIRST_NAME, EventDto.SRC_LAST_NAME, EventDto.SRC_TEL_NO, EventDto.SRC_EMAIL), EventDto.SRC_TYPE, Arrays.asList(EventSourceType.HOTLINE_PERSON, EventSourceType.INSTITUTIONAL_PARTNER), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(EventDto.SRC_MEDIA_WEBSITE, EventDto.SRC_MEDIA_NAME, EventDto.SRC_MEDIA_DETAILS), EventDto.SRC_TYPE, Collections.singletonList(EventSourceType.MEDIA_NEWS), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.TYPE_OF_PLACE_TEXT, EventDto.TYPE_OF_PLACE, Collections.singletonList(TypeOfPlace.OTHER), true);
    setTypeOfPlaceTextRequirement();
    locationForm.setFacilityFieldsVisible(getField(EventDto.TYPE_OF_PLACE).getValue() == TypeOfPlace.FACILITY, true);
    typeOfPlace.addValueChangeListener(e -> locationForm.setFacilityFieldsVisible(e.getProperty().getValue() == TypeOfPlace.FACILITY, true));
    regionField.addValueChangeListener(e -> {
        RegionReferenceDto region = (RegionReferenceDto) regionField.getValue();
        if (region != null) {
            responsibleUserSurveillanceSupervisors = FacadeProvider.getUserFacade().getUsersByRegionAndRoles(region, UserRole.SURVEILLANCE_SUPERVISOR);
        } else {
            responsibleUserSurveillanceSupervisors.clear();
        }
    });
    districtField.addValueChangeListener(e -> {
        DistrictReferenceDto district = (DistrictReferenceDto) districtField.getValue();
        if (district != null) {
            List<UserReferenceDto> currentDistrictSurveillanceOfficers = FacadeProvider.getUserFacade().getUserRefsByDistrict(district, false, UserRole.SURVEILLANCE_OFFICER);
            List<UserReferenceDto> responsibleUsers = new ArrayList<>();
            responsibleUsers.addAll(currentDistrictSurveillanceOfficers);
            responsibleUsers.addAll(responsibleUserSurveillanceSupervisors);
            FieldHelper.updateItems(responsibleUserField, responsibleUsers);
        } else {
            responsibleUserField.removeAllItems();
        }
    });
    FieldHelper.addSoftRequiredStyle(startDate, endDate, typeOfPlace, meansOfTransport, meansOfTransportDetails, connectionNumber, travelDate, responsibleUserField, srcType, srcInstitutionalPartnerType, srcInstitutionalPartnerTypeDetails, srcFirstName, srcLastName, srcTelNo, srcMediaWebsite, srcMediaName);
    // Make external ID field read-only when SORMAS is connected to a SurvNet instance
    if (StringUtils.isNotEmpty(FacadeProvider.getConfigFacade().getExternalSurveillanceToolGatewayUrl())) {
        setEnabled(false, EventDto.EXTERNAL_ID);
        ((TextField) getField(EventDto.EXTERNAL_ID)).setInputPrompt(I18nProperties.getString(Strings.promptExternalIdExternalSurveillanceTool));
    }
    addValueChangeListener((e) -> {
        ValidationUtils.initComponentErrorValidator(externalTokenField, getValue().getExternalToken(), Validations.duplicateExternalToken, externalTokenWarningLabel, (externalToken) -> FacadeProvider.getEventFacade().doesExternalTokenExist(externalToken, getValue().getUuid()));
        epidemiologicalEvidenceCheckBoxTree.initCheckboxes();
        laboratoryDiagnosticEvidenceCheckBoxTree.initCheckboxes();
        // Initialize specific risk field if disease is null
        if (getValue().getDisease() == null) {
            List<SpecificRisk> specificRiskValues = FacadeProvider.getCustomizableEnumFacade().getEnumValues(CustomizableEnumType.SPECIFIC_EVENT_RISK, null);
            FieldHelper.updateItems(specificRiskField, specificRiskValues);
            specificRiskField.setVisible(isVisibleAllowed(EventDto.SPECIFIC_RISK) && CollectionUtils.isNotEmpty(specificRiskValues));
        }
    });
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) CheckBoxTree(de.symeda.sormas.ui.utils.CheckBoxTree) H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) DiseaseTransmissionMode(de.symeda.sormas.api.event.DiseaseTransmissionMode) ValidationUtils(de.symeda.sormas.ui.utils.ValidationUtils) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) LayoutUtil.locs(de.symeda.sormas.ui.utils.LayoutUtil.locs) StringUtils(org.apache.commons.lang3.StringUtils) SpecificRisk(de.symeda.sormas.api.event.SpecificRisk) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) EpidemiologicalEvidenceDetail(de.symeda.sormas.api.event.EpidemiologicalEvidenceDetail) HumanTransmissionMode(de.symeda.sormas.api.event.HumanTransmissionMode) CssStyles(de.symeda.sormas.ui.utils.CssStyles) EventInvestigationStatus(de.symeda.sormas.api.event.EventInvestigationStatus) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) UserRole(de.symeda.sormas.api.user.UserRole) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ComboBox(com.vaadin.v7.ui.ComboBox) LaboratoryDiagnosticEvidenceDetail(de.symeda.sormas.api.event.LaboratoryDiagnosticEvidenceDetail) Field(com.vaadin.v7.ui.Field) EventDto(de.symeda.sormas.api.event.EventDto) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) TypeOfPlace(de.symeda.sormas.api.event.TypeOfPlace) List(java.util.List) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) InstitutionalPartnerType(de.symeda.sormas.api.event.InstitutionalPartnerType) TextField(com.vaadin.v7.ui.TextField) MeansOfTransport(de.symeda.sormas.api.event.MeansOfTransport) Descriptions(de.symeda.sormas.api.i18n.Descriptions) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) LABEL_WHITE_SPACE_NORMAL(de.symeda.sormas.ui.utils.CssStyles.LABEL_WHITE_SPACE_NORMAL) FacadeProvider(de.symeda.sormas.api.FacadeProvider) VerticalLayout(com.vaadin.ui.VerticalLayout) Converter(com.vaadin.v7.data.util.converter.Converter) EventStatus(de.symeda.sormas.api.event.EventStatus) ArrayList(java.util.ArrayList) 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) 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) Validations(de.symeda.sormas.api.i18n.Validations) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ResizableTextAreaWrapper(de.symeda.sormas.ui.utils.ResizableTextAreaWrapper) Captions(de.symeda.sormas.api.i18n.Captions) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) ParenteralTransmissionMode(de.symeda.sormas.api.event.ParenteralTransmissionMode) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Disease(de.symeda.sormas.api.Disease) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) TextArea(com.vaadin.v7.ui.TextArea) EventSourceType(de.symeda.sormas.api.event.EventSourceType) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) LayoutUtil.fluidColumn(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumn) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) Disease(de.symeda.sormas.api.Disease) TextArea(com.vaadin.v7.ui.TextArea) Label(com.vaadin.ui.Label) EventStatus(de.symeda.sormas.api.event.EventStatus) ArrayList(java.util.ArrayList) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) TextField(com.vaadin.v7.ui.TextField) List(java.util.List) ArrayList(java.util.ArrayList) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) ComboBox(com.vaadin.v7.ui.ComboBox) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) SpecificRisk(de.symeda.sormas.api.event.SpecificRisk) CheckBox(com.vaadin.v7.ui.CheckBox) DateField(com.vaadin.v7.ui.DateField)

Example 4 with LocationEditForm

use of de.symeda.sormas.ui.location.LocationEditForm in project SORMAS-Project by hzi-braunschweig.

the class CommitDiscardWrapperComponent method addDirtyHandler.

@SuppressWarnings("deprecation")
protected void addDirtyHandler(FieldGroup[] fieldGroups) {
    if (fieldGroups != null) {
        Stream.of(fieldGroups).forEach(fg -> fg.getFields().forEach(f -> f.addValueChangeListener(ev -> {
            final Object source = ((Field.ValueChangeEvent) ev).getSource();
            // moving it to a separate method breaks the logic at least on my dev system
            if (source instanceof PersonEditForm) {
                final PersonEditForm personEditForm = (PersonEditForm) source;
                final LocationEditForm locationEditForm = personEditForm.getField(PersonDto.ADDRESS);
                if (atLeastOneFieldModified(locationEditForm.getField(LocationDto.LATITUDE), locationEditForm.getField(LocationDto.LONGITUDE), locationEditForm.getField(LocationDto.LAT_LON_ACCURACY))) {
                    dirty = true;
                } else if (locationEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
                    dirty = true;
                } else if (personEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
                    dirty = true;
                }
            } else if (source instanceof EventDataForm) {
                final EventDataForm eventDataForm = (EventDataForm) source;
                final LocationEditForm locationEditForm = eventDataForm.getField(EventDto.EVENT_LOCATION);
                if (atLeastOneFieldModified(locationEditForm.getField(LocationDto.LATITUDE), locationEditForm.getField(LocationDto.LONGITUDE), locationEditForm.getField(LocationDto.LAT_LON_ACCURACY))) {
                    dirty = true;
                } else if (locationEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
                    dirty = true;
                } else if (eventDataForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
                    dirty = true;
                }
            } else if (source instanceof LocationEditForm) {
                final LocationEditForm locationEditForm = (LocationEditForm) source;
                if (atLeastOneFieldModified(locationEditForm.getField(LocationDto.LATITUDE), locationEditForm.getField(LocationDto.LONGITUDE), locationEditForm.getField(LocationDto.LAT_LON_ACCURACY))) {
                    dirty = true;
                } else if (locationEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
                    dirty = true;
                }
            } else if (source instanceof AccessibleTextField) {
                final AccessibleTextField accessibleTextField = (AccessibleTextField) source;
                if (accessibleTextField.isModified()) {
                    dirty = true;
                }
            } else {
                dirty = true;
            }
        })));
    }
}
Also used : Panel(com.vaadin.ui.Panel) EventDataForm(de.symeda.sormas.ui.events.EventDataForm) Arrays(java.util.Arrays) ClickListener(com.vaadin.ui.Button.ClickListener) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) VerticalLayout(com.vaadin.ui.VerticalLayout) Alignment(com.vaadin.ui.Alignment) Notifier(com.vaadin.event.Action.Notifier) AccessibleTextField(de.symeda.sormas.ui.location.AccessibleTextField) PersonDto(de.symeda.sormas.api.person.PersonDto) ArrayList(java.util.ArrayList) Buffered(com.vaadin.v7.data.Buffered) Notification(com.vaadin.ui.Notification) RichTextArea(com.vaadin.v7.ui.RichTextArea) Page(com.vaadin.server.Page) KeyCode(com.vaadin.event.ShortcutAction.KeyCode) AbstractLegacyComponent(com.vaadin.v7.ui.AbstractLegacyComponent) CannotProceedException(javax.naming.CannotProceedException) ValoTheme(com.vaadin.ui.themes.ValoTheme) LocationDto(de.symeda.sormas.api.location.LocationDto) ClickEvent(com.vaadin.ui.Button.ClickEvent) Collection(java.util.Collection) Field(com.vaadin.v7.ui.Field) EventDto(de.symeda.sormas.api.event.EventDto) InvalidValueException(com.vaadin.v7.data.Validator.InvalidValueException) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) List(java.util.List) Button(com.vaadin.ui.Button) Stream(java.util.stream.Stream) Type(com.vaadin.ui.Notification.Type) PersonEditForm(de.symeda.sormas.ui.person.PersonEditForm) HorizontalLayout(com.vaadin.ui.HorizontalLayout) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) TextArea(com.vaadin.v7.ui.TextArea) CommitException(com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException) Descriptions(de.symeda.sormas.api.i18n.Descriptions) Objects.nonNull(java.util.Objects.nonNull) Strings(de.symeda.sormas.api.i18n.Strings) Component(com.vaadin.ui.Component) AccessibleTextField(de.symeda.sormas.ui.location.AccessibleTextField) PersonEditForm(de.symeda.sormas.ui.person.PersonEditForm) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) EventDataForm(de.symeda.sormas.ui.events.EventDataForm) Buffered(com.vaadin.v7.data.Buffered)

Example 5 with LocationEditForm

use of de.symeda.sormas.ui.location.LocationEditForm in project SORMAS-Project by hzi-braunschweig.

the class SormasFieldGroupFieldFactory method createField.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T extends Field> T createField(Class<?> type, Class<T> fieldType) {
    if (type.isEnum()) {
        if (// no specific fieldType defined?
        fieldType.isAssignableFrom(Field.class) && (SymptomState.class.isAssignableFrom(type) || YesNoUnknown.class.isAssignableFrom(type))) {
            NullableOptionGroup field = new NullableOptionGroup();
            field.setImmediate(true);
            populateWithEnumData(field, (Class<? extends Enum>) type);
            CssStyles.style(field, ValoTheme.OPTIONGROUP_HORIZONTAL, CssStyles.OPTIONGROUP_CAPTION_INLINE);
            return (T) field;
        } else {
            if (Disease.class.isAssignableFrom(type)) {
                fieldType = (Class<T>) ComboBox.class;
                ComboBox field = ComboBoxHelper.createComboBoxV7();
                field.setImmediate(true);
                field.setNullSelectionAllowed(true);
                populateWithDiseaseData(field);
                return (T) field;
            } else {
                if (!AbstractSelect.class.isAssignableFrom(fieldType)) {
                    fieldType = (Class<T>) ComboBox.class;
                }
                T field = super.createField(type, fieldType);
                if (field instanceof OptionGroup) {
                    CssStyles.style(field, ValoTheme.OPTIONGROUP_HORIZONTAL);
                } else if (fieldType.isAssignableFrom(NullableOptionGroup.class)) {
                    NullableOptionGroup select = new NullableOptionGroup();
                    select.setImmediate(true);
                    populateWithEnumData(select, (Class<? extends Enum>) type);
                    CssStyles.style(select, ValoTheme.OPTIONGROUP_HORIZONTAL);
                    field = (T) select;
                } else if (field instanceof ComboBox) {
                    ((ComboBox) field).setFilteringMode(FilteringMode.CONTAINS);
                    ((ComboBox) field).setNullSelectionAllowed(true);
                }
                return field;
            }
        }
    } else if (Boolean.class.isAssignableFrom(type)) {
        fieldType = CheckBox.class.isAssignableFrom(fieldType) ? (Class<T>) CheckBox.class : (Class<T>) NullableOptionGroup.class;
        return createBooleanField(fieldType);
    } else if (ComboBox.class.isAssignableFrom(fieldType) || ComboBoxWithPlaceholder.class.isAssignableFrom(fieldType)) {
        ComboBoxWithPlaceholder combo = new ComboBoxWithPlaceholder();
        combo.setImmediate(true);
        return (T) combo;
    } else if (AbstractSelect.class.isAssignableFrom(fieldType)) {
        AbstractSelect field = createCompatibleSelect((Class<? extends AbstractSelect>) fieldType);
        field.setNullSelectionAllowed(true);
        return (T) field;
    } else if (LocationEditForm.class.isAssignableFrom(fieldType)) {
        return (T) new LocationEditForm(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (HealthConditionsForm.class.isAssignableFrom(fieldType)) {
        return (T) new HealthConditionsForm(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (DateTimeField.class.isAssignableFrom(fieldType)) {
        DateTimeField field = new DateTimeField();
        field.setConverter(new SormasDefaultConverterFactory().createDateConverter(Date.class));
        return (T) field;
    } else if (DateField.class.isAssignableFrom(fieldType)) {
        DateField field = super.createField(type, DateField.class);
        field.setDateFormat(DateFormatHelper.getDateFormatPattern());
        field.setLenient(true);
        field.setConverter(new SormasDefaultConverterFactory().createDateConverter(Date.class));
        return (T) field;
    } else if (PreviousHospitalizationsField.class.isAssignableFrom(fieldType)) {
        return (T) new PreviousHospitalizationsField(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (ExposuresField.class.isAssignableFrom(fieldType)) {
        return (T) new ExposuresField(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (ActivityAsCaseField.class.isAssignableFrom(fieldType)) {
        return (T) new ActivityAsCaseField(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (LocationsField.class.isAssignableFrom(fieldType)) {
        return (T) new LocationsField(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (VaccinationsField.class.isAssignableFrom(fieldType)) {
        return (T) new VaccinationsField(fieldAccessCheckers);
    } else if (JsonForm.class.isAssignableFrom(fieldType)) {
        return (T) new JsonForm(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (fieldType.equals(Field.class)) {
        // no specific field type defined -> fallbacks
        if (Date.class.isAssignableFrom(type)) {
            DateField field = super.createField(type, DateField.class);
            field.setDateFormat(DateFormatHelper.getDateFormatPattern());
            field.setLenient(true);
            field.setConverter(new SormasDefaultConverterFactory().createDateConverter(Date.class));
            return (T) field;
        } else if (ReferenceDto.class.isAssignableFrom(type)) {
            return (T) ComboBoxHelper.createComboBoxV7();
        }
    } else if (MultiSelect.class.isAssignableFrom(fieldType)) {
        return (T) MultiSelect.create(type);
    }
    return super.createField(type, fieldType);
}
Also used : SymptomState(de.symeda.sormas.api.symptoms.SymptomState) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) VaccinationsField(de.symeda.sormas.ui.vaccination.VaccinationsField) VaccinationsField(de.symeda.sormas.ui.vaccination.VaccinationsField) ExposuresField(de.symeda.sormas.ui.exposure.ExposuresField) DateField(com.vaadin.v7.ui.DateField) LocationsField(de.symeda.sormas.ui.person.LocationsField) Field(com.vaadin.v7.ui.Field) AbstractTextField(com.vaadin.v7.ui.AbstractTextField) ActivityAsCaseField(de.symeda.sormas.ui.ActivityAsCase.ActivityAsCaseField) PreviousHospitalizationsField(de.symeda.sormas.ui.hospitalization.PreviousHospitalizationsField) OptionGroup(com.vaadin.v7.ui.OptionGroup) HealthConditionsForm(de.symeda.sormas.ui.clinicalcourse.HealthConditionsForm) ExposuresField(de.symeda.sormas.ui.exposure.ExposuresField) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) MultiSelect(de.symeda.sormas.ui.utils.components.MultiSelect) ReferenceDto(de.symeda.sormas.api.ReferenceDto) ComboBox(com.vaadin.v7.ui.ComboBox) LocationsField(de.symeda.sormas.ui.person.LocationsField) Date(java.util.Date) PreviousHospitalizationsField(de.symeda.sormas.ui.hospitalization.PreviousHospitalizationsField) ActivityAsCaseField(de.symeda.sormas.ui.ActivityAsCase.ActivityAsCaseField) JsonForm(de.symeda.sormas.ui.utils.components.JsonForm) CheckBox(com.vaadin.v7.ui.CheckBox) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) DateField(com.vaadin.v7.ui.DateField)

Aggregations

LocationEditForm (de.symeda.sormas.ui.location.LocationEditForm)5 CheckBox (com.vaadin.v7.ui.CheckBox)3 Field (com.vaadin.v7.ui.Field)3 LocationDto (de.symeda.sormas.api.location.LocationDto)3 Label (com.vaadin.ui.Label)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 FieldGroup (com.vaadin.v7.data.fieldgroup.FieldGroup)2 ComboBox (com.vaadin.v7.ui.ComboBox)2 DateField (com.vaadin.v7.ui.DateField)2 TextArea (com.vaadin.v7.ui.TextArea)2 EventDto (de.symeda.sormas.api.event.EventDto)2 Captions (de.symeda.sormas.api.i18n.Captions)2 Descriptions (de.symeda.sormas.api.i18n.Descriptions)2 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)2 Strings (de.symeda.sormas.api.i18n.Strings)2 YesNoUnknown (de.symeda.sormas.api.utils.YesNoUnknown)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2