PatientDataService { public List<Period> calculatePeriods(VIAReportType VIAReportType) { List<Period> periods = new ArrayList<>(); if (VIAReportType.equals(MALARIA)) { calculateMalariaPeriods(periods); } else { calculatePTVPeriods(periods); } return periods; }  List<Period> calculatePeriods(VIAReportType VIAReportType); List<StockCard> getMalariaProductsStockCards(); List<Long> getMalariaProductsStockHand(); Optional<MalariaProgram> save(MalariaProgram malariaProgram); MalariaProgram findForPeriod(DateTime beginDate, DateTime endDate); List<Product> getMalariaProducts();  }
@Test public void shouldNotReturnPeriodsWhenThereAreNotPatientDataReportedAndCurrentPeriodIsNotOpenToRequisitions() throws LMISException { LMISTestApp.getInstance().setCurrentTimeMillis(DateTime.parse("2017-09-13").getMillis()); when(malariaProgramRepository.getFirstMovement()).thenReturn(null); List<Period> periods = patientDataService.calculatePeriods(VIAReportType.MALARIA); assertThat(periods.isEmpty(), is(true)); }
@Test public void shouldReturnCurrentPeriodWhenThereAreNotPatientDataReportedAndCurrentPeriodIsOpenToRequisitions() throws LMISException { DateTime today = calculateDateWithinRequisitionPeriod(); LMISTestApp.getInstance().setCurrentTimeMillis(today.getMillis()); when(malariaProgramRepository.getFirstMovement()).thenReturn(null); Period expectedPeriod = new Period(new DateTime(LMISTestApp.getInstance().getCurrentTimeMillis())); List<Period> periods = patientDataService.calculatePeriods(VIAReportType.MALARIA); assertThat(EqualsBuilder.reflectionEquals(expectedPeriod, periods.get(FIRST_PERIOD_POSITION)), is(true)); }
@Test public void shouldReturnPeriodsStartingFromFirstPatientDataReportedIncludingCurrent() throws LMISException { DateTime firstReportedDate = calculateDateWithinRequisitionPeriod(); DateTime today = calculateValidDateForRequisitionPeriodWithinTwelveMonths(firstReportedDate); LMISTestApp.getInstance().setCurrentTimeMillis(today.getMillis()); malariaProgram.setReportedDate(firstReportedDate); malariaProgram.setCreatedAt(firstReportedDate.toDate()); when(malariaProgramRepository.getFirstMovement()).thenReturn(malariaProgram); List<Period> periods = patientDataService.calculatePeriods(VIAReportType.MALARIA); assertThat(periods.size(), is(monthsAfterInitialReportedDate + CURRENT_MONTH)); }
@Test public void shouldReturnPeriodsStartingFromFirstPatientDataReportedExcludingCurrentWhenCurrentDateIsNotOpenToRequisitions() throws LMISException { DateTime firstReportedDate = calculateDateWithinRequisitionPeriod(); DateTime futureToday = calculateInvalidDateForRequisitionPeriodWithinTwelveMonths(firstReportedDate); LMISTestApp.getInstance().setCurrentTimeMillis(futureToday.getMillis()); malariaProgram.setReportedDate(firstReportedDate); malariaProgram.setCreatedAt(firstReportedDate.toDate()); when(malariaProgramRepository.getFirstMovement()).thenReturn(malariaProgram); List<Period> periods = patientDataService.calculatePeriods(VIAReportType.MALARIA); assertThat(periods.size(), is(monthsAfterInitialReportedDate)); }