use of de.symeda.sormas.ui.utils.NullableOptionGroup in project SORMAS-Project by hzi-braunschweig.
the class ActionEditForm method addFields.
@Override
protected void addFields() {
addField(ActionDto.EVENT, ComboBox.class);
DateTimeField date = addDateField(ActionDto.DATE, DateTimeField.class, -1);
date.setImmediate(true);
addField(ActionDto.PRIORITY, ComboBox.class);
addField(ActionDto.ACTION_STATUS, OptionGroup.class);
NullableOptionGroup actionContext = addField(ActionDto.ACTION_CONTEXT, NullableOptionGroup.class);
actionContext.setImmediate(true);
actionContext.addValueChangeListener(event -> updateByActionContext());
// XXX: set visible when other contexts will be managed
actionContext.setVisible(false);
addField(ActionDto.ACTION_MEASURE, TextField.class);
TextField title = addField(ActionDto.TITLE, TextField.class);
title.addStyleName(SOFT_REQUIRED);
RichTextArea description = addField(ActionDto.DESCRIPTION, RichTextArea.class);
description.setNullRepresentation("");
description.setImmediate(true);
RichTextArea reply = addField(ActionDto.REPLY, RichTextArea.class);
reply.setNullRepresentation("");
reply.setImmediate(true);
setRequired(true, ActionDto.ACTION_CONTEXT, ActionDto.DATE, ActionDto.ACTION_STATUS);
setReadOnly(true, ActionDto.ACTION_CONTEXT, ActionDto.EVENT);
}
use of de.symeda.sormas.ui.utils.NullableOptionGroup in project SORMAS-Project by hzi-braunschweig.
the class HospitalizationForm method addFields.
@SuppressWarnings("deprecation")
@Override
protected void addFields() {
if (caze == null || viewMode == null) {
return;
}
Label hospitalizationHeadingLabel = new Label(I18nProperties.getString(Strings.headingHospitalization));
hospitalizationHeadingLabel.addStyleName(H3);
getContent().addComponent(hospitalizationHeadingLabel, HOSPITALIZATION_HEADING_LOC);
Label previousHospitalizationsHeadingLabel = new Label(I18nProperties.getString(Strings.headingPreviousHospitalizations));
previousHospitalizationsHeadingLabel.addStyleName(H3);
getContent().addComponent(previousHospitalizationsHeadingLabel, PREVIOUS_HOSPITALIZATIONS_HEADING_LOC);
TextField facilityField = addCustomField(HEALTH_FACILITY, FacilityReferenceDto.class, TextField.class);
FacilityReferenceDto healthFacility = caze.getHealthFacility();
final boolean noneFacility = healthFacility == null || healthFacility.getUuid().equalsIgnoreCase(FacilityDto.NONE_FACILITY_UUID);
facilityField.setValue(noneFacility || !FacilityType.HOSPITAL.equals(caze.getFacilityType()) ? null : healthFacility.toString());
facilityField.setReadOnly(true);
final NullableOptionGroup admittedToHealthFacilityField = addField(HospitalizationDto.ADMITTED_TO_HEALTH_FACILITY, NullableOptionGroup.class);
final DateField admissionDateField = addField(HospitalizationDto.ADMISSION_DATE, DateField.class);
final DateField dischargeDateField = addDateField(HospitalizationDto.DISCHARGE_DATE, DateField.class, 7);
intensiveCareUnit = addField(HospitalizationDto.INTENSIVE_CARE_UNIT, NullableOptionGroup.class);
intensiveCareUnitStart = addField(HospitalizationDto.INTENSIVE_CARE_UNIT_START, DateField.class);
intensiveCareUnitStart.setVisible(false);
intensiveCareUnitEnd = addField(HospitalizationDto.INTENSIVE_CARE_UNIT_END, DateField.class);
intensiveCareUnitEnd.setVisible(false);
FieldHelper.setVisibleWhen(intensiveCareUnit, Arrays.asList(intensiveCareUnitStart, intensiveCareUnitEnd), Arrays.asList(YesNoUnknown.YES), true);
final Field isolationDateField = addField(HospitalizationDto.ISOLATION_DATE);
final TextArea descriptionField = addField(HospitalizationDto.DESCRIPTION, TextArea.class);
descriptionField.setRows(4);
final NullableOptionGroup isolatedField = addField(HospitalizationDto.ISOLATED, NullableOptionGroup.class);
final NullableOptionGroup leftAgainstAdviceField = addField(HospitalizationDto.LEFT_AGAINST_ADVICE, NullableOptionGroup.class);
final ComboBox hospitalizationReason = addField(HospitalizationDto.HOSPITALIZATION_REASON);
final TextField otherHospitalizationReason = addField(HospitalizationDto.OTHER_HOSPITALIZATION_REASON, TextField.class);
NullableOptionGroup hospitalizedPreviouslyField = addField(HospitalizationDto.HOSPITALIZED_PREVIOUSLY, NullableOptionGroup.class);
CssStyles.style(hospitalizedPreviouslyField, CssStyles.ERROR_COLOR_PRIMARY);
PreviousHospitalizationsField previousHospitalizationsField = addField(HospitalizationDto.PREVIOUS_HOSPITALIZATIONS, PreviousHospitalizationsField.class);
FieldHelper.setEnabledWhen(admittedToHealthFacilityField, Arrays.asList(YesNoUnknown.YES, YesNoUnknown.NO, YesNoUnknown.UNKNOWN), Arrays.asList(facilityField, admissionDateField, dischargeDateField, intensiveCareUnit, intensiveCareUnitStart, intensiveCareUnitEnd, isolationDateField, descriptionField, isolatedField, leftAgainstAdviceField, hospitalizationReason, otherHospitalizationReason), false);
initializeVisibilitiesAndAllowedVisibilities();
initializeAccessAndAllowedAccesses();
if (isVisibleAllowed(HospitalizationDto.ISOLATION_DATE)) {
FieldHelper.setVisibleWhen(getFieldGroup(), HospitalizationDto.ISOLATION_DATE, HospitalizationDto.ISOLATED, Arrays.asList(YesNoUnknown.YES), true);
}
if (isVisibleAllowed(HospitalizationDto.PREVIOUS_HOSPITALIZATIONS)) {
FieldHelper.setVisibleWhen(getFieldGroup(), HospitalizationDto.PREVIOUS_HOSPITALIZATIONS, HospitalizationDto.HOSPITALIZED_PREVIOUSLY, Arrays.asList(YesNoUnknown.YES), true);
}
FieldHelper.setVisibleWhen(getFieldGroup(), HospitalizationDto.OTHER_HOSPITALIZATION_REASON, HospitalizationDto.HOSPITALIZATION_REASON, Collections.singletonList(HospitalizationReasonType.OTHER), true);
// Validations
// Add a visual-only validator to check if symptomonsetdate<admissiondate, as saving should be possible either way
admissionDateField.addValueChangeListener(event -> {
if (caze.getSymptoms().getOnsetDate() != null && DateTimeComparator.getDateOnlyInstance().compare(admissionDateField.getValue(), caze.getSymptoms().getOnsetDate()) < 0) {
admissionDateField.setComponentError(new ErrorMessage() {
@Override
public ErrorLevel getErrorLevel() {
return ErrorLevel.INFO;
}
@Override
public String getFormattedHtmlMessage() {
return I18nProperties.getValidationError(Validations.afterDateSoft, admissionDateField.getCaption(), I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ONSET_DATE));
}
});
} else {
// remove all invalidity-indicators and re-evaluate field
admissionDateField.setComponentError(null);
admissionDateField.markAsDirty();
}
// re-evaluate validity of dischargeDate (necessary because discharge has to be after admission)
dischargeDateField.markAsDirty();
});
admissionDateField.addValidator(new DateComparisonValidator(admissionDateField, dischargeDateField, true, false, I18nProperties.getValidationError(Validations.beforeDate, admissionDateField.getCaption(), dischargeDateField.getCaption())));
dischargeDateField.addValidator(new DateComparisonValidator(dischargeDateField, admissionDateField, false, false, I18nProperties.getValidationError(Validations.afterDate, dischargeDateField.getCaption(), admissionDateField.getCaption())));
// re-evaluate admission date for consistent validation of all fields
dischargeDateField.addValueChangeListener(event -> admissionDateField.markAsDirty());
intensiveCareUnitStart.addValidator(new DateComparisonValidator(intensiveCareUnitStart, admissionDateField, false, false, I18nProperties.getValidationError(Validations.afterDate, intensiveCareUnitStart.getCaption(), admissionDateField.getCaption())));
intensiveCareUnitStart.addValidator(new DateComparisonValidator(intensiveCareUnitStart, intensiveCareUnitEnd, true, false, I18nProperties.getValidationError(Validations.beforeDate, intensiveCareUnitStart.getCaption(), intensiveCareUnitEnd.getCaption())));
intensiveCareUnitEnd.addValidator(new DateComparisonValidator(intensiveCareUnitEnd, intensiveCareUnitStart, false, false, I18nProperties.getValidationError(Validations.afterDate, intensiveCareUnitEnd.getCaption(), intensiveCareUnitStart.getCaption())));
intensiveCareUnitEnd.addValidator(new DateComparisonValidator(intensiveCareUnitEnd, dischargeDateField, true, false, I18nProperties.getValidationError(Validations.beforeDate, intensiveCareUnitEnd.getCaption(), dischargeDateField.getCaption())));
intensiveCareUnitStart.addValueChangeListener(event -> intensiveCareUnitEnd.markAsDirty());
intensiveCareUnitEnd.addValueChangeListener(event -> intensiveCareUnitStart.markAsDirty());
hospitalizedPreviouslyField.addValueChangeListener(e -> updatePrevHospHint(hospitalizedPreviouslyField, previousHospitalizationsField));
previousHospitalizationsField.addValueChangeListener(e -> updatePrevHospHint(hospitalizedPreviouslyField, previousHospitalizationsField));
}
use of de.symeda.sormas.ui.utils.NullableOptionGroup in project SORMAS-Project by hzi-braunschweig.
the class SampleController method addPathogenTestComponent.
/**
* @param sampleComponent
* to add the pathogen test create component to.
* @param pathogenTest
* the preset values to insert. May be null.
* @param caseSampleCount
* describes how many samples already exist for a case related to the pathogen test's sample (if a case exists, otherwise 0
* is valid).
* @param callback
* use it to define additional actions that need to be taken after the pathogen test is saved (e.g. refresh the UI)
* @return the pathogen test create component added.
*/
public PathogenTestForm addPathogenTestComponent(CommitDiscardWrapperComponent<? extends AbstractSampleForm> sampleComponent, PathogenTestDto pathogenTest, int caseSampleCount, Runnable callback) {
// add horizontal rule to clearly distinguish the component
Label horizontalRule = new Label("<br><hr /><br>", ContentMode.HTML);
horizontalRule.setWidth(100f, Unit.PERCENTAGE);
sampleComponent.addComponent(horizontalRule, sampleComponent.getComponentCount() - 1);
PathogenTestForm pathogenTestForm = new PathogenTestForm(sampleComponent.getWrappedComponent().getValue(), true, caseSampleCount, false);
// prefill fields
if (pathogenTest != null) {
pathogenTestForm.setValue(pathogenTest);
// show typingId field when it has a preset value
if (pathogenTest.getTypingId() != null && !"".equals(pathogenTest.getTypingId())) {
pathogenTestForm.getField(PathogenTestDto.TYPING_ID).setVisible(true);
}
} else {
pathogenTestForm.setValue(PathogenTestDto.build(sampleComponent.getWrappedComponent().getValue(), UserProvider.getCurrent().getUser()));
// remove value invalid for newly created pathogen tests
ComboBox pathogenTestResultField = pathogenTestForm.getField(PathogenTestDto.TEST_RESULT);
pathogenTestResultField.removeItem(PathogenTestResultType.NOT_DONE);
pathogenTestResultField.setValue(PathogenTestResultType.PENDING);
ComboBox testDiseaseField = pathogenTestForm.getField(PathogenTestDto.TESTED_DISEASE);
testDiseaseField.setValue(FacadeProvider.getDiseaseConfigurationFacade().getDefaultDisease());
}
// setup field updates
Field testLabField = pathogenTestForm.getField(PathogenTestDto.LAB);
NullableOptionGroup samplePurposeField = sampleComponent.getWrappedComponent().getField(SampleDto.SAMPLE_PURPOSE);
Runnable updateTestLabFieldRequired = () -> testLabField.setRequired(!SamplePurpose.INTERNAL.equals(samplePurposeField.getValue()));
updateTestLabFieldRequired.run();
samplePurposeField.addValueChangeListener(e -> updateTestLabFieldRequired.run());
// validate pathogen test create component before saving the sample
sampleComponent.addFieldGroups(pathogenTestForm.getFieldGroup());
CommitDiscardWrapperComponent.CommitListener savePathogenTest = () -> {
ControllerProvider.getPathogenTestController().savePathogenTest(pathogenTestForm.getValue(), null, true, true);
if (callback != null) {
callback.run();
}
};
sampleComponent.addCommitListener(savePathogenTest);
// Discard button configuration
Button discardButton = ButtonHelper.createButton(I18nProperties.getCaption(Captions.pathogenTestRemove));
VerticalLayout buttonLayout = new VerticalLayout(discardButton);
buttonLayout.setComponentAlignment(discardButton, Alignment.TOP_LEFT);
// add the discard button above the overall discard and commit buttons
sampleComponent.addComponent(buttonLayout, sampleComponent.getComponentCount() - 1);
discardButton.addClickListener(o -> {
sampleComponent.removeComponent(horizontalRule);
sampleComponent.removeComponent(buttonLayout);
sampleComponent.removeComponent(pathogenTestForm);
sampleComponent.removeFieldGroups(pathogenTestForm.getFieldGroup());
sampleComponent.removeCommitListener(savePathogenTest);
pathogenTestForm.discard();
});
// Country specific configuration
boolean germanInstance = FacadeProvider.getConfigFacade().isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY);
pathogenTestForm.getField(PathogenTestDto.REPORT_DATE).setVisible(germanInstance);
pathogenTestForm.getField(PathogenTestDto.EXTERNAL_ID).setVisible(germanInstance);
pathogenTestForm.getField(PathogenTestDto.EXTERNAL_ORDER_ID).setVisible(germanInstance);
pathogenTestForm.getField(PathogenTestDto.VIA_LIMS).setVisible(germanInstance);
// Sample creation specific configuration
final DateTimeField sampleDateField = sampleComponent.getWrappedComponent().getField(SampleDto.SAMPLE_DATE_TIME);
final DateTimeField testDateField = pathogenTestForm.getField(PathogenTestDto.TEST_DATE_TIME);
testDateField.addValidator(new DateComparisonValidator(testDateField, sampleDateField, false, false, I18nProperties.getValidationError(Validations.afterDate, testDateField.getCaption(), sampleDateField.getCaption())));
// add the pathogenTestForm above the overall discard and commit buttons
sampleComponent.addComponent(pathogenTestForm, sampleComponent.getComponentCount() - 1);
return pathogenTestForm;
}
use of de.symeda.sormas.ui.utils.NullableOptionGroup in project SORMAS-Project by hzi-braunschweig.
the class AbstractSampleForm method addCommonFields.
protected void addCommonFields() {
final NullableOptionGroup samplePurpose = addField(SampleDto.SAMPLE_PURPOSE, NullableOptionGroup.class);
addField(SampleDto.UUID).setReadOnly(true);
addField(SampleDto.REPORTING_USER).setReadOnly(true);
samplePurpose.addValueChangeListener(e -> updateRequestedTestFields());
addField(SampleDto.LAB_SAMPLE_ID, TextField.class);
final DateTimeField sampleDateField = addField(SampleDto.SAMPLE_DATE_TIME, DateTimeField.class);
sampleDateField.setInvalidCommitted(false);
addField(SampleDto.SAMPLE_MATERIAL, ComboBox.class);
addField(SampleDto.SAMPLE_MATERIAL_TEXT, TextField.class);
addField(SampleDto.SAMPLE_SOURCE, ComboBox.class);
addField(SampleDto.FIELD_SAMPLE_ID, TextField.class);
addDateField(SampleDto.SHIPMENT_DATE, DateField.class, 7);
addField(SampleDto.SHIPMENT_DETAILS, TextField.class);
addField(SampleDto.RECEIVED_DATE, DateField.class);
final ComboBox lab = addInfrastructureField(SampleDto.LAB);
lab.addItems(FacadeProvider.getFacilityFacade().getAllActiveLaboratories(true));
final TextField labDetails = addField(SampleDto.LAB_DETAILS, TextField.class);
labDetails.setVisible(false);
lab.addValueChangeListener(event -> updateLabDetailsVisibility(labDetails, event));
addField(SampleDto.SPECIMEN_CONDITION, ComboBox.class);
addField(SampleDto.NO_TEST_POSSIBLE_REASON, TextField.class);
TextArea comment = addField(SampleDto.COMMENT, TextArea.class);
comment.setRows(4);
comment.setDescription(I18nProperties.getPrefixDescription(SampleDto.I18N_PREFIX, SampleDto.COMMENT, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
addField(SampleDto.SHIPPED, CheckBox.class);
addField(SampleDto.RECEIVED, CheckBox.class);
ComboBox testResultField = addField(SampleDto.PATHOGEN_TEST_RESULT, ComboBox.class);
testResultField.removeItem(PathogenTestResultType.NOT_DONE);
addFields(SampleDto.SAMPLING_REASON, SampleDto.SAMPLING_REASON_DETAILS);
FieldHelper.setVisibleWhen(getFieldGroup(), SampleDto.SAMPLING_REASON_DETAILS, SampleDto.SAMPLING_REASON, Collections.singletonList(SamplingReason.OTHER_REASON), true);
}
use of de.symeda.sormas.ui.utils.NullableOptionGroup in project SORMAS-Project by hzi-braunschweig.
the class CaseCreateForm method addFields.
@Override
protected void addFields() {
NullableOptionGroup ogCaseOrigin = addField(CaseDataDto.CASE_ORIGIN, NullableOptionGroup.class);
ogCaseOrigin.setRequired(true);
TextField epidField = addField(CaseDataDto.EPID_NUMBER, TextField.class);
epidField.setInvalidCommitted(true);
style(epidField, ERROR_COLOR_PRIMARY);
if (!FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled()) {
TextField externalIdField = addField(CaseDataDto.EXTERNAL_ID, TextField.class);
style(externalIdField, ERROR_COLOR_PRIMARY);
} else {
CheckBox dontShareCheckbox = addField(CaseDataDto.DONT_SHARE_WITH_REPORTING_TOOL, CheckBox.class);
CaseFormHelper.addDontShareWithReportingTool(getContent(), () -> dontShareCheckbox, DONT_SHARE_WARNING_LOC);
}
addField(CaseDataDto.REPORT_DATE, DateField.class);
ComboBox diseaseField = addDiseaseField(CaseDataDto.DISEASE, false, true);
ComboBox diseaseVariantField = addField(CaseDataDto.DISEASE_VARIANT, ComboBox.class);
diseaseVariantDetailsField = addField(CaseDataDto.DISEASE_VARIANT_DETAILS, TextField.class);
diseaseVariantDetailsField.setVisible(false);
diseaseVariantField.setNullSelectionAllowed(true);
diseaseVariantField.setVisible(false);
addField(CaseDataDto.DISEASE_DETAILS, TextField.class);
NullableOptionGroup plagueType = addField(CaseDataDto.PLAGUE_TYPE, NullableOptionGroup.class);
addField(CaseDataDto.DENGUE_FEVER_TYPE, NullableOptionGroup.class);
addField(CaseDataDto.RABIES_TYPE, NullableOptionGroup.class);
addCustomField(PersonDto.FIRST_NAME, String.class, TextField.class);
addCustomField(PersonDto.LAST_NAME, String.class, TextField.class);
if (showPersonSearchButton) {
searchPersonButton = createPersonSearchButton(PERSON_SEARCH_LOC);
getContent().addComponent(searchPersonButton, PERSON_SEARCH_LOC);
}
TextField nationalHealthIdField = addCustomField(PersonDto.NATIONAL_HEALTH_ID, String.class, TextField.class);
TextField passportNumberField = addCustomField(PersonDto.PASSPORT_NUMBER, String.class, TextField.class);
if (CountryHelper.isCountry(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY)) {
nationalHealthIdField.setVisible(false);
}
if (CountryHelper.isInCountries(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY, CountryHelper.COUNTRY_CODE_FRANCE)) {
passportNumberField.setVisible(false);
}
birthDateDay = addCustomField(PersonDto.BIRTH_DATE_DD, Integer.class, ComboBox.class);
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateDay.setNullSelectionAllowed(true);
birthDateDay.addStyleName(FORCE_CAPTION);
birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
ComboBox birthDateMonth = addCustomField(PersonDto.BIRTH_DATE_MM, Integer.class, ComboBox.class);
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateMonth.setNullSelectionAllowed(true);
birthDateMonth.addItems(DateHelper.getMonthsInYear());
birthDateMonth.setPageLength(12);
birthDateMonth.addStyleName(FORCE_CAPTION);
birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
setItemCaptionsForMonths(birthDateMonth);
ComboBox birthDateYear = addCustomField(PersonDto.BIRTH_DATE_YYYY, Integer.class, 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 = addCustomField(PersonDto.SEX, Sex.class, ComboBox.class);
sex.setCaption(I18nProperties.getCaption(Captions.Person_sex));
ComboBox presentCondition = addCustomField(PersonDto.PRESENT_CONDITION, PresentCondition.class, ComboBox.class);
presentCondition.setCaption(I18nProperties.getCaption(Captions.Person_presentCondition));
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())));
differentPlaceOfStayJurisdiction = addCustomField(DIFFERENT_PLACE_OF_STAY_JURISDICTION, Boolean.class, CheckBox.class);
differentPlaceOfStayJurisdiction.addStyleName(VSPACE_3);
Label placeOfStayHeadingLabel = new Label(I18nProperties.getCaption(Captions.casePlaceOfStay));
placeOfStayHeadingLabel.addStyleName(H3);
getContent().addComponent(placeOfStayHeadingLabel, PLACE_OF_STAY_HEADING_LOC);
ComboBox region = addInfrastructureField(CaseDataDto.REGION);
districtCombo = addInfrastructureField(CaseDataDto.DISTRICT);
communityCombo = addInfrastructureField(CaseDataDto.COMMUNITY);
communityCombo.setNullSelectionAllowed(true);
// jurisdictionfields
Label jurisdictionHeadingLabel = new Label(I18nProperties.getString(Strings.headingCaseResponsibleJurisidction));
jurisdictionHeadingLabel.addStyleName(H3);
getContent().addComponent(jurisdictionHeadingLabel, RESPONSIBLE_JURISDICTION_HEADING_LOC);
ComboBox responsibleRegion = addInfrastructureField(CaseDataDto.RESPONSIBLE_REGION);
responsibleRegion.setRequired(true);
responsibleDistrictCombo = addInfrastructureField(CaseDataDto.RESPONSIBLE_DISTRICT);
responsibleDistrictCombo.setRequired(true);
responsibleCommunityCombo = addInfrastructureField(CaseDataDto.RESPONSIBLE_COMMUNITY);
responsibleCommunityCombo.setNullSelectionAllowed(true);
responsibleCommunityCombo.addStyleName(SOFT_REQUIRED);
InfrastructureFieldsHelper.initInfrastructureFields(responsibleRegion, responsibleDistrictCombo, responsibleCommunityCombo);
differentPointOfEntryJurisdiction = addCustomField(DIFFERENT_POINT_OF_ENTRY_JURISDICTION, Boolean.class, CheckBox.class);
differentPointOfEntryJurisdiction.addStyleName(VSPACE_3);
ComboBox pointOfEntryRegionCombo = addCustomField(POINT_OF_ENTRY_REGION, RegionReferenceDto.class, ComboBox.class);
pointOfEntryDistrictCombo = addCustomField(POINT_OF_ENTRY_DISTRICT, DistrictReferenceDto.class, ComboBox.class);
InfrastructureFieldsHelper.initInfrastructureFields(pointOfEntryRegionCombo, pointOfEntryDistrictCombo, null);
pointOfEntryDistrictCombo.addValueChangeListener(e -> updatePOEs());
if (showHomeAddressForm) {
addHomeAddressForm();
}
FieldHelper.setVisibleWhen(differentPlaceOfStayJurisdiction, Arrays.asList(region, districtCombo, communityCombo), Collections.singletonList(Boolean.TRUE), true);
FieldHelper.setVisibleWhen(differentPointOfEntryJurisdiction, Arrays.asList(pointOfEntryRegionCombo, pointOfEntryDistrictCombo), Collections.singletonList(Boolean.TRUE), true);
FieldHelper.setRequiredWhen(differentPlaceOfStayJurisdiction, Arrays.asList(region, districtCombo), Collections.singletonList(Boolean.TRUE), false, null);
ogCaseOrigin.addValueChangeListener(e -> {
boolean pointOfEntryRegionDistrictVisible = CaseOrigin.POINT_OF_ENTRY.equals(ogCaseOrigin.getValue()) && Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue());
pointOfEntryRegionCombo.setVisible(pointOfEntryRegionDistrictVisible);
pointOfEntryDistrictCombo.setVisible(pointOfEntryRegionDistrictVisible);
});
facilityOrHome = addCustomField(FACILITY_OR_HOME_LOC, TypeOfPlace.class, NullableOptionGroup.class, I18nProperties.getCaption(Captions.casePlaceOfStay));
facilityOrHome.removeAllItems();
for (TypeOfPlace place : TypeOfPlace.FOR_CASES) {
facilityOrHome.addItem(place);
facilityOrHome.setItemCaption(place, I18nProperties.getEnumCaption(place));
}
facilityOrHome.setItemCaptionMode(ItemCaptionMode.EXPLICIT);
facilityOrHome.setId("facilityOrHome");
facilityOrHome.setWidth(100, Unit.PERCENTAGE);
CssStyles.style(facilityOrHome, ValoTheme.OPTIONGROUP_HORIZONTAL);
facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
facilityTypeGroup.setId("typeGroup");
facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
facilityTypeGroup.addItems(FacilityTypeGroup.getAccomodationGroups());
getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
facilityType = ComboBoxHelper.createComboBoxV7();
facilityType.setId("type");
facilityType.setCaption(I18nProperties.getCaption(Captions.facilityType));
facilityType.setWidth(100, Unit.PERCENTAGE);
getContent().addComponent(facilityType, CaseDataDto.FACILITY_TYPE);
facilityCombo = addInfrastructureField(CaseDataDto.HEALTH_FACILITY);
facilityCombo.setImmediate(true);
TextField facilityDetails = addField(CaseDataDto.HEALTH_FACILITY_DETAILS, TextField.class);
facilityDetails.setVisible(false);
ComboBox cbPointOfEntry = addInfrastructureField(CaseDataDto.POINT_OF_ENTRY);
cbPointOfEntry.setImmediate(true);
TextField tfPointOfEntryDetails = addField(CaseDataDto.POINT_OF_ENTRY_DETAILS, TextField.class);
tfPointOfEntryDetails.setVisible(false);
if (convertedTravelEntry != null) {
differentPointOfEntryJurisdiction.setValue(true);
RegionReferenceDto regionReferenceDto = convertedTravelEntry.getPointOfEntryRegion() != null ? convertedTravelEntry.getPointOfEntryRegion() : convertedTravelEntry.getResponsibleRegion();
pointOfEntryRegionCombo.setValue(regionReferenceDto);
DistrictReferenceDto districtReferenceDto = convertedTravelEntry.getPointOfEntryDistrict() != null ? convertedTravelEntry.getPointOfEntryDistrict() : convertedTravelEntry.getResponsibleDistrict();
pointOfEntryDistrictCombo.setValue(districtReferenceDto);
differentPointOfEntryJurisdiction.setReadOnly(true);
pointOfEntryRegionCombo.setReadOnly(true);
pointOfEntryDistrictCombo.setReadOnly(true);
updatePOEs();
cbPointOfEntry.setReadOnly(true);
tfPointOfEntryDetails.setReadOnly(true);
ogCaseOrigin.setReadOnly(true);
}
region.addValueChangeListener(e -> {
RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(districtCombo, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
});
districtCombo.addValueChangeListener(e -> {
FieldHelper.removeItems(communityCombo);
DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(communityCombo, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
updateFacility();
if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
updatePOEs();
}
});
communityCombo.addValueChangeListener(e -> {
updateFacility();
});
facilityOrHome.addValueChangeListener(e -> {
FieldHelper.removeItems(facilityCombo);
if (TypeOfPlace.FACILITY.equals(facilityOrHome.getValue()) || ((facilityOrHome.getValue() instanceof java.util.Set) && TypeOfPlace.FACILITY.equals(facilityOrHome.getNullableValue()))) {
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();
}
if (CaseOrigin.IN_COUNTRY.equals(ogCaseOrigin.getValue())) {
facilityCombo.setRequired(true);
}
updateFacilityFields(facilityCombo, facilityDetails);
} else if (TypeOfPlace.HOME.equals(facilityOrHome.getValue()) || ((facilityOrHome.getValue() instanceof java.util.Set) && TypeOfPlace.HOME.equals(facilityOrHome.getNullableValue()))) {
setNoneFacility();
} else {
facilityCombo.removeAllItems();
facilityCombo.setValue(null);
updateFacilityFields(facilityCombo, facilityDetails);
}
});
facilityTypeGroup.addValueChangeListener(e -> {
FieldHelper.removeItems(facilityCombo);
FieldHelper.updateEnumData(facilityType, FacilityType.getAccommodationTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
});
facilityType.addValueChangeListener(e -> updateFacility());
region.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
JurisdictionLevel userJurisdictionLevel = UserRole.getJurisdictionLevel(UserProvider.getCurrent().getUserRoles());
if (userJurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY) {
region.setReadOnly(true);
responsibleRegion.setReadOnly(true);
districtCombo.setReadOnly(true);
responsibleDistrictCombo.setReadOnly(true);
communityCombo.setReadOnly(true);
responsibleCommunityCombo.setReadOnly(true);
differentPlaceOfStayJurisdiction.setVisible(false);
differentPlaceOfStayJurisdiction.setEnabled(false);
facilityOrHome.setImmediate(true);
// [FACILITY]
facilityOrHome.setValue(Sets.newHashSet(TypeOfPlace.FACILITY));
facilityOrHome.setReadOnly(true);
facilityTypeGroup.setValue(FacilityTypeGroup.MEDICAL_FACILITY);
facilityTypeGroup.setReadOnly(true);
facilityType.setValue(FacilityType.HOSPITAL);
facilityType.setReadOnly(true);
facilityCombo.setValue(UserProvider.getCurrent().getUser().getHealthFacility());
facilityCombo.setReadOnly(true);
}
if (!UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
ogCaseOrigin.addValueChangeListener(ev -> {
if (ev.getProperty().getValue() == CaseOrigin.IN_COUNTRY) {
setVisible(false, CaseDataDto.POINT_OF_ENTRY, CaseDataDto.POINT_OF_ENTRY_DETAILS);
differentPointOfEntryJurisdiction.setVisible(false);
setRequired(true, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE, CaseDataDto.HEALTH_FACILITY);
setRequired(false, CaseDataDto.POINT_OF_ENTRY);
updateFacilityFields(facilityCombo, facilityDetails);
} else {
setVisible(true, CaseDataDto.POINT_OF_ENTRY);
differentPointOfEntryJurisdiction.setVisible(true);
setRequired(true, CaseDataDto.POINT_OF_ENTRY);
if (userJurisdictionLevel != JurisdictionLevel.HEALTH_FACILITY) {
facilityOrHome.clear();
setRequired(false, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE, CaseDataDto.HEALTH_FACILITY);
}
updatePointOfEntryFields(cbPointOfEntry, tfPointOfEntryDetails);
}
});
}
// jurisdiction field valuechangelisteners
responsibleDistrictCombo.addValueChangeListener(e -> {
Boolean differentPlaceOfStay = differentPlaceOfStayJurisdiction.getValue();
if (!Boolean.TRUE.equals(differentPlaceOfStay)) {
updateFacility();
if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
updatePOEs();
}
}
});
responsibleCommunityCombo.addValueChangeListener((e) -> {
Boolean differentPlaceOfStay = differentPlaceOfStayJurisdiction.getValue();
if (differentPlaceOfStay == null || Boolean.FALSE.equals(differentPlaceOfStay)) {
updateFacility();
}
});
differentPlaceOfStayJurisdiction.addValueChangeListener(e -> {
updateFacility();
if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
updatePOEs();
}
});
// Set initial visibilities & accesses
initializeVisibilitiesAndAllowedVisibilities();
setRequired(true, CaseDataDto.REPORT_DATE, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, CaseDataDto.DISEASE, PersonDto.SEX, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE);
FieldHelper.addSoftRequiredStyle(plagueType, communityCombo, facilityDetails);
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));
FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.CASE_ORIGIN, Arrays.asList(CaseDataDto.HEALTH_FACILITY), Arrays.asList(CaseOrigin.IN_COUNTRY));
FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.CASE_ORIGIN, Arrays.asList(CaseDataDto.POINT_OF_ENTRY), Arrays.asList(CaseOrigin.POINT_OF_ENTRY));
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.PLAGUE_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.PLAGUE), true);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.DENGUE_FEVER_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.DENGUE), true);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.RABIES_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.RABIES), true);
FieldHelper.setVisibleWhen(facilityOrHome, Arrays.asList(facilityTypeGroup, facilityType, facilityCombo), Collections.singletonList(TypeOfPlace.FACILITY), false);
FieldHelper.setRequiredWhen(facilityOrHome, Arrays.asList(facilityTypeGroup, facilityType, facilityCombo), Collections.singletonList(TypeOfPlace.FACILITY), false, null);
facilityCombo.addValueChangeListener(e -> {
updateFacilityFields(facilityCombo, facilityDetails);
this.getValue().setFacilityType((FacilityType) facilityType.getValue());
});
cbPointOfEntry.addValueChangeListener(e -> {
updatePointOfEntryFields(cbPointOfEntry, tfPointOfEntryDetails);
});
addValueChangeListener(e -> {
if (UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
setVisible(false, CaseDataDto.CASE_ORIGIN, CaseDataDto.DISEASE, CaseDataDto.COMMUNITY, CaseDataDto.HEALTH_FACILITY);
setVisible(true, CaseDataDto.POINT_OF_ENTRY);
}
});
diseaseField.addValueChangeListener((ValueChangeListener) valueChangeEvent -> {
Disease disease = (Disease) valueChangeEvent.getProperty().getValue();
List<DiseaseVariant> diseaseVariants = FacadeProvider.getCustomizableEnumFacade().getEnumValues(CustomizableEnumType.DISEASE_VARIANT, disease);
FieldHelper.updateItems(diseaseVariantField, diseaseVariants);
diseaseVariantField.setVisible(disease != null && isVisibleAllowed(CaseDataDto.DISEASE_VARIANT) && CollectionUtils.isNotEmpty(diseaseVariants));
});
diseaseVariantField.addValueChangeListener(e -> {
DiseaseVariant diseaseVariant = (DiseaseVariant) e.getProperty().getValue();
diseaseVariantDetailsField.setVisible(diseaseVariant != null && diseaseVariant.matchPropertyValue(DiseaseVariant.HAS_DETAILS, true));
});
}
Aggregations