Search in sources :

Example 1 with ImmunizationDataForm

use of de.symeda.sormas.ui.immunization.components.form.ImmunizationDataForm 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));
    }
    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.addDeleteListener(() -> {
            FacadeProvider.getImmunizationFacade().deleteImmunization(immunizationDto.getUuid());
            UI.getCurrent().getNavigator().navigateTo(ImmunizationsView.VIEW_NAME);
        }, I18nProperties.getString(Strings.entityImmunization));
    }
    // Initialize 'Archive' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.IMMUNIZATION_ARCHIVE)) {
        boolean archived = FacadeProvider.getImmunizationFacade().isArchived(immunizationDto.getUuid());
        Button archiveButton = ButtonHelper.createButton(archived ? Captions.actionDearchive : Captions.actionArchive, e -> {
            if (editComponent.isModified()) {
                editComponent.commit();
            }
            if (archived) {
                ControllerProvider.getArchiveController().dearchiveEntity(immunizationDto, FacadeProvider.getImmunizationFacade(), Strings.headingDearchiveImmunization, Strings.confirmationDearchiveImmunization, Strings.entityImmunization, Strings.messageImmunizationDearchived, () -> navigateToImmunization(immunizationDto.getUuid()));
            } else {
                ControllerProvider.getArchiveController().archiveEntity(immunizationDto, FacadeProvider.getImmunizationFacade(), Strings.headingArchiveImmunization, Strings.confirmationArchiveImmunization, Strings.entityImmunization, Strings.messageImmunizationArchived, () -> navigateToImmunization(immunizationDto.getUuid()));
            }
        }, ValoTheme.BUTTON_LINK);
        editComponent.getButtonsPanel().addComponentAsFirst(archiveButton);
        editComponent.getButtonsPanel().setComponentAlignment(archiveButton, Alignment.BOTTOM_LEFT);
    }
    return editComponent;
}
Also used : ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) UserProvider(de.symeda.sormas.ui.UserProvider) Button(com.vaadin.ui.Button) 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)

Aggregations

Button (com.vaadin.ui.Button)1 AutomaticDeletionInfoDto (de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto)1 ImmunizationDto (de.symeda.sormas.api.immunization.ImmunizationDto)1 UserProvider (de.symeda.sormas.ui.UserProvider)1 ImmunizationDataForm (de.symeda.sormas.ui.immunization.components.form.ImmunizationDataForm)1 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)1 AutomaticDeletionLabel (de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)1