Search in sources :

Example 1 with AutomaticDeletionLabel

use of de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel 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)

Example 2 with AutomaticDeletionLabel

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

the class CaseController method getCaseDataEditComponent.

// public CommitDiscardWrapperComponent<? extends Component> getCaseCombinedEditComponent(final String caseUuid,
// final ViewMode viewMode) {
// 
// CaseDataDto caze = findCase(caseUuid);
// PersonDto person = FacadeProvider.getPersonFacade().getPersonByUuid(caze.getPerson().getUuid());
// 
// CaseDataForm caseEditForm = new CaseDataForm(person, caze.getDisease(), viewMode);
// caseEditForm.setValue(caze);
// 
// HospitalizationForm hospitalizationForm = new HospitalizationForm(caze, viewMode);
// hospitalizationForm.setValue(caze.getHospitalization());
// 
// SymptomsForm symptomsForm = new SymptomsForm(caze, caze.getDisease(), person, SymptomsContext.CASE, viewMode);
// symptomsForm.setValue(caze.getSymptoms());
// 
// EpiDataForm epiDataForm = new EpiDataForm(caze.getDisease(), viewMode);
// epiDataForm.setValue(caze.getEpiData());
// 
// CommitDiscardWrapperComponent<? extends Component> editView = AbstractEditForm
// .buildCommitDiscardWrapper(caseEditForm, hospitalizationForm, symptomsForm, epiDataForm);
// 
// editView.addCommitListener(new CommitListener() {
// @Override
// public void onCommit() {
// CaseDataDto cazeDto = caseEditForm.getValue();
// cazeDto.setHospitalization(hospitalizationForm.getValue());
// cazeDto.setSymptoms(symptomsForm.getValue());
// cazeDto.setEpiData(epiDataForm.getValue());
// 
// saveCase(cazeDto);
// }
// });
// 
// appendSpecialCommands(caze, editView);
// 
// return editView;
// }
public CommitDiscardWrapperComponent<CaseDataForm> getCaseDataEditComponent(final String caseUuid, final ViewMode viewMode) {
    CaseDataDto caze = findCase(caseUuid);
    AutomaticDeletionInfoDto automaticDeletionInfoDto = FacadeProvider.getCaseFacade().getAutomaticDeletionInfo(caseUuid);
    CaseDataForm caseEditForm = new CaseDataForm(caseUuid, FacadeProvider.getPersonFacade().getPersonByUuid(caze.getPerson().getUuid()), caze.getDisease(), caze.getSymptoms(), viewMode, caze.isPseudonymized());
    caseEditForm.setValue(caze);
    CommitDiscardWrapperComponent<CaseDataForm> editView = new CommitDiscardWrapperComponent<CaseDataForm>(caseEditForm, UserProvider.getCurrent().hasUserRight(UserRight.CASE_EDIT), caseEditForm.getFieldGroup());
    if (automaticDeletionInfoDto != null) {
        editView.getButtonsPanel().addComponentAsFirst(new AutomaticDeletionLabel(automaticDeletionInfoDto));
    }
    editView.addCommitListener(() -> {
        CaseDataDto oldCase = findCase(caseUuid);
        CaseDataDto cazeDto = caseEditForm.getValue();
        saveCaseWithFacilityChangedPrompt(cazeDto, oldCase);
    });
    editView.addDiscardListener(() -> caseEditForm.onDiscard());
    appendSpecialCommands(caze, editView);
    return editView;
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) AutomaticDeletionInfoDto(de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) AutomaticDeletionLabel(de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)

Example 3 with AutomaticDeletionLabel

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

the class EventParticipantsController method getEventParticipantDataEditComponent.

