Search in sources :

Example 6 with CommitDiscardWrapperComponent

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));
}
Also used : CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) SimilarImmunizationPopup(de.symeda.sormas.ui.immunization.components.fields.popup.SimilarImmunizationPopup)

Example 7 with CommitDiscardWrapperComponent

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));
        }
    });
}
Also used : Window(com.vaadin.ui.Window) PersonSelectionField(de.symeda.sormas.ui.person.PersonSelectionField) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) PersonImportSimilarityResult(de.symeda.sormas.ui.importer.PersonImportSimilarityResult) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto)

Example 8 with CommitDiscardWrapperComponent

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));
    }
}
Also used : Window(com.vaadin.ui.Window) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)

Example 9 with CommitDiscardWrapperComponent

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;
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) Field(com.vaadin.v7.ui.Field) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout)

Example 10 with CommitDiscardWrapperComponent

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;
}
Also used : CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) SampleDto(de.symeda.sormas.api.sample.SampleDto)

Aggregations

CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)101 Window (com.vaadin.ui.Window)34 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)22 EventDto (de.symeda.sormas.api.event.EventDto)17 Button (com.vaadin.ui.Button)16 CommitListener (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)15 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)13 PersonDto (de.symeda.sormas.api.person.PersonDto)13 ContactDto (de.symeda.sormas.api.contact.ContactDto)12 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)12 Label (com.vaadin.ui.Label)11 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)11 Notification (com.vaadin.ui.Notification)10 EventIndexDto (de.symeda.sormas.api.event.EventIndexDto)10 AutomaticDeletionLabel (de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)10 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)9 UserDto (de.symeda.sormas.api.user.UserDto)9 EventSelectionField (de.symeda.sormas.ui.events.eventLink.EventSelectionField)9 AutomaticDeletionInfoDto (de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto)8 SampleDto (de.symeda.sormas.api.sample.SampleDto)8