ChildReportingService { public void pncVisitHappened(SafeMap reportData) { String id = reportData.get(CHILD_ID_FIELD); Child child = allChildren.findByCaseId(id); Location location = loadLocationOfChild(child); reportDIarrhea(reportData, child, location); reportVisitsThatHappenWithin24HoursOfHomeDelivery(reportData, child, 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 shouldReportChildDiarrheaEpisodeWhenPNCVisitHappens() { when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "opv_0", "5", "female") .withAnm("ANM X") .withDateOfBirth("2012-01-01") .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(parse("2012-01-01"), parse("2012-01-02"))).thenReturn(true); service.pncVisitHappened(new SafeMap(EasyMap.create("pncVisitDate", "2012-01-01") .put("id", "MOTHER-CASE-1") .put("childId", "CASE X") .put("urineStoolProblems", "diarrhea") .put("deliveryPlace", "home") .put("referenceDate", "2012-01-01") .put("pncVisitDate", "2012-01-01") .put("submissionDate", "2012-01-02") .map())); verifyBothReportingCalls(CHILD_DIARRHEA, "2012-01-01"); }
@Test public void shouldNotReportDiarrheaEpisodeWhenPNCVisitHappensAndThereAreNoUrineStoolProblems() { when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "opv_0", "5", "female") .withAnm("ANM X") .withDateOfBirth("2012-01-01") .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(parse("2012-01-01"), parse("2012-01-02"))).thenReturn(true); service.pncVisitHappened(new SafeMap(EasyMap.create("pncVisitDate", "2012-01-01") .put("id", "MOTHER-CASE-1") .put("childId", "CASE X") .put("urineStoolProblems", null) .put("deliveryPlace", "home") .put("referenceDate", "2012-01-01") .put("pncVisitDate", "2012-01-01") .put("submissionDate", "2012-01-02") .map())); verifyNoReportingCalls(CHILD_DIARRHEA, "2012-01-01"); }
@Test public void shouldNotReportDiarrheaEpisodeWhenPNCVisitHappensAndChildDoesNotHaveDiarrhea() { when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "opv_0", "5", "female") .withAnm("ANM X") .withDateOfBirth("2012-01-01") .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(parse("2012-01-01"), parse("2012-01-02"))).thenReturn(true); service.pncVisitHappened(new SafeMap(EasyMap.create("pncVisitDate", "2012-01-01") .put("id", "MOTHER-CASE-1") .put("childId", "CASE X") .put("urineStoolProblems", "vomiting") .put("deliveryPlace", "home") .put("referenceDate", "2012-01-01") .put("pncVisitDate", "2012-01-01") .put("submissionDate", "2012-01-02") .map())); verifyNoReportingCalls(CHILD_DIARRHEA, "2012-01-01"); }
@Test public void shouldReportPNCVisitThatHappenOnTheSameDayOfHomeDelivery() { when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "opv_0", "5", "female") .withAnm("ANM X") .withDateOfBirth("2012-01-01") .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(parse("2012-01-01"), parse("2012-01-02"))).thenReturn(true); service.pncVisitHappened(new SafeMap(EasyMap.create("pncVisitDate", "2012-01-01") .put("id", "MOTHER-CASE-1") .put("childId", "CASE X") .put("urineStoolProblems", "diarrhea") .put("deliveryPlace", "home") .put("referenceDate", "2012-01-01") .put("pncVisitDate", "2012-01-01") .put("submissionDate", "2012-01-02") .map())); verifyBothReportingCalls(NRHM_PNC24, "2012-01-01"); }
@Test public void shouldReportPNCVisitThatHappenNextDayOfHomeDelivery() { when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "opv_0", "5", "female") .withAnm("ANM X") .withDateOfBirth("2012-01-01") .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(parse("2012-01-02"), parse("2012-01-02"))).thenReturn(true); service.pncVisitHappened(new SafeMap(EasyMap.create("pncVisitDate", "2012-01-01") .put("id", "MOTHER-CASE-1") .put("childId", "CASE X") .put("urineStoolProblems", "diarrhea") .put("deliveryPlace", "home") .put("referenceDate", "2012-01-01") .put("pncVisitDate", "2012-01-02") .put("submissionDate", "2012-01-02") .map())); verifyBothReportingCalls(NRHM_PNC24, "2012-01-02"); }
@Test public void shouldNotReportPNCVisitThatHappenTwoOrMoreDaysOfHomeDelivery() { when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "opv_0", "5", "female") .withAnm("ANM X") .withDateOfBirth("2012-01-01") .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(parse("2012-01-01"), parse("2012-01-02"))).thenReturn(true); service.pncVisitHappened(new SafeMap(EasyMap.create("pncVisitDate", "2012-01-01") .put("id", "MOTHER-CASE-1") .put("childId", "CASE X") .put("urineStoolProblems", "diarrhea") .put("deliveryPlace", "home") .put("referenceDate", "2012-01-01") .put("pncVisitDate", "2012-01-03") .put("submissionDate", "2012-01-02") .map())); verifyNoReportingCalls(NRHM_PNC24, "2012-01-01"); }
@Test public void shouldNotReportPNCVisitForNonHomeDelivery() { when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "opv_0", "5", "female") .withAnm("ANM X") .withDateOfBirth("2012-01-01") .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(parse("2012-01-01"), parse("2012-01-02"))).thenReturn(true); service.pncVisitHappened(new SafeMap(EasyMap.create("pncVisitDate", "2012-01-01") .put("id", "MOTHER-CASE-1") .put("childId", "CASE X") .put("urineStoolProblems", "diarrhea") .put("deliveryPlace", "phc") .put("referenceDate", "2012-01-01") .put("pncVisitDate", "2012-01-03") .put("submissionDate", "2012-01-02") .map())); verifyNoReportingCalls(NRHM_PNC24, "2012-01-01"); }