public CommitDiscardWrapperComponent<?> getEventParticipantDataEditComponent(String eventParticipantUuid) {
    final EventParticipantDto eventParticipant = FacadeProvider.getEventParticipantFacade().getEventParticipantByUuid(eventParticipantUuid);
    final EventDto event = FacadeProvider.getEventFacade().getEventByUuid(eventParticipant.getEvent().getUuid(), false);
    AutomaticDeletionInfoDto automaticDeletionInfoDto = FacadeProvider.getEventParticipantFacade().getAutomaticDeletionInfo(eventParticipantUuid);
    final EventParticipantEditForm editForm = new EventParticipantEditForm(event, eventParticipant.isPseudonymized(), eventParticipant.getPerson().isPseudonymized(), false);
    editForm.setValue(eventParticipant);
    editForm.setWidth(100, Unit.PERCENTAGE);
    final CommitDiscardWrapperComponent<EventParticipantEditForm> editComponent = createEventParticipantEditCommitWrapper(editForm, null);
    if (automaticDeletionInfoDto != null) {
        editComponent.getButtonsPanel().addComponentAsFirst(new AutomaticDeletionLabel(automaticDeletionInfoDto));
    }
    if (UserProvider.getCurrent().hasUserRight(UserRight.EVENTPARTICIPANT_DELETE)) {
        editComponent.addDeleteListener(() -> {
            FacadeProvider.getEventParticipantFacade().deleteEventParticipant(eventParticipant.toReference());
            ControllerProvider.getEventController().navigateToParticipants(eventParticipant.getEvent().getUuid());
        }, I18nProperties.getString(Strings.entityEventParticipant));
    }
    // Initialize 'Archive' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.EVENTPARTICIPANT_ARCHIVE)) {
        boolean archived = FacadeProvider.getEventParticipantFacade().isArchived(eventParticipant.getUuid());
        Button archiveButton = ButtonHelper.createButton(archived ? Captions.actionDearchive : Captions.actionArchive, e -> {
            if (editComponent.isModified()) {
                editComponent.commit();
            }
            if (archived) {
                ControllerProvider.getArchiveController().dearchiveEntity(eventParticipant, FacadeProvider.getEventParticipantFacade(), Strings.headingDearchiveEventParticipant, Strings.confirmationDearchiveEventParticipant, Strings.entityEventParticipant, Strings.messageEventParticipantDearchived, () -> navigateToData(eventParticipant.getUuid()));
            } else {
                ControllerProvider.getArchiveController().archiveEntity(eventParticipant, FacadeProvider.getEventParticipantFacade(), Strings.headingArchiveEventParticipant, Strings.confirmationArchiveEventParticipant, Strings.entityEventParticipant, Strings.messageEventParticipantArchived, () -> navigateToData(eventParticipant.getUuid()));
            }
        }, ValoTheme.BUTTON_LINK);
        editComponent.getButtonsPanel().addComponentAsFirst(archiveButton);
        editComponent.getButtonsPanel().setComponentAlignment(archiveButton, Alignment.BOTTOM_LEFT);
    }
    return editComponent;
}
Also used : Button(com.vaadin.ui.Button) EventDto(de.symeda.sormas.api.event.EventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) AutomaticDeletionInfoDto(de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto) AutomaticDeletionLabel(de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)

Example 4 with AutomaticDeletionLabel

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

the class EventController method getEventDataEditComponent.

