ECService { public void renewFPProduct(FormSubmission submission) { EligibleCouple couple = allEligibleCouples.findByCaseId(submission.entityId()); if (couple == null) { logger.warn("Tried to report FP Renew of a non-existing EC, with submission: " + submission); return; } allEligibleCouples.update(updateECWithRefills(submission, couple)); FPProductInformation fpProductInformation = new FPProductInformation( submission.entityId(), submission.anmId(), submission.getField(CURRENT_FP_METHOD_FIELD_NAME), null, submission.getField(DMPA_INJECTION_DATE_FIELD_NAME), submission.getField(NUMBER_OF_OCP_STRIPS_SUPPLIED_FIELD_NAME), submission.getField(OCP_REFILL_DATE_FIELD_NAME), submission.getField(NUMBER_OF_CONDOMS_SUPPLIED_FIELD_NAME), submission.getField(SUBMISSION_DATE_FIELD_NAME), null, null, null, null); schedulingService.renewFPProduct(fpProductInformation); } @Autowired  ECService(AllEligibleCouples allEligibleCouples, ECSchedulingService schedulingService, ECReportingService reportingService,
                     ReportFieldsDefinition reportFieldsDefinition); void registerEligibleCouple(FormSubmission submission); void reportFPComplications(FormSubmission submission); void reportFPChange(FormSubmission submission); void renewFPProduct(FormSubmission submission); void followupOnFPMethod(FormSubmission submission); void handleReferralFollowup(FormSubmission submission); void closeEligibleCouple(FormSubmission submission);  }
