ChildReportingService { public void sickVisitHappened(SafeMap reportData) { String id = reportData.get(ID); Child child = allChildren.findByCaseId(id); Location location = loadLocationOfChild(child); LocalDate childDateOfBirth = parse(child.dateOfBirth()); String submissionDate = reportData.get(SUBMISSION_DATE_FIELD_NAME); if (childDateOfBirth.plusYears(CHILD_DIARRHEA_THRESHOLD_IN_YEARS).isAfter(LocalDate.parse(submissionDate))) { if (!isBlank(reportData.get(CHILD_SIGNS)) && reportData.get(CHILD_SIGNS).contains(AllConstants.CommonChildFormFields.DIARRHEA_VALUE)) { reportToBoth(child, CHILD_DIARRHEA, reportData.get(SICK_VISIT_DATE), submissionDate, location); } else if (!isBlank(reportData.get(REPORT_CHILD_DISEASE)) && reportData.get(REPORT_CHILD_DISEASE).contains(AllConstants.ChildIllnessFields.DIARRHEA_DEHYDRATION_VALUE)) { reportToBoth(child, CHILD_DIARRHEA, reportData.get(REPORT_CHILD_DISEASE_DATE), submissionDate, 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 shouldReportChildDiarrheaEpisodeWhenSickVisitHappens() { 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(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); service.sickVisitHappened(new SafeMap(EasyMap.create("sickVisitDate", "2012-01-01") .put("id", "CASE X") .put("childSigns", "diarrhea") .put("submissionDate", "2012-01-01") .map())); verifyBothReportingCalls(CHILD_DIARRHEA, "2012-01-01"); }
@Test public void shouldNotReportDiarrheaEpisodeWhenSickVisitHappensAndChildDoesNotHaveDiarrhea() { 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(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); service.sickVisitHappened(new SafeMap(EasyMap.create("sickVisitDate", "2012-01-01") .put("id", "CASE X") .put("childSigns", null) .put("reportChildDisease", null) .put("submissionDate", "2012-01-01") .map())); verifyZeroInteractions(reportingService); }
@Test public void shouldReportChildDiarrheaEpisodeWhenSickVisitHappensAndChildHasDiarrhea() { 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(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); service.sickVisitHappened(new SafeMap(EasyMap.create("reportChildDiseaseDate", "2012-01-01") .put("id", "CASE X") .put("childSigns", null) .put("reportChildDisease", "diarrhea_dehydration") .put("submissionDate", "2012-01-01") .map())); verifyBothReportingCalls(CHILD_DIARRHEA, "2012-01-01"); }
@Test public void shouldNotReportChildDiarrheaEpisodeWhenSickVisitHappensAndChildAgeIsGreaterThanFive() { when(allChildren.findByCaseId("CASE X")).thenReturn(new Child("CASE X", "MOTHER-CASE-1", "opv_0", "5", "female") .withAnm("ANM X") .withDateOfBirth(parse("2012-01-01").minusYears(5).minusDays(1).toString()) .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-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); service.sickVisitHappened(new SafeMap(EasyMap.create("reportChildDiseaseDate", "2012-01-01") .put("id", "CASE X") .put("childSigns", null) .put("reportChildDisease", "diarrhea_dehydration") .put("submissionDate", "2012-01-01") .map())); verifyZeroInteractions(reportingService); }