Search in sources :

Example 11 with EventCriteria

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

the class EventFacadeEjbTest method testEventCriteriaSharedWithReportingTool.

@Test
public void testEventCriteriaSharedWithReportingTool() {
    RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf, UserRole.NATIONAL_USER);
    EventDto sharedEvent = creator.createEvent(user.toReference());
    ExternalShareInfo shareInfo = new ExternalShareInfo();
    shareInfo.setEvent(getEventService().getByUuid(sharedEvent.getUuid()));
    shareInfo.setSender(getUserService().getByUuid(user.getUuid()));
    shareInfo.setStatus(ExternalShareStatus.SHARED);
    getExternalShareInfoService().ensurePersisted(shareInfo);
    EventDto notSharedEvent = creator.createEvent(user.toReference());
    ;
    EventCriteria eventCriteriaForShared = new EventCriteria();
    eventCriteriaForShared.setOnlyEntitiesSharedWithExternalSurvTool(true);
    List<EventIndexDto> indexList = getEventFacade().getIndexList(eventCriteriaForShared, 0, 100, null);
    MatcherAssert.assertThat(indexList, hasSize(1));
    MatcherAssert.assertThat(indexList.get(0).getUuid(), is(sharedEvent.getUuid()));
    EventCriteria eventCriteriaForNotShared = new EventCriteria();
    eventCriteriaForNotShared.setOnlyEntitiesNotSharedWithExternalSurvTool(true);
    indexList = getEventFacade().getIndexList(eventCriteriaForNotShared, 0, 100, null);
    MatcherAssert.assertThat(indexList, hasSize(1));
    MatcherAssert.assertThat(indexList.get(0).getUuid(), is(notSharedEvent.getUuid()));
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) ExternalShareInfo(de.symeda.sormas.backend.share.ExternalShareInfo) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) EventCriteria(de.symeda.sormas.api.event.EventCriteria) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 12 with EventCriteria

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

the class EventFacadeEjbTest method testEventCriteriaLastShareWithReportingToolBetweenDates.

@Test
public void testEventCriteriaLastShareWithReportingToolBetweenDates() {
    RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf, UserRole.NATIONAL_USER);
    EventDto sharedEvent = creator.createEvent(user.toReference());
    ExternalShareInfo shareInfoMarch = new ExternalShareInfo();
    shareInfoMarch.setCreationDate(Timestamp.valueOf(LocalDateTime.of(2021, Month.MARCH, 20, 12, 31)));
    shareInfoMarch.setEvent(getEventService().getByUuid(sharedEvent.getUuid()));
    shareInfoMarch.setSender(getUserService().getByUuid(user.getUuid()));
    shareInfoMarch.setStatus(ExternalShareStatus.SHARED);
    getExternalShareInfoService().ensurePersisted(shareInfoMarch);
    ExternalShareInfo shareInfoApril = new ExternalShareInfo();
    shareInfoApril.setCreationDate(Timestamp.valueOf(LocalDateTime.of(2021, Month.APRIL, 20, 12, 31)));
    shareInfoApril.setEvent(getEventService().getByUuid(sharedEvent.getUuid()));
    shareInfoApril.setSender(getUserService().getByUuid(user.getUuid()));
    shareInfoApril.setStatus(ExternalShareStatus.DELETED);
    getExternalShareInfoService().ensurePersisted(shareInfoApril);
    creator.createEvent(user.toReference());
    creator.createEvent(user.toReference());
    EventCriteria eventCriteria = new EventCriteria();
    eventCriteria.setEventDateType(ExternalShareDateType.LAST_EXTERNAL_SURVEILLANCE_TOOL_SHARE);
    eventCriteria.eventDateBetween(Date.from(LocalDateTime.of(2021, Month.APRIL, 18, 12, 31).atZone(ZoneId.systemDefault()).toInstant()), Date.from(LocalDateTime.of(2021, Month.APRIL, 21, 12, 31).atZone(ZoneId.systemDefault()).toInstant()), ExternalShareDateType.LAST_EXTERNAL_SURVEILLANCE_TOOL_SHARE, DateFilterOption.DATE);
    List<EventIndexDto> indexList = getEventFacade().getIndexList(eventCriteria, 0, 100, null);
    MatcherAssert.assertThat(indexList, hasSize(1));
    MatcherAssert.assertThat(indexList.get(0).getUuid(), is(sharedEvent.getUuid()));
    // range before last share
    eventCriteria.eventDateBetween(Date.from(LocalDateTime.of(2021, Month.MARCH, 10, 12, 31).atZone(ZoneId.systemDefault()).toInstant()), Date.from(LocalDateTime.of(2021, Month.APRIL, 19, 10, 31).atZone(ZoneId.systemDefault()).toInstant()), ExternalShareDateType.LAST_EXTERNAL_SURVEILLANCE_TOOL_SHARE, DateFilterOption.DATE);
    indexList = getEventFacade().getIndexList(eventCriteria, 0, 100, null);
    MatcherAssert.assertThat(indexList, hasSize(0));
    // range after last share
    eventCriteria.eventDateBetween(Date.from(LocalDateTime.of(2021, Month.APRIL, 21, 12, 31).atZone(ZoneId.systemDefault()).toInstant()), Date.from(LocalDateTime.of(2021, Month.APRIL, 25, 10, 31).atZone(ZoneId.systemDefault()).toInstant()), ExternalShareDateType.LAST_EXTERNAL_SURVEILLANCE_TOOL_SHARE, DateFilterOption.DATE);
    indexList = getEventFacade().getIndexList(eventCriteria, 0, 100, null);
    MatcherAssert.assertThat(indexList, hasSize(0));
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) ExternalShareInfo(de.symeda.sormas.backend.share.ExternalShareInfo) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) EventCriteria(de.symeda.sormas.api.event.EventCriteria) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 13 with EventCriteria

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

