Search in sources :

Example 1 with DashboardCriteria

use of de.symeda.sormas.api.dashboard.DashboardCriteria in project SORMAS-Project by hzi-braunschweig.

the class DashboardDataProvider method refreshDataForConvertedContactsToCase.

private void refreshDataForConvertedContactsToCase() {
    DashboardCriteria dashboardCriteria = new DashboardCriteria().region(region).district(district).disease(disease).dateBetween(fromDate, toDate);
    setContactsConvertedToCaseCount(FacadeProvider.getDashboardFacade().countCasesConvertedFromContacts(dashboardCriteria));
}
Also used : DashboardCriteria(de.symeda.sormas.api.dashboard.DashboardCriteria)

Example 2 with DashboardCriteria

use of de.symeda.sormas.api.dashboard.DashboardCriteria 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 DashboardCriteria

use of de.symeda.sormas.api.dashboard.DashboardCriteria 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)

Example 4 with DashboardCriteria

use of de.symeda.sormas.api.dashboard.DashboardCriteria in project SORMAS-Project by hzi-braunschweig.

the class DashboardService method getDeathCountByDisease.

public Map<Disease, Long> getDeathCountByDisease(DashboardCriteria dashboardCriteria) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
    Root<Case> root = cq.from(Case.class);
    final CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, root);
    CaseJoins<Case> joins = (CaseJoins<Case>) caseQueryContext.getJoins();
    Join<Case, Person> person = joins.getPerson();
    Predicate filter = caseService.createUserFilter(cb, cq, root, new CaseUserFilterCriteria().excludeCasesFromContacts(true));
    filter = CriteriaBuilderHelper.and(cb, filter, createCaseCriteriaFilter(dashboardCriteria, caseQueryContext));
    filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(person.get(Person.CAUSE_OF_DEATH_DISEASE), root.get(Case.DISEASE)));
    if (filter != null) {
        cq.where(filter);
    }
    cq.multiselect(person.get(Person.CAUSE_OF_DEATH_DISEASE), cb.count(person));
    cq.groupBy(person.get(Person.CAUSE_OF_DEATH_DISEASE));
    List<Object[]> results = em.createQuery(cq).getResultList();
    Map<Disease, Long> outbreaks = results.stream().collect(Collectors.toMap(e -> (Disease) e[0], e -> (Long) e[1]));
    return outbreaks;
}
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) Person(de.symeda.sormas.backend.person.Person) CaseJoins(de.symeda.sormas.utils.CaseJoins)

Example 5 with DashboardCriteria

use of de.symeda.sormas.api.dashboard.DashboardCriteria in project SORMAS-Project by hzi-braunschweig.

the class DashboardFacadeEjb method getDashboardCaseStatistic.

