MotherReportingService { public void pncVisitHappened(SafeMap reportData) { Mother mother = allMothers.findByCaseId(reportData.get(ID)); Location location = loadLocationFromEC(mother); String thirdVisitDate = mother.thirdPNCVisitDate(); String visitDate = reportData.get(AllConstants.PNCVisitFormFields.VISIT_DATE_FIELD_NAME); if (thirdVisitDate != null && parse(visitDate).isEqual(parse(thirdVisitDate))) { reportToBoth(mother, PNC3, visitDate, reportData.get(SUBMISSION_DATE_FIELD_NAME), 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 shouldReportPNCVisit3DuringThirdPNCVisit() throws Exception { Mother mother = new Mother("CASE-1", "EC-CASE-1", "TC 1") .withAnm("ANM X") .withDetails(mapOf("pncVisitDates", "2011-12-25 2011-12-28 2012-01-01")) .withLMP(parse("2012-01-01")); SafeMap reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("pncVisitDates", "2011-12-25 2011-12-28 2012-01-01"); reportData.put("pncVisitDate", "2012-01-01"); reportData.put("submissionDate", "2012-01-02"); 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("2012-01-01"), parse("2012-01-02"))).thenReturn(true); service.pncVisitHappened(reportData); verifyBothReportingCalls(PNC3, "2012-01-01", "CASE-1"); }
@Test public void shouldNotReportPNCVisit3IfItsNotThirdPNCVisit() throws Exception { Mother mother = new Mother("CASE-1", "EC-CASE-1", "TC 1") .withAnm("ANM X") .withDetails(mapOf("pncVisitDates", "2011-12-25 2011-12-26 2011-12-28 2012-01-01")) .withLMP(parse("2012-01-01")); SafeMap reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("pncVisitDates", "2011-12-25 2011-12-26 2011-12-28 2012-01-01"); reportData.put("pncVisitDate", "2012-01-01"); when(allMothers.findByCaseId("CASE-1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); service.pncVisitHappened(reportData); verifyNoReportingCalls(PNC3, "2012-01-01", "CASE-1"); mother = new Mother("CASE-1", "EC-CASE-1", "TC 1") .withAnm("ANM X") .withDetails(mapOf("pncVisitDates", "2011-12-28 2012-01-01")) .withLMP(parse("2012-01-01")); reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("pncVisitDates", "2011-12-28 2012-01-01"); reportData.put("pncVisitDate", "2012-01-01"); when(allMothers.findByCaseId("CASE-1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); service.pncVisitHappened(reportData); mother = new Mother("CASE-1", "EC-CASE-1", "TC 1") .withAnm("ANM X") .withDetails(mapOf("pncVisitDates", "2012-01-01")) .withLMP(parse("2012-01-01")); verifyNoReportingCalls(PNC3, "2012-01-01", "CASE-1"); reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("pncVisitDates", "2012-01-01"); reportData.put("pncVisitDate", "2012-01-01"); when(allMothers.findByCaseId("CASE-1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); service.pncVisitHappened(reportData); verifyNoReportingCalls(PNC3, "2012-01-01", "CASE-1"); }