ChildReportingService { public void vitaminAProvided(SafeMap reportData) { Child child = allChildren.findByCaseId(reportData.get(ID)); Location location = loadLocationOfChild(child); if (child.isFemale()) { reportVitaminADose1ForFemaleChild(reportData, child, location); reportVitaminADose2ForFemaleChild(reportData, child, location); reportVitaminADose5ForFemaleChild(reportData, child, location); reportVitaminADose9ForFemaleChild(reportData, child, location); reportForVitaminADose_1_2_5_9(reportData, child, location, VIT_A_FOR_FEMALE); } else if (child.isMale()) { reportVitaminADose1ForMaleChild(reportData, child, location); reportVitaminADose2ForMaleChild(reportData, child, location); reportVitaminADose5ForMaleChild(reportData, child, location); reportVitaminADose9ForMaleChild(reportData, child, location); reportForVitaminADose_1_2_5_9(reportData, child, location, VIT_A_FOR_MALE); } } @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 shouldReportFirstVitaminDoseDuringImmunizationProvidedForFemaleChild() throws Exception { SafeMap reportingData = reportDataForVitaminA("1", "2012-01-02", "2012-01-02"); when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "bcg", "3", "female") .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-02"), LocalDate.parse("2012-01-02"))).thenReturn(true); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); service.vitaminAProvided(reportingData); verifyBothReportingCalls(VIT_A_1, "2012-01-02"); verifyBothReportingCalls(VIT_A_1_FOR_FEMALE_CHILD, "2012-01-02"); verifyBothReportingCalls(VIT_A_FOR_FEMALE, "2012-01-02"); verifyNoMoreInteractions(reportingService); }
@Test public void shouldReportSecondVitaminDoseDuringImmunizationProvidedForFemaleChild() throws Exception { SafeMap reportingData = reportDataForVitaminA("2", "2012-01-02", "2012-01-02"); when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "bcg", "3", "female") .withAnm("ANM X") .withThayiCard("TC 1")); 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-02"), LocalDate.parse("2012-01-02"))).thenReturn(true); service.vitaminAProvided(reportingData); verifyBothReportingCalls(VIT_A_2, "2012-01-02"); verifyBothReportingCalls(VIT_A_2_FOR_FEMALE_CHILD, "2012-01-02"); verifyBothReportingCalls(VIT_A_FOR_FEMALE, "2012-01-02"); verifyNoMoreInteractions(reportingService); }
@Test public void shouldReportFifthVitaminDoseDuringImmunizationProvidedForFemaleChild() throws Exception { SafeMap reportingData = reportDataForVitaminA("5", "2012-01-02", "2012-01-02"); when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "bcg", "3", "female") .withAnm("ANM X") .withThayiCard("TC 1")); 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-02"), LocalDate.parse("2012-01-02"))).thenReturn(true); service.vitaminAProvided(reportingData); verifyBothReportingCalls(VIT_A_FOR_FEMALE, "2012-01-02"); verifyBothReportingCalls(VIT_A_5_FOR_FEMALE_CHILD, "2012-01-02"); verifyNoMoreInteractions(reportingService); }
@Test public void shouldReportNinthVitaminDoseDuringImmunizationProvidedForFemaleChild() throws Exception { SafeMap reportingData = reportDataForVitaminA("9", "2012-01-02", "2012-01-02"); when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "bcg", "3", "female") .withAnm("ANM X") .withThayiCard("TC 1")); 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-02"), LocalDate.parse("2012-01-02"))).thenReturn(true); service.vitaminAProvided(reportingData); verifyBothReportingCalls(VIT_A_FOR_FEMALE, "2012-01-02"); verifyBothReportingCalls(VIT_A_9_FOR_FEMALE_CHILD, "2012-01-02"); verifyNoMoreInteractions(reportingService); }
@Test public void shouldReportFirstVitaminDoseDuringImmunizationProvidedForMaleChild() throws Exception { SafeMap reportingData = reportDataForVitaminA("1", "2012-01-02", "2012-01-02"); when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "bcg", "3", "male") .withAnm("ANM X") .withThayiCard("TC 1")); 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-02"), LocalDate.parse("2012-01-02"))).thenReturn(true); service.vitaminAProvided(reportingData); verifyBothReportingCalls(VIT_A_1, "2012-01-02"); verifyBothReportingCalls(VIT_A_1_FOR_MALE_CHILD, "2012-01-02"); verifyBothReportingCalls(VIT_A_FOR_MALE, "2012-01-02"); verifyNoMoreInteractions(reportingService); }
@Test public void shouldReportSecondVitaminDoseDuringImmunizationProvidedForMaleChild() throws Exception { SafeMap reportingData = reportDataForVitaminA("2", "2012-01-02", "2012-01-02"); when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "bcg", "3", "male") .withAnm("ANM X") .withThayiCard("TC 1")); 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-02"), LocalDate.parse("2012-01-02"))).thenReturn(true); service.vitaminAProvided(reportingData); verifyBothReportingCalls(VIT_A_2, "2012-01-02"); verifyBothReportingCalls(VIT_A_2_FOR_MALE_CHILD, "2012-01-02"); verifyBothReportingCalls(VIT_A_FOR_MALE, "2012-01-02"); verifyNoMoreInteractions(reportingService); }
@Test public void shouldReportFifthVitaminDoseDuringImmunizationProvidedForMaleChild() throws Exception { SafeMap reportingData = reportDataForVitaminA("5", "2012-01-02", "2012-01-02"); when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "bcg", "3", "male") .withAnm("ANM X") .withThayiCard("TC 1")); 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-02"), LocalDate.parse("2012-01-02"))).thenReturn(true); service.vitaminAProvided(reportingData); verifyBothReportingCalls(VIT_A_5_FOR_MALE_CHILD, "2012-01-02"); verifyBothReportingCalls(VIT_A_FOR_MALE, "2012-01-02"); verifyNoMoreInteractions(reportingService); }
@Test public void shouldReportNinthVitaminDoseDuringImmunizationProvidedForMaleChild() throws Exception { SafeMap reportingData = reportDataForVitaminA("9", "2012-01-02", "2012-01-02"); when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "bcg", "3", "male") .withAnm("ANM X") .withThayiCard("TC 1")); 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-02"), LocalDate.parse("2012-01-02"))).thenReturn(true); service.vitaminAProvided(reportingData); verifyBothReportingCalls(VIT_A_FOR_MALE, "2012-01-02"); verifyBothReportingCalls(VIT_A_9_FOR_MALE_CHILD, "2012-01-02"); verifyNoMoreInteractions(reportingService); }
@Test public void shouldNotReportThirdVitaminDoseDuringImmunizationProvidedForMaleChild() throws Exception { SafeMap reportingData = reportDataForVitaminA("3", "2012-01-02", "2012-01-02"); when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "bcg", "3", "male") .withAnm("ANM X") .withThayiCard("TC 1")); 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-02"), LocalDate.parse("2012-01-02"))).thenReturn(true); service.vitaminAProvided(reportingData); verifyNoMoreInteractions(reportingService); }