Search in sources :

Example 76 with ComboBox

use of com.vaadin.v7.ui.ComboBox in project SORMAS-Project by hzi-braunschweig.

the class BulkContactDataForm method addFields.

@Override
protected void addFields() {
    if (!initialized) {
        return;
    }
    classificationCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkContactClassification));
    getContent().addComponent(classificationCheckBox, CLASSIFICATION_CHECKBOX);
    NullableOptionGroup contactClassification = addField(ContactBulkEditData.CONTACT_CLASSIFICATION, NullableOptionGroup.class);
    contactClassification.setEnabled(false);
    if (singleSelectedDistrict != null) {
        contactOfficerCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkContactOfficer));
        getContent().addComponent(contactOfficerCheckBox, CONTACT_OFFICER_CHECKBOX);
        ComboBox contactOfficer = addField(ContactBulkEditData.CONTACT_OFFICER, ComboBox.class);
        contactOfficer.setEnabled(false);
        FieldHelper.addSoftRequiredStyleWhen(getFieldGroup(), contactOfficerCheckBox, Arrays.asList(ContactBulkEditData.CONTACT_OFFICER), Arrays.asList(true), null);
        Set<Disease> selectedDiseases = this.selectedContacts.stream().map(c -> c.getDisease()).collect(Collectors.toSet());
        List<UserReferenceDto> assignableContactOfficers = null;
        if (selectedDiseases.size() == 1) {
            Disease selectedDisease = selectedDiseases.iterator().next();
            assignableContactOfficers = FacadeProvider.getUserFacade().getUserRefsByDistrict(singleSelectedDistrict, selectedDisease, UserRight.CONTACT_RESPONSIBLE);
        } else {
            assignableContactOfficers = FacadeProvider.getUserFacade().getUserRefsByDistrict(singleSelectedDistrict, true, UserRight.CONTACT_RESPONSIBLE);
        }
        FieldHelper.updateItems(contactOfficer, assignableContactOfficers);
        contactOfficerCheckBox.addValueChangeListener(e -> {
            contactOfficer.setEnabled((boolean) e.getProperty().getValue());
        });
    }
    FieldHelper.setRequiredWhen(getFieldGroup(), classificationCheckBox, Arrays.asList(ContactBulkEditData.CONTACT_CLASSIFICATION), Arrays.asList(true));
    classificationCheckBox.addValueChangeListener(e -> {
        contactClassification.setEnabled((boolean) e.getProperty().getValue());
    });
}
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) CheckBox(com.vaadin.v7.ui.CheckBox) ComboBox(com.vaadin.v7.ui.ComboBox) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Collection(java.util.Collection) Set(java.util.Set) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) ContactBulkEditData(de.symeda.sormas.api.contact.ContactBulkEditData) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) UserRight(de.symeda.sormas.api.user.UserRight) List(java.util.List) Disease(de.symeda.sormas.api.Disease) ContactIndexDto(de.symeda.sormas.api.contact.ContactIndexDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) VSPACE_4(de.symeda.sormas.ui.utils.CssStyles.VSPACE_4) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Disease(de.symeda.sormas.api.Disease) CheckBox(com.vaadin.v7.ui.CheckBox) ComboBox(com.vaadin.v7.ui.ComboBox)

Example 77 with ComboBox

use of com.vaadin.v7.ui.ComboBox in project SORMAS-Project by hzi-braunschweig.

the class PathogenTestForm method addFields.

