Example usage for com.vaadin.v7.ui ComboBox setCaption

List of usage examples for com.vaadin.v7.ui ComboBox setCaption

Introduction

In this page you can find the example usage for com.vaadin.v7.ui ComboBox setCaption.

Prototype

public void setCaption(String caption);

Source Link

Document

Sets the caption of the component.

Usage

From source file:de.symeda.sormas.ui.configuration.infrastructure.CommunityEditForm.java

License:Open Source License

@Override
protected void addFields() {
    addField(CommunityDto.NAME, TextField.class);
    ComboBox region = new ComboBox();
    region.setCaption(I18nProperties.getPrefixCaption(CommunityDto.I18N_PREFIX, REGION_LOC));
    region.setWidth(100, Unit.PERCENTAGE);
    getContent().addComponent(region, REGION_LOC);
    ComboBox district = addField(CommunityDto.DISTRICT, ComboBox.class);

    setRequired(true, CommunityDto.NAME, CommunityDto.DISTRICT);
    region.setRequired(true);//from  www  .ja  v a  2s.  c o m

    region.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(district,
                regionDto != null ? FacadeProvider.getDistrictFacade().getAllByRegion(regionDto.getUuid())
                        : null);
    });

    district.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null && region.getValue() == null) {
            DistrictDto communityDistrict = FacadeProvider.getDistrictFacade()
                    .getDistrictByUuid(((DistrictReferenceDto) e.getProperty().getValue()).getUuid());
            region.setValue(communityDistrict.getRegion());
        }
    });

    region.addItems(FacadeProvider.getRegionFacade().getAllAsReference());

    // TODO: Workaround until cases and other data is properly transfered when infrastructure data changes
    if (!create) {
        region.setEnabled(false);
        district.setEnabled(false);
    }
}

From source file:de.symeda.sormas.ui.person.PersonEditForm.java

License:Open Source License

