Search in sources :

Example 1 with CaseUserFilterCriteria

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);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) ArrayList(java.util.ArrayList) CaseUserFilterCriteria(de.symeda.sormas.backend.caze.CaseUserFilterCriteria) Case(de.symeda.sormas.backend.caze.Case) Predicate(javax.persistence.criteria.Predicate) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) District(de.symeda.sormas.backend.infrastructure.district.District) CaseJoins(de.symeda.sormas.utils.CaseJoins)

Example 2 with CaseUserFilterCriteria

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EventService(de.symeda.sormas.backend.event.EventService) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) DashboardEventDto(de.symeda.sormas.api.dashboard.DashboardEventDto) EventJoins(de.symeda.sormas.utils.EventJoins) StringUtils(org.apache.commons.lang3.StringUtils) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) From(javax.persistence.criteria.From) DashboardCaseDto(de.symeda.sormas.api.dashboard.DashboardCaseDto) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CaseService(de.symeda.sormas.backend.caze.CaseService) Person(de.symeda.sormas.backend.person.Person) 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) User(de.symeda.sormas.backend.user.User) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) Order(javax.persistence.criteria.Order) Location(de.symeda.sormas.backend.location.Location) Community(de.symeda.sormas.backend.infrastructure.community.Community) CaseUserFilterCriteria(de.symeda.sormas.backend.caze.CaseUserFilterCriteria) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) DateHelper(de.symeda.sormas.api.utils.DateHelper) HashMap(java.util.HashMap) EventStatus(de.symeda.sormas.api.event.EventStatus) EventQueryContext(de.symeda.sormas.backend.event.EventQueryContext) ArrayList(java.util.ArrayList) Case(de.symeda.sormas.backend.caze.Case) DashboardCriteria(de.symeda.sormas.api.dashboard.DashboardCriteria) LocalBean(javax.ejb.LocalBean) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) CaseJoins(de.symeda.sormas.utils.CaseJoins) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) Event(de.symeda.sormas.backend.event.Event) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Disease(de.symeda.sormas.api.Disease) Collections(java.util.Collections) PresentCondition(de.symeda.sormas.api.person.PresentCondition) CaseUserFilterCriteria(de.symeda.sormas.backend.caze.CaseUserFilterCriteria) Case(de.symeda.sormas.backend.caze.Case) Predicate(javax.persistence.criteria.Predicate) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Person(de.symeda.sormas.backend.person.Person) CaseJoins(de.symeda.sormas.utils.CaseJoins)

Example 3 with CaseUserFilterCriteria

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) CaseUserFilterCriteria(de.symeda.sormas.backend.caze.CaseUserFilterCriteria) Case(de.symeda.sormas.backend.caze.Case) Predicate(javax.persistence.criteria.Predicate)

Example 4 with CaseUserFilterCriteria

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) CaseUserFilterCriteria(de.symeda.sormas.backend.caze.CaseUserFilterCriteria) Case(de.symeda.sormas.backend.caze.Case) Predicate(javax.persistence.criteria.Predicate)

Example 5 with CaseUserFilterCriteria

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EventService(de.symeda.sormas.backend.event.EventService) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) DashboardEventDto(de.symeda.sormas.api.dashboard.DashboardEventDto) EventJoins(de.symeda.sormas.utils.EventJoins) StringUtils(org.apache.commons.lang3.StringUtils) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) From(javax.persistence.criteria.From) DashboardCaseDto(de.symeda.sormas.api.dashboard.DashboardCaseDto) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CaseService(de.symeda.sormas.backend.caze.CaseService) Person(de.symeda.sormas.backend.person.Person) 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) User(de.symeda.sormas.backend.user.User) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) Order(javax.persistence.criteria.Order) Location(de.symeda.sormas.backend.location.Location) Community(de.symeda.sormas.backend.infrastructure.community.Community) CaseUserFilterCriteria(de.symeda.sormas.backend.caze.CaseUserFilterCriteria) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) DateHelper(de.symeda.sormas.api.utils.DateHelper) HashMap(java.util.HashMap) EventStatus(de.symeda.sormas.api.event.EventStatus) EventQueryContext(de.symeda.sormas.backend.event.EventQueryContext) ArrayList(java.util.ArrayList) Case(de.symeda.sormas.backend.caze.Case) DashboardCriteria(de.symeda.sormas.api.dashboard.DashboardCriteria) LocalBean(javax.ejb.LocalBean) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) CaseJoins(de.symeda.sormas.utils.CaseJoins) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) Event(de.symeda.sormas.backend.event.Event) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Disease(de.symeda.sormas.api.Disease) Collections(java.util.Collections) Disease(de.symeda.sormas.api.Disease) CaseUserFilterCriteria(de.symeda.sormas.backend.caze.CaseUserFilterCriteria) Case(de.symeda.sormas.backend.caze.Case) Predicate(javax.persistence.criteria.Predicate) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject)

Aggregations

CaseUserFilterCriteria (de.symeda.sormas.backend.caze.CaseUserFilterCriteria)10 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)10 Predicate (javax.persistence.criteria.Predicate)10 Case (de.symeda.sormas.backend.caze.Case)9 CaseQueryContext (de.symeda.sormas.backend.caze.CaseQueryContext)8 AbstractDomainObject (de.symeda.sormas.backend.common.AbstractDomainObject)6 District (de.symeda.sormas.backend.infrastructure.district.District)6 CaseJoins (de.symeda.sormas.utils.CaseJoins)6 ArrayList (java.util.ArrayList)6 Disease (de.symeda.sormas.api.Disease)5 CaseClassification (de.symeda.sormas.api.caze.CaseClassification)5 Order (javax.persistence.criteria.Order)5 DashboardCaseDto (de.symeda.sormas.api.dashboard.DashboardCaseDto)4 DateHelper (de.symeda.sormas.api.utils.DateHelper)4 CaseService (de.symeda.sormas.backend.caze.CaseService)4 CriteriaBuilderHelper (de.symeda.sormas.backend.common.CriteriaBuilderHelper)4 Community (de.symeda.sormas.backend.infrastructure.community.Community)4 Region (de.symeda.sormas.backend.infrastructure.region.Region)4 Location (de.symeda.sormas.backend.location.Location)4 User (de.symeda.sormas.backend.user.User)4