@Override
protected void addFields() {
    if (sample == null) {
        return;
    }
    pathogenTestHeadingLabel = new Label();
    pathogenTestHeadingLabel.addStyleName(H3);
    getContent().addComponent(pathogenTestHeadingLabel, PATHOGEN_TEST_HEADING_LOC);
    addDateField(PathogenTestDto.REPORT_DATE, DateField.class, 0);
    addField(PathogenTestDto.VIA_LIMS);
    addField(PathogenTestDto.EXTERNAL_ID);
    addField(PathogenTestDto.EXTERNAL_ORDER_ID);
    ComboBox testTypeField = addField(PathogenTestDto.TEST_TYPE, ComboBox.class);
    testTypeField.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
    testTypeField.setImmediate(true);
    pcrTestSpecification = addField(PathogenTestDto.PCR_TEST_SPECIFICATION, ComboBox.class);
    testTypeTextField = addField(PathogenTestDto.TEST_TYPE_TEXT, TextField.class);
    FieldHelper.addSoftRequiredStyle(testTypeTextField);
    DateTimeField sampleTestDateField = addField(PathogenTestDto.TEST_DATE_TIME, DateTimeField.class);
    sampleTestDateField.addValidator(new DateComparisonValidator(sampleTestDateField, sample.getSampleDateTime(), false, false, I18nProperties.getValidationError(Validations.afterDateWithDate, sampleTestDateField.getCaption(), I18nProperties.getPrefixCaption(SampleDto.I18N_PREFIX, SampleDto.SAMPLE_DATE_TIME), DateFormatHelper.formatDate(sample.getSampleDateTime()))));
    ComboBox lab = addInfrastructureField(PathogenTestDto.LAB);
    lab.addItems(FacadeProvider.getFacilityFacade().getAllActiveLaboratories(true));
    TextField labDetails = addField(PathogenTestDto.LAB_DETAILS, TextField.class);
    labDetails.setVisible(false);
    typingIdField = addField(PathogenTestDto.TYPING_ID, TextField.class);
    typingIdField.setVisible(false);
    ComboBox diseaseField = addDiseaseField(PathogenTestDto.TESTED_DISEASE, true, create);
    ComboBox diseaseVariantField = addField(PathogenTestDto.TESTED_DISEASE_VARIANT, ComboBox.class);
    diseaseVariantField.setNullSelectionAllowed(true);
    addField(PathogenTestDto.TESTED_DISEASE_DETAILS, TextField.class);
    TextField diseaseVariantDetailsField = addField(PathogenTestDto.TESTED_DISEASE_VARIANT_DETAILS, TextField.class);
    diseaseVariantDetailsField.setVisible(false);
    ComboBox testResultField = addField(PathogenTestDto.TEST_RESULT, ComboBox.class);
    testResultField.removeItem(PathogenTestResultType.NOT_DONE);
    addField(PathogenTestDto.SEROTYPE, TextField.class);
    TextField cqValueField = addField(PathogenTestDto.CQ_VALUE, TextField.class);
    cqValueField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, cqValueField.getCaption()));
    NullableOptionGroup testResultVerifiedField = addField(PathogenTestDto.TEST_RESULT_VERIFIED, NullableOptionGroup.class);
    testResultVerifiedField.setRequired(true);
    CheckBox fourFoldIncrease = addField(PathogenTestDto.FOUR_FOLD_INCREASE_ANTIBODY_TITER, CheckBox.class);
    CssStyles.style(fourFoldIncrease, VSPACE_3, VSPACE_TOP_4);
    fourFoldIncrease.setVisible(false);
    fourFoldIncrease.setEnabled(false);
    addField(PathogenTestDto.TEST_RESULT_TEXT, TextArea.class).setRows(6);
    addField(PathogenTestDto.PRELIMINARY).addStyleName(CssStyles.VSPACE_4);
    addField(PathogenTestDto.DELETION_REASON);
    addField(PathogenTestDto.OTHER_DELETION_REASON, TextArea.class).setRows(3);
    setVisible(false, PathogenTestDto.DELETION_REASON, PathogenTestDto.OTHER_DELETION_REASON);
    initializeAccessAndAllowedAccesses();
    initializeVisibilitiesAndAllowedVisibilities();
    pcrTestSpecification.setVisible(false);
    Map<Object, List<Object>> pcrTestSpecificationVisibilityDependencies = new HashMap<Object, List<Object>>() {

        {
            put(PathogenTestDto.TESTED_DISEASE, Arrays.asList(Disease.CORONAVIRUS));
            put(PathogenTestDto.TEST_TYPE, Arrays.asList(PathogenTestType.PCR_RT_PCR));
        }
    };
    FieldHelper.setVisibleWhen(getFieldGroup(), PathogenTestDto.PCR_TEST_SPECIFICATION, pcrTestSpecificationVisibilityDependencies, true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PathogenTestDto.TEST_TYPE_TEXT, PathogenTestDto.TEST_TYPE, Arrays.asList(PathogenTestType.PCR_RT_PCR, PathogenTestType.OTHER), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PathogenTestDto.TESTED_DISEASE_DETAILS, PathogenTestDto.TESTED_DISEASE, Arrays.asList(Disease.OTHER), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PathogenTestDto.TYPING_ID, PathogenTestDto.TEST_TYPE, Arrays.asList(PathogenTestType.PCR_RT_PCR, PathogenTestType.DNA_MICROARRAY, PathogenTestType.SEQUENCING), true);
    Map<Object, List<Object>> serotypeVisibilityDependencies = new HashMap<Object, List<Object>>() {

        private static final long serialVersionUID = 1967952323596082247L;

        {
            put(PathogenTestDto.TESTED_DISEASE, Arrays.asList(Disease.CSM));
            put(PathogenTestDto.TEST_RESULT, Arrays.asList(PathogenTestResultType.POSITIVE));
        }
    };
    FieldHelper.setVisibleWhen(getFieldGroup(), PathogenTestDto.SEROTYPE, serotypeVisibilityDependencies, true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PathogenTestDto.CQ_VALUE, PathogenTestDto.TEST_TYPE, Arrays.asList(PathogenTestType.CQ_VALUE_DETECTION), true);
    Consumer<Disease> updateDiseaseVariantField = disease -> {
        List<DiseaseVariant> diseaseVariants = FacadeProvider.getCustomizableEnumFacade().getEnumValues(CustomizableEnumType.DISEASE_VARIANT, disease);
        FieldHelper.updateItems(diseaseVariantField, diseaseVariants);
        diseaseVariantField.setVisible(disease != null && isVisibleAllowed(PathogenTestDto.TESTED_DISEASE_VARIANT) && CollectionUtils.isNotEmpty(diseaseVariants));
    };
    // trigger the update, as the disease may already be set
    updateDiseaseVariantField.accept((Disease) diseaseField.getValue());
    diseaseField.addValueChangeListener((ValueChangeListener) valueChangeEvent -> {
        Disease disease = (Disease) valueChangeEvent.getProperty().getValue();
        updateDiseaseVariantField.accept(disease);
        FieldHelper.updateItems(testTypeField, Arrays.asList(PathogenTestType.values()), FieldVisibilityCheckers.withDisease(disease), PathogenTestType.class);
    });
    diseaseVariantField.addValueChangeListener(e -> {
        DiseaseVariant diseaseVariant = (DiseaseVariant) e.getProperty().getValue();
        diseaseVariantDetailsField.setVisible(diseaseVariant != null && diseaseVariant.matchPropertyValue(DiseaseVariant.HAS_DETAILS, true));
    });
    testTypeField.addValueChangeListener(e -> {
        PathogenTestType testType = (PathogenTestType) e.getProperty().getValue();
        if (testType == PathogenTestType.IGM_SERUM_ANTIBODY || testType == PathogenTestType.IGG_SERUM_ANTIBODY) {
            fourFoldIncrease.setVisible(true);
            fourFoldIncrease.setEnabled(caseSampleCount >= 2);
        } else {
            fourFoldIncrease.setVisible(false);
            fourFoldIncrease.setEnabled(false);
        }
    });
    lab.addValueChangeListener(event -> {
        if (event.getProperty().getValue() != null && ((FacilityReferenceDto) event.getProperty().getValue()).getUuid().equals(FacilityDto.OTHER_FACILITY_UUID)) {
            labDetails.setVisible(true);
            labDetails.setRequired(true);
        } else {
            labDetails.setVisible(false);
            labDetails.setRequired(false);
            labDetails.clear();
        }
    });
    testTypeField.addValueChangeListener(e -> {
        PathogenTestType testType = (PathogenTestType) e.getProperty().getValue();
        if ((testType == PathogenTestType.PCR_RT_PCR && testResultField.getValue() == PathogenTestResultType.POSITIVE) || testType == PathogenTestType.CQ_VALUE_DETECTION) {
            cqValueField.setVisible(true);
        } else {
            cqValueField.setVisible(false);
            cqValueField.clear();
        }
    });
    testResultField.addValueChangeListener(e -> {
        PathogenTestResultType testResult = (PathogenTestResultType) e.getProperty().getValue();
        if ((testTypeField.getValue() == PathogenTestType.PCR_RT_PCR && testResult == PathogenTestResultType.POSITIVE) || testTypeField.getValue() == PathogenTestType.CQ_VALUE_DETECTION) {
            cqValueField.setVisible(true);
        } else {
            cqValueField.setVisible(false);
            cqValueField.clear();
        }
    });
    if (sample.getSamplePurpose() != SamplePurpose.INTERNAL) {
        // this only works for already saved samples
        setRequired(true, PathogenTestDto.LAB);
    }
    setRequired(true, PathogenTestDto.TEST_TYPE, PathogenTestDto.TESTED_DISEASE, PathogenTestDto.TEST_RESULT);
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) CheckBox(com.vaadin.v7.ui.CheckBox) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DateFormatHelper(de.symeda.sormas.ui.utils.DateFormatHelper) HashMap(java.util.HashMap) Converter(com.vaadin.v7.data.util.converter.Converter) CustomizableEnumType(de.symeda.sormas.api.customizableenum.CustomizableEnumType) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) LayoutUtil.loc(de.symeda.sormas.ui.utils.LayoutUtil.loc) CssStyles(de.symeda.sormas.ui.utils.CssStyles) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) Label(com.vaadin.ui.Label) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) Validations(de.symeda.sormas.api.i18n.Validations) ComboBox(com.vaadin.v7.ui.ComboBox) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ItemCaptionMode(com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) Consumer(java.util.function.Consumer) List(java.util.List) Disease(de.symeda.sormas.api.Disease) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) SampleDto(de.symeda.sormas.api.sample.SampleDto) TextArea(com.vaadin.v7.ui.TextArea) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) VSPACE_TOP_4(de.symeda.sormas.ui.utils.CssStyles.VSPACE_TOP_4) TextField(com.vaadin.v7.ui.TextField) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) Disease(de.symeda.sormas.api.Disease) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) TextArea(com.vaadin.v7.ui.TextArea) HashMap(java.util.HashMap) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) CheckBox(com.vaadin.v7.ui.CheckBox) TextField(com.vaadin.v7.ui.TextField) List(java.util.List)