@Override
protected void addFields() {
    if (!initialized) {
        // vars have to be set first
        return;/*w ww.  j  a v a 2 s. c om*/
    }

    addField(PersonDto.FIRST_NAME, TextField.class);
    addField(PersonDto.LAST_NAME, TextField.class);
    ComboBox sex = addField(PersonDto.SEX, ComboBox.class);
    addField(PersonDto.NICKNAME, TextField.class);
    addField(PersonDto.MOTHERS_MAIDEN_NAME, TextField.class);
    addFields(PersonDto.MOTHERS_NAME, PersonDto.FATHERS_NAME);
    ComboBox presentCondition = addField(PersonDto.PRESENT_CONDITION, ComboBox.class);
    birthDateDay = addField(PersonDto.BIRTH_DATE_DD, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateDay.setNullSelectionAllowed(true);
    ComboBox birthDateMonth = addField(PersonDto.BIRTH_DATE_MM, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateMonth.setNullSelectionAllowed(true);
    birthDateMonth.addItems(DateHelper.getMonthsInYear());
    birthDateMonth.setPageLength(12);
    setItemCaptionsForMonths(birthDateMonth);
    ComboBox birthDateYear = addField(PersonDto.BIRTH_DATE_YYYY, ComboBox.class);
    birthDateYear.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE));
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateYear.setNullSelectionAllowed(true);
    birthDateYear.addItems(DateHelper.getYearsToNow());
    birthDateYear.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
    DateField deathDate = addField(PersonDto.DEATH_DATE, DateField.class);
    TextField approximateAgeField = addField(PersonDto.APPROXIMATE_AGE, TextField.class);
    ComboBox approximateAgeTypeField = addField(PersonDto.APPROXIMATE_AGE_TYPE, ComboBox.class);
    addField(PersonDto.APPROXIMATE_AGE_REFERENCE_DATE, DateField.class);

    TextField tfGestationAgeAtBirth = addField(PersonDto.GESTATION_AGE_AT_BIRTH, TextField.class);
    tfGestationAgeAtBirth.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed,
            tfGestationAgeAtBirth.getCaption()));
    TextField tfBirthWeight = addField(PersonDto.BIRTH_WEIGHT, TextField.class);
    tfBirthWeight.setConversionError(
            I18nProperties.getValidationError(Validations.onlyNumbersAllowed, tfBirthWeight.getCaption()));

    AbstractSelect deathPlaceType = addField(PersonDto.DEATH_PLACE_TYPE, ComboBox.class);
    deathPlaceType.setNullSelectionAllowed(true);
    TextField deathPlaceDesc = addField(PersonDto.DEATH_PLACE_DESCRIPTION, TextField.class);
    DateField burialDate = addField(PersonDto.BURIAL_DATE, DateField.class);
    TextField burialPlaceDesc = addField(PersonDto.BURIAL_PLACE_DESCRIPTION, TextField.class);
    ComboBox burialConductor = addField(PersonDto.BURIAL_CONDUCTOR, ComboBox.class);
    addField(PersonDto.ADDRESS, LocationEditForm.class).setCaption(null);
    addField(PersonDto.PHONE, TextField.class);
    addField(PersonDto.PHONE_OWNER, TextField.class);

    addFields(PersonDto.OCCUPATION_TYPE, PersonDto.OCCUPATION_DETAILS, PersonDto.EDUCATION_TYPE,
            PersonDto.EDUCATION_DETAILS);

    ComboBox cbPlaceOfBirthRegion = addField(PersonDto.PLACE_OF_BIRTH_REGION, ComboBox.class);
    ComboBox cbPlaceOfBirthDistrict = addField(PersonDto.PLACE_OF_BIRTH_DISTRICT, ComboBox.class);
    ComboBox cbPlaceOfBirthCommunity = addField(PersonDto.PLACE_OF_BIRTH_COMMUNITY, ComboBox.class);
    ComboBox cbPlaceOfBirthFacility = addField(PersonDto.PLACE_OF_BIRTH_FACILITY, ComboBox.class);
    TextField tfPlaceOfBirthFacilityDetails = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_DETAILS,
            TextField.class);

    causeOfDeathField = addField(PersonDto.CAUSE_OF_DEATH, ComboBox.class);
    causeOfDeathDiseaseField = addDiseaseField(PersonDto.CAUSE_OF_DEATH_DISEASE, true);
    causeOfDeathDetailsField = addField(PersonDto.CAUSE_OF_DEATH_DETAILS, TextField.class);
    ComboBox facilityRegion = addField(PersonDto.OCCUPATION_REGION, ComboBox.class);
    facilityRegion.setImmediate(true);
    facilityRegion.setNullSelectionAllowed(true);
    ComboBox facilityDistrict = addField(PersonDto.OCCUPATION_DISTRICT, ComboBox.class);
    facilityDistrict.setImmediate(true);
    facilityDistrict.setNullSelectionAllowed(true);
    ComboBox facilityCommunity = addField(PersonDto.OCCUPATION_COMMUNITY, ComboBox.class);
    facilityCommunity.setImmediate(true);
    facilityCommunity.setNullSelectionAllowed(true);
    occupationFacility = addField(PersonDto.OCCUPATION_FACILITY, ComboBox.class);
    occupationFacility.setImmediate(true);
    occupationFacility.setNullSelectionAllowed(true);
    occupationFacilityDetails = addField(PersonDto.OCCUPATION_FACILITY_DETAILS, TextField.class);

    // Set requirements that don't need visibility changes and read only status

    setReadOnly(true, PersonDto.APPROXIMATE_AGE_REFERENCE_DATE);
    setRequired(true, PersonDto.FIRST_NAME, PersonDto.LAST_NAME);
    setVisible(false, PersonDto.OCCUPATION_DETAILS, PersonDto.OCCUPATION_FACILITY,
            PersonDto.OCCUPATION_FACILITY_DETAILS, PersonDto.OCCUPATION_REGION, PersonDto.OCCUPATION_DISTRICT,
            PersonDto.OCCUPATION_COMMUNITY, PersonDto.DEATH_DATE, PersonDto.DEATH_PLACE_TYPE,
            PersonDto.DEATH_PLACE_DESCRIPTION, PersonDto.BURIAL_DATE, PersonDto.BURIAL_PLACE_DESCRIPTION,
            PersonDto.BURIAL_CONDUCTOR, PersonDto.CAUSE_OF_DEATH, PersonDto.CAUSE_OF_DEATH_DETAILS,
            PersonDto.CAUSE_OF_DEATH_DISEASE);

    FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.EDUCATION_DETAILS, PersonDto.EDUCATION_TYPE,
            Arrays.asList(EducationType.OTHER), true);

    FieldHelper.addSoftRequiredStyle(presentCondition, sex, deathDate, deathPlaceDesc, deathPlaceType,
            causeOfDeathField, causeOfDeathDiseaseField, causeOfDeathDetailsField, burialDate, burialPlaceDesc,
            burialConductor);

    // Set initial visibilities

    initializeVisibilitiesAndAllowedVisibilities(disease, viewMode);

    if (!getField(PersonDto.OCCUPATION_TYPE).isVisible() && !getField(PersonDto.EDUCATION_TYPE).isVisible())
        occupationHeader.setVisible(false);
    if (!getField(PersonDto.ADDRESS).isVisible())
        addressHeader.setVisible(false);

    // Add listeners

    FieldHelper.setRequiredWhenNotNull(getFieldGroup(), PersonDto.APPROXIMATE_AGE,
            PersonDto.APPROXIMATE_AGE_TYPE);
    addFieldListeners(PersonDto.APPROXIMATE_AGE, e -> {
        @SuppressWarnings("unchecked")
        Field<ApproximateAgeType> ageTypeField = (Field<ApproximateAgeType>) getField(
                PersonDto.APPROXIMATE_AGE_TYPE);
        if (e.getProperty().getValue() == null) {
            ageTypeField.clear();
        } else {
            if (ageTypeField.isEmpty()) {
                ageTypeField.setValue(ApproximateAgeType.YEARS);
            }
        }
    });

    addFieldListeners(PersonDto.BIRTH_DATE_DD, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });

    addFieldListeners(PersonDto.BIRTH_DATE_MM, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });

    addFieldListeners(PersonDto.BIRTH_DATE_YYYY, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });

    addFieldListeners(PersonDto.DEATH_DATE, e -> updateApproximateAge());
    addFieldListeners(PersonDto.OCCUPATION_TYPE, e -> {
        updateOccupationFieldCaptions();
        toogleOccupationMetaFields();
    });

    addListenersToInfrastructureFields(cbPlaceOfBirthRegion, cbPlaceOfBirthDistrict, cbPlaceOfBirthCommunity,
            cbPlaceOfBirthFacility, tfPlaceOfBirthFacilityDetails);
    addListenersToInfrastructureFields(facilityRegion, facilityDistrict, facilityCommunity, occupationFacility,
            occupationFacilityDetails);
    cbPlaceOfBirthRegion.addItems(FacadeProvider.getRegionFacade().getAllAsReference());
    facilityRegion.addItems(FacadeProvider.getRegionFacade().getAllAsReference());

    addFieldListeners(PersonDto.PRESENT_CONDITION, e -> toogleDeathAndBurialFields());

    causeOfDeathField.addValueChangeListener(e -> {
        toggleCauseOfDeathFields(
                presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != null);
    });

    causeOfDeathDiseaseField.addValueChangeListener(e -> {
        toggleCauseOfDeathFields(
                presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != null);
    });

    addValueChangeListener(e -> {
        fillDeathAndBurialFields(deathPlaceType, deathPlaceDesc, burialPlaceDesc);
    });

    deathDate.addValidator(new DateComparisonValidator(deathDate, this::calcBirthDateValue, false, false,
            I18nProperties.getValidationError(Validations.afterDate, deathDate.getCaption(),
                    birthDateYear.getCaption())));
    burialDate.addValidator(new DateComparisonValidator(burialDate, deathDate, false, false, I18nProperties
            .getValidationError(Validations.afterDate, burialDate.getCaption(), deathDate.getCaption())));

    // Update the list of days according to the selected month and year
    birthDateYear.addValueChangeListener(e -> {
        updateListOfDays((Integer) e.getProperty().getValue(), (Integer) birthDateMonth.getValue());
    });
    birthDateMonth.addValueChangeListener(e -> {
        updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
    });
}

