Search in sources :

Example 51 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationController method selectOrCreateImmunization.

private void selectOrCreateImmunization(ImmunizationDto immunizationDto, Consumer<String> selectedImmunizationUuidConsumer) {
    ImmunizationSimilarityCriteria criteria = new ImmunizationSimilarityCriteria.Builder().withDisease(immunizationDto.getDisease()).withStartDate(immunizationDto.getStartDate()).withEndDate(immunizationDto.getEndDate()).withPerson(immunizationDto.getPerson().getUuid()).withMeansOfImmunization(immunizationDto.getMeansOfImmunization()).build();
    List<ImmunizationDto> similarImmunizations = FacadeProvider.getImmunizationFacade().getSimilarImmunizations(criteria);
    if (!similarImmunizations.isEmpty()) {
        ImmunizationPickOrCreateField pickOrCreateField = new ImmunizationPickOrCreateField(immunizationDto, similarImmunizations);
        pickOrCreateField.setWidth(1280, Sizeable.Unit.PIXELS);
        final CommitDiscardWrapperComponent<ImmunizationPickOrCreateField> component = new CommitDiscardWrapperComponent<>(pickOrCreateField);
        component.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
        component.getCommitButton().setEnabled(false);
        component.addCommitListener(() -> selectedImmunizationUuidConsumer.accept(pickOrCreateField.getValue()));
        pickOrCreateField.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
        VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateImmunization));
    } else {
        selectedImmunizationUuidConsumer.accept(immunizationDto.getUuid());
    }
}
Also used : ImmunizationSimilarityCriteria(de.symeda.sormas.api.immunization.ImmunizationSimilarityCriteria) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) ImmunizationPickOrCreateField(de.symeda.sormas.ui.immunization.components.fields.pickorcreate.ImmunizationPickOrCreateField) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)

Example 52 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationController method getImmunizationCreateComponent.

private CommitDiscardWrapperComponent<ImmunizationCreationForm> getImmunizationCreateComponent() {
    UserProvider currentUserProvider = UserProvider.getCurrent();
    if (currentUserProvider != null) {
        ImmunizationCreationForm createForm = new ImmunizationCreationForm();
        ImmunizationDto immunization = ImmunizationDto.build(null);
        immunization.setReportingUser(currentUserProvider.getUserReference());
        createForm.setValue(immunization);
        final CommitDiscardWrapperComponent<ImmunizationCreationForm> viewComponent = new CommitDiscardWrapperComponent<>(createForm, currentUserProvider.hasUserRight(UserRight.IMMUNIZATION_CREATE), createForm.getFieldGroup());
        viewComponent.addCommitListener(() -> {
            if (!createForm.getFieldGroup().isModified()) {
                final ImmunizationDto dto = createForm.getValue();
                PersonDto searchedPerson = createForm.getSearchedPerson();
                if (searchedPerson != null) {
                    dto.setPerson(searchedPerson.toReference());
                    selectOrCreateimmunizationForPerson(dto, searchedPerson.toReference());
                } else {
                    final PersonDto person = createForm.getPerson();
                    ControllerProvider.getPersonController().selectOrCreatePerson(person, I18nProperties.getString(Strings.infoSelectOrCreatePersonForImmunization), selectedPerson -> {
                        if (selectedPerson != null) {
                            selectOrCreateimmunizationForPerson(dto, selectedPerson);
                        }
                    }, true);
                }
            }
        });
        return viewComponent;
    }
    return null;
}
Also used : ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) UserProvider(de.symeda.sormas.ui.UserProvider) ImmunizationCreationForm(de.symeda.sormas.ui.immunization.components.form.ImmunizationCreationForm) PersonDto(de.symeda.sormas.api.person.PersonDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)

Example 53 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationController method getImmunizationDataEditComponent.

public CommitDiscardWrapperComponent<ImmunizationDataForm> getImmunizationDataEditComponent(ImmunizationDto immunizationDto) {
    ImmunizationDataForm immunizationDataForm = new ImmunizationDataForm(immunizationDto.isPseudonymized(), immunizationDto.getRelatedCase());
    immunizationDataForm.setValue(immunizationDto);
    UserProvider currentUserProvider = UserProvider.getCurrent();
    CommitDiscardWrapperComponent<ImmunizationDataForm> editComponent = new CommitDiscardWrapperComponent<ImmunizationDataForm>(immunizationDataForm, currentUserProvider != null && currentUserProvider.hasUserRight(UserRight.IMMUNIZATION_EDIT), immunizationDataForm.getFieldGroup()) {

        @Override
        public void discard() {
            immunizationDataForm.discard();
            super.discard();
        }
    };
    AutomaticDeletionInfoDto automaticDeletionInfoDto = FacadeProvider.getImmunizationFacade().getAutomaticDeletionInfo(immunizationDto.getUuid());
    if (automaticDeletionInfoDto != null) {
        editComponent.getButtonsPanel().addComponentAsFirst(new AutomaticDeletionLabel(automaticDeletionInfoDto));
    }
    if (immunizationDto.isDeleted()) {
        editComponent.getWrappedComponent().getField(ImmunizationDto.DELETION_REASON).setVisible(true);
        if (editComponent.getWrappedComponent().getField(ImmunizationDto.DELETION_REASON).getValue() == DeletionReason.OTHER_REASON) {
            editComponent.getWrappedComponent().getField(ImmunizationDto.OTHER_DELETION_REASON).setVisible(true);
        }
    }
    editComponent.addCommitListener(() -> {
        if (!immunizationDataForm.getFieldGroup().isModified()) {
            ImmunizationDto immunizationDtoValue = immunizationDataForm.getValue();
            List<ImmunizationDto> similarImmunizations = findSimilarImmunizations(immunizationDtoValue);
            if (similarImmunizations.isEmpty()) {
                FacadeProvider.getImmunizationFacade().save(immunizationDtoValue);
                if (immunizationDtoValue.getImmunizationStatus() == ImmunizationStatus.ACQUIRED) {
                    NotificationHelper.showNotification(I18nProperties.getString(Strings.messageImmunizationSavedVaccinationStatusUpdated), Notification.Type.WARNING_MESSAGE, -1);
                } else {
                    Notification.show(I18nProperties.getString(Strings.messageImmunizationSaved), Notification.Type.WARNING_MESSAGE);
                }
                SormasUI.refreshView();
            } else {
                showSimilarImmunizationPopup(immunizationDtoValue, similarImmunizations.get(0), this::saveImmunization);
            }
        }
    });
    // Initialize 'Delete' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.IMMUNIZATION_DELETE)) {
        editComponent.addDeleteWithReasonListener((deleteDetails) -> {
            FacadeProvider.getImmunizationFacade().delete(immunizationDto.getUuid(), deleteDetails);
            UI.getCurrent().getNavigator().navigateTo(ImmunizationsView.VIEW_NAME);
        }, I18nProperties.getString(Strings.entityImmunization));
    }
    // Initialize 'Archive' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.IMMUNIZATION_ARCHIVE)) {
        ControllerProvider.getArchiveController().addArchivingButton(immunizationDto, FacadeProvider.getImmunizationFacade(), CoreEntityArchiveMessages.IMMUNIZATION, editComponent, () -> navigateToImmunization(immunizationDto.getUuid()));
    }
    return editComponent;
}
Also used : ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) UserProvider(de.symeda.sormas.ui.UserProvider) ImmunizationDataForm(de.symeda.sormas.ui.immunization.components.form.ImmunizationDataForm) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) AutomaticDeletionInfoDto(de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto) AutomaticDeletionLabel(de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)

