ChildService { public void pncVisitHappened(FormSubmission submission) { Map<String, String> reportFieldsMap = submission.getFields(reportFieldsDefinition.get(submission.formName())); SubFormData subFormData = submission.getSubFormByName(AllConstants.Form.PNC_VISIT_CHILD_SUB_FORM_NAME); if (handleStillBirth(submission, subFormData)) return; for (Map<String, String> childFields : subFormData.instances()) { SafeMap reportingData = new SafeMap(reportFieldsMap); reportingData.put(ChildReportingService.CHILD_ID_FIELD, childFields.get(ID)); reportingData.put(URINE_STOOL_PROBLEMS, childFields.get(URINE_STOOL_PROBLEMS)); reportingData.put(SUBMISSION_DATE_FIELD_NAME, submission.getField(SUBMISSION_DATE_FIELD_NAME)); childReportingService.pncVisitHappened(reportingData); } } @Autowired  ChildService(ChildSchedulesService childSchedulesService,
                        AllMothers allMothers,
                        AllChildren allChildren,
                        ChildReportingService childReportingService, ActionService actionService, ReportFieldsDefinition reportFieldsDefinition); void registerChildren(FormSubmission submission); void registerChildrenForEC(FormSubmission submission); void registerChildrenForOA(FormSubmission submission); void updateChildImmunization(FormSubmission submission); void vitaminAProvided(FormSubmission submission); void closeChild(FormSubmission submission); void pncOAChildRegistration(FormSubmission submission); void pncVisitHappened(FormSubmission submission); void sickVisitHappened(FormSubmission submission); static final String IMMUNIZATIONS_SEPARATOR; }
@Test public void shouldReportWhenPNCVisitHappened() { FormSubmission submission = create() .withFormName("pnc_visit") .withANMId("anm id 1") .withEntityId("mother id 1") .addFormField("pncVisitDate", "2012-01-01") .addFormField("submissionDate", "2012-01-01") .withSubForm(new SubFormData("child_pnc_visit", asList(EasyMap.create("id", "child id 1").put("urineStoolProblems", "diarrhea").map()))) .build(); when(reportFieldsDefinition.get("pnc_visit")).thenReturn(asList("id", "pncVisitDate")); service.pncVisitHappened(submission); verify(childReportingService).pncVisitHappened(new SafeMap( create("pncVisitDate", "2012-01-01") .put("id", "mother id 1") .put("childId", "child id 1") .put("urineStoolProblems", "diarrhea") .put("submissionDate", "2012-01-01") .map())); }
@Test public void shouldNotCreateChildWhenThereIsStillBirth() { FormSubmission submission = create() .withFormName("pnc_visit") .withANMId("anm id 1") .withEntityId("mother id 1") .addFormField("pncVisitDate", "2012-01-01") .addFormField("deliveryOutcome", "still_birth") .withSubForm(new SubFormData("child_pnc_visit", asList(EasyMap.create("id", "child id 1").map()))) .build(); service.pncVisitHappened(submission); verify(allChildren).remove("child id 1"); verifyNoMoreInteractions(childReportingService); }