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