ECService { public void followupOnFPMethod(FormSubmission submission) { EligibleCouple couple = allEligibleCouples.findByCaseId(submission.entityId()); if (couple == null) { logger.warn("Tried to report FP follow up of a non-existing EC, with submission: " + submission); return; } couple = updateECWithFPFollowUp(couple, submission, submission.getField(FP_FOLLOWUP_DATE_FIELD_NAME)); allEligibleCouples.update(couple); FPProductInformation fpProductInformation = new FPProductInformation( submission.entityId(), submission.anmId(), submission.getField(CURRENT_FP_METHOD_FIELD_NAME), null, null, null, null, null, submission.getField(SUBMISSION_DATE_FIELD_NAME), null, submission.getField(FP_FOLLOWUP_DATE_FIELD_NAME), submission.getField(NEEDS_FOLLOWUP_FIELD_NAME), submission.getField(NEEDS_REFERRAL_FOLLOWUP_FIELD_NAME)); schedulingService.fpFollowup(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 shouldUpdateECAndECSchedulesWhenFPFollowupOccurs() throws Exception { List<MaleSterilizationFPDetails> maleSterilizationFPDetails = new ArrayList<>(); maleSterilizationFPDetails.add(new MaleSterilizationFPDetails("nsv", "2010-01-01", null)); List<String> followUpVisitDates = new ArrayList<>(); followUpVisitDates.add("2010-10-20"); maleSterilizationFPDetails.add(new MaleSterilizationFPDetails("nsv", "2010-10-01", followUpVisitDates)); EligibleCouple ec = new EligibleCouple("entity id 1", "EC Number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withMaleSterilizationFPDetails(maleSterilizationFPDetails) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()); when(allEligibleCouples.findByCaseId("entity id 1")).thenReturn(ec); FormSubmission submission = FormSubmissionBuilder.create() .withFormName("fp_followup") .withANMId("anm id 1") .addFormField("currentMethod", "male_sterilization") .addFormField("submissionDate", "2011-01-01") .addFormField("fpFollowupDate", "2010-12-20") .addFormField("needsFollowup", "yes") .addFormField("needsReferralFollowup", "no") .build(); List<MaleSterilizationFPDetails> expectedMaleSterilizationDetails = new ArrayList<>(); expectedMaleSterilizationDetails.add(new MaleSterilizationFPDetails("nsv", "2010-01-01", null)); expectedMaleSterilizationDetails.add(new MaleSterilizationFPDetails("nsv", "2010-10-01", asList("2010-10-20", "2010-12-20"))); EligibleCouple expectedEC = new EligibleCouple("entity id 1", "EC Number 1") .withMaleSterilizationFPDetails(expectedMaleSterilizationDetails) .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()); ecService.followupOnFPMethod(submission); verify(schedulingService).fpFollowup(new FPProductInformation("entity id 1", "anm id 1", "male_sterilization", null, null, null, null, null, "2011-01-01", null, "2010-12-20", "yes", "no")); verify(allEligibleCouples).update(eq(expectedEC)); }
@Test public void shouldUpdateECAndECSchedulesWhenFPFollowupOccursForFemaleSterilization() throws Exception { List<FemaleSterilizationFPDetails> femaleSterilizationFPDetails = new ArrayList<>(); femaleSterilizationFPDetails.add(new FemaleSterilizationFPDetails("minilap", "2010-01-01", new ArrayList<String>())); List<String> followUpVisitDates = new ArrayList<>(); followUpVisitDates.add("2010-10-20"); femaleSterilizationFPDetails.add(new FemaleSterilizationFPDetails("minilap", "2010-10-01", followUpVisitDates)); EligibleCouple ec = new EligibleCouple("entity id 1", "EC Number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()) .withFemaleSterilizationFPDetails(femaleSterilizationFPDetails); when(allEligibleCouples.findByCaseId("entity id 1")).thenReturn(ec); FormSubmission submission = FormSubmissionBuilder.create() .withFormName("fp_followup") .withANMId("anm id 1") .addFormField("currentMethod", "female_sterilization") .addFormField("submissionDate", "2011-01-01") .addFormField("fpFollowupDate", "2010-12-20") .addFormField("needsFollowup", "yes") .addFormField("needsReferralFollowup", "no") .build(); List<FemaleSterilizationFPDetails> expectedFemaleSterilizationDetails = new ArrayList<>(); expectedFemaleSterilizationDetails.add(new FemaleSterilizationFPDetails("minilap", "2010-01-01", new ArrayList<String>())); expectedFemaleSterilizationDetails.add(new FemaleSterilizationFPDetails("minilap", "2010-10-01", asList("2010-10-20", "2010-12-20"))); EligibleCouple expectedEC = new EligibleCouple("entity id 1", "EC Number 1") .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()) .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withFemaleSterilizationFPDetails(femaleSterilizationFPDetails); ecService.followupOnFPMethod(submission); verify(schedulingService).fpFollowup(new FPProductInformation("entity id 1", "anm id 1", "female_sterilization", null, null, null, null, null, "2011-01-01", null, "2010-12-20", "yes", "no")); verify(allEligibleCouples).update(eq(expectedEC)); }
@Test public void shouldNotDoAnythingDuringFPFollowupWhenNoECIsFound() throws Exception { when(allEligibleCouples.findByCaseId("entity id 1")).thenReturn(null); FormSubmission submission = FormSubmissionBuilder.create().build(); ecService.followupOnFPMethod(submission); verify(allEligibleCouples).findByCaseId("entity id 1"); verifyZeroInteractions(reportingService); verifyZeroInteractions(schedulingService); }