MotherReportingService { public void ancVisit(SafeMap reportData) { Mother mother = allMothers.findByCaseId(reportData.get(ID)); Location location = loadLocationFromEC(mother); reportANC4Visit(reportData, mother, location); } @Autowired  MotherReportingService(ReportingService reportingService, AllMothers allMothers, AllEligibleCouples allEligibleCouples, ReportMonth reportMonth); void registerANC(SafeMap reportData); void ancVisit(SafeMap reportData); void ttProvided(SafeMap reportData); void deliveryOutcome(SafeMap reportData); void pncVisitHappened(SafeMap reportData); void closeANC(SafeMap reportData); void closePNC(SafeMap reportData); void reportToBoth(Mother mother, Indicator indicator, String date, String submissionDate, Location location); void pncRegistrationOA(SafeMap reportData); void deleteReports(String motherCaseId); static final int NUMBER_OF_DAYS_IN_12_WEEKS; static final int NUMBER_OF_DAYS_IN_PNC_PERIOD; }
@Test public void shouldReportANC4ProvidedWhenANCVisitIsAfter36WeeksAndAlready3ANCVisitsHappened() { String visitDate = parse("2012-01-01").plusWeeks(36).toString(); String submissionDate = visitDate; Map<String, String> ancVisit1 = create("ancVisitDate", "2012-03-04") .put("ancVisitNumber", "1") .map(); Map<String, String> ancVisit2 = create("ancVisitDate", "2012-05-04") .put("ancVisitNumber", "2") .map(); Map<String, String> ancVisit3 = create("ancVisitDate", "2012-07-04") .put("ancVisitNumber", "3") .map(); Map<String, String> ancVisit4 = create("ancVisitDate", visitDate) .put("ancVisitNumber", "4") .map(); List<Map<String, String>> ancVisits = asList(ancVisit1, ancVisit2, ancVisit4, ancVisit3); Mother mother = new Mother("CASE-1", "EC-CASE-1", "TC 1") .withAnm("ANM X") .withLMP(parse("2012-01-01")) .withANCVisits(ancVisits); SafeMap reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("ancVisitDate", visitDate); reportData.put("ancVisitNumber", "4"); reportData.put("submissionDate", submissionDate); when(allMothers.findByCaseId("CASE-1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(parse(visitDate), parse(submissionDate))).thenReturn(true); service.ancVisit(reportData); verifyBothReportingCalls(ANC4, visitDate, "CASE-1"); }
@Test public void shouldNotReportANC4WhenANCVisitHappenedIs4ButDoesNotHave3ANCVisitsAlready() { String visitDate = parse("2012-01-01").plusWeeks(36).toString(); String submissionDate = visitDate; Map<String, String> ancVisit4 = create("ancVisitDate", visitDate) .put("ancVisitNumber", "4") .map(); List<Map<String, String>> ancVisits = asList(ancVisit4); Mother mother = new Mother("CASE-1", "EC-CASE-1", "TC 1") .withAnm("ANM X") .withLMP(parse("2012-01-01")) .withANCVisits(ancVisits); SafeMap reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("ancVisitDate", visitDate); reportData.put("submissionDate", submissionDate); reportData.put("ancVisitNumber", "4"); when(allMothers.findByCaseId("CASE-1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); service.ancVisit(reportData); verifyNoReportingCalls(ANC4, visitDate, "CASE-1"); Map<String, String> ancVisit1 = create("ancVisitDate", "2012-03-04") .put("ancVisitNumber", "1") .map(); Map<String, String> ancVisit2 = create("ancVisitDate", "2012-05-04") .put("ancVisitNumber", "2") .map(); ancVisits = asList(ancVisit1, ancVisit2, ancVisit4); mother = new Mother("CASE-1", "EC-CASE-1", "TC 1") .withAnm("ANM X") .withLMP(parse("2012-01-01")) .withANCVisits(ancVisits); reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("ancVisitDate", visitDate); reportData.put("ancVisitNumber", "4"); reportData.put("submissionDate", submissionDate); when(allMothers.findByCaseId("CASE-1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); service.ancVisit(reportData); verifyNoReportingCalls(ANC4, visitDate, "CASE-1"); }
@Test public void shouldNotReportANC4WhenANCVisitIsNotFourthVisit() { Map<String, String> ancVisit1 = create("ancVisitDate", "2012-03-04") .put("ancVisitNumber", "1") .map(); Map<String, String> ancVisit2 = create("ancVisitDate", "2012-05-04") .put("ancVisitNumber", "2") .map(); Map<String, String> ancVisit3 = create("ancVisitDate", "2012-07-04") .put("ancVisitNumber", "3") .map(); List<Map<String, String>> ancVisits = asList(ancVisit1, ancVisit2, ancVisit3); Mother mother = new Mother("CASE-1", "EC-CASE-1", "TC 1") .withAnm("ANM X") .withLMP(parse("2012-01-01")) .withANCVisits(ancVisits); String visitDate = parse("2012-01-01").plusWeeks(36).toString(); String submissionDate = visitDate; SafeMap reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("ancVisitDate", visitDate); reportData.put("ancVisitNumber", "3"); reportData.put("submissionDate", submissionDate); when(allMothers.findByCaseId("CASE-1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); service.ancVisit(reportData); verifyNoReportingCalls(ANC4, visitDate, "CASE-1"); }
@Test public void shouldNotReportANC4WhenANCVisitIsBefore36Weeks() { String visitDate = parse("2012-01-01").plusWeeks(36).minusDays(1).toString(); String submissionDate = visitDate; Map<String, String> ancVisit1 = create("ancVisitDate", "2012-03-04") .put("ancVisitNumber", "1") .map(); Map<String, String> ancVisit2 = create("ancVisitDate", "2012-05-04") .put("ancVisitNumber", "2") .map(); Map<String, String> ancVisit3 = create("ancVisitDate", "2012-07-04") .put("ancVisitNumber", "3") .map(); Map<String, String> ancVisit4 = create("ancVisitDate", visitDate) .put("ancVisitNumber", "4") .map(); List<Map<String, String>> ancVisits = asList(ancVisit1, ancVisit2, ancVisit3, ancVisit4); Mother mother = new Mother("CASE-1", "EC-CASE-1", "TC 1") .withAnm("ANM X") .withLMP(parse("2012-01-01")) .withANCVisits(ancVisits); SafeMap reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("ancVisitDate", visitDate); reportData.put("ancVisitNumber", "4"); reportData.put("submissionDate", submissionDate); when(allMothers.findByCaseId("CASE-1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); service.ancVisit(reportData); verifyNoReportingCalls(ANC4, visitDate, "CASE-1"); }
@Test public void shouldNotReportANC4WhenVisitNumberIsInvalid() { String visitDate = parse("2012-01-01").plusWeeks(36).toString(); String submissionDate = visitDate; SafeMap reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("ancVisitDate", visitDate); reportData.put("ancVisitNumber", ""); reportData.put("submissionDate", submissionDate); when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); service.ancVisit(reportData); verifyNoReportingCalls(ANC4, visitDate, "CASE-1"); }