Search in sources :

Example 16 with DateField

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

the class PreviousHospitalizationEditForm method addFields.

@Override
protected void addFields() {
    addField(PreviousHospitalizationDto.ADMITTED_TO_HEALTH_FACILITY, NullableOptionGroup.class);
    DateField admissionDate = addField(PreviousHospitalizationDto.ADMISSION_DATE, DateField.class);
    DateField dischargeDate = addField(PreviousHospitalizationDto.DISCHARGE_DATE, DateField.class);
    addField(PreviousHospitalizationDto.ISOLATED, NullableOptionGroup.class);
    addField(PreviousHospitalizationDto.ISOLATION_DATE);
    addField(PreviousHospitalizationDto.DESCRIPTION, TextArea.class).setRows(4);
    regionCombo = addInfrastructureField(PreviousHospitalizationDto.REGION);
    districtCombo = addInfrastructureField(PreviousHospitalizationDto.DISTRICT);
    ComboBox facilityCommunity = addInfrastructureField(PreviousHospitalizationDto.COMMUNITY);
    facilityCommunity.setNullSelectionAllowed(true);
    healthFacilityCombo = addInfrastructureField(PreviousHospitalizationDto.HEALTH_FACILITY);
    TextField healthFacilityDetails = addField(CaseDataDto.HEALTH_FACILITY_DETAILS, TextField.class);
    healthFacilityDetails.setVisible(false);
    addField(PreviousHospitalizationDto.HOSPITALIZATION_REASON);
    addField(PreviousHospitalizationDto.OTHER_HOSPITALIZATION_REASON, TextField.class);
    intensiveCareUnit = addField(PreviousHospitalizationDto.INTENSIVE_CARE_UNIT, NullableOptionGroup.class);
    intensiveCareUnitStart = addField(PreviousHospitalizationDto.INTENSIVE_CARE_UNIT_START, DateField.class);
    intensiveCareUnitStart.setVisible(false);
    intensiveCareUnitEnd = addField(PreviousHospitalizationDto.INTENSIVE_CARE_UNIT_END, DateField.class);
    intensiveCareUnitEnd.setVisible(false);
    FieldHelper.setVisibleWhen(intensiveCareUnit, Arrays.asList(intensiveCareUnitStart, intensiveCareUnitEnd), Arrays.asList(YesNoUnknown.YES), true);
    healthFacilityCombo.setImmediate(true);
    initializeAccessAndAllowedAccesses();
    if (isVisibleAllowed(PreviousHospitalizationDto.ISOLATION_DATE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), PreviousHospitalizationDto.ISOLATION_DATE, PreviousHospitalizationDto.ISOLATED, Arrays.asList(YesNoUnknown.YES), true);
    }
    FieldHelper.setVisibleWhen(getFieldGroup(), PreviousHospitalizationDto.OTHER_HOSPITALIZATION_REASON, PreviousHospitalizationDto.HOSPITALIZATION_REASON, Collections.singletonList(HospitalizationReasonType.OTHER), true);
    regionCombo.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        boolean isEmpty = regionDto == null || regionDto.equals(unknownRegion);
        FieldHelper.removeItems(districtCombo);
        FieldHelper.updateItems(districtCombo, addUnknown(isEmpty ? null : FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()), unknownDistrict));
    });
    districtCombo.addValueChangeListener(e -> {
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        boolean isEmpty = districtDto == null || districtDto.equals(unknownDistrict);
        FieldHelper.removeItems(healthFacilityCombo);
        FieldHelper.updateItems(facilityCommunity, isEmpty ? null : FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()));
        FieldHelper.updateItems(healthFacilityCombo, addUnknown(isEmpty ? null : FacadeProvider.getFacilityFacade().getActiveHospitalsByDistrict(districtDto, true), unknownFacility));
    });
    facilityCommunity.addValueChangeListener(e -> {
        CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
        DistrictReferenceDto district = (DistrictReferenceDto) districtCombo.getValue();
        boolean isDistrictEmpty = district == null || district.equals(unknownDistrict);
        if (unknownFacility.equals(healthFacilityCombo.getValue())) {
            FieldHelper.removeItems(healthFacilityCombo);
        }
        FieldHelper.updateItems(healthFacilityCombo, addUnknown(communityDto != null ? FacadeProvider.getFacilityFacade().getActiveHospitalsByCommunity(communityDto, true) : isDistrictEmpty ? null : FacadeProvider.getFacilityFacade().getActiveHospitalsByDistrict(district, true), unknownFacility));
    });
    regionCombo.addItems(addUnknown(FacadeProvider.getRegionFacade().getAllActiveByServerCountry(), unknownRegion));
    healthFacilityCombo.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null) {
            boolean otherHealthFacility = ((FacilityReferenceDto) e.getProperty().getValue()).getUuid().equals(FacilityDto.OTHER_FACILITY_UUID);
            boolean noneHealthFacility = ((FacilityReferenceDto) e.getProperty().getValue()).getUuid().equals(FacilityDto.NONE_FACILITY_UUID);
            boolean visibleAndRequired = otherHealthFacility || noneHealthFacility;
            healthFacilityDetails.setVisible(visibleAndRequired);
            healthFacilityDetails.setRequired(visibleAndRequired);
            if (otherHealthFacility) {
                healthFacilityDetails.setCaption(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.HEALTH_FACILITY_DETAILS));
            }
            if (noneHealthFacility) {
                healthFacilityDetails.setCaption(I18nProperties.getCaption(Captions.CaseData_noneHealthFacilityDetails));
            }
            if (!visibleAndRequired) {
                healthFacilityDetails.clear();
            }
        } else {
            healthFacilityDetails.setVisible(false);
            healthFacilityDetails.setRequired(false);
            healthFacilityDetails.clear();
        }
    });
    // Validations
    admissionDate.addValidator(new DateComparisonValidator(admissionDate, dischargeDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, admissionDate.getCaption(), dischargeDate.getCaption())));
    dischargeDate.addValidator(new DateComparisonValidator(dischargeDate, admissionDate, false, false, I18nProperties.getValidationError(Validations.afterDate, dischargeDate.getCaption(), admissionDate.getCaption())));
    intensiveCareUnitStart.addValidator(new DateComparisonValidator(intensiveCareUnitStart, admissionDate, false, true, I18nProperties.getValidationError(Validations.afterDate, intensiveCareUnitStart.getCaption(), admissionDate.getCaption())));
    intensiveCareUnitStart.addValidator(new DateComparisonValidator(intensiveCareUnitStart, intensiveCareUnitEnd, true, true, I18nProperties.getValidationError(Validations.beforeDate, intensiveCareUnitStart.getCaption(), intensiveCareUnitEnd.getCaption())));
    intensiveCareUnitStart.addValidator(new DateComparisonValidator(intensiveCareUnitStart, dischargeDate, true, true, I18nProperties.getValidationError(Validations.beforeDate, intensiveCareUnitStart.getCaption(), dischargeDate.getCaption())));
    intensiveCareUnitEnd.addValidator(new DateComparisonValidator(intensiveCareUnitEnd, intensiveCareUnitStart, false, true, I18nProperties.getValidationError(Validations.afterDate, intensiveCareUnitEnd.getCaption(), intensiveCareUnitStart.getCaption())));
    intensiveCareUnitEnd.addValidator(new DateComparisonValidator(intensiveCareUnitEnd, dischargeDate, true, true, I18nProperties.getValidationError(Validations.beforeDate, intensiveCareUnitEnd.getCaption(), dischargeDate.getCaption())));
    FieldHelper.addSoftRequiredStyle(admissionDate, dischargeDate, facilityCommunity, healthFacilityDetails);
    if (isEditableAllowed(PreviousHospitalizationDto.HEALTH_FACILITY)) {
        setRequired(true, PreviousHospitalizationDto.REGION, PreviousHospitalizationDto.DISTRICT, PreviousHospitalizationDto.HEALTH_FACILITY);
    } else {
        setReadOnly(true, PreviousHospitalizationDto.REGION, PreviousHospitalizationDto.DISTRICT);
    }
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) TextArea(com.vaadin.v7.ui.TextArea) ComboBox(com.vaadin.v7.ui.ComboBox) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator)

Aggregations

DateField (com.vaadin.v7.ui.DateField)15 TextField (com.vaadin.v7.ui.TextField)13 ComboBox (com.vaadin.v7.ui.ComboBox)12 Field (com.vaadin.v7.ui.Field)11 DateComparisonValidator (de.symeda.sormas.ui.utils.DateComparisonValidator)11 Label (com.vaadin.ui.Label)10 TextArea (com.vaadin.v7.ui.TextArea)10 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)8 CheckBox (com.vaadin.v7.ui.CheckBox)7 Disease (de.symeda.sormas.api.Disease)7 FacadeProvider (de.symeda.sormas.api.FacadeProvider)7 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)7 Strings (de.symeda.sormas.api.i18n.Strings)7 Validations (de.symeda.sormas.api.i18n.Validations)7 FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)7 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)7 VSPACE_3 (de.symeda.sormas.ui.utils.CssStyles.VSPACE_3)7 FieldHelper (de.symeda.sormas.ui.utils.FieldHelper)7 LayoutUtil.fluidRowLocs (de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs)7 Date (java.util.Date)7