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