public DashboardCaseStatisticDto getDashboardCaseStatistic(DashboardCriteria dashboardCriteria) {
    List<DashboardCaseDto> dashboardCases = dashboardService.getCases(dashboardCriteria);
    long newCases = dashboardCases.size();
    long fatalCasesCount = dashboardCases.stream().filter(DashboardCaseDto::wasFatal).count();
    float fatalityRate = 100 * ((float) fatalCasesCount / (float) (newCases == 0 ? 1 : newCases));
    fatalityRate = Math.round(fatalityRate * 100) / 100f;
    List<DashboardQuarantineDataDto> casesInQuarantineDtos = dashboardCases.stream().map(DashboardCaseDto::getDashboardQuarantineDataDto).filter(quarantineData(dashboardCriteria.getDateFrom(), dashboardCriteria.getDateTo())).collect(Collectors.toList());
    long casesInQuarantineCount = casesInQuarantineDtos.size();
    long casesPlacedInQuarantineCount = casesInQuarantineDtos.stream().filter(dashboardQuarantineDataDto -> (dashboardQuarantineDataDto.getQuarantineFrom() != null && dashboardCriteria.getDateFrom().before(DateUtils.addDays(dashboardQuarantineDataDto.getQuarantineFrom(), 1)) && dashboardQuarantineDataDto.getQuarantineFrom().before(dashboardCriteria.getDateTo()))).count();
    long casesWithReferenceDefinitionFulfilledCount = dashboardCases.stream().filter(cases -> cases.getCaseReferenceDefinition() == CaseReferenceDefinition.FULFILLED).count();
    long outbreakDistrictCount = outbreakFacade.getOutbreakDistrictCount(new OutbreakCriteria().region(dashboardCriteria.getRegion()).district(dashboardCriteria.getDistrict()).disease(dashboardCriteria.getDisease()).reportedBetween(dashboardCriteria.getDateFrom(), dashboardCriteria.getDateTo()));
    Map<CaseClassification, Integer> casesCountByClassification = dashboardService.getCasesCountByClassification(dashboardCriteria.includeNotACaseClassification(true));
    return new DashboardCaseStatisticDto(casesCountByClassification, casesCountByClassification.values().stream().reduce(0, Integer::sum), fatalCasesCount, fatalityRate, outbreakDistrictCount, casesInQuarantineCount, casesPlacedInQuarantineCount, casesWithReferenceDefinitionFulfilledCount, dashboardService.countCasesConvertedFromContacts(dashboardCriteria), dashboardService.getLastReportedDistrictName(dashboardCriteria));
}
Also used : FeatureType(de.symeda.sormas.api.feature.FeatureType) OutbreakFacadeEjb(de.symeda.sormas.backend.outbreak.OutbreakFacadeEjb) Date(java.util.Date) DashboardEventDto(de.symeda.sormas.api.dashboard.DashboardEventDto) CaseReferenceDefinition(de.symeda.sormas.api.caze.CaseReferenceDefinition) 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) ArrayList(java.util.ArrayList) EventCriteria(de.symeda.sormas.api.event.EventCriteria) DashboardCriteria(de.symeda.sormas.api.dashboard.DashboardCriteria) Map(java.util.Map) FeatureConfigurationFacadeEjb(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb) LocalBean(javax.ejb.LocalBean) DiseaseConfigurationFacadeEjb(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb) SampleFacadeEjb(de.symeda.sormas.backend.sample.SampleFacadeEjb) EpiCurveGrouping(de.symeda.sormas.api.dashboard.EpiCurveGrouping) EJB(javax.ejb.EJB) DashboardCaseDto(de.symeda.sormas.api.dashboard.DashboardCaseDto) OutbreakCriteria(de.symeda.sormas.api.outbreak.OutbreakCriteria) Stateless(javax.ejb.Stateless) CriteriaDateType(de.symeda.sormas.api.utils.criteria.CriteriaDateType) Predicate(java.util.function.Predicate) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) District(de.symeda.sormas.backend.infrastructure.district.District) DiseaseBurdenDto(de.symeda.sormas.api.disease.DiseaseBurdenDto) Collectors(java.util.stream.Collectors) DateUtils(org.apache.commons.lang3.time.DateUtils) DashboardCaseStatisticDto(de.symeda.sormas.api.dashboard.DashboardCaseStatisticDto) DashboardFacade(de.symeda.sormas.api.dashboard.DashboardFacade) PresentCondition(de.symeda.sormas.api.person.PresentCondition) List(java.util.List) DashboardQuarantineDataDto(de.symeda.sormas.api.dashboard.DashboardQuarantineDataDto) Disease(de.symeda.sormas.api.Disease) TreeMap(java.util.TreeMap) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) EventFacadeEjb(de.symeda.sormas.backend.event.EventFacadeEjb) Collections(java.util.Collections) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) DashboardCaseStatisticDto(de.symeda.sormas.api.dashboard.DashboardCaseStatisticDto) DashboardQuarantineDataDto(de.symeda.sormas.api.dashboard.DashboardQuarantineDataDto) OutbreakCriteria(de.symeda.sormas.api.outbreak.OutbreakCriteria) DashboardCaseDto(de.symeda.sormas.api.dashboard.DashboardCaseDto)

Aggregations

DashboardCriteria (de.symeda.sormas.api.dashboard.DashboardCriteria)11 Date (java.util.Date)8 DashboardCaseDto (de.symeda.sormas.api.dashboard.DashboardCaseDto)7 DashboardEventDto (de.symeda.sormas.api.dashboard.DashboardEventDto)7 Disease (de.symeda.sormas.api.Disease)6 CaseClassification (de.symeda.sormas.api.caze.CaseClassification)6 EventStatus (de.symeda.sormas.api.event.EventStatus)6 PresentCondition (de.symeda.sormas.api.person.PresentCondition)6 DateHelper (de.symeda.sormas.api.utils.DateHelper)6 District (de.symeda.sormas.backend.infrastructure.district.District)6 ArrayList (java.util.ArrayList)6 Collections (java.util.Collections)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 EJB (javax.ejb.EJB)6 LocalBean (javax.ejb.LocalBean)6 Stateless (javax.ejb.Stateless)6 Case (de.symeda.sormas.backend.caze.Case)4