public CommitDiscardWrapperComponent<EventDataForm> getEventDataEditComponent(final String eventUuid, Consumer<EventStatus> saveCallback) {
    EventDto event = findEvent(eventUuid);
    AutomaticDeletionInfoDto automaticDeletionInfoDto = FacadeProvider.getEventFacade().getAutomaticDeletionInfo(eventUuid);
    EventDataForm eventEditForm = new EventDataForm(false, event.isPseudonymized());
    eventEditForm.setValue(event);
    final CommitDiscardWrapperComponent<EventDataForm> editView = new CommitDiscardWrapperComponent<EventDataForm>(eventEditForm, UserProvider.getCurrent().hasUserRight(UserRight.EVENT_EDIT), eventEditForm.getFieldGroup());
    if (automaticDeletionInfoDto != null) {
        editView.getButtonsPanel().addComponentAsFirst(new AutomaticDeletionLabel(automaticDeletionInfoDto));
    }
    editView.addCommitListener(() -> {
        if (!eventEditForm.getFieldGroup().isModified()) {
            EventDto eventDto = eventEditForm.getValue();
            final UserDto user = UserProvider.getCurrent().getUser();
            final RegionReferenceDto userRegion = user.getRegion();
            final DistrictReferenceDto userDistrict = user.getDistrict();
            final RegionReferenceDto epEventRegion = eventDto.getEventLocation().getRegion();
            final DistrictReferenceDto epEventDistrict = eventDto.getEventLocation().getDistrict();
            final Boolean eventOutsideJurisdiction = (userRegion != null && !userRegion.equals(epEventRegion) || userDistrict != null && !userDistrict.equals(epEventDistrict));
            if (eventOutsideJurisdiction) {
                VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingEventJurisdictionUpdated), new Label(I18nProperties.getString(Strings.messageEventJurisdictionUpdated)), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), 500, confirmed -> {
                    if (confirmed) {
                        saveEvent(saveCallback, eventDto);
                    }
                });
            } else {
                saveEvent(saveCallback, eventDto);
            }
        }
    });
    if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_DELETE)) {
        editView.addDeleteListener(() -> {
            if (!existEventParticipantsLinkedToEvent(event)) {
                try {
                    FacadeProvider.getEventFacade().deleteEvent(event.getUuid());
                } catch (ExternalSurveillanceToolException e) {
                    Notification.show(String.format(I18nProperties.getString(Strings.ExternalSurveillanceToolGateway_notificationEntryNotDeleted), DataHelper.getShortUuid(event.getUuid())), "", Type.ERROR_MESSAGE);
                }
            } else {
                VaadinUiUtil.showSimplePopupWindow(I18nProperties.getString(Strings.headingEventNotDeleted), I18nProperties.getString(Strings.messageEventsNotDeletedReason));
            }
            UI.getCurrent().getNavigator().navigateTo(EventsView.VIEW_NAME);
        }, I18nProperties.getString(Strings.entityEvent));
    }
    // Initialize 'Archive' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_ARCHIVE)) {
        boolean archived = FacadeProvider.getEventFacade().isArchived(eventUuid);
        Button archiveEventButton = ButtonHelper.createButton(archived ? Captions.actionDearchive : Captions.actionArchive, e -> {
            if (editView.isModified()) {
                editView.commit();
            }
            if (archived) {
                ControllerProvider.getArchiveController().dearchiveEntity(event, FacadeProvider.getEventFacade(), Strings.headingDearchiveEvent, Strings.confirmationDearchiveEvent, Strings.entityEvent, Strings.messageEventDearchived, () -> navigateToData(event.getUuid()));
            } else {
                ControllerProvider.getArchiveController().archiveEntity(event, FacadeProvider.getEventFacade(), Strings.headingArchiveEvent, Strings.confirmationArchiveEvent, Strings.entityEvent, Strings.messageEventArchived, () -> navigateToData(event.getUuid()));
            }
        }, ValoTheme.BUTTON_LINK);
        editView.getButtonsPanel().addComponentAsFirst(archiveEventButton);
        editView.getButtonsPanel().setComponentAlignment(archiveEventButton, Alignment.BOTTOM_LEFT);
    }
    return editView;
}
Also used : UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) AutomaticDeletionLabel(de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel) Label(com.vaadin.ui.Label) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Button(com.vaadin.ui.Button) AutomaticDeletionInfoDto(de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto) AutomaticDeletionLabel(de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)

Example 5 with AutomaticDeletionLabel

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

the class TravelEntryController method getTravelEntryDataEditComponent.

