Search in sources :

Example 6 with EventCriteria

use of de.symeda.sormas.api.event.EventCriteria 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 7 with EventCriteria

use of de.symeda.sormas.api.event.EventCriteria in project SORMAS-Project by hzi-braunschweig.

the class EventActionsGrid method setLazyDataProvider.

public void setLazyDataProvider() {
    DataProvider<EventActionIndexDto, EventCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getActionFacade().getEventActionList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> (int) FacadeProvider.getActionFacade().countEventActions(query.getFilter().orElse(null)));
    setDataProvider(dataProvider);
    setSelectionMode(SelectionMode.NONE);
}
Also used : EventActionIndexDto(de.symeda.sormas.api.event.EventActionIndexDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) EventCriteria(de.symeda.sormas.api.event.EventCriteria)

Example 8 with EventCriteria

use of de.symeda.sormas.api.event.EventCriteria in project SORMAS-Project by hzi-braunschweig.

the class LabMessageController method pickOrCreateEvent.

private void pickOrCreateEvent(LabMessageDto labMessageDto, PersonDto person) {
    EventSelectionField eventSelect = new EventSelectionField(labMessageDto.getTestedDisease(), I18nProperties.getString(Strings.infoPickOrCreateEventForLabMessage), null);
    eventSelect.setWidth(1024, Sizeable.Unit.PIXELS);
    Window window = VaadinUiUtil.createPopupWindow();
    final CommitDiscardWrapperComponent<EventSelectionField> component = new CommitDiscardWrapperComponent<>(eventSelect);
    component.addCommitListener(() -> {
        EventIndexDto selectedEvent = eventSelect.getValue();
        if (selectedEvent != null) {
            EventCriteria eventCriteria = new EventCriteria();
            eventCriteria.setPerson(person.toReference());
            eventCriteria.setUserFilterIncluded(false);
            List<EventIndexDto> eventIndexDtos = FacadeProvider.getEventFacade().getIndexList(eventCriteria, null, null, null);
            EventReferenceDto eventReferenceDto = new EventReferenceDto(selectedEvent.getUuid());
            if (!eventIndexDtos.contains(selectedEvent)) {
                createEventParticipant(FacadeProvider.getEventFacade().getEventByUuid(eventReferenceDto.getUuid(), false), labMessageDto, person);
            } else {
                CommitDiscardWrapperComponent<VerticalLayout> commitDiscardWrapperComponent = new CommitDiscardWrapperComponent<>(new VerticalLayout(new Label(I18nProperties.getString(Strings.infoEventParticipantAlreadyExisting))));
                commitDiscardWrapperComponent.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionContinue));
                commitDiscardWrapperComponent.getDiscardButton().setCaption(I18nProperties.getCaption(Captions.actionBack));
                commitDiscardWrapperComponent.addCommitListener(() -> {
                    EventParticipantReferenceDto participant = FacadeProvider.getEventParticipantFacade().getReferenceByEventAndPerson(selectedEvent.getUuid(), person.getUuid());
                    List<SampleDto> samples = FacadeProvider.getSampleFacade().getSimilarSamples(createSampleCriteria(labMessageDto).eventParticipant(participant));
                    if (samples.isEmpty()) {
                        createSample(SampleDto.build(UserProvider.getCurrent().getUserReference(), participant), labMessageDto, selectedEvent.getDisease(), false);
                    } else {
                        pickOrCreateSample(FacadeProvider.getEventParticipantFacade().getByUuid(participant.getUuid()), labMessageDto, samples);
                    }
                });
                commitDiscardWrapperComponent.addDiscardListener(() -> pickOrCreateEvent(labMessageDto, person));
                VaadinUiUtil.showModalPopupWindow(commitDiscardWrapperComponent, I18nProperties.getCaption(Captions.info));
            }
        } else {
            createEvent(labMessageDto, person);
        }
        window.close();
    });
    component.addDiscardListener(window::close);
    eventSelect.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
    window.setContent(component);
    window.setCaption(I18nProperties.getString(Strings.headingPickOrCreateEvent));
    UI.getCurrent().addWindow(window);
}
Also used : Window(com.vaadin.ui.Window) Label(com.vaadin.ui.Label) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) EventCriteria(de.symeda.sormas.api.event.EventCriteria) EventSelectionField(de.symeda.sormas.ui.events.eventLink.EventSelectionField) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) VerticalLayout(com.vaadin.ui.VerticalLayout) SampleDto(de.symeda.sormas.api.sample.SampleDto)