From source file:de.symeda.sormas.ui.symptoms.SymptomsForm.java

License:Open Source License

@Override
protected void addFields() {
    if (disease == null || symptomsContext == null) {
        // workaround to stop initialization until disease is set 
        return;/*from   w w w. j  a v  a2s  . c  om*/
    }

    // Add fields

    DateField onsetDateField = addField(SymptomsDto.ONSET_DATE, DateField.class);
    ComboBox onsetSymptom = addField(SymptomsDto.ONSET_SYMPTOM, ComboBox.class);
    if (symptomsContext == SymptomsContext.CASE) {
        onsetDateField.addValidator(new DateComparisonValidator(onsetDateField,
                caze.getHospitalization().getAdmissionDate(), true, false,
                I18nProperties.getValidationError(Validations.beforeDateSoft, onsetDateField.getCaption(),
                        I18nProperties.getPrefixCaption(HospitalizationDto.I18N_PREFIX,
                                HospitalizationDto.ADMISSION_DATE))));
        onsetDateField.setInvalidCommitted(true);
    }

    ComboBox temperature = addField(SymptomsDto.TEMPERATURE, ComboBox.class);
    for (Float temperatureValue : SymptomsHelper.getTemperatureValues()) {
        temperature.addItem(temperatureValue);
        temperature.setItemCaption(temperatureValue, SymptomsHelper.getTemperatureString(temperatureValue));
    }
    if (symptomsContext == SymptomsContext.CASE) {
        temperature.setCaption(I18nProperties.getCaption(Captions.symptomsMaxTemperature));
    }
    addField(SymptomsDto.TEMPERATURE_SOURCE);

    ComboBox bloodPressureSystolic = addField(SymptomsDto.BLOOD_PRESSURE_SYSTOLIC, ComboBox.class);
    bloodPressureSystolic.addItems(SymptomsHelper.getBloodPressureValues());
    ComboBox bloodPressureDiastolic = addField(SymptomsDto.BLOOD_PRESSURE_DIASTOLIC, ComboBox.class);
    bloodPressureDiastolic.addItems(SymptomsHelper.getBloodPressureValues());
    ComboBox heartRate = addField(SymptomsDto.HEART_RATE, ComboBox.class);
    heartRate.addItems(SymptomsHelper.getHeartRateValues());
    ComboBox respiratoryRate = addField(SymptomsDto.RESPIRATORY_RATE, ComboBox.class);
    respiratoryRate.addItems(SymptomsHelper.getRespiratoryRateValues());
    ComboBox weight = addField(SymptomsDto.WEIGHT, ComboBox.class);
    for (Integer weightValue : SymptomsHelper.getWeightValues()) {
        weight.addItem(weightValue);
        weight.setItemCaption(weightValue, SymptomsHelper.getDecimalString(weightValue));
    }
    ComboBox height = addField(SymptomsDto.HEIGHT, ComboBox.class);
    height.addItems(SymptomsHelper.getHeightValues());
    ComboBox midUpperArmCircumference = addField(SymptomsDto.MID_UPPER_ARM_CIRCUMFERENCE, ComboBox.class);
    for (Integer circumferenceValue : SymptomsHelper.getMidUpperArmCircumferenceValues()) {
        midUpperArmCircumference.addItem(circumferenceValue);
        midUpperArmCircumference.setItemCaption(circumferenceValue,
                SymptomsHelper.getDecimalString(circumferenceValue));
    }
    ComboBox glasgowComaScale = addField(SymptomsDto.GLASGOW_COMA_SCALE, ComboBox.class);
    glasgowComaScale.addItems(SymptomsHelper.getGlasgowComaScaleValues());

    addFields(SymptomsDto.FEVER, SymptomsDto.VOMITING, SymptomsDto.DIARRHEA, SymptomsDto.BLOOD_IN_STOOL,
            SymptomsDto.NAUSEA, SymptomsDto.ABDOMINAL_PAIN, SymptomsDto.HEADACHE, SymptomsDto.MUSCLE_PAIN,
            SymptomsDto.FATIGUE_WEAKNESS, SymptomsDto.SKIN_RASH, SymptomsDto.NECK_STIFFNESS,
            SymptomsDto.SORE_THROAT, SymptomsDto.COUGH, SymptomsDto.RUNNY_NOSE,
            SymptomsDto.DIFFICULTY_BREATHING, SymptomsDto.CHEST_PAIN, SymptomsDto.CONJUNCTIVITIS,
            SymptomsDto.EYE_PAIN_LIGHT_SENSITIVE, SymptomsDto.KOPLIKS_SPOTS, SymptomsDto.THROBOCYTOPENIA,
            SymptomsDto.OTITIS_MEDIA, SymptomsDto.HEARINGLOSS, SymptomsDto.DEHYDRATION,
            SymptomsDto.ANOREXIA_APPETITE_LOSS, SymptomsDto.REFUSAL_FEEDOR_DRINK, SymptomsDto.JOINT_PAIN,
            SymptomsDto.HICCUPS, SymptomsDto.BACKACHE, SymptomsDto.EYES_BLEEDING, SymptomsDto.JAUNDICE,
            SymptomsDto.DARK_URINE, SymptomsDto.STOMACH_BLEEDING, SymptomsDto.RAPID_BREATHING,
            SymptomsDto.SWOLLEN_GLANDS, SymptomsDto.SYMPTOMS_COMMENTS, SymptomsDto.UNEXPLAINED_BLEEDING,
            SymptomsDto.GUMS_BLEEDING, SymptomsDto.INJECTION_SITE_BLEEDING, SymptomsDto.NOSE_BLEEDING,
            SymptomsDto.BLOODY_BLACK_STOOL, SymptomsDto.RED_BLOOD_VOMIT, SymptomsDto.DIGESTED_BLOOD_VOMIT,
            SymptomsDto.COUGHING_BLOOD, SymptomsDto.BLEEDING_VAGINA, SymptomsDto.SKIN_BRUISING,
            SymptomsDto.BLOOD_URINE, SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS,
            SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS_TEXT, SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS,
            SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS_TEXT, SymptomsDto.LESIONS, SymptomsDto.LESIONS_THAT_ITCH,
            SymptomsDto.LESIONS_SAME_STATE, SymptomsDto.LESIONS_SAME_SIZE, SymptomsDto.LESIONS_DEEP_PROFOUND,
            SymptomsDto.LESIONS_FACE, SymptomsDto.LESIONS_LEGS, SymptomsDto.LESIONS_SOLES_FEET,
            SymptomsDto.LESIONS_PALMS_HANDS, SymptomsDto.LESIONS_THORAX, SymptomsDto.LESIONS_ARMS,
            SymptomsDto.LESIONS_GENITALS, SymptomsDto.LESIONS_ALL_OVER_BODY,
            SymptomsDto.LYMPHADENOPATHY_AXILLARY, SymptomsDto.LYMPHADENOPATHY_CERVICAL,
            SymptomsDto.LYMPHADENOPATHY_INGUINAL, SymptomsDto.CHILLS_SWEATS, SymptomsDto.BEDRIDDEN,
            SymptomsDto.ORAL_ULCERS, SymptomsDto.PAINFUL_LYMPHADENITIS, SymptomsDto.BLACKENING_DEATH_OF_TISSUE,
            SymptomsDto.BUBOES_GROIN_ARMPIT_NECK, SymptomsDto.BULGING_FONTANELLE,
            SymptomsDto.PHARYNGEAL_ERYTHEMA, SymptomsDto.PHARYNGEAL_EXUDATE, SymptomsDto.OEDEMA_FACE_NECK,
            SymptomsDto.OEDEMA_LOWER_EXTREMITY, SymptomsDto.LOSS_SKIN_TURGOR, SymptomsDto.PALPABLE_LIVER,
            SymptomsDto.PALPABLE_SPLEEN, SymptomsDto.MALAISE, SymptomsDto.SUNKEN_EYES_FONTANELLE,
            SymptomsDto.SIDE_PAIN, SymptomsDto.FLUID_IN_LUNG_CAVITY, SymptomsDto.TREMOR,
            SymptomsDto.BILATERAL_CATARACTS, SymptomsDto.UNILATERAL_CATARACTS, SymptomsDto.CONGENITAL_GLAUCOMA,
            SymptomsDto.CONGENITAL_HEART_DISEASE, SymptomsDto.PIGMENTARY_RETINOPATHY,
            SymptomsDto.RADIOLUCENT_BONE_DISEASE, SymptomsDto.SPLENOMEGALY, SymptomsDto.MICROCEPHALY,
            SymptomsDto.MENINGOENCEPHALITIS, SymptomsDto.PURPURIC_RASH, SymptomsDto.DEVELOPMENTAL_DELAY,
            SymptomsDto.CONGENITAL_HEART_DISEASE_TYPE, SymptomsDto.CONGENITAL_HEART_DISEASE_DETAILS,
            SymptomsDto.JAUNDICE_WITHIN_24_HOURS_OF_BIRTH, SymptomsDto.PATIENT_ILL_LOCATION);
    addField(SymptomsDto.LESIONS_ONSET_DATE, DateField.class);

    // complications
    addFields(SymptomsDto.ALTERED_CONSCIOUSNESS, SymptomsDto.CONFUSED_DISORIENTED,
            SymptomsDto.HEMORRHAGIC_SYNDROME, SymptomsDto.HYPERGLYCEMIA, SymptomsDto.HYPOGLYCEMIA,
            SymptomsDto.MENINGEAL_SIGNS, SymptomsDto.SEIZURES, SymptomsDto.SEPSIS, SymptomsDto.SHOCK);

    monkeypoxImageFieldIds = Arrays.asList(SymptomsDto.LESIONS_RESEMBLE_IMG1, SymptomsDto.LESIONS_RESEMBLE_IMG2,
            SymptomsDto.LESIONS_RESEMBLE_IMG3, SymptomsDto.LESIONS_RESEMBLE_IMG4);
    for (String propertyId : monkeypoxImageFieldIds) {
        @SuppressWarnings("rawtypes")
        Field monkeypoxImageField = addField(propertyId);
        CssStyles.style(monkeypoxImageField, CssStyles.VSPACE_NONE);
    }

    // Set initial visibilities

    initializeVisibilitiesAndAllowedVisibilities(disease, viewMode);

    if (symptomsContext != SymptomsContext.CLINICAL_VISIT) {
        setVisible(false, SymptomsDto.BLOOD_PRESSURE_SYSTOLIC, SymptomsDto.BLOOD_PRESSURE_DIASTOLIC,
                SymptomsDto.HEART_RATE, SymptomsDto.RESPIRATORY_RATE, SymptomsDto.WEIGHT, SymptomsDto.HEIGHT,
                SymptomsDto.MID_UPPER_ARM_CIRCUMFERENCE, SymptomsDto.GLASGOW_COMA_SCALE);
    } else {
        setVisible(false, SymptomsDto.ONSET_SYMPTOM, SymptomsDto.ONSET_DATE);
    }

    // Initialize lists

    conditionalBleedingSymptomFieldIds = Arrays.asList(SymptomsDto.GUMS_BLEEDING,
            SymptomsDto.INJECTION_SITE_BLEEDING, SymptomsDto.NOSE_BLEEDING, SymptomsDto.BLOODY_BLACK_STOOL,
            SymptomsDto.RED_BLOOD_VOMIT, SymptomsDto.DIGESTED_BLOOD_VOMIT, SymptomsDto.EYES_BLEEDING,
            SymptomsDto.COUGHING_BLOOD, SymptomsDto.BLEEDING_VAGINA, SymptomsDto.SKIN_BRUISING,
            SymptomsDto.STOMACH_BLEEDING, SymptomsDto.BLOOD_URINE, SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS);
    lesionsFieldIds = Arrays.asList(SymptomsDto.LESIONS_SAME_STATE, SymptomsDto.LESIONS_SAME_SIZE,
            SymptomsDto.LESIONS_DEEP_PROFOUND, SymptomsDto.LESIONS_THAT_ITCH);
    lesionsLocationFieldIds = Arrays.asList(SymptomsDto.LESIONS_FACE, SymptomsDto.LESIONS_LEGS,
            SymptomsDto.LESIONS_SOLES_FEET, SymptomsDto.LESIONS_PALMS_HANDS, SymptomsDto.LESIONS_THORAX,
            SymptomsDto.LESIONS_ARMS, SymptomsDto.LESIONS_GENITALS, SymptomsDto.LESIONS_ALL_OVER_BODY);
    unconditionalSymptomFieldIds = Arrays.asList(SymptomsDto.FEVER, SymptomsDto.VOMITING, SymptomsDto.DIARRHEA,
            SymptomsDto.BLOOD_IN_STOOL, SymptomsDto.NAUSEA, SymptomsDto.ABDOMINAL_PAIN, SymptomsDto.HEADACHE,
            SymptomsDto.MUSCLE_PAIN, SymptomsDto.FATIGUE_WEAKNESS, SymptomsDto.SKIN_RASH,
            SymptomsDto.NECK_STIFFNESS, SymptomsDto.SORE_THROAT, SymptomsDto.COUGH, SymptomsDto.RUNNY_NOSE,
            SymptomsDto.DIFFICULTY_BREATHING, SymptomsDto.CHEST_PAIN, SymptomsDto.CONJUNCTIVITIS,
            SymptomsDto.EYE_PAIN_LIGHT_SENSITIVE, SymptomsDto.KOPLIKS_SPOTS, SymptomsDto.THROBOCYTOPENIA,
            SymptomsDto.OTITIS_MEDIA, SymptomsDto.HEARINGLOSS, SymptomsDto.DEHYDRATION,
            SymptomsDto.ANOREXIA_APPETITE_LOSS, SymptomsDto.REFUSAL_FEEDOR_DRINK, SymptomsDto.JOINT_PAIN,
            SymptomsDto.HICCUPS, SymptomsDto.BACKACHE, SymptomsDto.JAUNDICE, SymptomsDto.DARK_URINE,
            SymptomsDto.RAPID_BREATHING, SymptomsDto.SWOLLEN_GLANDS, SymptomsDto.UNEXPLAINED_BLEEDING,
            SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS, SymptomsDto.LESIONS,
            SymptomsDto.LYMPHADENOPATHY_AXILLARY, SymptomsDto.LYMPHADENOPATHY_CERVICAL,
            SymptomsDto.LYMPHADENOPATHY_INGUINAL, SymptomsDto.CHILLS_SWEATS, SymptomsDto.BEDRIDDEN,
            SymptomsDto.ORAL_ULCERS, SymptomsDto.PAINFUL_LYMPHADENITIS, SymptomsDto.BLACKENING_DEATH_OF_TISSUE,
            SymptomsDto.BUBOES_GROIN_ARMPIT_NECK, SymptomsDto.BULGING_FONTANELLE,
            SymptomsDto.PHARYNGEAL_ERYTHEMA, SymptomsDto.PHARYNGEAL_EXUDATE, SymptomsDto.OEDEMA_FACE_NECK,
            SymptomsDto.OEDEMA_LOWER_EXTREMITY, SymptomsDto.LOSS_SKIN_TURGOR, SymptomsDto.PALPABLE_LIVER,
            SymptomsDto.PALPABLE_SPLEEN, SymptomsDto.MALAISE, SymptomsDto.SUNKEN_EYES_FONTANELLE,
            SymptomsDto.SIDE_PAIN, SymptomsDto.FLUID_IN_LUNG_CAVITY, SymptomsDto.TREMOR,
            SymptomsDto.BILATERAL_CATARACTS, SymptomsDto.UNILATERAL_CATARACTS, SymptomsDto.CONGENITAL_GLAUCOMA,
            SymptomsDto.CONGENITAL_HEART_DISEASE, SymptomsDto.RADIOLUCENT_BONE_DISEASE,
            SymptomsDto.SPLENOMEGALY, SymptomsDto.MICROCEPHALY, SymptomsDto.MENINGOENCEPHALITIS,
            SymptomsDto.DEVELOPMENTAL_DELAY, SymptomsDto.PURPURIC_RASH, SymptomsDto.PIGMENTARY_RETINOPATHY,
            // complications
            SymptomsDto.ALTERED_CONSCIOUSNESS, SymptomsDto.CONFUSED_DISORIENTED,
            SymptomsDto.HEMORRHAGIC_SYNDROME, SymptomsDto.HYPERGLYCEMIA, SymptomsDto.HYPOGLYCEMIA,
            SymptomsDto.MENINGEAL_SIGNS, SymptomsDto.SEIZURES, SymptomsDto.SEPSIS, SymptomsDto.SHOCK);

    // Set visibilities

    FieldHelper.setVisibleWhen(getFieldGroup(), conditionalBleedingSymptomFieldIds,
            SymptomsDto.UNEXPLAINED_BLEEDING, Arrays.asList(SymptomState.YES), true, SymptomsDto.class,
            disease);

    FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS_TEXT,
            SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS, Arrays.asList(SymptomState.YES), true);

    FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS_TEXT,
            SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS, Arrays.asList(SymptomState.YES), true);

    FieldHelper.setVisibleWhen(getFieldGroup(), lesionsFieldIds, SymptomsDto.LESIONS,
            Arrays.asList(SymptomState.YES), true);

    FieldHelper.setVisibleWhen(getFieldGroup(), lesionsLocationFieldIds, SymptomsDto.LESIONS,
            Arrays.asList(SymptomState.YES), true);

    FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.LESIONS_ONSET_DATE, SymptomsDto.LESIONS,
            Arrays.asList(SymptomState.YES), true);

    FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.CONGENITAL_HEART_DISEASE_TYPE,
            SymptomsDto.CONGENITAL_HEART_DISEASE, Arrays.asList(SymptomState.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.CONGENITAL_HEART_DISEASE_DETAILS,
            SymptomsDto.CONGENITAL_HEART_DISEASE_TYPE, Arrays.asList(CongenitalHeartDiseaseType.OTHER), true);
    if (isVisibleAllowed(getFieldGroup().getField(SymptomsDto.JAUNDICE_WITHIN_24_HOURS_OF_BIRTH))) {
        FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.JAUNDICE_WITHIN_24_HOURS_OF_BIRTH,
                SymptomsDto.JAUNDICE, Arrays.asList(SymptomState.YES), true);
    }

    FieldHelper.addSoftRequiredStyle(getField(SymptomsDto.LESIONS_ONSET_DATE));

    boolean isInfant = person != null && person.getApproximateAge() != null
            && ((person.getApproximateAge() <= 12
                    && person.getApproximateAgeType() == ApproximateAgeType.MONTHS)
                    || person.getApproximateAge() <= 1);
    if (!isInfant) {
        getFieldGroup().getField(SymptomsDto.BULGING_FONTANELLE).setVisible(false);
    }

    // Handle visibility of lesions locations caption
    Label lesionsLocationsCaption = new Label(I18nProperties.getCaption(Captions.symptomsLesionsLocations));
    CssStyles.style(lesionsLocationsCaption, CssStyles.VSPACE_3);
    getContent().addComponent(lesionsLocationsCaption, LESIONS_LOCATIONS_LOC);
    getContent().getComponent(LESIONS_LOCATIONS_LOC)
            .setVisible(getFieldGroup().getField(SymptomsDto.LESIONS).getValue() == SymptomState.YES);
    getFieldGroup().getField(SymptomsDto.LESIONS).addValueChangeListener(e -> {
        getContent().getComponent(LESIONS_LOCATIONS_LOC)
                .setVisible(e.getProperty().getValue() == SymptomState.YES);
    });

    // Symptoms hint text
    Label symptomsHint = new Label(
            I18nProperties.getString(symptomsContext == SymptomsContext.CASE ? Strings.messageSymptomsHint
                    : Strings.messageSymptomsVisitHint),
            ContentMode.HTML);
    getContent().addComponent(symptomsHint, SYMPTOMS_HINT_LOC);

    if (disease == Disease.MONKEYPOX) {
        setUpMonkeypoxVisibilities();
    }

    if (symptomsContext != SymptomsContext.CASE) {
        getFieldGroup().getField(SymptomsDto.PATIENT_ILL_LOCATION).setVisible(false);
    }

    FieldHelper.setRequiredWhen(getFieldGroup(),
            getFieldGroup().getField(SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS),
            Arrays.asList(SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS_TEXT), Arrays.asList(SymptomState.YES),
            disease);
    FieldHelper.setRequiredWhen(getFieldGroup(),
            getFieldGroup().getField(SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS),
            Arrays.asList(SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS_TEXT), Arrays.asList(SymptomState.YES),
            disease);
    FieldHelper.setRequiredWhen(getFieldGroup(), getFieldGroup().getField(SymptomsDto.LESIONS), lesionsFieldIds,
            Arrays.asList(SymptomState.YES), disease);
    FieldHelper.setRequiredWhen(getFieldGroup(), getFieldGroup().getField(SymptomsDto.LESIONS),
            monkeypoxImageFieldIds, Arrays.asList(SymptomState.YES), disease);

    addListenerForOnsetFields(onsetSymptom, onsetDateField);

    Button clearAllButton = new Button(I18nProperties.getCaption(Captions.actionClearAll));
    clearAllButton.addStyleName(ValoTheme.BUTTON_LINK);

    clearAllButton.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            for (Object symptomId : unconditionalSymptomFieldIds) {
                getFieldGroup().getField(symptomId).setValue(null);
            }
            for (Object symptomId : conditionalBleedingSymptomFieldIds) {
                getFieldGroup().getField(symptomId).setValue(null);
            }
            for (Object symptomId : lesionsFieldIds) {
                getFieldGroup().getField(symptomId).setValue(null);
            }
            for (Object symptomId : lesionsLocationFieldIds) {
                getFieldGroup().getField(symptomId).setValue(null);
            }
            for (Object symptomId : monkeypoxImageFieldIds) {
                getFieldGroup().getField(symptomId).setValue(null);
            }
        }
    });

    Button setEmptyToNoButton = new Button(I18nProperties.getCaption(Captions.symptomsSetClearedToNo));
    setEmptyToNoButton.addStyleName(ValoTheme.BUTTON_LINK);

    setEmptyToNoButton.addClickListener(new ClickListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void buttonClick(ClickEvent event) {
            for (Object symptomId : unconditionalSymptomFieldIds) {
                Field<SymptomState> symptom = (Field<SymptomState>) getFieldGroup().getField(symptomId);
                if (symptom.isVisible() && symptom.getValue() == null) {
                    symptom.setValue(SymptomState.NO);
                }
            }
            for (Object symptomId : conditionalBleedingSymptomFieldIds) {
                Field<SymptomState> symptom = (Field<SymptomState>) getFieldGroup().getField(symptomId);
                if (symptom.isVisible() && symptom.getValue() == null) {
                    symptom.setValue(SymptomState.NO);
                }
            }
            for (Object symptomId : lesionsFieldIds) {
                Field<SymptomState> symptom = (Field<SymptomState>) getFieldGroup().getField(symptomId);
                if (symptom.isVisible() && symptom.getValue() == null) {
                    symptom.setValue(SymptomState.NO);
                }
            }
            for (Object symptomId : monkeypoxImageFieldIds) {
                Field<SymptomState> symptom = (Field<SymptomState>) getFieldGroup().getField(symptomId);
                if (symptom.isVisible() && symptom.getValue() == null) {
                    symptom.setValue(SymptomState.NO);
                }
            }
        }
    });

    // Complications heading - not displayed for Rubella (dirty, should be made generic)
    Label complicationsHeading = new Label(I18nProperties.getString(Strings.headingComplications));
    CssStyles.style(complicationsHeading, CssStyles.H3);
    if (disease != Disease.CONGENITAL_RUBELLA) {
        getContent().addComponent(complicationsHeading, COMPLICATIONS_HEADING);
    }

    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.addComponent(clearAllButton);
    buttonsLayout.addComponent(setEmptyToNoButton);
    buttonsLayout.setDefaultComponentAlignment(Alignment.MIDDLE_RIGHT);
    getContent().addComponent(buttonsLayout, BUTTONS_LOC);
}