use of com.vaadin.v7.ui.Field 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 com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.
the class PersonFilterForm method applyDependenciesOnNewValue.
@Override
protected void applyDependenciesOnNewValue(PersonCriteria criteria) {
final UserDto user = currentUserDto();
final JurisdictionLevel userJurisdictionLevel = UserRole.getJurisdictionLevel(UserProvider.getCurrent().getUserRoles());
final ComboBox districtFilter = getField(PersonCriteria.DISTRICT);
final ComboBox communityFilter = getField(PersonCriteria.COMMUNITY);
// Get initial field values according to user and criteria
final RegionReferenceDto region = user.getRegion() == null ? criteria.getRegion() : user.getRegion();
final DistrictReferenceDto district = user.getDistrict() == null ? criteria.getDistrict() : user.getDistrict();
final CommunityReferenceDto community = user.getCommunity() == null ? criteria.getCommunity() : user.getCommunity();
// district
if (region != null) {
enableFields(districtFilter);
districtFilter.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
// community
if (district != null) {
districtFilter.setValue(district);
communityFilter.addItems(FacadeProvider.getCommunityFacade().getAllActiveByDistrict(district.getUuid()));
enableFields(communityFilter);
if (community != null) {
communityFilter.setValue(community);
}
} else {
clearAndDisableFields(communityFilter);
}
} else {
clearAndDisableFields(districtFilter, communityFilter);
}
// Disable fields according to user & jurisdiction
if (userJurisdictionLevel == JurisdictionLevel.DISTRICT) {
clearAndDisableFields(districtFilter);
} else if (userJurisdictionLevel == JurisdictionLevel.COMMUNITY) {
clearAndDisableFields(districtFilter, communityFilter);
} else if (userJurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY) {
clearAndDisableFields(districtFilter, communityFilter);
}
ComboBox birthDateDD = getField(PersonCriteria.BIRTHDATE_DD);
if (getField(PersonCriteria.BIRTHDATE_YYYY).getValue() != null && getField(PersonCriteria.BIRTHDATE_MM).getValue() != null) {
birthDateDD.addItems(DateHelper.getDaysInMonth((Integer) getField(PersonCriteria.BIRTHDATE_MM).getValue(), (Integer) getField(PersonCriteria.BIRTHDATE_YYYY).getValue()));
birthDateDD.setEnabled(true);
} else {
birthDateDD.clear();
birthDateDD.setEnabled(false);
}
}
use of com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.
the class ExpressionProcessorTest method testConfigureExpressionFieldsWithTooltip.
@Test
public void testConfigureExpressionFieldsWithTooltip() {
expressionProcessor.configureExpressionFieldsWithTooltip();
final TextField field = (TextField) campaignFormBuilder.getFields().get("childrenLivingInHouses");
assertThat(field.getDescription(), is("Calculated based on: Number of < 5 years children vaccinated based on recall"));
final TextField fieldRecall = (TextField) campaignFormBuilder.getFields().get("childrenVaccinatedRecall");
assertThat(fieldRecall.getDescription(), isEmptyOrNullString());
}
use of com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.
the class VaccinationEditForm method addFields.
@Override
protected void addFields() {
addField(VaccinationDto.REPORT_DATE).setRequired(true);
addField(VaccinationDto.REPORTING_USER).setReadOnly(true);
addField(VaccinationDto.VACCINATION_DATE);
Field vaccineName = addField(VaccinationDto.VACCINE_NAME);
addField(VaccinationDto.OTHER_VACCINE_NAME);
Field vaccineManufacturer = addField(VaccinationDto.VACCINE_MANUFACTURER);
addField(VaccinationDto.OTHER_VACCINE_MANUFACTURER);
vaccineName.addValueChangeListener(e -> {
Vaccine vaccine = (Vaccine) e.getProperty().getValue();
if (vaccine != null) {
vaccineManufacturer.setValue(vaccine.getManufacturer());
}
});
addField(VaccinationDto.VACCINE_TYPE);
addField(VaccinationDto.VACCINATION_INFO_SOURCE);
addField(VaccinationDto.VACCINE_DOSE);
addField(VaccinationDto.VACCINE_INN);
addField(VaccinationDto.VACCINE_UNII_CODE);
addField(VaccinationDto.VACCINE_BATCH_NUMBER);
addField(VaccinationDto.VACCINE_ATC_CODE);
FieldHelper.setVisibleWhen(getFieldGroup(), VaccinationDto.OTHER_VACCINE_NAME, VaccinationDto.VACCINE_NAME, Collections.singletonList(Vaccine.OTHER), true);
FieldHelper.setVisibleWhen(getFieldGroup(), VaccinationDto.OTHER_VACCINE_MANUFACTURER, VaccinationDto.VACCINE_MANUFACTURER, Collections.singletonList(VaccineManufacturer.OTHER), true);
addField(VaccinationDto.PREGNANT);
addField(VaccinationDto.TRIMESTER);
addField(VaccinationDto.HEALTH_CONDITIONS, HealthConditionsForm.class).setCaption(null);
initializeVisibilitiesAndAllowedVisibilities();
if (isVisibleAllowed(VaccinationDto.PREGNANT)) {
FieldHelper.setVisibleWhen(getFieldGroup(), VaccinationDto.TRIMESTER, VaccinationDto.PREGNANT, Collections.singletonList(YesNoUnknown.YES), true);
}
}
use of com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.
the class ContactDataForm method updateFollowUpStatusComponents.
@SuppressWarnings("unchecked")
private void updateFollowUpStatusComponents() {
getContent().removeComponent(CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);
getContent().removeComponent(LOST_FOLLOW_UP_BTN_LOC);
Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(ContactDto.FOLLOW_UP_STATUS);
boolean followUpVisible = getValue() != null && statusField.isVisible();
if (followUpVisible && UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_EDIT)) {
FollowUpStatus followUpStatus = statusField.getValue();
tfExpectedFollowUpUntilDate.setVisible(followUpStatus != FollowUpStatus.NO_FOLLOW_UP);
boolean followUpCanceledOrLost = followUpStatus == FollowUpStatus.CANCELED || followUpStatus == FollowUpStatus.LOST;
cbOverwriteFollowUpUntil.setReadOnly(followUpCanceledOrLost);
dfFollowUpUntil.setReadOnly(followUpCanceledOrLost || Boolean.TRUE != cbOverwriteFollowUpUntil.getValue());
if (followUpStatus == FollowUpStatus.FOLLOW_UP) {
Button cancelButton = ButtonHelper.createButton(Captions.contactCancelFollowUp, event -> {
setFollowUpStatus(FollowUpStatus.CANCELED);
});
cancelButton.setWidth(100, Unit.PERCENTAGE);
getContent().addComponent(cancelButton, CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);
Button lostButton = ButtonHelper.createButton(Captions.contactLostToFollowUp, event -> {
setFollowUpStatus(FollowUpStatus.LOST);
});
lostButton.setWidth(100, Unit.PERCENTAGE);
getContent().addComponent(lostButton, LOST_FOLLOW_UP_BTN_LOC);
} else if (followUpStatus == FollowUpStatus.CANCELED || followUpStatus == FollowUpStatus.LOST) {
Button resumeButton = ButtonHelper.createButton(Captions.contactResumeFollowUp, event -> {
setFollowUpStatus(FollowUpStatus.FOLLOW_UP);
}, CssStyles.FORCE_CAPTION);
resumeButton.setWidth(100, Unit.PERCENTAGE);
getContent().addComponent(resumeButton, CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);
}
}
}
Aggregations