Search in sources :

Example 21 with CommitDiscardWrapperComponent

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

the class EventController method selectOrCreateEvent.

public void selectOrCreateEvent(CaseReferenceDto caseRef) {
    CaseDataDto caseDataDto = FacadeProvider.getCaseFacade().getCaseDataByUuid(caseRef.getUuid());
    EventSelectionField eventSelect = new EventSelectionField(caseDataDto.getDisease(), I18nProperties.getString(Strings.infoPickOrCreateEventForCase), null);
    eventSelect.setWidth(1100, Sizeable.Unit.PIXELS);
    final CommitDiscardWrapperComponent<EventSelectionField> component = new CommitDiscardWrapperComponent<>(eventSelect);
    component.addCommitListener(() -> {
        EventIndexDto selectedEvent = eventSelect.getValue();
        if (selectedEvent != null) {
            EventCriteria eventCriteria = new EventCriteria();
            eventCriteria.caze(caseRef);
            eventCriteria.setUserFilterIncluded(false);
            List<EventIndexDto> eventIndexDto = FacadeProvider.getEventFacade().getIndexList(eventCriteria, null, null, null);
            EventReferenceDto eventReferenceDto = new EventReferenceDto(selectedEvent.getUuid());
            if (!eventIndexDto.contains(selectedEvent)) {
                linkCaseToEvent(eventReferenceDto, caseDataDto, caseRef);
                SormasUI.refreshView();
            } else {
                SormasUI.refreshView();
                Notification notification = new Notification(I18nProperties.getString(Strings.messagePersonAlreadyCaseInEvent), "", Type.HUMANIZED_MESSAGE);
                notification.setDelayMsec(10000);
                notification.show(Page.getCurrent());
            }
        } else {
            create(caseRef);
            SormasUI.refreshView();
        }
    });
    eventSelect.setSelectionChangeCallback((commitAllowed) -> {
        component.getCommitButton().setEnabled(commitAllowed);
    });
    VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateEvent));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) EventCriteria(de.symeda.sormas.api.event.EventCriteria) Notification(com.vaadin.ui.Notification) EventSelectionField(de.symeda.sormas.ui.events.eventLink.EventSelectionField)

Example 22 with CommitDiscardWrapperComponent

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

the class EventController method selectOrCreateSuperordinateEvent.

public void selectOrCreateSuperordinateEvent(EventReferenceDto subordinateEventRef) {
    Set<String> excludedUuids = new HashSet<>();
    excludedUuids.add(subordinateEventRef.getUuid());
    excludedUuids.addAll(FacadeProvider.getEventFacade().getAllSubordinateEventUuids(subordinateEventRef.getUuid()));
    EventDto subordinateEvent = FacadeProvider.getEventFacade().getEventByUuid(subordinateEventRef.getUuid(), false);
    EventSelectionField selectionField = EventSelectionField.forSuperordinateEvent(subordinateEvent, excludedUuids);
    selectionField.setWidth(1100, Sizeable.Unit.PIXELS);
    final CommitDiscardWrapperComponent<EventSelectionField> component = new CommitDiscardWrapperComponent<>(selectionField);
    component.addCommitListener(() -> {
        EventIndexDto selectedEvent = selectionField.getValue();
        if (selectedEvent != null) {
            subordinateEvent.setSuperordinateEvent(selectedEvent.toReference());
            FacadeProvider.getEventFacade().save(subordinateEvent);
            navigateToData(subordinateEventRef.getUuid());
            Notification.show(I18nProperties.getString(Strings.messageEventLinkedAsSuperordinate), Type.TRAY_NOTIFICATION);
        } else {
            createSuperordinateEvent(subordinateEventRef);
        }
    });
    selectionField.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
    VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateEvent));
}
Also used : EventDto(de.symeda.sormas.api.event.EventDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) HashSet(java.util.HashSet) EventSelectionField(de.symeda.sormas.ui.events.eventLink.EventSelectionField)

Example 23 with CommitDiscardWrapperComponent

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

the class EventController method selectOrCreateEventForCaseList.

public void selectOrCreateEventForCaseList(List<CaseReferenceDto> caseRefs) {
    if (caseRefs == null || caseRefs.isEmpty()) {
        return;
    }
    List<CaseDataDto> caseDataDtos = FacadeProvider.getCaseFacade().getByUuids(caseRefs.stream().map(ReferenceDto::getUuid).collect(Collectors.toList()));
    EventSelectionField eventSelect = new EventSelectionField(caseDataDtos.stream().findFirst().get().getDisease(), I18nProperties.getString(Strings.infoPickOrCreateEventForCases), null);
    eventSelect.setWidth(1100, Sizeable.Unit.PIXELS);
    final CommitDiscardWrapperComponent<EventSelectionField> component = new CommitDiscardWrapperComponent<>(eventSelect);
    component.addCommitListener(() -> {
        EventIndexDto selectedEvent = eventSelect.getValue();
        if (selectedEvent != null) {
            EventReferenceDto eventReferenceDto = new EventReferenceDto(selectedEvent.getUuid());
            linkCasesToEvent(eventReferenceDto, caseDataDtos);
        } else {
            createFromCaseList(caseRefs);
            SormasUI.refreshView();
        }
    });
    eventSelect.setSelectionChangeCallback(commitAllowed -> component.getCommitButton().setEnabled(commitAllowed));
    VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateEvent));
}
Also used : ReferenceDto(de.symeda.sormas.api.ReferenceDto) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) EventGroupReferenceDto(de.symeda.sormas.api.event.EventGroupReferenceDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) EventSelectionField(de.symeda.sormas.ui.events.eventLink.EventSelectionField)

Example 24 with CommitDiscardWrapperComponent

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

the class EventController method getEventCreateComponentForContactList.

public CommitDiscardWrapperComponent<EventDataForm> getEventCreateComponentForContactList(List<ContactReferenceDto> contactRefs) {
    List<ContactDto> contactDtos = FacadeProvider.getContactFacade().getByUuids(contactRefs.stream().map(c -> c.getUuid()).collect(Collectors.toList()));
    EventDataForm eventCreateForm = new EventDataForm(true, false);
    eventCreateForm.setValue(createNewEvent(contactDtos.stream().findFirst().get().getDisease()));
    eventCreateForm.getField(EventDto.DISEASE).setReadOnly(true);
    final CommitDiscardWrapperComponent<EventDataForm> editView = new CommitDiscardWrapperComponent<EventDataForm>(eventCreateForm, UserProvider.getCurrent().hasUserRight(UserRight.EVENT_CREATE), eventCreateForm.getFieldGroup());
    List<ContactDto> finalContactDtos = contactDtos;
    editView.addCommitListener(() -> {
        if (!eventCreateForm.getFieldGroup().isModified()) {
            EventDto dto = eventCreateForm.getValue();
            FacadeProvider.getEventFacade().save(dto);
            Notification.show(I18nProperties.getString(Strings.messageEventCreated), Type.WARNING_MESSAGE);
            linkContactsToEvent(new EventReferenceDto(dto.getUuid()), finalContactDtos);
        }
    });
    return editView;
}
Also used : EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) EventDto(de.symeda.sormas.api.event.EventDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)

Example 25 with CommitDiscardWrapperComponent

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

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