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()));
}
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));
}
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]));
}
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());
}
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());
}
Aggregations