ChildReportingService { public void reportToBoth(Child child, Indicator indicator, String serviceProvidedDate, String submissionDate, Location location) { if (!reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse(serviceProvidedDate), LocalDate.parse(submissionDate))) return; report(child, indicator, serviceProvidedDate, location); } @Autowired  ChildReportingService(ReportingService reportingService, AllChildren allChildren, AllMothers allMothers,
                                 AllEligibleCouples allEligibleCouples,
                                 AllInfantBalanceOnHandReportTokens allInfantBalanceOnHandReportTokens, ReportMonth reportMonth, MCTSReporter mctsReporter); void registerChild(SafeMap reportData); void immunizationProvided(SafeMap reportData, List<String> previousImmunizations); void vitaminAProvided(SafeMap reportData); void pncVisitHappened(SafeMap reportData); void sickVisitHappened(SafeMap reportData); void closeChild(SafeMap reportData); void reportToBoth(Child child, Indicator indicator, String serviceProvidedDate, String submissionDate, Location location); void reportToBoth(Child child, Indicator indicator, String serviceProvidedDate, Location location); void reportInfantAndChildBalance(); void reportInfantBalanceOnHand(); void reportInfantBalanceTurningOneYearOld(); void reportInfantBalanceTotalNumberOfOAChildren(); void reportInfantBalanceLessThanOneYearOld(); void reportChildBalanceLessThanFiveYearOld(); static final String CHILD_ID_FIELD; }
@Test public void shouldUseECNumberAsExternalIdWhenThayiCardNumberIsNotPresent() throws Exception { DateUtil.fakeIt(parse("2013-02-01")); Child child = new Child("child id 1", "mother id 1", "bcg", "3", "female").withAnm("ANM X"); Mother mother = new Mother("mother id 1", "ec id 1", "thayi card 1"); EligibleCouple ec = new EligibleCouple("ec id 1", "123").withLocation("bherya", "Sub Center", "PHC X").asOutOfArea(); Location location = new Location("bherya", "Sub Center", "PHC X"); when(allMothers.findByCaseId("mother id 1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("ec id 1")).thenReturn(ec); when(reportMonth.isDateWithinCurrentReportMonth(LocalDate.parse("2013-01-01"))).thenReturn(true); service.reportToBoth(child, Indicator.FP_IUD, "2013-01-01", location); verifyBothReportingCalls(Indicator.FP_IUD, "2013-01-01", "child id 1", "123"); }
@Test public void shouldNotReportWhenServiceProvidedDateAndFormSubmissionDateBelongToDifferentReportingMonth() throws Exception { Child child = new Child("child id 1", "mother id 1", "bcg", "3", "female").withAnm("ANM X"); Location location = new Location("bherya", "Sub Center", "PHC X"); when(reportMonth.areDatesBelongToSameReportingMonth(parse("2013-01-01"), parse("2013-01-26"))).thenReturn(false); service.reportToBoth(child, Indicator.FP_IUD, "2013-01-01", "2013-01-26", location); verify(reportMonth).areDatesBelongToSameReportingMonth(parse("2013-01-01"), parse("2013-01-26")); verifyZeroInteractions(reportingService); }