ChildService { public void vitaminAProvided(FormSubmission submission) { Child child = allChildren.findByCaseId(submission.entityId()); if (child == null) { logger.warn("Found that Vitamin A was provided to a not registered child with entity ID: " + submission.entityId()); return; } updateVitaminDetailsToChildEntity(submission, child); SafeMap reportFieldsMap = new SafeMap(submission.getFields(reportFieldsDefinition.get(submission.formName()))); childReportingService.vitaminAProvided(reportFieldsMap); } @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 shouldReportVitaminADosageWhenVitaminADosageIsGiven() { when(allChildren.findByCaseId("child id 1")).thenReturn(new Child("child id 1", "Mother id 1", "bcg", "3", "male")); FormSubmission submission = create() .withFormName("vitamin_a") .withEntityId("child id 1") .withANMId("anm id 1") .addFormField("vitaminADate", "2013-01-01") .addFormField("some-field", "some-value") .build(); when(reportFieldsDefinition.get("vitamin_a")).thenReturn(asList("some-field")); service.vitaminAProvided(submission); verify(childReportingService).vitaminAProvided(new SafeMap(mapOf("some-field", "some-value"))); }
@Test public void shouldUpdateVitaminADosageInChild() { when(allChildren.findByCaseId("Case X")).thenReturn(new Child("Case X", "Mother id 1", "bcg", "3", "male")); FormSubmission submission = create() .withFormName("vitamin_a") .withEntityId("Case X") .withANMId("anm id 1") .addFormField("some-field", "some-value") .addFormField("vitaminADose", "1") .addFormField("vitaminADate", "2013-01-01") .build(); service.vitaminAProvided(submission); verify(allChildren).update(new Child("Case X", "Mother id 1", "bcg", "3", "male") .withVitaminADoses(mapOf("dose1", "2013-01-01"))); }