RegisterService { public ANCRegister getANCRegister(String anmIdentifier) { ArrayList<ANCRegisterEntry> ancRegisterEntries = new ArrayList<>(); List<Mother> mothers = allMothers.findAllOpenMothersForANM(anmIdentifier); List<String> ecIDs = collect(mothers, on(Mother.class).ecCaseId()); List<EligibleCouple> ecs = allEligibleCouples.findAll(ecIDs); for (Mother mother : mothers) { EligibleCouple ec = selectUnique(ecs, having(on(EligibleCouple.class).caseId(), equalTo(mother.ecCaseId()))); ANCRegisterEntry entry = new ANCRegisterEntry() .withANCNumber(mother.getDetail(ANC_NUMBER)) .withRegistrationDate(mother.getDetail(REGISTRATION_DATE)) .withECNumber(ec.ecNumber()) .withThayiCardNumber(mother.thayiCardNumber()) .withAadharCardNumber(ec.getDetail(AADHAR_NUMBER)) .withWifeName(ec.wifeName()) .withHusbandName(ec.husbandName()) .withAddress(ec.getDetail(HOUSEHOLD_ADDRESS)) .withWifeDOB(ec.wifeDOB()) .withPhoneNumber(ec.getDetail(PHONE_NUMBER)) .withWifeEducationLevel(ec.getDetail(WIFE_EDUCATIONAL_LEVEL)) .withHusbandEducationLevel(ec.getDetail(HUSBAND_EDUCATION_LEVEL)) .withCaste(ec.getDetail(CASTE)) .withReligion(ec.getDetail(RELIGION)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withBPLCardNumber(ec.getDetail(BPL_CARD_NUMBER)) .withJSYBeneficiary(mother.getDetail(JSY_BENEFICIARY)) .withGravida(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withYoungestChildDOB(ec.getDetail(YOUNGEST_CHILD_DOB)) .withLMP(mother.lmp().toString()) .withEDD(mother.getDetail(EDD)) .withHeight(mother.getDetail(HEIGHT)) .withBloodGroup(mother.getDetail(BLOOD_GROUP)) .withIsHRP(mother.getDetail(IS_HIGH_RISK)); ancRegisterEntries.add(entry); } return new ANCRegister(ancRegisterEntries); } @Autowired  RegisterService(AllMothers allMothers,
                           AllEligibleCouples allEligibleCouples); ANCRegister getANCRegister(String anmIdentifier); ECRegister getECRegister(String anmIdentifier);  }
@Test public void shouldGetANCRegisterForAGivenANM() 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") .withDetails( create("aadharNumber", "aadhar card number 1") .put("householdAddress", "address1") .put("phoneNumber", "phone 1") .put("educationalLevel", "wife education level") .put("husbandEducationLevel", "husband education level") .put("caste", "sc") .put("religion", "hindu") .put("economicStatus", "bpl") .put("bplCardNumber", "bpl card number 1") .put("numberOfPregnancies", "1") .put("parity", "2") .put("numberOfLivingChildren", "3") .put("numberOfStillBirths", "4") .put("numberOfAbortions", "5") .put("youngestChildDOB", "2012-01-01") .put("womanDOB", "1989-01-01") .map()) .withCouple("name1", "name2"); when(allMothers.findAllOpenMothersForANM("anm1")).thenReturn(asList(mother)); when(allEligibleCouples.findAll(asList("ecCaseId"))).thenReturn(asList(eligibleCouple)); ANCRegister expectedRegister = new ANCRegister(asList(new ANCRegisterEntry() .withANCNumber("OA899") .withRegistrationDate("2014-01-01") .withECNumber("123") .withThayiCardNumber("thayi card number 1") .withAadharCardNumber("aadhar card number 1") .withWifeName("name1") .withHusbandName("name2") .withAddress("address1") .withWifeDOB("1989-01-01") .withPhoneNumber("phone 1") .withWifeEducationLevel("wife education level") .withHusbandEducationLevel("husband education level") .withCaste("sc") .withReligion("hindu") .withEconomicStatus("bpl") .withBPLCardNumber("bpl card number 1") .withJSYBeneficiary("yes") .withGravida("1") .withParity("2") .withNumberOfLivingChildren("3") .withNumberOfStillBirths("4") .withNumberOfAbortions("5") .withYoungestChildDOB("2012-01-01") .withLMP("2013-12-30") .withEDD("2014-09-01") .withHeight("150") .withBloodGroup("o -ve") .withIsHRP("yes"))); ANCRegister register = registerService.getANCRegister("anm1"); assertEquals(expectedRegister, register); }
@Test public void shouldGetANCRegisterForANCOutOfAreaWithoutDOB() throws Exception { DateUtil.fakeIt(LocalDate.parse("2014-01-01")); 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") .withDetails( create("aadharNumber", "aadhar card number 1") .put("householdAddress", "address1") .put("phoneNumber", "phone 1") .put("educationalLevel", "wife education level") .put("husbandEducationLevel", "husband education level") .put("caste", "sc") .put("religion", "hindu") .put("economicStatus", "bpl") .put("bplCardNumber", "bpl card number 1") .put("numberOfPregnancies", "1") .put("parity", "2") .put("numberOfLivingChildren", "3") .put("numberOfStillBirths", "4") .put("numberOfAbortions", "5") .put("youngestChildDOB", "2012-01-01") .put("wifeAge", "26") .map()) .withCouple("name1", "name2"); when(allMothers.findAllOpenMothersForANM("anm1")).thenReturn(asList(mother)); when(allEligibleCouples.findAll(asList("ecCaseId"))).thenReturn(asList(eligibleCouple)); ANCRegister expectedRegister = new ANCRegister(asList(new ANCRegisterEntry() .withANCNumber("OA899") .withRegistrationDate("2014-01-01") .withECNumber("123") .withThayiCardNumber("thayi card number 1") .withAadharCardNumber("aadhar card number 1") .withWifeName("name1") .withHusbandName("name2") .withAddress("address1") .withWifeDOB("1988-01-01") .withPhoneNumber("phone 1") .withWifeEducationLevel("wife education level") .withHusbandEducationLevel("husband education level") .withCaste("sc") .withReligion("hindu") .withEconomicStatus("bpl") .withBPLCardNumber("bpl card number 1") .withJSYBeneficiary("yes") .withGravida("1") .withParity("2") .withNumberOfLivingChildren("3") .withNumberOfStillBirths("4") .withNumberOfAbortions("5") .withYoungestChildDOB("2012-01-01") .withLMP("2013-12-30") .withEDD("2014-09-01") .withHeight("150") .withBloodGroup("o -ve") .withIsHRP("yes"))); ANCRegister register = registerService.getANCRegister("anm1"); assertEquals(expectedRegister, register); }