ANCService { public void ancInvestigations(FormSubmission submission) { Mother mother = allMothers.findByCaseId(submission.entityId()); if (mother == null) { logger.warn("Tried to close case without registered mother for case ID: " + submission.entityId()); return; } Map<String, String> ancInvestigations = create(TEST_DATE, submission.getField(TEST_DATE)) .put(TESTS_RESULTS_TO_ENTER, submission.getField(TESTS_RESULTS_TO_ENTER)) .put(TESTS_POSITIVE_RESULTS, submission.getField(TESTS_POSITIVE_RESULTS)) .put(BILE_PIGMENTS, submission.getField(BILE_PIGMENTS)) .put(BILE_SALTS, submission.getField(BILE_SALTS)) .put(WOMAN_BLOOD_GROUP, submission.getField(WOMAN_BLOOD_GROUP)) .put(RH_INCOMPATIBLE_COUPLE, submission.getField(RH_INCOMPATIBLE_COUPLE)) .map(); mother.updateANCInvestigationsInformation(ancInvestigations); allMothers.update(mother); } @Autowired  ANCService(AllMothers allMothers,
                      AllEligibleCouples eligibleCouples,
                      ANCSchedulesService ancSchedulesService,
                      ActionService actionService,
                      MotherReportingService reportingService,
                      ReportFieldsDefinition reportFieldsDefinition); void registerANC(FormSubmission submission); void registerOutOfAreaANC(FormSubmission submission); void ancVisit(FormSubmission submission); void ttProvided(FormSubmission submission); void ifaTabletsGiven(FormSubmission submission); void hbTest(FormSubmission submission); void deliveryPlanned(FormSubmission submission); void deliveryOutcome(FormSubmission submission); void close(FormSubmission submission); void ancInvestigations(FormSubmission submission);  }
@Test public void shouldHandleANCInvestigations() { FormSubmission submission = create() .withFormName("anc_investigations") .withANMId("anm id 1") .withEntityId("entity id 1") .addFormField("testDate", "2013-01-01") .addFormField("testResultsToEnter", "urine_sugar mp hiv") .addFormField("testsResultPositive", "urine_sugar") .addFormField("bileSalts", "absent") .addFormField("bilePigments", "absent") .addFormField("womanBloodGroup", "ab_positive") .addFormField("rhIncompatibleCouple", "no") .build(); Mother mother = new Mother("entity id 1", "ec id 1", "TC1") .withDetails(mapOf("someKey", "someValue")); when(allMothers.findByCaseId("entity id 1")).thenReturn(mother); service.ancInvestigations(submission); Mother updatedMother = new Mother("entity id 1", "ec id 1", "TC1") .withDetails(mapOf("someKey", "someValue")) .withANCInvestigations(asList( create("testDate", "2013-01-01") .put("testResultsToEnter", "urine_sugar mp hiv") .put("testsResultPositive", "urine_sugar") .put("bileSalts", "absent") .put("bilePigments", "absent") .put("womanBloodGroup", "ab_positive") .put("rhIncompatibleCouple", "no") .map() )); verify(allMothers).update(updatedMother); }
@Test public void shouldUpdateANCInvestigationsWhenItAlreadyExists() { FormSubmission submission = create() .withFormName("anc_investigations") .withANMId("anm id 1") .withEntityId("entity id 1") .addFormField("testDate", "2013-01-01") .addFormField("testResultsToEnter", "urine_sugar mp hiv") .addFormField("testsResultPositive", "urine_sugar") .addFormField("bileSalts", "absent") .addFormField("bilePigments", "absent") .addFormField("womanBloodGroup", "ab_positive") .addFormField("rhIncompatibleCouple", "no") .build(); List<Map<String, String>> ancInvestigations = new ArrayList<>(); ancInvestigations.add(create("testDate", "2012-09-01") .put("bileSalts", "present") .put("bilePigments", "present") .map()); Mother mother = new Mother("entity id 1", "ec id 1", "TC1") .withANCInvestigations(ancInvestigations) .withDetails(mapOf("someKey", "someValue")); when(allMothers.findByCaseId("entity id 1")).thenReturn(mother); service.ancInvestigations(submission); Mother updatedMother = new Mother("entity id 1", "ec id 1", "TC1") .withDetails(mapOf("someKey", "someValue")) .withANCInvestigations(asList( create("testDate", "2012-09-01") .put("bileSalts", "present") .put("bilePigments", "present") .map(), create("testDate", "2013-01-01") .put("testResultsToEnter", "urine_sugar mp hiv") .put("testsResultPositive", "urine_sugar") .put("bileSalts", "absent") .put("bilePigments", "absent") .put("womanBloodGroup", "ab_positive") .put("rhIncompatibleCouple", "no") .map() )); verify(allMothers).update(updatedMother); }