ECService { public void registerEligibleCouple(FormSubmission submission) { EligibleCouple eligibleCouple = allEligibleCouples.findByCaseId(submission.entityId()); String fpMethod = submission.getField(CURRENT_FP_METHOD_FIELD_NAME); initializeECWithEmptyFPDetails(eligibleCouple); updateECWithFPDetails(eligibleCouple, submission, fpMethod); allEligibleCouples.update(eligibleCouple.withANMIdentifier(submission.anmId())); List<String> reportFields = reportFieldsDefinition.get(submission.formName()); reportingService.registerEC(new SafeMap(submission.getFields(reportFields))); 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), submission.getField(FP_METHOD_CHANGE_DATE_FIELD_NAME), null, null, null); schedulingService.registerEC(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 shouldRegisterEligibleCouple() throws Exception { FormSubmission submission = FormSubmissionBuilder.create() .withFormName("ec_registration") .withANMId("anm id 1") .withEntityId("entity id 1") .addFormField("someKey", "someValue") .addFormField("lmpDate", "2011-01-01") .addFormField("uptResult", "negative") .addFormField("currentMethod", "iud") .addFormField("isHighPriority", "yes") .addFormField("submissionDate", "2011-01-01") .addFormField("dmpaInjectionDate", "2010-12-20") .addFormField("numberOfOCPDelivered", "1") .addFormField("ocpRefillDate", "2010-12-25") .addFormField("iudPlace", "phc") .addFormField("familyPlanningMethodChangeDate", "2011-01-01") .build(); EligibleCouple eligibleCouple = new EligibleCouple("entity id 1", "0").withCouple("Wife 1", "Husband 1"); when(allEligibleCouples.findByCaseId("entity id 1")).thenReturn(eligibleCouple); when(reportFieldsDefinition.get("ec_registration")).thenReturn(asList("someKey")); ecService.registerEligibleCouple(submission); verify(allEligibleCouples).update(Matchers.eq(eligibleCouple .withANMIdentifier("ANM X") .withIUDFPDetails(asList(new IUDFPDetails("2011-01-01", "phc", "2011-01-01", "negative"))) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()) )); verify(reportingService).registerEC(new SafeMap(mapOf("someKey", "someValue"))); verify(schedulingService).registerEC(new FPProductInformation("entity id 1", "anm id 1", "iud", null, "2010-12-20", "1", "2010-12-25" , null, "2011-01-01", "2011-01-01", null, null, null)); }
@Test public void shouldRegisterEligibleCoupleAndUpdateCondomDetails() throws Exception { FormSubmission submission = FormSubmissionBuilder.create() .withFormName("ec_registration") .withANMId("anm id 1") .withEntityId("entity id 1") .addFormField("someKey", "someValue") .addFormField("lmpDate", "2011-01-01") .addFormField("uptResult", "negative") .addFormField("currentMethod", "some method") .addFormField("isHighPriority", "yes") .addFormField("submissionDate", "2011-01-01") .addFormField("dmpaInjectionDate", "2010-12-20") .addFormField("familyPlanningMethodChangeDate", "2011-01-01") .addFormField("numberOfCondomsSupplied", "20") .build(); EligibleCouple eligibleCouple = new EligibleCouple("entity id 1", "0").withCouple("Wife 1", "Husband 1"); when(allEligibleCouples.findByCaseId("entity id 1")).thenReturn(eligibleCouple); when(reportFieldsDefinition.get("ec_registration")).thenReturn(asList("someKey")); ecService.registerEligibleCouple(submission); verify(allEligibleCouples).update(eligibleCouple .withANMIdentifier("ANM X") .withCondomFPDetails(asList(new CondomFPDetails("2011-01-01", asList(create("date", "2011-01-01").put("quantity", "20").map()))))); verify(reportingService).registerEC(new SafeMap(mapOf("someKey", "someValue"))); verify(schedulingService).registerEC(new FPProductInformation("entity id 1", "anm id 1", "some method", null, "2010-12-20", null, null , "20", "2011-01-01", "2011-01-01", null, null, null)); }