ChildReportingService { public void reportInfantBalanceTotalNumberOfOAChildren() { List<EligibleCouple> outOfAreaCouples = allEligibleCouples.findAllOutOfAreaCouples(); List<String> ecIds = extract(outOfAreaCouples, on(EligibleCouple.class).caseId()); List<Mother> outOfAreaMothers = allMothers.findAllOpenMothersByECCaseId(ecIds); List<String> motherIds = extract(outOfAreaMothers, on(Mother.class).caseId()); List<Child> outOfAreaChildren = allChildren.findAllOpenChildrenByMotherId(motherIds); logger.info(MessageFormat.format("Found {0} children for reporting Infant Balance (O/A children) ", outOfAreaChildren.size())); updateInfantBalanceOAChildren(outOfAreaChildren, outOfAreaMothers, outOfAreaCouples, Indicator.INFANT_BALANCE_OA_CHILDREN, DateUtil.today().toString()); } @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 shouldReportTotalNumberOfOAChildrenWhenInfantBalanceIsReported() throws Exception { DateUtil.fakeIt(parse("2013-02-01")); Mother mother = new Mother("mother id 1", "ec id 1", "thayi card 1"); Child child = new Child("child id 1", "mother id 1", "bcg", "3", "female").withThayiCard("thayi card 1").withAnm("ANM X"); EligibleCouple ec = new EligibleCouple("ec id 1", "123").withLocation("bherya", "Sub Center", "PHC X").asOutOfArea(); when(allEligibleCouples.findAllOutOfAreaCouples()).thenReturn(asList(ec)); when(allMothers.findAllOpenMothersByECCaseId(asList("ec id 1"))).thenReturn(asList(mother)); when(allMothers.findAllOpenMothersByECCaseId(asList("ec id 1"))).thenReturn(asList(mother)); when(allChildren.findAllOpenChildrenByMotherId(asList("mother id 1"))).thenReturn(asList(child)); when(reportMonth.startOfCurrentReportMonth(parse("2013-02-01"))).thenReturn(parse("2013-01-26")); when(reportMonth.endOfCurrentReportMonth(parse("2013-02-01"))).thenReturn(parse("2013-02-25")); when(reportMonth.isDateWithinCurrentReportMonth(any(LocalDate.class))).thenReturn(true); service.reportInfantBalanceTotalNumberOfOAChildren(); verifyBothUpdateReportCalls(Indicator.INFANT_BALANCE_OA_CHILDREN, "2013-02-01", "child id 1", "thayi card 1", "2013-01-26", "2013-02-25"); }
@Test public void shouldReportTotalNumberOfOAChildrenWithExternalIdAsECNumberIfThayiCardNumberIsNotPresent() throws Exception { DateUtil.fakeIt(parse("2013-02-01")); Mother mother = new Mother("mother id 1", "ec id 1", null); Child child = new Child("child id 1", "mother id 1", "bcg", "3", "female").withAnm("ANM X"); EligibleCouple ec = new EligibleCouple("ec id 1", "123").withLocation("bherya", "Sub Center", "PHC X").asOutOfArea(); when(allEligibleCouples.findAllOutOfAreaCouples()).thenReturn(asList(ec)); when(allMothers.findAllOpenMothersByECCaseId(asList("ec id 1"))).thenReturn(asList(mother)); when(allMothers.findAllOpenMothersByECCaseId(asList("ec id 1"))).thenReturn(asList(mother)); when(allChildren.findAllOpenChildrenByMotherId(asList("mother id 1"))).thenReturn(asList(child)); when(reportMonth.startOfCurrentReportMonth(parse("2013-02-01"))).thenReturn(parse("2013-01-26")); when(reportMonth.endOfCurrentReportMonth(parse("2013-02-01"))).thenReturn(parse("2013-02-25")); when(reportMonth.isDateWithinCurrentReportMonth(any(LocalDate.class))).thenReturn(true); service.reportInfantBalanceTotalNumberOfOAChildren(); verifyBothUpdateReportCalls(Indicator.INFANT_BALANCE_OA_CHILDREN, "2013-02-01", "child id 1", "123", "2013-01-26", "2013-02-25"); }