use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationController method showSimilarImmunizationPopup.
private void showSimilarImmunizationPopup(ImmunizationDto immunizationDto, ImmunizationDto similarImmunization, Consumer<ImmunizationDto> callback) {
SimilarImmunizationPopup similarImmunizationPopup = new SimilarImmunizationPopup(immunizationDto, similarImmunization);
similarImmunizationPopup.setWidth(1280, Sizeable.Unit.PIXELS);
final CommitDiscardWrapperComponent<SimilarImmunizationPopup> component = new CommitDiscardWrapperComponent<>(similarImmunizationPopup);
component.getCommitButton().addClickListener(clickEvent -> callback.accept(immunizationDto));
component.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionSaveChanges));
component.getDiscardButton().setCaption(I18nProperties.getCaption(Captions.actionAdjustChanges));
VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingSimilarImmunization));
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class EventImporter method handlePersonSimilarity.
/**
* Presents a popup window to the user that allows them to deal with detected potentially duplicate persons.
* By passing the desired result to the resultConsumer, the importer decided how to proceed with the import process.
*/
protected void handlePersonSimilarity(PersonDto newPerson, Consumer<PersonImportSimilarityResult> resultConsumer) {
currentUI.accessSynchronously(() -> {
PersonSelectionField personSelect = new PersonSelectionField(newPerson, I18nProperties.getString(Strings.infoSelectOrCreatePersonForImport));
personSelect.setWidth(1024, Unit.PIXELS);
if (personSelect.hasMatches()) {
final CommitDiscardWrapperComponent<PersonSelectionField> component = new CommitDiscardWrapperComponent<>(personSelect);
component.addCommitListener(() -> {
SimilarPersonDto person = personSelect.getValue();
if (person == null) {
resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.CREATE));
} else {
resultConsumer.accept(new PersonImportSimilarityResult(person, ImportSimilarityResultOption.PICK));
}
});
component.addDiscardListener(() -> resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.SKIP)));
personSelect.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
Window window = VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreatePerson));
window.addCloseListener(event -> resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.SKIP)));
personSelect.selectBestMatch();
} else {
resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.CREATE));
}
});
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class SurveillanceReportController method openEditWindow.
private void openEditWindow(SurveillanceReportDto report, String titleTag, boolean canDelete, Runnable callback) {
SurveillanceReportForm surveillanceReportForm = new SurveillanceReportForm(report);
surveillanceReportForm.setWidth(600, Sizeable.Unit.PIXELS);
final CommitDiscardWrapperComponent<SurveillanceReportForm> editView = new CommitDiscardWrapperComponent<>(surveillanceReportForm, surveillanceReportForm.getFieldGroup());
editView.addCommitListener(() -> {
FacadeProvider.getSurveillanceReportFacade().saveSurveillanceReport(surveillanceReportForm.getValue());
callback.run();
});
Window window = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(titleTag));
if (canDelete) {
editView.addDeleteListener(() -> {
FacadeProvider.getSurveillanceReportFacade().deleteSurveillanceReport(report.getUuid());
window.close();
callback.run();
}, I18nProperties.getCaption(SurveillanceReportDto.I18N_PREFIX));
}
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent 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.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class PathogenTestController method getPathogenTestEditComponent.
public CommitDiscardWrapperComponent<PathogenTestForm> getPathogenTestEditComponent(String pathogenTestUuid, Runnable doneCallback, BiConsumer<PathogenTestDto, Runnable> onSavedPathogenTest) {
// get fresh data
PathogenTestDto pathogenTest = facade.getByUuid(pathogenTestUuid);
SampleDto sample = FacadeProvider.getSampleFacade().getSampleByUuid(pathogenTest.getSample().getUuid());
PathogenTestForm form = new PathogenTestForm(sample, false, 0, pathogenTest.isPseudonymized());
form.setValue(pathogenTest);
final CommitDiscardWrapperComponent<PathogenTestForm> editView = new CommitDiscardWrapperComponent<>(form, UserProvider.getCurrent().hasUserRight(UserRight.PATHOGEN_TEST_EDIT), form.getFieldGroup());
editView.addCommitListener(() -> {
if (!form.getFieldGroup().isModified()) {
savePathogenTest(form.getValue(), onSavedPathogenTest, false, false);
doneCallback.run();
SormasUI.refreshView();
}
});
return editView;
}
Aggregations