ChildReportingService { public void immunizationProvided(SafeMap reportData, List<String> previousImmunizations) { Child child = allChildren.findByCaseId(reportData.get(ID)); List<String> immunizations = new ArrayList<>(asList(reportData.get(IMMUNIZATIONS_GIVEN_FIELD_NAME).split(" "))); immunizations.removeAll(previousImmunizations); Location location = loadLocationOfChild(child); reportImmunizations(child, immunizations, location, reportData.get(IMMUNIZATION_DATE_FIELD_NAME), reportData.get(SUBMISSION_DATE_FIELD_NAME)); } @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 shouldMakeAReportingCallForEachNewlyProvidedImmunization() throws Exception { SafeMap reportingData = reportDataForImmunization("opv_1 bcg measles", "", "2012-01-01"); when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "bcg", "3", "female") .withLocation("bherya", "Sub Center", "PHC X") .withAnm("ANM X") .withThayiCard("TC 1")); when(allMothers.findByCaseId("MOTHER-CASE-1")).thenReturn(new Mother("MOTHER-CASE-1", "EC-CASE-1", "TC 1")); when(reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); service.immunizationProvided(reportingData, asList("opv_1")); verifyBothReportingCalls(BCG, "2012-01-01"); verifyBothReportingCalls(MEASLES, "2012-01-01"); verifyNoMoreInteractions(reportingService); }
@Test public void shouldNotSendChildReportingDataWhenWrongImmunizationIsProvided() throws Exception { SafeMap reportingData = new SafeMap(); reportingData.put("anmIdentifier", "ANM X"); reportingData.put("immunizationDate", "2012-01-01"); reportingData.put("submissionDate", "2012-01-01"); when(allChildren.findByCaseId("CASE X")).thenReturn(CHILD); when(allMothers.findByCaseId("MOTHER-CASE-1")).thenReturn(new Mother("MOTHER-CASE-1", "EC-CASE-1", "TC 1")); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); service.immunizationProvided(reportDataForImmunization("NON_EXISTENT_IMMUNIZATION bcg", "", "2012-01-01"), new ArrayList<String>()); verifyBothReportingCalls(BCG, "2012-01-01"); verifyNoMoreInteractions(reportingService); }