use of de.symeda.sormas.api.dashboard.DashboardCaseDto in project SORMAS-Project by hzi-braunschweig.
the class DashboardService method getCases.
public List<DashboardCaseDto> getCases(DashboardCriteria dashboardCriteria) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<DashboardCaseDto> cq = cb.createQuery(DashboardCaseDto.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);
List<DashboardCaseDto> result;
if (filter != null) {
cq.where(filter);
cq.multiselect(caze.get(Case.ID), caze.get(Case.UUID), caze.get(Case.REPORT_DATE), caze.get(Case.CASE_CLASSIFICATION), caze.get(Case.DISEASE), person.get(Person.PRESENT_CONDITION), person.get(Person.CAUSE_OF_DEATH_DISEASE), caze.get(Case.QUARANTINE_FROM), caze.get(Case.QUARANTINE_TO), caze.get(Case.CASE_REFERENCE_DEFINITION));
result = em.createQuery(cq).getResultList();
} else {
result = Collections.emptyList();
}
return result;
}
use of de.symeda.sormas.api.dashboard.DashboardCaseDto 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));
}
use of de.symeda.sormas.api.dashboard.DashboardCaseDto in project SORMAS-Project by hzi-braunschweig.
the class DashboardFacadeEjbTest method testGetCasesForDashboard.
@Test
public void testGetCasesForDashboard() {
TestDataCreator.RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
TestDataCreator.RDCFEntities rdcf2 = creator.createRDCFEntities("Region2", "District2", "Community2", "Facility2");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
PersonDto cazePerson = creator.createPerson("Case", "Person");
CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
CaseDataDto caze2 = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf2);
caze2.setSharedToCountry(true);
getCaseFacade().save(caze2);
DashboardCriteria dashboardCriteria = new DashboardCriteria().region(caze.getResponsibleRegion()).district(caze.getDistrict()).disease(caze.getDisease()).newCaseDateType(NewCaseDateType.MOST_RELEVANT).dateBetween(DateHelper.subtractDays(new Date(), 1), DateHelper.addDays(new Date(), 1));
List<DashboardCaseDto> dashboardCaseDtos = getDashboardFacade().getCases(dashboardCriteria);
// List should have only one entry; shared case should not appear
assertEquals(1, dashboardCaseDtos.size());
}
Aggregations