@Test public void shouldUpdateECSchedulesWhenCondomFPProductIsRenewed() throws Exception { List<Map<String, String>> refillsForFirstCondomFPDetail = new ArrayList<>(); refillsForFirstCondomFPDetail.add(create("date", "2010-01-01").put("quantity", "10").map()); refillsForFirstCondomFPDetail.add(create("date", "2010-05-01").put("quantity", "10").map()); List<Map<String, String>> refillsForSecondCondomFPDetail = new ArrayList<>(); refillsForSecondCondomFPDetail.add(create("date", "2011-01-01").put("quantity", "10").map()); List<CondomFPDetails> condomFPDetails = new ArrayList<>(); condomFPDetails.add(new CondomFPDetails("2010-01-01", refillsForFirstCondomFPDetail)); condomFPDetails.add(new CondomFPDetails("2011-01-01", refillsForSecondCondomFPDetail)); EligibleCouple ec = new EligibleCouple("entity id 1", "EC Number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(condomFPDetails) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()); when(allEligibleCouples.findByCaseId("entity id 1")).thenReturn(ec); FormSubmission submission = FormSubmissionBuilder.create() .withFormName("renew_fp_product") .withANMId("anm id 1") .addFormField("currentMethod", "condom") .addFormField("fpRenewMethodVisitDate", "2011-01-01") .addFormField("submissionDate", "2011-01-01") .addFormField("numberOfOCPDelivered", "1") .addFormField("ocpRefillDate", "2010-12-25") .addFormField("dmpaInjectionDate", "2010-12-20") .addFormField("numberOfCondomsSupplied", "20") .build(); List<Map<String, String>> expectedRefillsForFirstCondomFPDetail = new ArrayList<>(); expectedRefillsForFirstCondomFPDetail.add(create("date", "2010-01-01").put("quantity", "10").map()); expectedRefillsForFirstCondomFPDetail.add(create("date", "2010-05-01").put("quantity", "10").map()); List<Map<String, String>> expectedRefillsForSecondCondomFPDetail = new ArrayList<>(); expectedRefillsForSecondCondomFPDetail.add(create("date", "2011-01-01").put("quantity", "10").map()); expectedRefillsForSecondCondomFPDetail.add(create("date", "2011-01-01").put("quantity", "20").map()); List<CondomFPDetails> expectedCondomDetails = new ArrayList<>(); expectedCondomDetails.add(new CondomFPDetails("2010-01-01", expectedRefillsForFirstCondomFPDetail)); expectedCondomDetails.add(new CondomFPDetails("2011-01-01", expectedRefillsForSecondCondomFPDetail)); EligibleCouple expectedEC = new EligibleCouple("entity id 1", "EC Number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(expectedCondomDetails) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()); ecService.renewFPProduct(submission); verify(schedulingService).renewFPProduct(new FPProductInformation("entity id 1", "anm id 1", "condom", null, "2010-12-20", "1", "2010-12-25", "20", "2011-01-01", null, null, null, null)); verify(allEligibleCouples).update(expectedEC); }
@Test public void shouldUpdateECSchedulesWhenOCPFPProductIsRenewed() throws Exception { List<Map<String, String>> refillsForFirstOCPFPDetail = new ArrayList<>(); refillsForFirstOCPFPDetail.add(create("date", "2010-01-01").put("quantity", "10").map()); refillsForFirstOCPFPDetail.add(create("date", "2010-05-01").put("quantity", "10").map()); List<Map<String, String>> refillsForSecondOCPFPDetail = new ArrayList<>(); refillsForSecondOCPFPDetail.add(create("date", "2011-01-01").put("quantity", "10").map()); List<OCPFPDetails> ocpFPDetails = new ArrayList<>(); ocpFPDetails.add(new OCPFPDetails("2010-01-01", refillsForFirstOCPFPDetail, null, null)); ocpFPDetails.add(new OCPFPDetails("2011-01-01", refillsForSecondOCPFPDetail, null, null)); EligibleCouple ec = new EligibleCouple("entity id 1", "EC Number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(ocpFPDetails) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()); when(allEligibleCouples.findByCaseId("entity id 1")).thenReturn(ec); FormSubmission submission = FormSubmissionBuilder.create() .withFormName("renew_fp_product") .withANMId("anm id 1") .addFormField("currentMethod", "ocp") .addFormField("fpRenewMethodVisitDate", "2011-01-01") .addFormField("submissionDate", "2011-01-01") .addFormField("numberOfOCPDelivered", "15") .addFormField("ocpRefillDate", "2010-12-25") .addFormField("dmpaInjectionDate", "2010-12-20") .addFormField("numberOfCondomsSupplied", "20") .build(); List<Map<String, String>> expectedRefillsForFirstOCPFPDetail = new ArrayList<>(); expectedRefillsForFirstOCPFPDetail.add(create("date", "2010-01-01").put("quantity", "10").map()); expectedRefillsForFirstOCPFPDetail.add(create("date", "2010-05-01").put("quantity", "10").map()); List<Map<String, String>> expectedRefillsForSecondOCPFPDetail = new ArrayList<>(); expectedRefillsForSecondOCPFPDetail.add(create("date", "2011-01-01").put("quantity", "10").map()); expectedRefillsForSecondOCPFPDetail.add(create("date", "2011-01-01").put("quantity", "15").map()); List<OCPFPDetails> expectedOCPDetails = new ArrayList<>(); expectedOCPDetails.add(new OCPFPDetails("2010-01-01", expectedRefillsForFirstOCPFPDetail,null,null)); expectedOCPDetails.add(new OCPFPDetails("2011-01-01", expectedRefillsForSecondOCPFPDetail,null,null)); EligibleCouple expectedEC = new EligibleCouple("entity id 1", "EC Number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(expectedOCPDetails) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()); ecService.renewFPProduct(submission); verify(schedulingService).renewFPProduct(new FPProductInformation("entity id 1", "anm id 1", "ocp", null, "2010-12-20", "15", "2010-12-25", "20", "2011-01-01", null, null, null, null)); verify(allEligibleCouples).update(expectedEC); }
@Test public void shouldNotDoAnythingDuringRenewFPProductWhenNoECIsFound() throws Exception { when(allEligibleCouples.findByCaseId("entity id 1")).thenReturn(null); FormSubmission submission = FormSubmissionBuilder.create().build(); ecService.renewFPProduct(submission); verify(allEligibleCouples).findByCaseId("entity id 1"); verifyZeroInteractions(reportingService); verifyZeroInteractions(schedulingService); }