ECReportingService { public void fpChange(SafeMap reportData) { EligibleCouple couple = allEligibleCouples.findByCaseId(reportData.get(ID)); reportIndicator(reportData, couple, Indicator.from(reportData.get(NEW_FP_METHOD_FIELD_NAME)), reportData.get(FP_METHOD_CHANGE_DATE_FIELD_NAME), reportData.get(SUBMISSION_DATE_FIELD_NAME)); reportOCPCasteBasedIndicators(reportData, couple, reportData.get(NEW_FP_METHOD_FIELD_NAME)); reportFemaleSterilizationEconomicStatusBasedIndicators(reportData, couple, reportData.get(NEW_FP_METHOD_FIELD_NAME)); } @Autowired  ECReportingService(ReportingService service, AllEligibleCouples allEligibleCouples, ReportMonth reportMonth); void registerEC(SafeMap reportData); void fpChange(SafeMap reportData); void reportIndicator(SafeMap reportData, EligibleCouple ec, Indicator indicator, String serviceProvidedDate,
                                String submissionDate); void deleteReportsForEC(String ecCaseId);  }
@Test public void shouldReportFPMethodChange() throws Exception { when(allEligibleCouples.findByCaseId("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "EC NUMBER 1").withANMIdentifier("ANM X").withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); SafeMap reportData = new SafeMap(create("id", "EC CASE 1") .put("currentMethod", "ocp") .put("newMethod", "iud") .put("familyPlanningMethodChangeDate", "2012-01-01") .put("method_still_the_same", "no") .put("submissionDate", "2012-01-01") .map()); service.fpChange(reportData); verify(reportingService).sendReportData(ReportingData.anmReportData("ANM X", "EC CASE 1", Indicator.FP_IUD, "2012-01-01")); verify(reportingService).sendReportData(ReportingData.serviceProvidedData("ANM X", "EC NUMBER 1", Indicator.FP_IUD, "2012-01-01", new Location("bherya", "Sub Center", "PHC X"), "EC CASE 1")); verifyNoMoreInteractions(reportingService); }
@Test public void shouldReportOCPC_OthersWhenFPMethodChangeAndCasteIsOthers() throws Exception { when(allEligibleCouples.findByCaseId("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "EC NUMBER 1").withANMIdentifier("ANM X").withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); SafeMap reportData = new SafeMap(create("id", "EC CASE 1") .put("currentMethod", "iud") .put("newMethod", "ocp") .put("familyPlanningMethodChangeDate", "2012-01-01") .put("caste", "c_others") .put("submissionDate", "2012-01-01") .map()); service.fpChange(reportData); verify(reportingService).sendReportData(ReportingData.anmReportData("ANM X", "EC CASE 1", Indicator.FP_OCP_CASTE_OTHERS, "2012-01-01")); verify(reportingService).sendReportData(ReportingData.serviceProvidedData("ANM X", "EC NUMBER 1", Indicator.FP_OCP_CASTE_OTHERS, "2012-01-01", new Location("bherya", "Sub Center", "PHC X"), "EC CASE 1")); }
@Test public void shouldReportOCPSTWhenFPMethodChangeAndCasteIsST() throws Exception { when(allEligibleCouples.findByCaseId("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "EC NUMBER 1").withANMIdentifier("ANM X").withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); SafeMap reportData = new SafeMap(create("id", "EC CASE 1") .put("currentMethod", "iud") .put("newMethod", "ocp") .put("familyPlanningMethodChangeDate", "2012-01-01") .put("caste", "st") .put("submissionDate", "2012-01-01") .map()); service.fpChange(reportData); verify(reportingService).sendReportData(ReportingData.anmReportData("ANM X", "EC CASE 1", Indicator.FP_OCP_ST, "2012-01-01")); verify(reportingService).sendReportData(ReportingData.serviceProvidedData("ANM X", "EC NUMBER 1", Indicator.FP_OCP_ST, "2012-01-01", new Location("bherya", "Sub Center", "PHC X"), "EC CASE 1")); }
@Test public void shouldReportOCPSCWhenFPMethodChangeAndCasteIsSC() throws Exception { when(allEligibleCouples.findByCaseId("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "EC NUMBER 1").withANMIdentifier("ANM X").withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); SafeMap reportData = new SafeMap(create("id", "EC CASE 1") .put("currentMethod", "iud") .put("newMethod", "ocp") .put("familyPlanningMethodChangeDate", "2012-01-01") .put("caste", "sc") .put("submissionDate", "2012-01-01") .map()); service.fpChange(reportData); verify(reportingService).sendReportData(ReportingData.anmReportData("ANM X", "EC CASE 1", Indicator.FP_OCP_SC, "2012-01-01")); verify(reportingService).sendReportData(ReportingData.serviceProvidedData("ANM X", "EC NUMBER 1", Indicator.FP_OCP_SC, "2012-01-01", new Location("bherya", "Sub Center", "PHC X"), "EC CASE 1")); }
@Test public void shouldReportFemaleSterilizationBPLWhenFPMethodIsChangedAndEconomicStatusIsBPL() throws Exception { when(allEligibleCouples.findByCaseId("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "EC NUMBER 1").withANMIdentifier("ANM X").withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); SafeMap reportData = new SafeMap(create("id", "EC CASE 1") .put("currentMethod", "iud") .put("newMethod", "female_sterilization") .put("familyPlanningMethodChangeDate", "2012-01-01") .put("caste", "") .put("economicStatus", "bpl") .put("submissionDate", "2012-01-01") .map()); service.fpChange(reportData); verify(reportingService).sendReportData(ReportingData.anmReportData("ANM X", "EC CASE 1", Indicator.FP_FEMALE_STERILIZATION_BPL, "2012-01-01")); verify(reportingService).sendReportData(ReportingData.serviceProvidedData("ANM X", "EC NUMBER 1", Indicator.FP_FEMALE_STERILIZATION_BPL, "2012-01-01", new Location("bherya", "Sub Center", "PHC X"), "EC CASE 1")); }
@Test public void shouldReportFemaleSterilizationAPLWhenFPMethodIsChangedAndEconomicStatusIsAPL() throws Exception { when(allEligibleCouples.findByCaseId("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "EC NUMBER 1").withANMIdentifier("ANM X").withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); SafeMap reportData = new SafeMap(create("id", "EC CASE 1") .put("currentMethod", "iud") .put("newMethod", "female_sterilization") .put("familyPlanningMethodChangeDate", "2012-01-01") .put("caste", "") .put("economicStatus", "apl") .put("submissionDate", "2012-01-01") .map()); service.fpChange(reportData); verify(reportingService).sendReportData(ReportingData.anmReportData("ANM X", "EC CASE 1", Indicator.FP_FEMALE_STERILIZATION_APL, "2012-01-01")); verify(reportingService).sendReportData(ReportingData.serviceProvidedData("ANM X", "EC NUMBER 1", Indicator.FP_FEMALE_STERILIZATION_APL, "2012-01-01", new Location("bherya", "Sub Center", "PHC X"), "EC CASE 1")); }
@Test public void shouldNotReportFemaleSterilizationEconomicStatusWhenFPMethodIsChangedAndEconomicStatusIsNotSpecified() throws Exception { when(allEligibleCouples.findByCaseId("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "EC NUMBER 1").withANMIdentifier("ANM X").withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse("2012-01-01"), LocalDate.parse("2012-01-01"))).thenReturn(true); SafeMap reportData = new SafeMap(create("id", "EC CASE 1") .put("currentMethod", "iud") .put("newMethod", "female_sterilization") .put("familyPlanningMethodChangeDate", "2012-01-01") .put("caste", "") .put("economicStatus", "") .put("submissionDate", "2012-01-01") .map()); service.fpChange(reportData); verify(reportingService).sendReportData(ReportingData.anmReportData("ANM X", "EC CASE 1", Indicator.FP_FEMALE_STERILIZATION, "2012-01-01")); verify(reportingService).sendReportData(ReportingData.serviceProvidedData("ANM X", "EC NUMBER 1", Indicator.FP_FEMALE_STERILIZATION, "2012-01-01", new Location("bherya", "Sub Center", "PHC X"), "EC CASE 1")); verifyNoMoreInteractions(reportingService); }