public CommitDiscardWrapperComponent<TravelEntryDataForm> getTravelEntryDataEditComponent(String travelEntryUuid) {
    TravelEntryDto travelEntry = findTravelEntry(travelEntryUuid);
    AutomaticDeletionInfoDto automaticDeletionInfoDto = FacadeProvider.getTravelEntryFacade().getAutomaticDeletionInfo(travelEntryUuid);
    TravelEntryDataForm travelEntryEditForm = new TravelEntryDataForm(travelEntryUuid, travelEntry.isPseudonymized());
    travelEntryEditForm.setValue(travelEntry);
    CommitDiscardWrapperComponent<TravelEntryDataForm> editComponent = new CommitDiscardWrapperComponent<>(travelEntryEditForm, UserProvider.getCurrent().hasUserRight(UserRight.TRAVEL_ENTRY_EDIT), travelEntryEditForm.getFieldGroup());
    if (automaticDeletionInfoDto != null) {
        editComponent.getButtonsPanel().addComponentAsFirst(new AutomaticDeletionLabel(automaticDeletionInfoDto));
    }
    editComponent.addCommitListener(() -> {
        if (!travelEntryEditForm.getFieldGroup().isModified()) {
            TravelEntryDto travelEntryDto = travelEntryEditForm.getValue();
            FacadeProvider.getTravelEntryFacade().save(travelEntryDto);
            Notification.show(I18nProperties.getString(Strings.messageTravelEntrySaved), Notification.Type.WARNING_MESSAGE);
            SormasUI.refreshView();
        }
    });
    editComponent.addDiscardListener(() -> travelEntryEditForm.onDiscard());
    // Initialize 'Delete' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.TRAVEL_ENTRY_DELETE)) {
        editComponent.addDeleteListener(() -> {
            FacadeProvider.getTravelEntryFacade().deleteTravelEntry(travelEntry.getUuid());
            UI.getCurrent().getNavigator().navigateTo(TravelEntriesView.VIEW_NAME);
        }, I18nProperties.getString(Strings.entityTravel));
    }
    // Initialize 'Archive' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.TRAVEL_ENTRY_ARCHIVE)) {
        boolean archived = FacadeProvider.getTravelEntryFacade().isArchived(travelEntryUuid);
        Button archiveTravelEntryButton = ButtonHelper.createButton(archived ? Captions.actionDearchive : Captions.actionArchive, e -> {
            if (editComponent.isModified()) {
                editComponent.commit();
            }
            if (archived) {
                ControllerProvider.getArchiveController().dearchiveEntity(travelEntry, FacadeProvider.getTravelEntryFacade(), Strings.headingDearchiveTravelEntry, Strings.confirmationDearchiveTravelEntry, Strings.entityTravel, Strings.messageTravelEntryDearchived, () -> navigateToTravelEntry(travelEntry.getUuid()));
            } else {
                ControllerProvider.getArchiveController().archiveEntity(travelEntry, FacadeProvider.getTravelEntryFacade(), Strings.headingArchiveTravelEntry, Strings.confirmationArchiveTravelEntry, Strings.entityTravel, Strings.messageTravelEntryArchived, () -> navigateToTravelEntry(travelEntry.getUuid()));
            }
        }, ValoTheme.BUTTON_LINK);
        editComponent.getButtonsPanel().addComponentAsFirst(archiveTravelEntryButton);
        editComponent.getButtonsPanel().setComponentAlignment(archiveTravelEntryButton, Alignment.BOTTOM_LEFT);
    }
    return editComponent;
}
Also used : Button(com.vaadin.ui.Button) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) AutomaticDeletionInfoDto(de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) AutomaticDeletionLabel(de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)

Aggregations

AutomaticDeletionInfoDto (de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto)6 AutomaticDeletionLabel (de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)6 Button (com.vaadin.ui.Button)5 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)5 EventDto (de.symeda.sormas.api.event.EventDto)2 Label (com.vaadin.ui.Label)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 ContactDto (de.symeda.sormas.api.contact.ContactDto)1 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)1 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)1 ExternalSurveillanceToolException (de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException)1 ImmunizationDto (de.symeda.sormas.api.immunization.ImmunizationDto)1 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)1 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)1 TravelEntryDto (de.symeda.sormas.api.travelentry.TravelEntryDto)1 UserDto (de.symeda.sormas.api.user.UserDto)1 UserProvider (de.symeda.sormas.ui.UserProvider)1 ImmunizationDataForm (de.symeda.sormas.ui.immunization.components.form.ImmunizationDataForm)1