Search in sources :

Example 1 with WeeklyReportCriteria

use of de.symeda.sormas.api.report.WeeklyReportCriteria in project SORMAS-Project by hzi-braunschweig.

the class WeeklyReportFacadeEjb method getSummariesPerRegion.

@Override
public List<WeeklyReportRegionSummaryDto> getSummariesPerRegion(EpiWeek epiWeek) {
    JurisdictionLevel jurisdictionLevel = userService.getCurrentUser().getJurisdictionLevel();
    if (jurisdictionLevel != JurisdictionLevel.NONE & jurisdictionLevel != JurisdictionLevel.NATION) {
        return new ArrayList<>();
    }
    List<WeeklyReportRegionSummaryDto> summaryDtos = new ArrayList<>();
    WeeklyReportCriteria regionReportCriteria = new WeeklyReportCriteria().epiWeek(epiWeek);
    List<Region> regions = regionService.getAll(Region.NAME, true);
    for (Region region : regions) {
        WeeklyReportRegionSummaryDto summaryDto = new WeeklyReportRegionSummaryDto();
        summaryDto.setRegion(RegionFacadeEjb.toReferenceDto(region));
        Long officers = userService.countByDistricts(region.getDistricts(), UserRight.WEEKLYREPORT_CREATE);
        if (officers.intValue() == 0) {
            // summarize only regions that do have officers
            continue;
        }
        summaryDto.setOfficers(officers.intValue());
        Long informants = userService.countByCommunities(region.getDistricts(), UserRight.WEEKLYREPORT_CREATE);
        informants += userService.countByHealthFacilities(region.getDistricts(), UserRight.WEEKLYREPORT_CREATE);
        informants += userService.countByPointOfEntries(region.getDistricts(), UserRight.WEEKLYREPORT_CREATE);
        summaryDto.setInformants(informants.intValue());
        regionReportCriteria.reportingUserRegion(summaryDto.getRegion());
        regionReportCriteria.officerReport(true);
        regionReportCriteria.zeroReport(false);
        Long officerCaseReports = weeklyReportService.countByCriteria(regionReportCriteria, null);
        summaryDto.setOfficerCaseReports(officerCaseReports.intValue());
        regionReportCriteria.zeroReport(true);
        Long officerZeroReports = weeklyReportService.countByCriteria(regionReportCriteria, null);
        summaryDto.setOfficerZeroReports(officerZeroReports.intValue());
        regionReportCriteria.officerReport(false);
        regionReportCriteria.zeroReport(false);
        Long informantCaseReports = weeklyReportService.countByCriteria(regionReportCriteria, null);
        summaryDto.setInformantCaseReports(informantCaseReports.intValue());
        regionReportCriteria.zeroReport(true);
        Long informantZeroReports = weeklyReportService.countByCriteria(regionReportCriteria, null);
        summaryDto.setInformantZeroReports(informantZeroReports.intValue());
        summaryDtos.add(summaryDto);
    }
    return summaryDtos;
}
Also used : JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) ArrayList(java.util.ArrayList) WeeklyReportRegionSummaryDto(de.symeda.sormas.api.report.WeeklyReportRegionSummaryDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) WeeklyReportCriteria(de.symeda.sormas.api.report.WeeklyReportCriteria)

Example 2 with WeeklyReportCriteria

use of de.symeda.sormas.api.report.WeeklyReportCriteria in project SORMAS-Project by hzi-braunschweig.

the class WeeklyReportFacadeEjb method getSummariesPerOfficer.