Example 9 with EventCriteria

use of de.symeda.sormas.api.event.EventCriteria in project SORMAS-Project by hzi-braunschweig.

the class EventService method createEventDateFilter.

private Predicate createEventDateFilter(CriteriaQuery<?> cq, CriteriaBuilder cb, From<?, Event> from, EventCriteria eventCriteria) {
    Predicate filter = null;
    CriteriaDateType eventDateType = eventCriteria.getEventDateType();
    Date eventDateFrom = eventCriteria.getEventDateFrom();
    Date eventDateTo = eventCriteria.getEventDateTo();
    if (eventDateType == null || eventDateType == EventCriteriaDateType.EVENT_DATE) {
        Predicate eventDateFilter = null;
        if (eventDateFrom != null && eventDateTo != null) {
            eventDateFilter = cb.or(cb.and(cb.isNull(from.get(Event.END_DATE)), cb.between(from.get(Event.START_DATE), eventDateFrom, eventDateTo)), cb.and(cb.isNull(from.get(Event.START_DATE)), cb.between(from.get(Event.END_DATE), eventDateFrom, eventDateTo)), cb.and(cb.greaterThanOrEqualTo(from.get(Event.END_DATE), eventDateFrom), cb.lessThanOrEqualTo(from.get(Event.START_DATE), eventDateTo)));
        } else if (eventDateFrom != null) {
            eventDateFilter = cb.or(cb.and(cb.isNull(from.get(Event.END_DATE)), cb.greaterThanOrEqualTo(from.get(Event.START_DATE), eventDateFrom)), cb.and(cb.isNull(from.get(Event.START_DATE)), cb.greaterThanOrEqualTo(from.get(Event.END_DATE), eventDateFrom)));
        } else if (eventDateTo != null) {
            eventDateFilter = cb.or(cb.and(cb.isNull(from.get(Event.START_DATE)), cb.lessThanOrEqualTo(from.get(Event.END_DATE), eventDateTo)), cb.and(cb.isNull(from.get(Event.END_DATE)), cb.lessThanOrEqualTo(from.get(Event.START_DATE), eventDateTo)));
        }
        if (eventDateFrom != null || eventDateTo != null) {
            filter = CriteriaBuilderHelper.and(cb, filter, eventDateFilter);
        }
    } else if (eventDateType == EventCriteriaDateType.REPORT_DATE) {
        Predicate eventDateFilter = null;
        if (eventDateFrom != null && eventDateTo != null) {
            eventDateFilter = cb.between(from.get(Event.REPORT_DATE_TIME), eventDateFrom, eventDateTo);
        } else if (eventDateFrom != null) {
            eventDateFilter = cb.greaterThanOrEqualTo(from.get(Event.REPORT_DATE_TIME), eventDateFrom);
        } else if (eventDateTo != null) {
            eventDateFilter = cb.lessThanOrEqualTo(from.get(Event.REPORT_DATE_TIME), eventDateTo);
        }
        if (eventDateFrom != null || eventDateTo != null) {
            filter = CriteriaBuilderHelper.and(cb, filter, eventDateFilter);
        }
    } else if (eventDateType == ExternalShareDateType.LAST_EXTERNAL_SURVEILLANCE_TOOL_SHARE) {
        filter = externalShareInfoService.buildLatestSurvToolShareDateFilter(cq, cb, from, ExternalShareInfo.EVENT, (latestShareDate) -> {
            if (eventDateFrom != null && eventDateTo != null) {
                return cb.between(latestShareDate, eventDateFrom, eventDateTo);
            } else if (eventDateFrom != null) {
                return cb.greaterThanOrEqualTo(latestShareDate, eventDateFrom);
            } else {
                return cb.lessThanOrEqualTo(latestShareDate, eventDateTo);
            }
        });
    }
    return filter;
}
Also used : Arrays(java.util.Arrays) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) SampleJurisdictionPredicateValidator(de.symeda.sormas.backend.sample.SampleJurisdictionPredicateValidator) Date(java.util.Date) ChangeDateBuilder(de.symeda.sormas.backend.common.ChangeDateBuilder) AbstractCoreAdoService(de.symeda.sormas.backend.common.AbstractCoreAdoService) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) EventJoins(de.symeda.sormas.utils.EventJoins) StringUtils(org.apache.commons.lang3.StringUtils) EventCriteriaDateType(de.symeda.sormas.api.event.EventCriteriaDateType) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) Predicate(javax.persistence.criteria.Predicate) ActionService(de.symeda.sormas.backend.action.ActionService) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) ExternalShareInfo(de.symeda.sormas.backend.share.ExternalShareInfo) UserRole(de.symeda.sormas.api.user.UserRole) From(javax.persistence.criteria.From) Path(javax.persistence.criteria.Path) ExternalShareDateType(de.symeda.sormas.api.utils.criteria.ExternalShareDateType) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Action(de.symeda.sormas.backend.action.Action) CaseService(de.symeda.sormas.backend.caze.CaseService) Person(de.symeda.sormas.backend.person.Person) Transactional(javax.transaction.Transactional) Timestamp(java.sql.Timestamp) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Collectors(java.util.stream.Collectors) List(java.util.List) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) PersonQueryContext(de.symeda.sormas.backend.person.PersonQueryContext) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) DeletableAdo(de.symeda.sormas.backend.common.DeletableAdo) Optional(java.util.Optional) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) Location(de.symeda.sormas.backend.location.Location) Sample(de.symeda.sormas.backend.sample.Sample) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) TaskService(de.symeda.sormas.backend.task.TaskService) DateHelper(de.symeda.sormas.api.utils.DateHelper) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) ExternalDataUtil(de.symeda.sormas.backend.util.ExternalDataUtil) ArrayList(java.util.ArrayList) Case(de.symeda.sormas.backend.caze.Case) EventCriteria(de.symeda.sormas.api.event.EventCriteria) CollectionUtils(org.apache.commons.collections.CollectionUtils) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) LocalBean(javax.ejb.LocalBean) SampleJoins(de.symeda.sormas.backend.sample.SampleJoins) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ChangeDateFilterBuilder(de.symeda.sormas.backend.common.ChangeDateFilterBuilder) ExternalShareInfoService(de.symeda.sormas.backend.share.ExternalShareInfoService) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) Task(de.symeda.sormas.backend.task.Task) CriteriaDateType(de.symeda.sormas.api.utils.criteria.CriteriaDateType) Disease(de.symeda.sormas.api.Disease) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) Subquery(javax.persistence.criteria.Subquery) Collections(java.util.Collections) EventCriteriaDateType(de.symeda.sormas.api.event.EventCriteriaDateType) CriteriaDateType(de.symeda.sormas.api.utils.criteria.CriteriaDateType) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate)