the class EventService method getEventCountByDisease.

public Map<Disease, Long> getEventCountByDisease(EventCriteria eventCriteria) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
    Root<Event> event = cq.from(Event.class);
    cq.multiselect(event.get(Event.DISEASE), cb.count(event));
    cq.groupBy(event.get(Event.DISEASE));
    Predicate filter = createDefaultFilter(cb, event);
    filter = CriteriaBuilderHelper.and(cb, filter, buildCriteriaFilter(eventCriteria, new EventQueryContext(cb, cq, event)));
    filter = CriteriaBuilderHelper.and(cb, filter, createUserFilter(cb, cq, event));
    if (filter != null)
        cq.where(filter);
    List<Object[]> results = em.createQuery(cq).getResultList();
    return results.stream().collect(Collectors.toMap(e -> (Disease) e[0], e -> (Long) e[1]));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) 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) Disease(de.symeda.sormas.api.Disease) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Predicate(javax.persistence.criteria.Predicate)

Example 14 with EventCriteria

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

the class EventFacadeEjbUserFilterTest method testIndexListWhenParticipantIsInJurisdictionButEventIsNot.

@Test
public void testIndexListWhenParticipantIsInJurisdictionButEventIsNot() {
    loginWith(nationalUser);
    EventDto event1 = creator.createEvent(EventStatus.SIGNAL, EventInvestigationStatus.PENDING, "TitleEv1", "DescriptionEv1", "John1", "Doe1", "12345", TypeOfPlace.PUBLIC_PLACE, DateHelper.subtractDays(new Date(), 1), new Date(), nationalUser.toReference(), nationalUser.toReference(), Disease.EVD, rdcf1.district);
    EventDto event2 = creator.createEvent(EventStatus.EVENT, EventInvestigationStatus.PENDING, "TitleEv2", "DescriptionEv2", "John2", "Doe2", "12345", TypeOfPlace.FACILITY, DateHelper.subtractDays(new Date(), 1), new Date(), nationalUser.toReference(), nationalUser.toReference(), Disease.EVD, rdcf2.district);
    loginWith(districtUser1);
    EventCriteria eventCriteria = new EventCriteria();
    assertEquals(1, getEventFacade().getIndexList(eventCriteria, 0, 100, null).size());
    PersonDto event2Person1 = creator.createPerson("Event2", "Part1");
    creator.createEventParticipant(event2.toReference(), event2Person1, "event2 participant 1", nationalUser.toReference(), rdcf1);
    PersonDto event2Person2 = creator.createPerson("Event2", "Part2");
    creator.createEventParticipant(event2.toReference(), event2Person2, "event2 participant 2", nationalUser.toReference(), rdcf2);
    List<EventIndexDto> indexList = getEventFacade().getIndexList(eventCriteria, 0, 100, Arrays.asList(new SortProperty(Event.EVENT_TITLE)));
    assertEquals(2, indexList.size());
    // not checking here for pseudonymized because there is no field yet on event index that is sensitive/personal
    Assert.assertTrue(indexList.get(0).getInJurisdictionOrOwned());
    Assert.assertFalse(indexList.get(1).getInJurisdictionOrOwned());
    assertEquals(2, getEventParticipantFacade().getIndexList(new EventParticipantCriteria().withEvent(event2.toReference()), 0, 100, null).size());
    loginWith(districtUser2);
    assertEquals(1, getEventFacade().getIndexList(eventCriteria, 0, 100, null).size());
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) PersonDto(de.symeda.sormas.api.person.PersonDto) EventDto(de.symeda.sormas.api.event.EventDto) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) EventCriteria(de.symeda.sormas.api.event.EventCriteria) Date(java.util.Date) Test(org.junit.Test) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest)

Example 15 with EventCriteria

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

the class EventFacadeEjbTest method testGetIndexList.

@Test
public void testGetIndexList() {
    RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    creator.createEvent(EventStatus.SIGNAL, EventInvestigationStatus.PENDING, "TitleEv1", "DescriptionEv1", "First", "Name", "12345", TypeOfPlace.PUBLIC_PLACE, DateHelper.subtractDays(new Date(), 1), new Date(), user.toReference(), user.toReference(), Disease.EVD, rdcf.district);
    creator.createEvent(EventStatus.EVENT, EventInvestigationStatus.PENDING, "TitleEv2", "DescriptionEv2", "First", "Name", "12345", TypeOfPlace.FACILITY, DateHelper.subtractDays(new Date(), 1), new Date(), user.toReference(), user.toReference(), Disease.EVD, rdcf.district);
    EventCriteria eventCriteria = new EventCriteria();
    List<EventIndexDto> results = getEventFacade().getIndexList(eventCriteria, 0, 100, null);
    assertEquals(2, results.size());
    eventCriteria.eventStatus(EventStatus.SIGNAL);
    results = getEventFacade().getIndexList(eventCriteria, 0, 100, null);
    assertEquals(1, results.size());
    assertEquals("TitleEv1", results.get(0).getEventTitle());
    eventCriteria.eventStatus(null);
    eventCriteria.setTypeOfPlace(TypeOfPlace.FACILITY);
    results = getEventFacade().getIndexList(eventCriteria, 0, 100, null);
    assertEquals(1, results.size());
    assertEquals("TitleEv2", results.get(0).getEventTitle());
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) UserDto(de.symeda.sormas.api.user.UserDto) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) EventCriteria(de.symeda.sormas.api.event.EventCriteria) 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