use of de.symeda.sormas.backend.event.EventQueryContext in project SORMAS-Project by hzi-braunschweig.
the class ActionService method buildEventCriteriaFilter.
public Predicate buildEventCriteriaFilter(EventCriteria criteria, ActionQueryContext actionQueryContext) {
CriteriaBuilder cb = actionQueryContext.getCriteriaBuilder();
ActionJoins joins = (ActionJoins) actionQueryContext.getJoins();
From<Action, Action> action = joins.getRoot();
From<Action, Event> event = joins.getEvent(JoinType.INNER);
Predicate filter = eventService.buildCriteriaFilter(criteria, new EventQueryContext(cb, actionQueryContext.getQuery(), event));
if (criteria.getActionChangeDateFrom() != null && criteria.getActionChangeDateTo() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.between(action.get(Action.CHANGE_DATE), criteria.getActionChangeDateFrom(), criteria.getActionChangeDateTo()));
} else if (criteria.getActionChangeDateFrom() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.greaterThanOrEqualTo(action.get(Action.CHANGE_DATE), criteria.getActionChangeDateFrom()));
} else if (criteria.getActionChangeDateTo() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.lessThanOrEqualTo(action.get(Action.CHANGE_DATE), criteria.getActionChangeDateTo()));
}
if (criteria.getActionDateFrom() != null && criteria.getActionDateTo() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.between(action.get(Action.DATE), criteria.getActionDateFrom(), criteria.getActionDateTo()));
} else if (criteria.getActionDateFrom() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.greaterThanOrEqualTo(action.get(Action.DATE), criteria.getActionDateFrom()));
} else if (criteria.getActionDateTo() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.lessThanOrEqualTo(action.get(Action.DATE), criteria.getActionDateTo()));
}
if (criteria.getActionStatus() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(action.get(Action.ACTION_STATUS), criteria.getActionStatus()));
}
return filter;
}
use of de.symeda.sormas.backend.event.EventQueryContext in project SORMAS-Project by hzi-braunschweig.
the class TaskJurisdictionPredicateValidator method of.
public static TaskJurisdictionPredicateValidator of(TaskQueryContext qc, User user) {
final List<PredicateJurisdictionValidator> associatedJurisdictionValidators = new ArrayList<>();
final CriteriaBuilder cb = qc.getCriteriaBuilder();
final TaskJoins joins = (TaskJoins) qc.getJoins();
associatedJurisdictionValidators.add(CaseJurisdictionPredicateValidator.of(new CaseQueryContext(cb, qc.getQuery(), joins.getCaze()), user));
associatedJurisdictionValidators.add(ContactJurisdictionPredicateValidator.of(new ContactQueryContext(cb, qc.getQuery(), joins.getContact()), user));
associatedJurisdictionValidators.add(EventJurisdictionPredicateValidator.of(new EventQueryContext(cb, qc.getQuery(), joins.getEvent()), user));
return new TaskJurisdictionPredicateValidator(cb, joins, user, associatedJurisdictionValidators);
}
use of de.symeda.sormas.backend.event.EventQueryContext in project SORMAS-Project by hzi-braunschweig.
the class TaskService method getJurisdictionSelections.
public List<Selection<?>> getJurisdictionSelections(TaskQueryContext qc) {
CriteriaBuilder cb = qc.getCriteriaBuilder();
TaskJoins joins = (TaskJoins) qc.getJoins();
ContactJoins<Task> contactJoins = new ContactJoins<>(joins.getContact());
return Arrays.asList(JurisdictionHelper.booleanSelector(cb, inJurisdictionOrOwned(qc)), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getCaze()), caseService.inJurisdictionOrOwned(new CaseQueryContext(cb, qc.getQuery(), joins.getCaze())))), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getContact()), contactService.inJurisdictionOrOwned(new ContactQueryContext<>(cb, qc.getQuery(), joins.getContact())))), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getContact()), cb.isNotNull(contactJoins.getCaze()), caseService.inJurisdictionOrOwned(new CaseQueryContext(cb, qc.getQuery(), contactJoins.getCaze())))), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getEvent()), eventService.inJurisdictionOrOwned(new EventQueryContext<>(cb, qc.getQuery(), joins.getEvent())))), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getTravelEntry()), travelEntryService.inJurisdictionOrOwned(new TravelEntryQueryContext(cb, qc.getQuery(), joins.getTravelEntry())))));
}
use of de.symeda.sormas.backend.event.EventQueryContext in project SORMAS-Project by hzi-braunschweig.
the class DashboardService method getEventCountByStatus.
public Map<EventStatus, Long> getEventCountByStatus(DashboardCriteria dashboardCriteria) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<Event> event = cq.from(Event.class);
EventQueryContext eventQueryContext = new EventQueryContext(cb, cq, event);
cq.multiselect(event.get(Event.EVENT_STATUS), cb.count(event));
cq.groupBy(event.get(Event.EVENT_STATUS));
Predicate filter = eventService.createDefaultFilter(cb, event);
filter = CriteriaBuilderHelper.and(cb, filter, buildEventCriteriaFilter(dashboardCriteria, eventQueryContext));
filter = CriteriaBuilderHelper.and(cb, filter, eventService.createUserFilter(cb, cq, event));
if (filter != null)
cq.where(filter);
List<Object[]> results = em.createQuery(cq).getResultList();
return results.stream().collect(Collectors.toMap(e -> (EventStatus) e[0], e -> (Long) e[1]));
}
use of de.symeda.sormas.backend.event.EventQueryContext in project SORMAS-Project by hzi-braunschweig.
the class DashboardService method getNewEvents.
public List<DashboardEventDto> getNewEvents(DashboardCriteria dashboardCriteria) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<DashboardEventDto> cq = cb.createQuery(DashboardEventDto.class);
Root<Event> event = cq.from(Event.class);
EventQueryContext eventQueryContext = new EventQueryContext(cb, cq, event);
EventJoins<Event> eventJoins = (EventJoins<Event>) eventQueryContext.getJoins();
Join<Event, Location> eventLocation = eventJoins.getLocation();
Join<Location, District> eventDistrict = eventJoins.getDistrict();
Predicate filter = eventService.createDefaultFilter(cb, event);
filter = CriteriaBuilderHelper.and(cb, filter, buildEventCriteriaFilter(dashboardCriteria, eventQueryContext));
filter = CriteriaBuilderHelper.and(cb, filter, eventService.createUserFilter(cb, cq, event));
List<DashboardEventDto> result;
if (filter != null) {
cq.where(filter);
cq.multiselect(event.get(Event.UUID), event.get(Event.EVENT_STATUS), event.get(Event.EVENT_INVESTIGATION_STATUS), event.get(Event.DISEASE), event.get(Event.DISEASE_DETAILS), event.get(Event.START_DATE), event.get(Event.REPORT_LAT), event.get(Event.REPORT_LON), eventLocation.get(Location.LATITUDE), eventLocation.get(Location.LONGITUDE), eventJoins.getReportingUser().get(User.UUID), eventJoins.getResponsibleUser().get(User.UUID), eventJoins.getRegion().get(Region.UUID), eventDistrict.get(District.NAME), eventDistrict.get(District.UUID), eventJoins.getCommunity().get(Community.UUID), JurisdictionHelper.booleanSelector(cb, eventService.inJurisdictionOrOwned(eventQueryContext)));
result = em.createQuery(cq).getResultList();
} else {
result = Collections.emptyList();
}
return result;
}
Aggregations