@Override
public List<WeeklyReportOfficerSummaryDto> getSummariesPerOfficer(RegionReferenceDto regionRef, EpiWeek epiWeek) {
    WeeklyReportCriteria officerReportCriteria = new WeeklyReportCriteria().epiWeek(epiWeek);
    WeeklyReportCriteria informantsReportCriteria = new WeeklyReportCriteria().epiWeek(epiWeek).officerReport(false);
    Region region = regionService.getByReferenceDto(regionRef);
    Stream<User> officers = userService.getAllByDistrictsAndUserRights(region.getDistricts(), Collections.singletonList(UserRight.WEEKLYREPORT_CREATE)).stream();
    officers = weeklyReportService.filterWeeklyReportUsers(userService.getCurrentUser(), officers);
    List<WeeklyReportOfficerSummaryDto> summaryDtos = officers.sorted(Comparator.comparing(a -> a.getDistrict().getName())).map(officer -> {
        WeeklyReportOfficerSummaryDto summaryDto = new WeeklyReportOfficerSummaryDto();
        summaryDto.setOfficer(UserFacadeEjb.toReferenceDto(officer));
        summaryDto.setDistrict(DistrictFacadeEjb.toReferenceDto(officer.getDistrict()));
        {
            officerReportCriteria.reportingUser(new UserReferenceDto(officer.getUuid()));
            weeklyReportService.queryByCriteria(officerReportCriteria, null, null, true).stream().findFirst().ifPresent(officerReport -> {
                summaryDto.setOfficerReportDate(officerReport.getReportDateTime());
                summaryDto.setTotalCaseCount(officerReport.getTotalNumberOfCases());
            });
        }
        {
            Long informants = userService.countByAssignedOfficer(officer, UserRight.WEEKLYREPORT_CREATE);
            summaryDto.setInformants(informants.intValue());
        }
        informantsReportCriteria.assignedOfficer(summaryDto.getOfficer());
        {
            informantsReportCriteria.zeroReport(false);
            Long informantCaseReports = weeklyReportService.countByCriteria(informantsReportCriteria, null);
            summaryDto.setInformantCaseReports(informantCaseReports.intValue());
        }
        {
            informantsReportCriteria.zeroReport(true);
            Long informantZeroReports = weeklyReportService.countByCriteria(informantsReportCriteria, null);
            summaryDto.setInformantZeroReports(informantZeroReports.intValue());
        }
        return summaryDto;
    }).collect(Collectors.toList());
    return summaryDtos;
}
Also used : DtoHelper(de.symeda.sormas.backend.util.DtoHelper) RolesAllowed(javax.annotation.security.RolesAllowed) Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek) LoggerFactory(org.slf4j.LoggerFactory) CommunityFacadeEjb(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) Valid(javax.validation.Valid) WeeklyReportCriteria(de.symeda.sormas.api.report.WeeklyReportCriteria) TransactionAttributeType(javax.ejb.TransactionAttributeType) WeeklyReportDto(de.symeda.sormas.api.report.WeeklyReportDto) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) Stateless(javax.ejb.Stateless) FacilityService(de.symeda.sormas.backend.infrastructure.facility.FacilityService) CommunityService(de.symeda.sormas.backend.infrastructure.community.CommunityService) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Region(de.symeda.sormas.backend.infrastructure.region.Region) NotNull(javax.validation.constraints.NotNull) WeeklyReportEntryDto(de.symeda.sormas.api.report.WeeklyReportEntryDto) Collectors(java.util.stream.Collectors) TaskType(de.symeda.sormas.api.task.TaskType) PointOfEntryService(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntryService) List(java.util.List) UserService(de.symeda.sormas.backend.user.UserService) Stream(java.util.stream.Stream) DistrictFacadeEjb(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb) User(de.symeda.sormas.backend.user.User) LocalDate(java.time.LocalDate) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) TaskService(de.symeda.sormas.backend.task.TaskService) LocalDateTime(java.time.LocalDateTime) DateHelper(de.symeda.sormas.api.utils.DateHelper) FacilityFacadeEjb(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb) ArrayList(java.util.ArrayList) WeeklyReportOfficerSummaryDto(de.symeda.sormas.api.report.WeeklyReportOfficerSummaryDto) TransactionAttribute(javax.ejb.TransactionAttribute) TaskStatus(de.symeda.sormas.api.task.TaskStatus) LocalBean(javax.ejb.LocalBean) EJB(javax.ejb.EJB) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) TaskContext(de.symeda.sormas.api.task.TaskContext) WeeklyReportRegionSummaryDto(de.symeda.sormas.api.report.WeeklyReportRegionSummaryDto) Logger(org.slf4j.Logger) DataHelper(de.symeda.sormas.api.utils.DataHelper) Task(de.symeda.sormas.backend.task.Task) RegionFacadeEjb(de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) UserRight(de.symeda.sormas.api.user.UserRight) WeeklyReportFacade(de.symeda.sormas.api.report.WeeklyReportFacade) WeeklyReportReferenceDto(de.symeda.sormas.api.report.WeeklyReportReferenceDto) DateHelper8(de.symeda.sormas.backend.util.DateHelper8) Comparator(java.util.Comparator) Collections(java.util.Collections) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) User(de.symeda.sormas.backend.user.User) WeeklyReportOfficerSummaryDto(de.symeda.sormas.api.report.WeeklyReportOfficerSummaryDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) WeeklyReportCriteria(de.symeda.sormas.api.report.WeeklyReportCriteria)