Example 78 with ComboBox

use of com.vaadin.v7.ui.ComboBox in project SORMAS-Project by hzi-braunschweig.

the class PersonCreateForm method updatePresentConditionEnum.

public void updatePresentConditionEnum(Disease disease) {
    ComboBox presentConditionField = getField(PersonDto.PRESENT_CONDITION);
    PresentCondition currentValue = (PresentCondition) presentConditionField.getValue();
    List<PresentCondition> validValues;
    if (disease == null) {
        validValues = Arrays.asList(PresentCondition.values());
    } else {
        FieldVisibilityCheckers fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(disease);
        validValues = Arrays.stream(PresentCondition.values()).filter(c -> fieldVisibilityCheckers.isVisible(PresentCondition.class, c.name())).collect(Collectors.toList());
        if (currentValue != null && !validValues.contains(currentValue)) {
            validValues.add(currentValue);
        }
    }
    FieldHelper.updateEnumData(presentConditionField, validValues);
}
Also used : PresentCondition(de.symeda.sormas.api.person.PresentCondition) ComboBox(com.vaadin.v7.ui.ComboBox) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)

Example 79 with ComboBox

use of com.vaadin.v7.ui.ComboBox in project SORMAS-Project by hzi-braunschweig.

the class PersonEditForm method initializePresentConditionField.

