ECReportingService { public void reportIndicator(SafeMap reportData, EligibleCouple ec, Indicator indicator, String serviceProvidedDate, String submissionDate) { if ((!isBlank(serviceProvidedDate) && !reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse(serviceProvidedDate), LocalDate.parse(submissionDate))) || indicator == null) return; String externalId = ec.ecNumber(); if (externalId == null) { externalId = reportData.get(AllConstants.ReportDataParameters.EXTERNAL_ID); } ReportingData serviceProvidedData = ReportingData.serviceProvidedData(ec.anmIdentifier(), externalId, indicator, serviceProvidedDate, new Location(ec.village(), ec.subCenter(), ec.phc()), ec.caseId()); ReportingData anmReportData = ReportingData.anmReportData(ec.anmIdentifier(), ec.caseId(), indicator, serviceProvidedDate); if (reportData.has(AllConstants.ReportDataParameters.QUANTITY)) { serviceProvidedData.withQuantity(reportData.get(AllConstants.ReportDataParameters.QUANTITY)); anmReportData.withQuantity(reportData.get(AllConstants.ReportDataParameters.QUANTITY)); } service.sendReportData(serviceProvidedData); service.sendReportData(anmReportData); } @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 shouldReportQuantityWhenProvided() throws Exception { EligibleCouple ec = new EligibleCouple("EC CASE 1", "EC NUMBER 1").withANMIdentifier("ANM X").withLocation("bherya", "Sub Center", "PHC X"); when(allEligibleCouples.findByCaseId("EC CASE 1")).thenReturn(ec); when(reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse("2013-01-01"), LocalDate.parse("2013-01-01"))).thenReturn(true); SafeMap reportData = new SafeMap( create("id", "EC CASE 1") .put("familyPlanningMethodChangeDate", "2013-01-01") .put("quantity", "10") .put("submissionDate", "2013-01-01") .map()); service.reportIndicator(reportData, ec, Indicator.CONDOM_QTY, reportData.get(FP_METHOD_CHANGE_DATE_FIELD_NAME), reportData.get(SUBMISSION_DATE_FIELD_NAME)); verify(reportingService).sendReportData(ReportingData.anmReportData("ANM X", "EC CASE 1", Indicator.CONDOM_QTY, "2013-01-01").withQuantity("10")); verify(reportingService).sendReportData(ReportingData.serviceProvidedData("ANM X", "EC NUMBER 1", Indicator.CONDOM_QTY, "2013-01-01", new Location("bherya", "Sub Center", "PHC X"), "EC CASE 1").withQuantity("10")); }
@Test public void shouldUseExternalIdIfECNumberIsNotAvailable() throws Exception { EligibleCouple ec = new EligibleCouple("EC CASE 1", null).withANMIdentifier("ANM X").withLocation("bherya", "Sub Center", "PHC X"); when(allEligibleCouples.findByCaseId("EC CASE 1")).thenReturn(ec); when(reportMonth.areDatesBelongToSameReportingMonth(LocalDate.parse("2013-01-01"), LocalDate.parse("2013-01-01"))).thenReturn(true); SafeMap reportData = new SafeMap( create("id", "EC CASE 1") .put("familyPlanningMethodChangeDate", "2013-01-01") .put("externalId", "external id 1") .put("submissionDate", "2013-01-01") .map()); service.reportIndicator(reportData, ec, Indicator.CONDOM_QTY, reportData.get(FP_METHOD_CHANGE_DATE_FIELD_NAME), reportData.get(SUBMISSION_DATE_FIELD_NAME)); verify(reportingService).sendReportData(ReportingData.serviceProvidedData("ANM X", "external id 1", Indicator.CONDOM_QTY, "2013-01-01", new Location("bherya", "Sub Center", "PHC X"), "EC CASE 1")); }
@Test public void shouldNotReportIfServiceProvidedDateIsNotInCurrentReportingMonth() 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("2013-01-01"), LocalDate.parse("2013-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", "2013-01-01") .map()); service.reportIndicator(reportData, null, Indicator.CONDOM_QTY, "2012-01-01", reportData.get(SUBMISSION_DATE_FIELD_NAME)); verifyZeroInteractions(reportingService); }