@Test
  public void shouldUpdateANMInformationOfEligibleCoupleWhenOAPNCIsRegistered() {
    DateTime currentTime = DateUtil.now();
    mockCurrentDate(currentTime);
    when(allMothers.findByEcCaseId("ec id 1"))
        .thenReturn(asList(new Mother("mother id 1", "ec id 1", "tc 1")));
    when(allEligibleCouples.findByCaseId("ec id 1"))
        .thenReturn(new EligibleCouple("ec id 1", "123"));
    FormSubmission submission =
        create()
            .withFormName("pnc_registration_oa")
            .withANMId("anm id 1")
            .withEntityId("ec id 1")
            .addFormField("referenceDate", "2012-01-01")
            .addFormField("didWomanSurvive", "yes")
            .withSubForm(
                new SubFormData(
                    "child_registration_oa", Collections.<Map<String, String>>emptyList()))
            .build();

    service.pncRegistrationOA(submission);

    verify(allEligibleCouples)
        .update(new EligibleCouple("ec id 1", "123").withANMIdentifier("anm id 1"));
  }
  @Test
  public void shouldUpdateMotherWithChildrenDetailsWhenPNCRegistrationOA() {
    when(allMothers.findByEcCaseId("ec id 1"))
        .thenReturn(asList(new Mother("mother id 1", "ec id 1", "tc 1")));
    when(allEligibleCouples.findByCaseId("ec id 1"))
        .thenReturn(new EligibleCouple("ec id 1", "123"));
    FormSubmission submission =
        create()
            .withFormName("pnc_registration_oa")
            .withANMId("anm id 1")
            .withEntityId("ec id 1")
            .addFormField("referenceDate", "2012-01-01")
            .addFormField("didWomanSurvive", "yes")
            .withSubForm(
                new SubFormData(
                    "child_registration_oa",
                    asList(
                        EasyMap.create("id", "child id 1")
                            .put("gender", "male")
                            .put("weight", "2")
                            .map(),
                        EasyMap.create("id", "child id 2")
                            .put("gender", "female")
                            .put("weight", "3")
                            .map())))
            .build();

    service.pncRegistrationOA(submission);

    verify(allMothers)
        .update(
            new Mother("mother id 1", "ec id 1", "tc 1")
                .withAnm("anm id 1")
                .withChildrenDetails(
                    asList(
                        EasyMap.create("id", "child id 1")
                            .put("gender", "male")
                            .put("weight", "2")
                            .put("immunizationsAtBirth", null)
                            .map(),
                        EasyMap.create("id", "child id 2")
                            .put("gender", "female")
                            .put("weight", "3")
                            .put("immunizationsAtBirth", null)
                            .map())));
  }
  @Test
  public void shouldNotEnrollPNCIntoSchedulesDuringPNCRegistrationIfMotherDoesNotExists() {
    DateTime currentTime = DateUtil.now();
    mockCurrentDate(currentTime);
    when(allMothers.findByEcCaseId("ec id 1")).thenReturn(Collections.EMPTY_LIST);
    FormSubmission submission =
        create()
            .withFormName("pnc_registration_oa")
            .withANMId("anm id 1")
            .withEntityId("ec id 1")
            .addFormField("referenceDate", "2012-01-01")
            .addFormField("didWomanSurvive", "")
            .withSubForm(
                new SubFormData("child_registration", Collections.<Map<String, String>>emptyList()))
            .build();

    service.pncRegistrationOA(submission);

    verifyZeroInteractions(pncSchedulesService);
  }
  @Test
  public void shouldReportPNCRegistrationOA() throws Exception {
    when(reportFieldsDefinition.get("pnc_registration_oa")).thenReturn(asList("some-key"));
    when(allMothers.findByEcCaseId("entity id 1"))
        .thenReturn(asList(new Mother("entity id 1", "ec id 1", "tc 1")));
    when(allEligibleCouples.findByCaseId("ec id 1"))
        .thenReturn(new EligibleCouple("ec id 1", "123"));

    FormSubmission submission =
        create()
            .withFormName("pnc_registration_oa")
            .addFormField("some-key", "value")
            .withSubForm(
                new SubFormData(
                    "child_registration_oa", Collections.<Map<String, String>>emptyList()))
            .build();
    service.pncRegistrationOA(submission);

    SafeMap reportFields = new SafeMap(mapOf("some-key", "value"));
    verify(motherReportingService).pncRegistrationOA(reportFields);
  }
  @Test
  public void shouldNotEnrollPNCIntoSchedulesPNCRegistrationIfWomanDied() {
    DateTime currentTime = DateUtil.now();
    mockCurrentDate(currentTime);
    when(allMothers.findByEcCaseId("ec id 1"))
        .thenReturn(asList(new Mother("mother id 1", "ec id 1", "tc 1")));
    when(allEligibleCouples.findByCaseId("ec id 1"))
        .thenReturn(new EligibleCouple("ec id 1", "123"));
    FormSubmission submission =
        create()
            .withFormName("pnc_registration_oa")
            .withANMId("anm id 1")
            .withEntityId("ec id 1")
            .addFormField("referenceDate", "2012-01-01")
            .addFormField("didWomanSurvive", "no")
            .withSubForm(
                new SubFormData(
                    "child_registration_oa", Collections.<Map<String, String>>emptyList()))
            .build();

    service.pncRegistrationOA(submission);

    verifyZeroInteractions(pncSchedulesService);
  }
  @Test
  public void shouldNotAddChildrenDetailsInTheCaseOfStillBirthDuringPNCRegistrationOA()
      throws Exception {
    when(allMothers.findByEcCaseId("ec id 1"))
        .thenReturn(asList(new Mother("mother id 1", "ec id 1", "tc 1")));
    when(allEligibleCouples.findByCaseId("ec id 1"))
        .thenReturn(new EligibleCouple("ec id 1", "123"));
    FormSubmission submission =
        create()
            .withFormName("pnc_registration_oa")
            .withANMId("anm id 1")
            .withEntityId("ec id 1")
            .addFormField("referenceDate", "2012-01-01")
            .addFormField("deliveryOutcome", "still_birth")
            .addFormField("didWomanSurvive", "yes")
            .withSubForm(
                new SubFormData(
                    "child_registration_oa", asList(EasyMap.create("id", "child id 1").map())))
            .build();

    service.pncRegistrationOA(submission);

    verify(allMothers).update(new Mother("mother id 1", "ec id 1", "tc 1").withAnm("anm id 1"));
  }