private void initializePresentConditionField() {
    PresentCondition presentCondition = getValue().getPresentCondition();
    ComboBox presentConditionField = getField(PersonDto.PRESENT_CONDITION);
    if (this.disease != null || FacadeProvider.getDiseaseConfigurationFacade().getDefaultDisease() != null) {
        Disease disease = this.disease != null ? this.disease : FacadeProvider.getDiseaseConfigurationFacade().getDefaultDisease();
        FieldVisibilityCheckers fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(disease);
        List<PresentCondition> validValues = Arrays.stream(PresentCondition.values()).filter(c -> fieldVisibilityCheckers.isVisible(PresentCondition.class, c.name())).collect(Collectors.toList());
        PresentCondition currentValue = (PresentCondition) presentConditionField.getValue();
        if (currentValue != null && !validValues.contains(currentValue)) {
            validValues.add(currentValue);
        }
        presentConditionField.removeValueChangeListener(presentConditionChangeListener);
        FieldHelper.updateEnumData(presentConditionField, validValues);
        presentConditionField.addValueChangeListener(presentConditionChangeListener);
    }
    /*
		 * It may happen that the person currently has a present condition that usually shall not be shows for the form's disease.
		 * In that case, the present condition is added as selectable item here.
		 */
    if (presentCondition != null && presentConditionField.getItem(presentCondition) == null) {
        Item currentItem = presentConditionField.addItem(presentCondition);
        currentItem.getItemProperty(SormasFieldGroupFieldFactory.CAPTION_PROPERTY_ID).setValue(presentCondition.toString());
    }
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) ValidationUtils(de.symeda.sormas.ui.utils.ValidationUtils) LayoutUtil.divsCss(de.symeda.sormas.ui.utils.LayoutUtil.divsCss) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) EducationType(de.symeda.sormas.api.person.EducationType) CountryFieldVisibilityChecker(de.symeda.sormas.api.utils.fieldvisibility.checkers.CountryFieldVisibilityChecker) StringUtils(org.apache.commons.lang3.StringUtils) CauseOfDeath(de.symeda.sormas.api.person.CauseOfDeath) PersonDto(de.symeda.sormas.api.person.PersonDto) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) CssStyles(de.symeda.sormas.ui.utils.CssStyles) PersonContext(de.symeda.sormas.api.person.PersonContext) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) Item(com.vaadin.v7.data.Item) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) Property(com.vaadin.v7.data.Property) ViewMode(de.symeda.sormas.ui.utils.ViewMode) GregorianCalendar(java.util.GregorianCalendar) ComboBox(com.vaadin.v7.ui.ComboBox) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) 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) SormasFieldGroupFieldFactory(de.symeda.sormas.ui.utils.SormasFieldGroupFieldFactory) List(java.util.List) TextField(com.vaadin.v7.ui.TextField) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) Descriptions(de.symeda.sormas.api.i18n.Descriptions) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) LayoutUtil.oneOfTwoCol(de.symeda.sormas.ui.utils.LayoutUtil.oneOfTwoCol) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) OccupationType(de.symeda.sormas.api.person.OccupationType) 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) ApproximateAgeHelper(de.symeda.sormas.api.person.ApproximateAgeType.ApproximateAgeHelper) DateHelper(de.symeda.sormas.api.utils.DateHelper) OutbreakFieldVisibilityChecker(de.symeda.sormas.ui.utils.OutbreakFieldVisibilityChecker) CustomLayout(com.vaadin.ui.CustomLayout) Calendar(java.util.Calendar) LayoutUtil.loc(de.symeda.sormas.ui.utils.LayoutUtil.loc) Label(com.vaadin.ui.Label) LayoutUtil.oneOfFourCol(de.symeda.sormas.ui.utils.LayoutUtil.oneOfFourCol) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) Validations(de.symeda.sormas.api.i18n.Validations) Month(java.time.Month) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Pair(de.symeda.sormas.api.utils.DataHelper.Pair) ApproximateAgeValidator(de.symeda.sormas.ui.utils.ApproximateAgeValidator) ResizableTextAreaWrapper(de.symeda.sormas.ui.utils.ResizableTextAreaWrapper) Captions(de.symeda.sormas.api.i18n.Captions) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ItemCaptionMode(com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Disease(de.symeda.sormas.api.Disease) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) TextArea(com.vaadin.v7.ui.TextArea) LayoutUtil.fluidColumnLocCss(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLocCss) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) Salutation(de.symeda.sormas.api.person.Salutation) Item(com.vaadin.v7.data.Item) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Disease(de.symeda.sormas.api.Disease) ComboBox(com.vaadin.v7.ui.ComboBox) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)

