Search in sources :

Example 1 with DashboardCaseDto

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) DashboardCaseDto(de.symeda.sormas.api.dashboard.DashboardCaseDto) 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) Person(de.symeda.sormas.backend.person.Person) CaseJoins(de.symeda.sormas.utils.CaseJoins)

Example 2 with DashboardCaseDto

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

Example 3 with DashboardCaseDto

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());
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) DashboardCriteria(de.symeda.sormas.api.dashboard.DashboardCriteria) DashboardCaseDto(de.symeda.sormas.api.dashboard.DashboardCaseDto) Date(java.util.Date) Test(org.junit.Test) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest)

Aggregations

DashboardCaseDto (de.symeda.sormas.api.dashboard.DashboardCaseDto)3 DashboardCriteria (de.symeda.sormas.api.dashboard.DashboardCriteria)2 Date (java.util.Date)2 Disease (de.symeda.sormas.api.Disease)1 CaseClassification (de.symeda.sormas.api.caze.CaseClassification)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 CaseReferenceDefinition (de.symeda.sormas.api.caze.CaseReferenceDefinition)1 DashboardCaseStatisticDto (de.symeda.sormas.api.dashboard.DashboardCaseStatisticDto)1 DashboardEventDto (de.symeda.sormas.api.dashboard.DashboardEventDto)1 DashboardFacade (de.symeda.sormas.api.dashboard.DashboardFacade)1 DashboardQuarantineDataDto (de.symeda.sormas.api.dashboard.DashboardQuarantineDataDto)1 EpiCurveGrouping (de.symeda.sormas.api.dashboard.EpiCurveGrouping)1 DiseaseBurdenDto (de.symeda.sormas.api.disease.DiseaseBurdenDto)1 EventCriteria (de.symeda.sormas.api.event.EventCriteria)1 EventStatus (de.symeda.sormas.api.event.EventStatus)1 FeatureType (de.symeda.sormas.api.feature.FeatureType)1 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)1 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)1 OutbreakCriteria (de.symeda.sormas.api.outbreak.OutbreakCriteria)1 PersonDto (de.symeda.sormas.api.person.PersonDto)1