@Test public void shouldGetPeriodsEmptyListOfPeriodsForFacility()throws Exception { Date startDate = new Date(2015,2,2); Date endDate = new Date(); when(repository.getLastReport(2L, 2L)).thenReturn(null); when(programService.getProgramStartDate(2L, 2L)).thenReturn(startDate); when(periodService.getAllPeriodsForDateRange(1L, startDate, endDate)).thenReturn(null); List<ReportStatusDTO> response = service.getPeriodsFor(2L, 2L, endDate); assertThat(response.size(), is(0)); }
public List<ReportStatusDTO> getPeriodsFor(Long facilityId, Long programId, Date endDate) { Date startDate = programService.getProgramStartDate(facilityId, programId); Long scheduleId = repository.getScheduleFor(facilityId, programId); VaccineReport lastRequest = repository.getLastReport(facilityId, programId); if (lastRequest != null) { lastRequest.setPeriod(periodService.getById(lastRequest.getPeriodId())); startDate = lastRequest.getPeriod().getStartDate(); } List<ReportStatusDTO> results = new ArrayList<>(); List<ProcessingPeriod> periods = periodService.getAllPeriodsForDateRange(scheduleId, startDate, endDate); if (lastRequest != null && lastRequest.getStatus().equals(ReportStatus.DRAFT)) { ReportStatusDTO reportStatusDTO = new ReportStatusDTO(); reportStatusDTO.setPeriodName(lastRequest.getPeriod().getName()); reportStatusDTO.setPeriodId(lastRequest.getPeriod().getId()); reportStatusDTO.setStatus(lastRequest.getStatus().toString()); reportStatusDTO.setProgramId(programId); reportStatusDTO.setFacilityId(facilityId); reportStatusDTO.setId(lastRequest.getId()); results.add(reportStatusDTO); } for (ProcessingPeriod period : emptyIfNull(periods)) { if (lastRequest == null || !lastRequest.getPeriodId().equals(period.getId())) { ReportStatusDTO reportStatusDTO = new ReportStatusDTO(); reportStatusDTO.setPeriodName(period.getName()); reportStatusDTO.setPeriodId(period.getId()); reportStatusDTO.setProgramId(programId); reportStatusDTO.setFacilityId(facilityId); results.add(reportStatusDTO); } } return results; }
VaccineReportService { public List<ReportStatusDTO> getPeriodsFor(Long facilityId, Long programId, Date endDate) { Date startDate = programService.getProgramStartDate(facilityId, programId); Long scheduleId = repository.getScheduleFor(facilityId, programId); VaccineReport lastRequest = repository.getLastReport(facilityId, programId); if (lastRequest != null) { lastRequest.setPeriod(periodService.getById(lastRequest.getPeriodId())); startDate = lastRequest.getPeriod().getStartDate(); } List<ReportStatusDTO> results = new ArrayList<>(); List<ProcessingPeriod> periods = periodService.getAllPeriodsForDateRange(scheduleId, startDate, endDate); if (lastRequest != null && lastRequest.getStatus().equals(ReportStatus.DRAFT)) { ReportStatusDTO reportStatusDTO = new ReportStatusDTO(); reportStatusDTO.setPeriodName(lastRequest.getPeriod().getName()); reportStatusDTO.setPeriodId(lastRequest.getPeriod().getId()); reportStatusDTO.setStatus(lastRequest.getStatus().toString()); reportStatusDTO.setProgramId(programId); reportStatusDTO.setFacilityId(facilityId); reportStatusDTO.setId(lastRequest.getId()); results.add(reportStatusDTO); } for (ProcessingPeriod period : emptyIfNull(periods)) { if (lastRequest == null || !lastRequest.getPeriodId().equals(period.getId())) { ReportStatusDTO reportStatusDTO = new ReportStatusDTO(); reportStatusDTO.setPeriodName(period.getName()); reportStatusDTO.setPeriodId(period.getId()); reportStatusDTO.setProgramId(programId); reportStatusDTO.setFacilityId(facilityId); results.add(reportStatusDTO); } } return results; } }
VaccineReportService { public List<ReportStatusDTO> getPeriodsFor(Long facilityId, Long programId, Date endDate) { Date startDate = programService.getProgramStartDate(facilityId, programId); Long scheduleId = repository.getScheduleFor(facilityId, programId); VaccineReport lastRequest = repository.getLastReport(facilityId, programId); if (lastRequest != null) { lastRequest.setPeriod(periodService.getById(lastRequest.getPeriodId())); startDate = lastRequest.getPeriod().getStartDate(); } List<ReportStatusDTO> results = new ArrayList<>(); List<ProcessingPeriod> periods = periodService.getAllPeriodsForDateRange(scheduleId, startDate, endDate); if (lastRequest != null && lastRequest.getStatus().equals(ReportStatus.DRAFT)) { ReportStatusDTO reportStatusDTO = new ReportStatusDTO(); reportStatusDTO.setPeriodName(lastRequest.getPeriod().getName()); reportStatusDTO.setPeriodId(lastRequest.getPeriod().getId()); reportStatusDTO.setStatus(lastRequest.getStatus().toString()); reportStatusDTO.setProgramId(programId); reportStatusDTO.setFacilityId(facilityId); reportStatusDTO.setId(lastRequest.getId()); results.add(reportStatusDTO); } for (ProcessingPeriod period : emptyIfNull(periods)) { if (lastRequest == null || !lastRequest.getPeriodId().equals(period.getId())) { ReportStatusDTO reportStatusDTO = new ReportStatusDTO(); reportStatusDTO.setPeriodName(period.getName()); reportStatusDTO.setPeriodId(period.getId()); reportStatusDTO.setProgramId(programId); reportStatusDTO.setFacilityId(facilityId); results.add(reportStatusDTO); } } return results; }  }
VaccineReportService { public List<ReportStatusDTO> getPeriodsFor(Long facilityId, Long programId, Date endDate) { Date startDate = programService.getProgramStartDate(facilityId, programId); Long scheduleId = repository.getScheduleFor(facilityId, programId); VaccineReport lastRequest = repository.getLastReport(facilityId, programId); if (lastRequest != null) { lastRequest.setPeriod(periodService.getById(lastRequest.getPeriodId())); startDate = lastRequest.getPeriod().getStartDate(); } List<ReportStatusDTO> results = new ArrayList<>(); List<ProcessingPeriod> periods = periodService.getAllPeriodsForDateRange(scheduleId, startDate, endDate); if (lastRequest != null && lastRequest.getStatus().equals(ReportStatus.DRAFT)) { ReportStatusDTO reportStatusDTO = new ReportStatusDTO(); reportStatusDTO.setPeriodName(lastRequest.getPeriod().getName()); reportStatusDTO.setPeriodId(lastRequest.getPeriod().getId()); reportStatusDTO.setStatus(lastRequest.getStatus().toString()); reportStatusDTO.setProgramId(programId); reportStatusDTO.setFacilityId(facilityId); reportStatusDTO.setId(lastRequest.getId()); results.add(reportStatusDTO); } for (ProcessingPeriod period : emptyIfNull(periods)) { if (lastRequest == null || !lastRequest.getPeriodId().equals(period.getId())) { ReportStatusDTO reportStatusDTO = new ReportStatusDTO(); reportStatusDTO.setPeriodName(period.getName()); reportStatusDTO.setPeriodId(period.getId()); reportStatusDTO.setProgramId(programId); reportStatusDTO.setFacilityId(facilityId); results.add(reportStatusDTO); } } return results; }  @Transactional VaccineReport initialize(Long facilityId, Long programId, Long periodId, Long userId); @Transactional void save(VaccineReport report, Long userId); @Transactional void submit(VaccineReport report, Long userId); List<ReportStatusDTO> getReportedPeriodsFor(Long facilityId, Long programId); List<ReportStatusDTO> getPeriodsFor(Long facilityId, Long programId, Date endDate); VaccineReport getById(Long id); Long getReportIdForFacilityAndPeriod(Long facilityId, Long periodId); List<HashMap<String, Object>> vaccineUsageTrend(String facilityCode, String productCode, Long periodId, Long zoneId); Map<String, Object> getMonthlyVaccineReport(Long facilityId, Long periodId, Long zoneId); }
VaccineReportService { public List<ReportStatusDTO> getPeriodsFor(Long facilityId, Long programId, Date endDate) { Date startDate = programService.getProgramStartDate(facilityId, programId); Long scheduleId = repository.getScheduleFor(facilityId, programId); VaccineReport lastRequest = repository.getLastReport(facilityId, programId); if (lastRequest != null) { lastRequest.setPeriod(periodService.getById(lastRequest.getPeriodId())); startDate = lastRequest.getPeriod().getStartDate(); } List<ReportStatusDTO> results = new ArrayList<>(); List<ProcessingPeriod> periods = periodService.getAllPeriodsForDateRange(scheduleId, startDate, endDate); if (lastRequest != null && lastRequest.getStatus().equals(ReportStatus.DRAFT)) { ReportStatusDTO reportStatusDTO = new ReportStatusDTO(); reportStatusDTO.setPeriodName(lastRequest.getPeriod().getName()); reportStatusDTO.setPeriodId(lastRequest.getPeriod().getId()); reportStatusDTO.setStatus(lastRequest.getStatus().toString()); reportStatusDTO.setProgramId(programId); reportStatusDTO.setFacilityId(facilityId); reportStatusDTO.setId(lastRequest.getId()); results.add(reportStatusDTO); } for (ProcessingPeriod period : emptyIfNull(periods)) { if (lastRequest == null || !lastRequest.getPeriodId().equals(period.getId())) { ReportStatusDTO reportStatusDTO = new ReportStatusDTO(); reportStatusDTO.setPeriodName(period.getName()); reportStatusDTO.setPeriodId(period.getId()); reportStatusDTO.setProgramId(programId); reportStatusDTO.setFacilityId(facilityId); results.add(reportStatusDTO); } } return results; }  @Transactional VaccineReport initialize(Long facilityId, Long programId, Long periodId, Long userId); @Transactional void save(VaccineReport report, Long userId); @Transactional void submit(VaccineReport report, Long userId); List<ReportStatusDTO> getReportedPeriodsFor(Long facilityId, Long programId); List<ReportStatusDTO> getPeriodsFor(Long facilityId, Long programId, Date endDate); VaccineReport getById(Long id); Long getReportIdForFacilityAndPeriod(Long facilityId, Long periodId); List<HashMap<String, Object>> vaccineUsageTrend(String facilityCode, String productCode, Long periodId, Long zoneId); Map<String, Object> getMonthlyVaccineReport(Long facilityId, Long periodId, Long zoneId); static final String VACCINE_REPORT_VACCINE_CATEGORY_CODE; static final String VACCINE_REPORT_VITAMINS_CATEGORY_CODE; static final String VACCINE_REPORT_SYRINGES_CATEGORY_CODE; }