Search in sources :

Example 21 with ComboBox

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

the class MaternalHistoryForm method addFields.

@Override
protected void addFields() {
    Label maternalHistoryHeadingLabel = new Label(I18nProperties.getString(Strings.headingMaternalHistory));
    maternalHistoryHeadingLabel.addStyleName(H3);
    getContent().addComponent(maternalHistoryHeadingLabel, MATERNAL_HISTORY_HEADING_LOC);
    TextField tfChildrenNumber = addField(MaternalHistoryDto.CHILDREN_NUMBER, TextField.class);
    tfChildrenNumber.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfChildrenNumber.getCaption()));
    TextField tfAgeAtBirth = addField(MaternalHistoryDto.AGE_AT_BIRTH, TextField.class);
    tfAgeAtBirth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfAgeAtBirth.getCaption()));
    TextField tfConjunctivitisMonth = addField(MaternalHistoryDto.CONJUNCTIVITIS_MONTH, TextField.class);
    tfConjunctivitisMonth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfConjunctivitisMonth.getCaption()));
    TextField tfMaculopapularRashMonth = addField(MaternalHistoryDto.MACULOPAPULAR_RASH_MONTH, TextField.class);
    tfMaculopapularRashMonth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfMaculopapularRashMonth.getCaption()));
    TextField tfSwollenLymphsMonth = addField(MaternalHistoryDto.SWOLLEN_LYMPHS_MONTH, TextField.class);
    tfSwollenLymphsMonth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfSwollenLymphsMonth.getCaption()));
    TextField tfArthralgiaArthritisMonth = addField(MaternalHistoryDto.ARTHRALGIA_ARTHRITIS_MONTH, TextField.class);
    tfArthralgiaArthritisMonth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfArthralgiaArthritisMonth.getCaption()));
    TextField otherComplicationsMonth = addField(MaternalHistoryDto.OTHER_COMPLICATIONS_MONTH, TextField.class);
    otherComplicationsMonth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, otherComplicationsMonth.getCaption()));
    TextField rashExposureMonth = addField(MaternalHistoryDto.RASH_EXPOSURE_MONTH, TextField.class);
    rashExposureMonth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, rashExposureMonth.getCaption()));
    addFields(MaternalHistoryDto.CONJUNCTIVITIS_ONSET, MaternalHistoryDto.MACULOPAPULAR_RASH_ONSET, MaternalHistoryDto.SWOLLEN_LYMPHS_ONSET, MaternalHistoryDto.ARTHRALGIA_ARTHRITIS_ONSET, MaternalHistoryDto.OTHER_COMPLICATIONS_ONSET, MaternalHistoryDto.OTHER_COMPLICATIONS_DETAILS, MaternalHistoryDto.RUBELLA_ONSET, MaternalHistoryDto.RASH_EXPOSURE_DATE);
    addField(MaternalHistoryDto.CONJUNCTIVITIS, NullableOptionGroup.class);
    addField(MaternalHistoryDto.MACULOPAPULAR_RASH, NullableOptionGroup.class);
    addField(MaternalHistoryDto.SWOLLEN_LYMPHS, NullableOptionGroup.class);
    addField(MaternalHistoryDto.ARTHRALGIA_ARTHRITIS, NullableOptionGroup.class);
    addField(MaternalHistoryDto.OTHER_COMPLICATIONS, NullableOptionGroup.class);
    addField(MaternalHistoryDto.RUBELLA, NullableOptionGroup.class);
    addField(MaternalHistoryDto.RASH_EXPOSURE, NullableOptionGroup.class);
    ComboBox cbRashExposureRegion = addInfrastructureField(MaternalHistoryDto.RASH_EXPOSURE_REGION);
    ComboBox cbRashExposureDistrict = addInfrastructureField(MaternalHistoryDto.RASH_EXPOSURE_DISTRICT);
    ComboBox cbRashExposureCommunity = addInfrastructureField(MaternalHistoryDto.RASH_EXPOSURE_COMMUNITY);
    initializeAccessAndAllowedAccesses();
    cbRashExposureRegion.addValueChangeListener(e -> {
        RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(cbRashExposureDistrict, region != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()) : null);
    });
    cbRashExposureDistrict.addValueChangeListener(e -> {
        FieldHelper.removeItems(cbRashExposureCommunity);
        DistrictReferenceDto district = (DistrictReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(cbRashExposureCommunity, district != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(district.getUuid()) : null);
    });
    cbRashExposureRegion.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(MaternalHistoryDto.CONJUNCTIVITIS_ONSET, MaternalHistoryDto.CONJUNCTIVITIS_MONTH), MaternalHistoryDto.CONJUNCTIVITIS, Arrays.asList(YesNoUnknown.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(MaternalHistoryDto.MACULOPAPULAR_RASH_ONSET, MaternalHistoryDto.MACULOPAPULAR_RASH_MONTH), MaternalHistoryDto.MACULOPAPULAR_RASH, Arrays.asList(YesNoUnknown.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(MaternalHistoryDto.SWOLLEN_LYMPHS_ONSET, MaternalHistoryDto.SWOLLEN_LYMPHS_MONTH), MaternalHistoryDto.SWOLLEN_LYMPHS, Arrays.asList(YesNoUnknown.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(MaternalHistoryDto.ARTHRALGIA_ARTHRITIS_ONSET, MaternalHistoryDto.ARTHRALGIA_ARTHRITIS_MONTH), MaternalHistoryDto.ARTHRALGIA_ARTHRITIS, Arrays.asList(YesNoUnknown.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(MaternalHistoryDto.OTHER_COMPLICATIONS_ONSET, MaternalHistoryDto.OTHER_COMPLICATIONS_MONTH, MaternalHistoryDto.OTHER_COMPLICATIONS_DETAILS), MaternalHistoryDto.OTHER_COMPLICATIONS, Arrays.asList(YesNoUnknown.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(MaternalHistoryDto.RUBELLA_ONSET), MaternalHistoryDto.RUBELLA, Arrays.asList(YesNoUnknown.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(MaternalHistoryDto.RASH_EXPOSURE_DATE, MaternalHistoryDto.RASH_EXPOSURE_MONTH, MaternalHistoryDto.RASH_EXPOSURE_REGION, MaternalHistoryDto.RASH_EXPOSURE_DISTRICT, MaternalHistoryDto.RASH_EXPOSURE_COMMUNITY), MaternalHistoryDto.RASH_EXPOSURE, Arrays.asList(YesNoUnknown.YES), true);
}
Also used : RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) TextField(com.vaadin.v7.ui.TextField) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)

Example 22 with ComboBox

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

the class PortHealthInfoForm method addAirportFields.

private void addAirportFields() {
    addFields(PortHealthInfoDto.AIRLINE_NAME, PortHealthInfoDto.FLIGHT_NUMBER, PortHealthInfoDto.DEPARTURE_AIRPORT, PortHealthInfoDto.SEAT_NUMBER, PortHealthInfoDto.TRANSIT_STOP_DETAILS_1, PortHealthInfoDto.TRANSIT_STOP_DETAILS_2, PortHealthInfoDto.TRANSIT_STOP_DETAILS_3, PortHealthInfoDto.TRANSIT_STOP_DETAILS_4, PortHealthInfoDto.TRANSIT_STOP_DETAILS_5);
    DateTimeField dfDepartureDateTime = addField(PortHealthInfoDto.DEPARTURE_DATE_TIME, DateTimeField.class);
    DateTimeField dfArrivalDateTime = addField(PortHealthInfoDto.ARRIVAL_DATE_TIME, DateTimeField.class);
    addField(PortHealthInfoDto.FREE_SEATING, NullableOptionGroup.class);
    ComboBox cbNumberOfTransitStops = addField(PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, ComboBox.class);
    cbNumberOfTransitStops.addItems(DataHelper.buildIntegerList(0, 5));
    // Visibility
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.TRANSIT_STOP_DETAILS_1, PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, Arrays.asList(1, 2, 3, 4, 5), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.TRANSIT_STOP_DETAILS_2, PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, Arrays.asList(2, 3, 4, 5), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.TRANSIT_STOP_DETAILS_3, PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, Arrays.asList(3, 4, 5), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.TRANSIT_STOP_DETAILS_4, PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, Arrays.asList(4, 5), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.TRANSIT_STOP_DETAILS_5, PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, Arrays.asList(5), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.SEAT_NUMBER, PortHealthInfoDto.FREE_SEATING, Arrays.asList(YesNoUnknown.NO), true);
    // Validations
    dfDepartureDateTime.addValidator(new DateComparisonValidator(dfDepartureDateTime, dfArrivalDateTime, true, false, I18nProperties.getValidationError(Validations.beforeDate, dfDepartureDateTime.getCaption(), dfArrivalDateTime.getCaption())));
    dfArrivalDateTime.addValidator(new DateComparisonValidator(dfArrivalDateTime, dfDepartureDateTime, false, false, I18nProperties.getValidationError(Validations.afterDate, dfArrivalDateTime.getCaption(), dfDepartureDateTime.getCaption())));
}
Also used : ComboBox(com.vaadin.v7.ui.ComboBox) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator)

Example 23 with ComboBox

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

the class SurveillanceReportForm method addFacilityTypeGroupField.

private ComboBox addFacilityTypeGroupField() {
    ComboBox facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
    facilityTypeGroup.setId(FACILITY_TYPE_GROUP_LOC);
    facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
    facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
    facilityTypeGroup.addItems(FacilityTypeGroup.values());
    getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
    return facilityTypeGroup;
}
Also used : ComboBox(com.vaadin.v7.ui.ComboBox)

Example 24 with ComboBox

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

the class PersonCreateForm method addFields.

@Override
protected void addFields() {
    addField(PersonDto.FIRST_NAME, TextField.class);
    addField(PersonDto.LAST_NAME, TextField.class);
    if (showPersonSearchButton) {
        searchPersonButton = createPersonSearchButton(PERSON_SEARCH_LOC);
        getContent().addComponent(searchPersonButton, PERSON_SEARCH_LOC);
    }
    birthDateDay = addField(PersonDto.BIRTH_DATE_DD, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateDay.setNullSelectionAllowed(true);
    birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
    birthDateDay.setCaption("");
    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);
    birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
    birthDateMonth.setCaption("");
    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);
    birthDateYear.setInputPrompt(I18nProperties.getString(Strings.year));
    birthDateDay.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) birthDateMonth.getValue(), (Integer) e));
    birthDateMonth.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) e, (Integer) birthDateDay.getValue()));
    birthDateYear.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) e, (Integer) birthDateMonth.getValue(), (Integer) birthDateDay.getValue()));
    // Update the list of days according to the selected month and year
    birthDateYear.addValueChangeListener(e -> {
        updateListOfDays((Integer) e.getProperty().getValue(), (Integer) birthDateMonth.getValue());
        birthDateMonth.markAsDirty();
        birthDateDay.markAsDirty();
    });
    birthDateMonth.addValueChangeListener(e -> {
        updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
        birthDateYear.markAsDirty();
        birthDateDay.markAsDirty();
    });
    birthDateDay.addValueChangeListener(e -> {
        birthDateYear.markAsDirty();
        birthDateMonth.markAsDirty();
    });
    ComboBox sex = addField(PersonDto.SEX, ComboBox.class);
    addField(PersonDto.PASSPORT_NUMBER, TextField.class);
    addField(PersonDto.NATIONAL_HEALTH_ID, TextField.class);
    ComboBox presentCondition = addField(PersonDto.PRESENT_CONDITION, ComboBox.class);
    presentCondition.setVisible(showPresentCondition);
    FieldHelper.addSoftRequiredStyle(presentCondition, sex);
    if (showSymptomsOnsetDate) {
        addCustomField(SymptomsDto.ONSET_DATE, Date.class, DateField.class, I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ONSET_DATE));
    }
    TextField phone = addCustomField(PersonDto.PHONE, String.class, TextField.class);
    phone.setCaption(I18nProperties.getCaption(Captions.Person_phone));
    TextField email = addCustomField(PersonDto.EMAIL_ADDRESS, String.class, TextField.class);
    email.setCaption(I18nProperties.getCaption(Captions.Person_emailAddress));
    phone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, phone.getCaption())));
    email.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, email.getCaption())));
    if (showHomeAddressForm) {
        addHomeAddressForm();
    }
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    hideValidationUntilNextCommit();
    setRequired(true, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX);
}
Also used : EmailValidator(com.vaadin.v7.data.validator.EmailValidator) ComboBox(com.vaadin.v7.ui.ComboBox) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) TextField(com.vaadin.v7.ui.TextField)

