use of de.symeda.sormas.backend.caze.CaseUserFilterCriteria in project SORMAS-Project by hzi-braunschweig.
the class DashboardService method getLastReportedDistrictName.
public String getLastReportedDistrictName(DashboardCriteria dashboardCriteria) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Case> caze = cq.from(Case.class);
final CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, caze);
final CaseJoins<Case> joins = (CaseJoins<Case>) caseQueryContext.getJoins();
Join<Case, District> district = joins.getResponsibleDistrict();
Predicate filter = caseService.createUserFilter(cb, cq, caze, new CaseUserFilterCriteria().excludeCasesFromContacts(true));
filter = CriteriaBuilderHelper.and(cb, filter, createCaseCriteriaFilter(dashboardCriteria, caseQueryContext));
if (filter != null) {
cq.where(filter);
}
cq.select(district.get(District.NAME));
List<Order> order = new ArrayList<>();
order.add(cb.desc(caze.get(Case.REPORT_DATE)));
order.add(cb.desc(caze.get(Case.CREATION_DATE)));
cq.orderBy(order);
return QueryHelper.getFirstResult(em, cq, t -> t == null ? StringUtils.EMPTY : t);
}
use of de.symeda.sormas.backend.caze.CaseUserFilterCriteria in project SORMAS-Project by hzi-braunschweig.
the class DashboardService method getCasesCountPerPersonCondition.
public Map<PresentCondition, Integer> getCasesCountPerPersonCondition(DashboardCriteria dashboardCriteria) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<Case> caze = cq.from(Case.class);
final CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, caze);
final CaseJoins<Case> joins = (CaseJoins<Case>) caseQueryContext.getJoins();
Join<Case, Person> person = joins.getPerson();
Predicate filter = caseService.createUserFilter(cb, cq, caze, new CaseUserFilterCriteria().excludeCasesFromContacts(true));
Predicate criteriaFilter = createCaseCriteriaFilter(dashboardCriteria, caseQueryContext);
filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
if (filter != null) {
cq.where(filter);
}
cq.groupBy(person.get(Person.PRESENT_CONDITION));
cq.multiselect(person.get(Person.PRESENT_CONDITION), cb.count(caze));
List<Object[]> results = em.createQuery(cq).getResultList();
Map<PresentCondition, Integer> resultMap = results.stream().collect(Collectors.toMap(e -> e[0] != null ? (PresentCondition) e[0] : PresentCondition.UNKNOWN, e -> ((Number) e[1]).intValue()));
return resultMap;
}
use of de.symeda.sormas.backend.caze.CaseUserFilterCriteria in project SORMAS-Project by hzi-braunschweig.
the class DashboardService method getCasesCountByClassification.
public Map<CaseClassification, Integer> getCasesCountByClassification(DashboardCriteria dashboardCriteria) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<Case> caze = cq.from(Case.class);
final CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, caze);
Predicate filter = caseService.createUserFilter(cb, cq, caze, new CaseUserFilterCriteria().excludeCasesFromContacts(true));
Predicate criteriaFilter = createCaseCriteriaFilter(dashboardCriteria, caseQueryContext);
filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
Map<CaseClassification, Integer> result;
if (filter != null) {
cq.multiselect(caze.get(Case.CASE_CLASSIFICATION), cb.count(caze.get(Case.CASE_CLASSIFICATION)));
cq.where(filter);
cq.groupBy(caze.get(Case.CASE_CLASSIFICATION));
result = em.createQuery(cq).getResultStream().collect(Collectors.toMap(tuple -> (CaseClassification) tuple[0], tuple -> ((Number) tuple[1]).intValue()));
} else {
result = Collections.emptyMap();
}
return result;
}
use of de.symeda.sormas.backend.caze.CaseUserFilterCriteria in project SORMAS-Project by hzi-braunschweig.
the class DashboardService method countCasesConvertedFromContacts.
public long countCasesConvertedFromContacts(DashboardCriteria dashboardCriteria) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Case> caze = cq.from(Case.class);
final CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, caze);
Predicate filter = caseService.createUserFilter(cb, cq, caze, new CaseUserFilterCriteria().excludeCasesFromContacts(true));
Predicate criteriaFilter = createCaseCriteriaFilter(dashboardCriteria, caseQueryContext);
filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
caze.join(Case.CONVERTED_FROM_CONTACT, JoinType.INNER);
if (filter != null) {
cq.where(filter);
}
cq.select(cb.countDistinct(caze));
return em.createQuery(cq).getSingleResult();
}
use of de.symeda.sormas.backend.caze.CaseUserFilterCriteria in project SORMAS-Project by hzi-braunschweig.
the class DashboardService method getCaseCountByDisease.
public Map<Disease, Long> getCaseCountByDisease(DashboardCriteria dashboardCriteria) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<Case> caze = cq.from(Case.class);
final CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, caze);
Predicate filter = caseService.createUserFilter(cb, cq, caze, new CaseUserFilterCriteria().excludeCasesFromContacts(true));
filter = CriteriaBuilderHelper.and(cb, filter, createCaseCriteriaFilter(dashboardCriteria, caseQueryContext));
if (filter != null) {
cq.where(filter);
}
cq.groupBy(caze.get(Case.DISEASE));
cq.multiselect(caze.get(Case.DISEASE), cb.count(caze));
List<Object[]> results = em.createQuery(cq).getResultList();
Map<Disease, Long> resultMap = results.stream().collect(Collectors.toMap(e -> (Disease) e[0], e -> (Long) e[1]));
return resultMap;
}
Aggregations