WeeklyReportFacadeEjb implements WeeklyReportFacade { @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.getAllByRegionAndUserRolesInJurisdiction(region, UserRole.SURVEILLANCE_OFFICER).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, UserRole.HOSPITAL_INFORMANT, UserRole.COMMUNITY_INFORMANT); 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; }  @Override List<WeeklyReportDto> getAllWeeklyReportsAfter(Date date); @Override List<WeeklyReportDto> getByUuids(List<String> uuids); @Override WeeklyReportDto getByUuid(String uuid); @Override WeeklyReportDto saveWeeklyReport(WeeklyReportDto dto); @Override List<String> getAllUuids(); @Override List<WeeklyReportRegionSummaryDto> getSummariesPerRegion(EpiWeek epiWeek); @Override List<WeeklyReportOfficerSummaryDto> getSummariesPerOfficer(RegionReferenceDto regionRef, EpiWeek epiWeek); @Override WeeklyReportDto getByEpiWeekAndUser(EpiWeek epiWeek, UserReferenceDto userRef); WeeklyReport fromDto(@NotNull WeeklyReportDto source); WeeklyReportEntry fromDto(WeeklyReportEntryDto source); static WeeklyReportReferenceDto toReferenceDto(WeeklyReport entity); static WeeklyReportDto toDto(WeeklyReport source); static WeeklyReportEntryDto toDto(WeeklyReportEntry source); @RolesAllowed(UserRole._SYSTEM) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) void generateSubmitWeeklyReportTasks();  }
@Test public void testGetSummariesPerOfficer() { EpiWeek previousEpiWeek = DateHelper.getPreviousEpiWeek(new Date()); createFacilityInformantReport(informant1, new Date(), previousEpiWeek.getWeek(), previousEpiWeek.getYear(), 1); createCommunityInformantReport(informant3, new Date(), previousEpiWeek.getWeek(), previousEpiWeek.getYear(), 1); createFacilityInformantReport(informant4, new Date(), previousEpiWeek.getWeek(), previousEpiWeek.getYear(), 0); List<WeeklyReportOfficerSummaryDto> summariesPerRegion = getWeeklyReportFacade().getSummariesPerOfficer(officer.getRegion(), previousEpiWeek); assertEquals(1, summariesPerRegion.size()); WeeklyReportOfficerSummaryDto summary = summariesPerRegion.get(0); assertEquals(4, summary.getInformants()); assertEquals(2, summary.getInformantCaseReports()); assertEquals(1, summary.getInformantZeroReports()); assertEquals(1, summary.getInformantMissingReports()); }