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);
}
}
Aggregations