Example 10 with EventCriteria

use of de.symeda.sormas.api.event.EventCriteria in project SORMAS-Project by hzi-braunschweig.

the class EventFacadeEjbTest method testGetExportList.

@Test
public void testGetExportList() {
    RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf, UserRole.SURVEILLANCE_SUPERVISOR);
    creator.createEvent(EventStatus.SIGNAL, EventInvestigationStatus.PENDING, "Title", "Description", "First", "Name", "12345", TypeOfPlace.PUBLIC_PLACE, DateHelper.subtractDays(new Date(), 1), new Date(), user.toReference(), user.toReference(), Disease.EVD, rdcf.district);
    EventCriteria eventCriteria = new EventCriteria();
    eventCriteria.setDisease(Disease.EVD);
    List<EventExportDto> results = getEventFacade().getExportList(eventCriteria, Collections.emptySet(), 0, 100);
    // List should have one entry
    assertThat(results, Matchers.hasSize(1));
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) UserDto(de.symeda.sormas.api.user.UserDto) EventCriteria(de.symeda.sormas.api.event.EventCriteria) EventExportDto(de.symeda.sormas.api.event.EventExportDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

EventCriteria (de.symeda.sormas.api.event.EventCriteria)22 EventIndexDto (de.symeda.sormas.api.event.EventIndexDto)11 Date (java.util.Date)11 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)9 EventDto (de.symeda.sormas.api.event.EventDto)8 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)7 Test (org.junit.Test)7 UserDto (de.symeda.sormas.api.user.UserDto)6 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)6 ExternalShareInfo (de.symeda.sormas.backend.share.ExternalShareInfo)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Button (com.vaadin.ui.Button)4 Label (com.vaadin.ui.Label)4 Notification (com.vaadin.ui.Notification)4 EntityRelevanceStatus (de.symeda.sormas.api.EntityRelevanceStatus)4 SortProperty (de.symeda.sormas.api.utils.SortProperty)4 District (de.symeda.sormas.backend.infrastructure.district.District)4 Collections (java.util.Collections)4