Example 54 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 55 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class ContactController method getContactDataEditComponent.

public CommitDiscardWrapperComponent<ContactDataForm> getContactDataEditComponent(String contactUuid, final ViewMode viewMode, boolean isPsuedonymized) {
    // editForm.setWidth(editForm.getWidth() * 8/12, Unit.PIXELS);
    ContactDto contact = FacadeProvider.getContactFacade().getByUuid(contactUuid);
    AutomaticDeletionInfoDto automaticDeletionInfoDto = FacadeProvider.getContactFacade().getAutomaticDeletionInfo(contactUuid);
    ContactDataForm editForm = new ContactDataForm(contact.getDisease(), viewMode, isPsuedonymized);
    editForm.setValue(contact);
    final CommitDiscardWrapperComponent<ContactDataForm> editComponent = new CommitDiscardWrapperComponent<ContactDataForm>(editForm, UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_EDIT), editForm.getFieldGroup());
    if (automaticDeletionInfoDto != null) {
        editComponent.getButtonsPanel().addComponentAsFirst(new AutomaticDeletionLabel(automaticDeletionInfoDto));
    }
    if (contact.isDeleted()) {
        editComponent.getWrappedComponent().getField(ContactDto.DELETION_REASON).setVisible(true);
        if (editComponent.getWrappedComponent().getField(ContactDto.DELETION_REASON).getValue() == DeletionReason.OTHER_REASON) {
            editComponent.getWrappedComponent().getField(ContactDto.OTHER_DELETION_REASON).setVisible(true);
        }
    }
    editComponent.addCommitListener(() -> {
        if (!editForm.getFieldGroup().isModified()) {
            ContactDto dto = editForm.getValue();
            fillPersonAddressIfEmpty(dto, () -> FacadeProvider.getPersonFacade().getPersonByUuid(dto.getPerson().getUuid()));
            FacadeProvider.getContactFacade().save(dto);
            Notification.show(I18nProperties.getString(Strings.messageContactSaved), Type.WARNING_MESSAGE);
            SormasUI.refreshView();
        }
    });
    if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_DELETE)) {
        editComponent.addDeleteWithReasonListener((deleteDetails) -> {
            FacadeProvider.getContactFacade().delete(contact.getUuid(), deleteDetails);
            UI.getCurrent().getNavigator().navigateTo(ContactsView.VIEW_NAME);
        }, I18nProperties.getString(Strings.entityContact));
    }
    // Initialize 'Archive' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_ARCHIVE)) {
        ControllerProvider.getArchiveController().addArchivingButton(contact, FacadeProvider.getContactFacade(), CoreEntityArchiveMessages.CONTACT, editComponent, () -> navigateToView(ContactDataView.VIEW_NAME, contact.getUuid(), false));
    }
    return editComponent;
}
Also used : ContactDto(de.symeda.sormas.api.contact.ContactDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) AutomaticDeletionInfoDto(de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) AutomaticDeletionLabel(de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)

Aggregations

CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)114 Window (com.vaadin.ui.Window)44 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)25 EventDto (de.symeda.sormas.api.event.EventDto)20 Label (com.vaadin.ui.Label)17 PersonDto (de.symeda.sormas.api.person.PersonDto)17 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)15 CommitListener (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)15 ContactDto (de.symeda.sormas.api.contact.ContactDto)14 Button (com.vaadin.ui.Button)13 Notification (com.vaadin.ui.Notification)13 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)13 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)12 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)12 SampleDto (de.symeda.sormas.api.sample.SampleDto)12 UserProvider (de.symeda.sormas.ui.UserProvider)12 EventIndexDto (de.symeda.sormas.api.event.EventIndexDto)11 AutomaticDeletionLabel (de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)11 ArrayList (java.util.ArrayList)11 VerticalLayout (com.vaadin.ui.VerticalLayout)10