Example 25 with ComboBox

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

the class PersonEditForm method addFields.

@Override
protected void addFields() {
    personInformationHeadingLabel = new Label(I18nProperties.getString(Strings.headingPersonInformation));
    personInformationHeadingLabel.addStyleName(H3);
    getContent().addComponent(personInformationHeadingLabel, PERSON_INFORMATION_HEADING_LOC);
    addField(PersonDto.UUID).setReadOnly(true);
    firstNameField = addField(PersonDto.FIRST_NAME, TextField.class);
    lastNameField = addField(PersonDto.LAST_NAME, TextField.class);
    addFields(PersonDto.SALUTATION, PersonDto.OTHER_SALUTATION);
    FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.OTHER_SALUTATION, PersonDto.SALUTATION, Salutation.OTHER, true);
    ComboBox sex = addField(PersonDto.SEX, ComboBox.class);
    addField(PersonDto.BIRTH_NAME, TextField.class);
    addField(PersonDto.NICKNAME, TextField.class);
    addField(PersonDto.MOTHERS_MAIDEN_NAME, TextField.class);
    addFields(PersonDto.MOTHERS_NAME, PersonDto.FATHERS_NAME);
    addFields(PersonDto.NAMES_OF_GUARDIANS);
    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);
    birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
    birthDateDay.setCaption("");
    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);
    birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
    birthDateMonth.setCaption("");
    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);
    birthDateYear.setInputPrompt(I18nProperties.getString(Strings.year));
    birthDateDay.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) birthDateMonth.getValue(), (Integer) e));
    birthDateMonth.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) e, (Integer) birthDateDay.getValue()));
    birthDateYear.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) e, (Integer) birthDateMonth.getValue(), (Integer) birthDateDay.getValue()));
    DateField deathDate = addField(PersonDto.DEATH_DATE, DateField.class);
    TextField approximateAgeField = addField(PersonDto.APPROXIMATE_AGE, TextField.class);
    approximateAgeField.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, approximateAgeField.getCaption()));
    ComboBox approximateAgeTypeField = addField(PersonDto.APPROXIMATE_AGE_TYPE, ComboBox.class);
    addField(PersonDto.APPROXIMATE_AGE_REFERENCE_DATE, DateField.class);
    approximateAgeField.addValidator(new ApproximateAgeValidator(approximateAgeField, approximateAgeTypeField, I18nProperties.getValidationError(Validations.softApproximateAgeTooHigh)));
    TextField tfGestationAgeAtBirth = addField(PersonDto.GESTATION_AGE_AT_BIRTH, TextField.class);
    tfGestationAgeAtBirth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfGestationAgeAtBirth.getCaption()));
    TextField tfBirthWeight = addField(PersonDto.BIRTH_WEIGHT, TextField.class);
    tfBirthWeight.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, 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);
    addressForm = addField(PersonDto.ADDRESS, LocationEditForm.class);
    addressForm.setCaption(null);
    addField(PersonDto.ADDRESSES, LocationsField.class).setCaption(null);
    PersonContactDetailsField personContactDetailsField = addField(PersonDto.PERSON_CONTACT_DETAILS, PersonContactDetailsField.class);
    personContactDetailsField.setThisPerson(getValue());
    personContactDetailsField.setCaption(null);
    personContactDetailsField.setPseudonymized(isPseudonymized);
    addFields(PersonDto.OCCUPATION_TYPE, PersonDto.OCCUPATION_DETAILS, PersonDto.ARMED_FORCES_RELATION_TYPE, PersonDto.EDUCATION_TYPE, PersonDto.EDUCATION_DETAILS);
    List<CountryReferenceDto> countries = FacadeProvider.getCountryFacade().getAllActiveAsReference();
    addInfrastructureField(PersonDto.BIRTH_COUNTRY).addItems(countries);
    addInfrastructureField(PersonDto.CITIZENSHIP).addItems(countries);
    addFields(PersonDto.PASSPORT_NUMBER, PersonDto.NATIONAL_HEALTH_ID);
    Field externalId = addField(PersonDto.EXTERNAL_ID);
    if (FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled()) {
        externalId.setEnabled(false);
    }
    TextField externalTokenField = addField(PersonDto.EXTERNAL_TOKEN);
    Label externalTokenWarningLabel = new Label(I18nProperties.getString(Strings.messagePersonExternalTokenWarning));
    externalTokenWarningLabel.addStyleNames(VSPACE_3, LABEL_WHITE_SPACE_NORMAL);
    getContent().addComponent(externalTokenWarningLabel, EXTERNAL_TOKEN_WARNING_LOC);
    addField(PersonDto.INTERNAL_TOKEN);
    addField(PersonDto.HAS_COVID_APP).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
    addField(PersonDto.COVID_CODE_DELIVERED).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
    if (personContext != PersonContext.CASE) {
        setVisible(false, PersonDto.HAS_COVID_APP, PersonDto.COVID_CODE_DELIVERED);
    }
    ComboBox cbPlaceOfBirthRegion = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_REGION);
    ComboBox cbPlaceOfBirthDistrict = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_DISTRICT);
    ComboBox cbPlaceOfBirthCommunity = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_COMMUNITY);
    ComboBox placeOfBirthFacilityType = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_TYPE);
    FieldHelper.removeItems(placeOfBirthFacilityType);
    placeOfBirthFacilityType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
    placeOfBirthFacilityType.addItems(FacilityType.getPlaceOfBirthTypes());
    cbPlaceOfBirthFacility = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_FACILITY);
    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);
    // 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, PersonDto.SEX);
    setVisible(false, PersonDto.OCCUPATION_DETAILS, 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();
    initializeAccessAndAllowedAccesses();
    if (!getField(PersonDto.OCCUPATION_TYPE).isVisible() && !getField(PersonDto.ARMED_FORCES_RELATION_TYPE).isVisible() && !getField(PersonDto.EDUCATION_TYPE).isVisible())
        occupationHeader.setVisible(false);
    if (!getField(PersonDto.ADDRESS).isVisible())
        addressHeader.setVisible(false);
    if (!getField(PersonDto.ADDRESSES).isVisible())
        addressesHeader.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 (!ageTypeField.isReadOnly()) {
            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();
        toggleOccupationMetaFields();
    });
    addListenersToInfrastructureFields(cbPlaceOfBirthRegion, cbPlaceOfBirthDistrict, cbPlaceOfBirthCommunity, placeOfBirthFacilityType, cbPlaceOfBirthFacility, tfPlaceOfBirthFacilityDetails, true);
    cbPlaceOfBirthRegion.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    this.presentConditionChangeListener = new PresentConditionChangeListener();
    addFieldListeners(PersonDto.PRESENT_CONDITION, presentConditionChangeListener);
    causeOfDeathField.addValueChangeListener(e -> {
        boolean causeOfDeathVisible = presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != PresentCondition.UNKNOWN && presentCondition.getValue() != null;
        toggleCauseOfDeathFields(causeOfDeathVisible);
    });
    causeOfDeathDiseaseField.addValueChangeListener(e -> {
        boolean causeOfDeathVisible = presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != PresentCondition.UNKNOWN && presentCondition.getValue() != null;
        toggleCauseOfDeathFields(causeOfDeathVisible);
    });
    addValueChangeListener(e -> fillDeathAndBurialFields(deathPlaceType, deathPlaceDesc, burialPlaceDesc));
    deathDate.addValidator(new DateComparisonValidator(deathDate, this::calcBirthDateValue, false, false, I18nProperties.getValidationError(Validations.afterDate, deathDate.getCaption(), birthDateYear.getCaption())));
    deathDate.addValidator(new DateComparisonValidator(deathDate, burialDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, deathDate.getCaption(), burialDate.getCaption())));
    deathDate.addValueChangeListener(value -> {
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    burialDate.addValidator(new DateComparisonValidator(burialDate, this::calcBirthDateValue, false, false, I18nProperties.getValidationError(Validations.afterDate, burialDate.getCaption(), birthDateYear.getCaption())));
    burialDate.addValidator(new DateComparisonValidator(burialDate, deathDate, false, false, I18nProperties.getValidationError(Validations.afterDate, burialDate.getCaption(), deathDate.getCaption())));
    burialDate.addValueChangeListener(b -> {
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    // Update the list of days according to the selected month and year
    birthDateYear.addValueChangeListener(e -> {
        updateListOfDays((Integer) e.getProperty().getValue(), (Integer) birthDateMonth.getValue());
        birthDateMonth.markAsDirty();
        birthDateDay.markAsDirty();
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    birthDateMonth.addValueChangeListener(e -> {
        updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
        birthDateYear.markAsDirty();
        birthDateDay.markAsDirty();
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    birthDateDay.addValueChangeListener(e -> {
        birthDateYear.markAsDirty();
        birthDateMonth.markAsDirty();
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    addValueChangeListener((e) -> {
        ValidationUtils.initComponentErrorValidator(externalTokenField, getValue().getExternalToken(), Validations.duplicateExternalToken, externalTokenWarningLabel, (externalToken) -> FacadeProvider.getPersonFacade().doesExternalTokenExist(externalToken, getValue().getUuid()));
        personContactDetailsField.setThisPerson((PersonDto) e.getProperty().getValue());
    });
    Label generalCommentLabel = new Label(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS));
    generalCommentLabel.addStyleName(H3);
    getContent().addComponent(generalCommentLabel, GENERAL_COMMENT_LOC);
    TextArea additionalDetails = addField(PersonDto.ADDITIONAL_DETAILS, TextArea.class, new ResizableTextAreaWrapper<>(false));
    additionalDetails.setRows(6);
    additionalDetails.setDescription(I18nProperties.getPrefixDescription(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    CssStyles.style(additionalDetails, CssStyles.CAPTION_HIDDEN);
}
Also used : TextArea(com.vaadin.v7.ui.TextArea) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) ApproximateAgeValidator(de.symeda.sormas.ui.utils.ApproximateAgeValidator)

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