PNCService { public void reportPPFamilyPlanning(FormSubmission submission) { Mother mother = allMothers.findByCaseId(submission.entityId()); EligibleCouple eligibleCouple = allEligibleCouples.findByCaseId(mother.ecCaseId()); EligibleCouple updatedEligibleCouple = updateECWithFPMethod(submission, eligibleCouple); allEligibleCouples.update(updatedEligibleCouple); } @Autowired  PNCService(ActionService actionService,
                      PNCSchedulesService pncSchedulesService,
                      AllEligibleCouples allEligibleCouples,
                      AllMothers allMothers,
                      AllChildren allChildren,
                      MotherReportingService motherReportingService,
                      ReportFieldsDefinition reportFieldsDefinition); void deliveryOutcome(FormSubmission submission); void pncRegistrationOA(FormSubmission submission); void close(FormSubmission submission); void autoClosePNCCase(String entityId); void pncVisitHappened(FormSubmission submission); void reportPPFamilyPlanning(FormSubmission submission);  }
@Test public void shouldUpdateMotherWithNewFamilyPlanningWhenPPFPIsSubmitted() throws Exception { FormSubmission submission = create() .withFormName("postpartum_family_planning") .withEntityId("mother id 1") .addFormField("some-key", "value") .addFormField("currentMethod", "female_sterilization") .addFormField("familyPlanningMethodChangeDate", "2010-01-01") .addFormField("femaleSterilizationType", "minilap") .build(); Mother mother = new Mother("mother id 1", "ec id 1", "thayi card number 1"); EligibleCouple eligibleCouple = new EligibleCouple("ec id 1", "ec number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withFemaleSterilizationFPDetails(new ArrayList<FemaleSterilizationFPDetails>()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()); when(allMothers.findByCaseId("mother id 1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("ec id 1")).thenReturn(eligibleCouple); service.reportPPFamilyPlanning(submission); List<FemaleSterilizationFPDetails> femaleSterilizationFPDetails = new ArrayList<>(); femaleSterilizationFPDetails.add(new FemaleSterilizationFPDetails("minilap", "2010-01-01")); EligibleCouple expectedEC = eligibleCouple.withFemaleSterilizationFPDetails(femaleSterilizationFPDetails); verify(allEligibleCouples).update(expectedEC); }
@Test public void shouldUpdateMotherWithNewFamilyPlanningIUDWhenPPFPIsSubmitted() throws Exception { FormSubmission submission = create() .withFormName("postpartum_family_planning") .withEntityId("mother id 1") .addFormField("some-key", "value") .addFormField("currentMethod", "iud") .addFormField("familyPlanningMethodChangeDate", "2010-01-01") .addFormField("iudPlace", "phc") .build(); Mother mother = new Mother("mother id 1", "ec id 1", "thayi card number 1"); EligibleCouple eligibleCouple = new EligibleCouple("ec id 1", "ec number 1") .withIUDFPDetails(new ArrayList<IUDFPDetails>()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()); when(allMothers.findByCaseId("mother id 1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("ec id 1")).thenReturn(eligibleCouple); service.reportPPFamilyPlanning(submission); ArrayList<IUDFPDetails> iudFPDetails = new ArrayList<>(); iudFPDetails.add(new IUDFPDetails("2010-01-01", "phc", null, null)); EligibleCouple expectedEC = eligibleCouple.withIUDFPDetails(iudFPDetails); verify(allEligibleCouples).update(expectedEC); }
@Test public void shouldUpdateMotherWithNewFamilyPlanningFSWhenPPFPIsSubmitted() throws Exception { FormSubmission submission = create() .withFormName("postpartum_family_planning") .withEntityId("mother id 1") .addFormField("some-key", "value") .addFormField("currentMethod", "female_sterilization") .addFormField("familyPlanningMethodChangeDate", "2010-01-01") .addFormField("femaleSterilizationType", "minilap") .build(); Mother mother = new Mother("mother id 1", "ec id 1", "thayi card number 1"); EligibleCouple eligibleCouple = new EligibleCouple("ec id 1", "ec number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withFemaleSterilizationFPDetails(new ArrayList<FemaleSterilizationFPDetails>()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()); when(allMothers.findByCaseId("mother id 1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("ec id 1")).thenReturn(eligibleCouple); service.reportPPFamilyPlanning(submission); ArrayList<FemaleSterilizationFPDetails> femaleSterilizationFPDetails = new ArrayList<>(); femaleSterilizationFPDetails.add(new FemaleSterilizationFPDetails("minilap", "2010-01-01")); EligibleCouple expectedEC = new EligibleCouple("ec id 1", "ec number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()) .withFemaleSterilizationFPDetails(femaleSterilizationFPDetails); verify(allEligibleCouples).update(expectedEC); }
@Test public void shouldUpdateMotherWithNewFamilyPlanningCondomWhenPPFPIsSubmitted() throws Exception { FormSubmission submission = create() .withFormName("postpartum_family_planning") .withEntityId("mother id 1") .addFormField("some-key", "value") .addFormField("currentMethod", "condom") .addFormField("familyPlanningMethodChangeDate", "2010-01-01") .addFormField("numberOfCondomsSupplied", "20") .build(); Mother mother = new Mother("mother id 1", "ec id 1", "thayi card number 1"); EligibleCouple eligibleCouple = new EligibleCouple("ec id 1", "ec number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(new ArrayList<CondomFPDetails>()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()); when(allMothers.findByCaseId("mother id 1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("ec id 1")).thenReturn(eligibleCouple); service.reportPPFamilyPlanning(submission); List<CondomFPDetails> condomFPDetails = new ArrayList<>(); condomFPDetails.add(new CondomFPDetails("2010-01-01", asList(EasyMap.create("date", "2010-01-01").put("quantity", "20").map()))); EligibleCouple expectedEC = new EligibleCouple("ec id 1", "ec number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()) .withCondomFPDetails(condomFPDetails); verify(allEligibleCouples).update(expectedEC); }