Example 3 with WeeklyReportCriteria

use of de.symeda.sormas.api.report.WeeklyReportCriteria in project SORMAS-Project by hzi-braunschweig.

the class WeeklyReportService method queryByCriteria.

public List<WeeklyReport> queryByCriteria(WeeklyReportCriteria criteria, User user, String orderProperty, boolean asc) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<WeeklyReport> cq = cb.createQuery(WeeklyReport.class);
    Root<WeeklyReport> from = cq.from(WeeklyReport.class);
    Optional.ofNullable(orderProperty).map(from::get).map(p -> asc ? cb.asc(p) : cb.desc(p)).ifPresent(cq::orderBy);
    CriteriaBuilderHelper.and(cb, Optional.ofNullable(createUserFilter(cb, cq, from)), buildCriteriaFilter(criteria, cb, from)).ifPresent(cq::where);
    return em.createQuery(cq).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Join(javax.persistence.criteria.Join) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) EpiWeek(de.symeda.sormas.api.utils.EpiWeek) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) WeeklyReportCriteria(de.symeda.sormas.api.report.WeeklyReportCriteria) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) Predicate(javax.persistence.criteria.Predicate) AdoServiceWithUserFilter(de.symeda.sormas.backend.common.AdoServiceWithUserFilter) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) LocalBean(javax.ejb.LocalBean) UserRole(de.symeda.sormas.api.user.UserRole) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) From(javax.persistence.criteria.From) EJB(javax.ejb.EJB) Path(javax.persistence.criteria.Path) Root(javax.persistence.criteria.Root) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Region(de.symeda.sormas.backend.infrastructure.region.Region) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) List(java.util.List) UserService(de.symeda.sormas.backend.user.UserService) Stream(java.util.stream.Stream) User(de.symeda.sormas.backend.user.User) Optional(java.util.Optional) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel)

Aggregations

WeeklyReportCriteria (de.symeda.sormas.api.report.WeeklyReportCriteria)3 JurisdictionLevel (de.symeda.sormas.api.user.JurisdictionLevel)3 Region (de.symeda.sormas.backend.infrastructure.region.Region)3 WeeklyReportRegionSummaryDto (de.symeda.sormas.api.report.WeeklyReportRegionSummaryDto)2 EpiWeek (de.symeda.sormas.api.utils.EpiWeek)2 DistrictService (de.symeda.sormas.backend.infrastructure.district.DistrictService)2 RegionService (de.symeda.sormas.backend.infrastructure.region.RegionService)2 User (de.symeda.sormas.backend.user.User)2 UserService (de.symeda.sormas.backend.user.UserService)2 List (java.util.List)2 Stream (java.util.stream.Stream)2 EJB (javax.ejb.EJB)2 LocalBean (javax.ejb.LocalBean)2 Stateless (javax.ejb.Stateless)2 FacilityType (de.symeda.sormas.api.infrastructure.facility.FacilityType)1 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)1 WeeklyReportDto (de.symeda.sormas.api.report.WeeklyReportDto)1 WeeklyReportEntryDto (de.symeda.sormas.api.report.WeeklyReportEntryDto)1 WeeklyReportFacade (de.symeda.sormas.api.report.WeeklyReportFacade)1 WeeklyReportOfficerSummaryDto (de.symeda.sormas.api.report.WeeklyReportOfficerSummaryDto)1