RegisterService { public ECRegister getECRegister(String anmIdentifier) { ArrayList<ECRegisterEntry> ecRegisterEntries = new ArrayList<>(); List<EligibleCouple> ecs = allEligibleCouples.allOpenECsForANM(anmIdentifier); for (EligibleCouple ec : ecs) { Integer gravida = Integer.parseInt(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) + Integer.parseInt(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) + Integer.parseInt(ec.getDetail(NUMBER_OF_ABORTIONS)); List<Mother> mothers = allMothers.findAllOpenMothersByECCaseId(asList(ec.caseId())); boolean isPregnant = mothers.size() > 0; ECRegisterEntry ecRegisterEntry = new ECRegisterEntry() .withECNumber(ec.ecNumber()) .withWifeName(ec.wifeName()) .withHusbandName(ec.husbandName()) .withRegistrationDate(ec.getDetail(REGISTRATION_DATE)) .withVillage(ec.village()) .withSubCenter(ec.subCenter()) .withPHC(ec.phc()) .withWifeAge(ec.getDetail(WIFE_AGE)) .withHusbandAge(ec.getDetail(HUSBAND_AGE)) .withHouseholdNumber(ec.getDetail(HOUSEHOLD_NUMBER)) .withHouseholdAddress(ec.getDetail(HOUSEHOLD_ADDRESS)) .withHeadOfHousehold(ec.getDetail(HEAD_OF_HOUSEHOLD)) .withReligion(ec.getDetail(RELIGION)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withWifeEducationLevel(ec.getDetail(WIFE_EDUCATIONAL_LEVEL)) .withHusbandEducationLevel(ec.getDetail(HUSBAND_EDUCATION_LEVEL)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withParity(ec.getDetail(PARITY)) .withGravida(gravida.toString()) .withNumberOfLivingMaleChildren(ec.getDetail(NUMBER_OF_LIVING_MALE_CHILDREN)) .withNumberOfLivingFemaleChildren(ec.getDetail(NUMBER_OF_LIVING_FEMALE_CHILDREN)) .withYoungestChildAge(ec.getDetail(YOUNGEST_CHILD_AGE)) .withCurrentFPMethod(ec.getDetail(CURRENT_FP_METHOD_FIELD_NAME)) .withCurrentFPMethodStartDate(ec.getDetail(FP_METHOD_CHANGE_DATE_FIELD_NAME)) .withPregnancyStatus(isPregnant); ecRegisterEntries.add(ecRegisterEntry); } return new ECRegister(ecRegisterEntries); } @Autowired  RegisterService(AllMothers allMothers,
                           AllEligibleCouples allEligibleCouples); ANCRegister getANCRegister(String anmIdentifier); ECRegister getECRegister(String anmIdentifier);  }
@Test public void shouldGetECRegisterForAGivenANM() throws Exception { Mother mother = new Mother("caseId", "ecCaseId", "thayi card number 1") .withLMP(LocalDate.parse("2013-12-30")) .withDetails( create("ancNumber", "OA899") .put("registrationDate", "2014-01-01") .put("isJSYBeneficiary", "yes") .put("edd", "2014-09-01") .put("height", "150") .put("bloodGroup", "o -ve") .put("isHighRisk", "yes") .map() ); EligibleCouple eligibleCouple = new EligibleCouple("ecCaseId", "123") .withANMIdentifier("anm1") .withLocation("village", "sc", "phc") .withCouple("wife Name", "husband Name") .withDetails( create("registrationDate", "2013-01-01") .put("wifeName", "wife Name") .put("husbandName", "husband Name") .put("wifeAge", "23") .put("husbandAge", "32") .put("householdNumber", "22") .put("householdAddress", "HH Address") .put("headOfHousehold", "Head of HH") .put("religion", "religion") .put("caste", "caste") .put("economicStatus", "bpl") .put("educationalLevel", "wife education level") .put("husbandEducationLevel", "husband education level") .put("parity", "1") .put("numberOfLivingChildren", "1") .put("numberOfLivingMaleChildren", "1") .put("numberOfLivingFemaleChild", "0") .put("numberOfAbortions", "0") .put("numberOfStillBirths", "0") .put("youngestChildAge", "1") .put("currentMethod", "ocp") .put("familyPlanningMethodChangeDate", "2012-01-01") .map() ); when(allEligibleCouples.allOpenECsForANM("anm1")).thenReturn(asList(eligibleCouple)); when(allMothers.findAllOpenMothersByECCaseId(asList("ecCaseId"))).thenReturn(asList(mother)); ECRegister expectedRegister = new ECRegister(asList(new ECRegisterEntry() .withECNumber("123") .withRegistrationDate("2013-01-01") .withWifeName("wife Name") .withHusbandName("husband Name") .withVillage("village") .withSubCenter("sc") .withPHC("phc") .withWifeAge("23") .withHusbandAge("32") .withHouseholdNumber("22") .withHouseholdAddress("HH Address") .withHeadOfHousehold("Head of HH") .withReligion("religion") .withCaste("caste") .withEconomicStatus("bpl") .withWifeEducationLevel("wife education level") .withHusbandEducationLevel("husband education level") .withGravida("1") .withParity("1") .withNumberOfLivingChildren("1") .withNumberOfLivingMaleChildren("1") .withNumberOfLivingFemaleChildren("0") .withNumberOfStillBirths("0") .withNumberOfAbortions("0") .withYoungestChildAge("1") .withCurrentFPMethod("ocp") .withCurrentFPMethodStartDate("2012-01-01") .withPregnancyStatus(true) )); ECRegister register = registerService.getECRegister("anm1"); assertEquals(expectedRegister, register); }