MotherReportingService { public void ttProvided(SafeMap reportData) { Mother mother = allMothers.findByCaseId(reportData.get(ID)); Location location = loadLocationFromEC(mother); reportTTVisit(reportData.get(TT_DOSE_FIELD), reportData.get(TT_DATE_FIELD), reportData.get(SUBMISSION_DATE_FIELD_NAME), 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 shouldReportTT1ProvidedIfTTDoseIsTT1() { SafeMap reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("ttDose", "tt1"); reportData.put("ttDate", "2012-01-23"); reportData.put("submissionDate", "2012-01-23"); 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-23"), parse("2012-01-23"))).thenReturn(true); service.ttProvided(reportData); verifyBothReportingCalls(TT1, "2012-01-23", "CASE-1"); }
@Test public void shouldReportTT2AndSUBTTProvidedIfTTDoseIsTT2() { SafeMap reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("ttDose", "tt2"); reportData.put("ttDate", "2012-01-23"); reportData.put("submissionDate", "2012-01-23"); 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-23"), parse("2012-01-23"))).thenReturn(true); service.ttProvided(reportData); verifyBothReportingCalls(TT2, "2012-01-23", "CASE-1"); verifyBothReportingCalls(SUB_TT, "2012-01-23", "CASE-1"); }
@Test public void shouldReportTTBAndSUBTTProvidedIfTTDoseIsTTBooster() { SafeMap reportData = new SafeMap(); reportData.put("id", "CASE-1"); reportData.put("ttDose", "ttbooster"); reportData.put("ttDate", "2012-01-23"); reportData.put("submissionDate", "2012-01-23"); 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-23"), parse("2012-01-23"))).thenReturn(true); service.ttProvided(reportData); verifyBothReportingCalls(TTB, "2012-01-23", "CASE-1"); verifyBothReportingCalls(SUB_TT, "2012-01-23", "CASE-1"); }