Example 80 with ComboBox

use of com.vaadin.v7.ui.ComboBox 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);
        Set<Disease> selectedDiseases = this.selectedCases.stream().map(c -> c.getDisease()).collect(Collectors.toSet());
        List<UserReferenceDto> assignableCaseResponsibles = null;
        if (selectedDiseases.size() == 1) {
            Disease selectedDisease = selectedDiseases.iterator().next();
            assignableCaseResponsibles = FacadeProvider.getUserFacade().getUserRefsByDistrict(singleSelectedDistrict, selectedDisease, UserRight.CASE_RESPONSIBLE);
        } else {
            assignableCaseResponsibles = FacadeProvider.getUserFacade().getUserRefsByDistrict(singleSelectedDistrict, true, UserRight.CASE_RESPONSIBLE);
        }
        FieldHelper.updateItems(surveillanceOfficer, assignableCaseResponsibles);
        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) 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) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Collection(java.util.Collection) Set(java.util.Set) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) 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) UserRight(de.symeda.sormas.api.user.UserRight) 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) Disease(de.symeda.sormas.api.Disease) 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)

Aggregations

ComboBox (com.vaadin.v7.ui.ComboBox)113 TextField (com.vaadin.v7.ui.TextField)43 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)31 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)28 Label (com.vaadin.ui.Label)24 Disease (de.symeda.sormas.api.Disease)24 TextArea (com.vaadin.v7.ui.TextArea)19 UserDto (de.symeda.sormas.api.user.UserDto)19 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)19 DateField (com.vaadin.v7.ui.DateField)18 List (java.util.List)18 CheckBox (com.vaadin.v7.ui.CheckBox)17 FacadeProvider (de.symeda.sormas.api.FacadeProvider)17 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)17 DateComparisonValidator (de.symeda.sormas.ui.utils.DateComparisonValidator)17 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)16 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)16 Field (com.vaadin.v7.ui.Field)15 FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)15 Captions (de.symeda.sormas.api.i18n.Captions)14