FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()) .withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate(ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered(ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()) .withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); FPClients getClients(); static final String OCP_REFILL_ALERT_NAME; static final String CONDOM_REFILL_ALERT_NAME; static final String DMPA_INJECTABLE_REFILL_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_1_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_2_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_3_ALERT_NAME; static final String MALE_STERILIZATION_FOLLOWUP_1_ALERT_NAME; static final String MALE_STERILIZATION_FOLLOWUP_2_ALERT_NAME; static final String IUD_FOLLOWUP_1_ALERT_NAME; static final String IUD_FOLLOWUP_2_ALERT_NAME; static final String FP_FOLLOWUP_ALERT_NAME; static final String FP_REFERRAL_FOLLOWUP_ALERT_NAME; }
@Test public void shouldMapECToFPClient() throws Exception { Map<String, String> details = create("wifeAge", "22") .put("currentMethod", "condom") .put("familyPlanningMethodChangeDate", "2013-01-02") .put("sideEffects", "sideEffects 1") .put("numberOfPregnancies", "2") .put("parity", "2") .put("numberOfLivingChildren", "1") .put("numberOfStillBirths", "1") .put("numberOfAbortions", "0") .put("isHighPriority", Boolean.toString(false)) .put("isYoungestChildUnderTwo", "yes") .put("youngestChildAge", "3") .put("complicationDate", "2011-05-05") .put("caste", "sc") .put("economicStatus", "bpl") .put("fpFollowupDate", "2013-03-04") .put("iudPlace", "iudPlace") .put("iudPerson", "iudPerson") .put("numberOfCondomsSupplied", "numberOfCondomsSupplied") .put("numberOfCentchromanPillsDelivered", "numberOfCentchromanPillsDelivered") .put("numberOfOCPDelivered", "numberOfOCPDelivered") .put("condomSideEffect", "condom side effect") .put("iudSidEffect", "iud side effect") .put("ocpSideEffect", "ocp side effect") .put("sterilizationSideEffect", "sterilization side effect") .put("injectableSideEffect", "injectable side effect") .put("otherSideEffect", "other side effect") .put("highPriorityReason", "high priority reason") .map(); EligibleCouple ec = new EligibleCouple("EC Case 1", "Woman A", "Husband A", "EC Number 1", "Bherya", "Bherya SC", details) .withPhotoPath("new photo path"); when(allEligibleCouples.all()).thenReturn(asList(ec)); FPClient expectedFPClient = new FPClient("EC Case 1", "Woman A", "Husband A", "Bherya", "EC Number 1") .withAge("22") .withFPMethod("condom") .withFamilyPlanningMethodChangeDate("2013-01-02") .withComplicationDate("2011-05-05") .withIUDPlace("iudPlace") .withIUDPerson("iudPerson") .withNumberOfCondomsSupplied("numberOfCondomsSupplied") .withNumberOfCentchromanPillsDelivered("numberOfCentchromanPillsDelivered") .withNumberOfOCPDelivered("numberOfOCPDelivered").withFPMethodFollowupDate("2013-03-04") .withCaste("sc") .withEconomicStatus("bpl") .withNumberOfPregnancies("2") .withParity("2") .withNumberOfLivingChildren("1") .withNumberOfStillBirths("1") .withNumberOfAbortions("0") .withIsYoungestChildUnderTwo(true) .withYoungestChildAge("3") .withIsHighPriority(false) .withPhotoPath("new photo path") .withCondomSideEffect("condom side effect") .withIUDSidEffect("iud side effect") .withOCPSideEffect("ocp side effect") .withSterilizationSideEffect("sterilization side effect") .withInjectableSideEffect("injectable side effect") .withOtherSideEffect("other side effect") .withHighPriorityReason("high priority reason") .withAlerts(Collections.<AlertDTO>emptyList()); FPClients actualClients = controller.getClients(); assertEquals(asList(expectedFPClient), actualClients); }
@Test public void shouldCreateFPClientsWithOCPRefillAlert() throws Exception { EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 3", "Bherya", "Bherya SC", emptyDetails); Alert ocpRefillAlert = new Alert("entity id 1", "OCP Refill", "OCP Refill", normal, "2013-01-01", "2013-02-01"); when(allEligibleCouples.all()).thenReturn(asList(ec)); when(alertService.findByEntityIdAndAlertNames("entity id 1", EC_ALERTS)).thenReturn(asList(ocpRefillAlert)); FPClients actualClients = controller.getClients(); verify(alertService).findByEntityIdAndAlertNames("entity id 1", EC_ALERTS); AlertDTO expectedAlertDto = new AlertDTO("OCP Refill", "normal", "2013-01-01"); FPClient expectedEC = createFPClient("entity id 1", "Woman C", "Husband C", "Bherya", "EC Number 3").withAlerts(asList(expectedAlertDto)).withNumberOfAbortions("0").withNumberOfPregnancies("0").withNumberOfStillBirths("0").withNumberOfLivingChildren("0").withParity("0"); assertEquals(asList(expectedEC), actualClients); }
@Test public void shouldCreateFPClientsWithRefillFollowUps() throws Exception { EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 3", "Bherya", "Bherya SC", EasyMap.create("currentMethod", "condom").map()); Alert condomRefillAlert = new Alert("entity id 1", "Condom Refill", "Condom Refill", urgent, "2013-01-01", "2013-02-01"); when(allEligibleCouples.all()).thenReturn(asList(ec)); when(alertService.findByEntityIdAndAlertNames("entity id 1", EC_ALERTS)).thenReturn(asList(condomRefillAlert)); when(context.getStringResource(R.string.str_refill)).thenReturn("refill"); FPClients clients = controller.getClients(); verify(alertService).findByEntityIdAndAlertNames("entity id 1", EC_ALERTS); AlertDTO expectedAlertDto = new AlertDTO("Condom Refill", "urgent", "2013-01-01"); FPClient expectedEC = createFPClient("entity id 1", "Woman C", "Husband C", "Bherya", "EC Number 3") .withAlerts(asList(expectedAlertDto)) .withNumberOfAbortions("0") .withNumberOfPregnancies("0") .withNumberOfStillBirths("0") .withNumberOfLivingChildren("0") .withParity("0") .withFPMethod("condom") .withRefillFollowUps(new RefillFollowUps("Condom Refill", expectedAlertDto, "refill")); assertEquals(asList(expectedEC), clients); }
@Test public void shouldNotIncludePregnantECsWhenFPClientsIsCreated() throws Exception { EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 3", "Bherya", "Bherya SC", emptyDetails); EligibleCouple pregnantEC = new EligibleCouple("entity id 2", "Woman D", "Husband D", "EC Number 4", "Bherya", "Bherya SC", emptyDetails); when(allEligibleCouples.all()).thenReturn(asList(ec, pregnantEC)); when(allBeneficiaries.isPregnant("entity id 1")).thenReturn(false); when(allBeneficiaries.isPregnant("entity id 2")).thenReturn(true); FPClients actualClients = controller.getClients(); verify(allBeneficiaries).isPregnant("entity id 1"); verify(allBeneficiaries).isPregnant("entity id 2"); FPClient expectedEC = createFPClient("entity id 1", "Woman C", "Husband C", "Bherya", "EC Number 3").withNumberOfAbortions("0").withNumberOfPregnancies("0").withNumberOfStillBirths("0").withNumberOfLivingChildren("0").withParity("0"); assertEquals(asList(expectedEC), actualClients); }