ChildService { public void closeChild(FormSubmission submission) { if (!allChildren.childExists(submission.entityId())) { logger.warn("Found close child request without registered child for entity id: " + submission.entityId()); return; } allChildren.close(submission.entityId()); actionService.markAllAlertsAsInactive(submission.entityId()); SafeMap reportFieldsMap = new SafeMap(submission.getFields(reportFieldsDefinition.get(submission.formName()))); childReportingService.closeChild(reportFieldsMap); childSchedulesService.unenrollChild(submission.entityId()); } @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 shouldCreateACloseChildActionForChildCaseClose() { DateTime currentTime = DateUtil.now(); mockCurrentDate(currentTime); FormSubmission submission = create() .withFormName("child_close") .withANMId("anm id 1") .withEntityId("child id 1") .build(); when(allChildren.childExists("child id 1")).thenReturn(true); service.closeChild(submission); verify(actionService).markAllAlertsAsInactive("child id 1"); }
@Test public void shouldUnenrollChildWhoseCaseHasBeenClosed() { FormSubmission submission = create() .withFormName("child_close") .withANMId("anm id 1") .withEntityId("child id 1") .build(); when(allChildren.childExists("child id 1")).thenReturn(true); service.closeChild(submission); verify(childSchedulesService).unenrollChild("child id 1"); }
@Test public void shouldReportWhenChildCaseIsClosed() { FormSubmission submission = create() .withFormName("child_close") .withANMId("anm id 1") .withEntityId("child id 1") .addFormField("someKey", "someValue") .build(); when(allChildren.childExists("child id 1")).thenReturn(true); when(reportFieldsDefinition.get("child_close")).thenReturn(asList("someKey")); service.closeChild(submission); verify(childReportingService).closeChild(new SafeMap(EXTRA_DATA.get("child_close"))); }
@Test public void shouldCloseWhenChildCaseIsClosed() { FormSubmission submission = create() .withFormName("child_close") .withANMId("anm id 1") .withEntityId("child id 1") .build(); when(allChildren.childExists("child id 1")).thenReturn(true); service.closeChild(submission); verify(allChildren).close("child id 1"); }
@Test public void shouldNotDoAnythingIfChildDoesNotExistsDuringClose() { FormSubmission submission = create() .withFormName("child_close") .withANMId("anm id 1") .withEntityId("child id 1") .build(); when(allChildren.childExists("child id 1")).thenReturn(false); service.closeChild(submission); verify(allChildren).childExists("child id 1"); verifyZeroInteractions(childReportingService); verifyZeroInteractions(childSchedulesService); verifyZeroInteractions(actionService); verifyNoMoreInteractions(allChildren); }