PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()) .withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)) .withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()) .withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate(ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered(ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications(pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts) .withServicesProvided(servicesProvided) .withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService,
                                      AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries,
                                      Cache<String> cache, Cache<PNCClients> pncClientsCache);  PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService,
                                      AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries,
                                      Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); PNCClients getClients(); String villages();  }
@Test public void shouldSortPNCsByWifeName() throws Exception { Map<String, String> details = mapOf("edd", "Tue, 25 Feb 2014 00:00:00 GMT"); EligibleCouple ec2 = new EligibleCouple("EC Case 2", "Woman B", "Husband B", "EC Number 2", "kavalu_hosur", "Bherya SC", emptyMap); EligibleCouple ec3 = new EligibleCouple("EC Case 3", "Woman C", "Husband C", "EC Number 3", "Bherya", "Bherya SC", emptyMap); EligibleCouple ec1 = new EligibleCouple("EC Case 1", "Woman A", "Husband A", "EC Number 1", "Bherya", null, emptyMap); Mother m1 = new Mother("Entity X", "EC Case 2", "thayi 1", "2013-05-25").withDetails(details); Mother m2 = new Mother("Entity Y", "EC Case 3", "thayi 2", "2013-05-25").withDetails(details); Mother m3 = new Mother("Entity Z", "EC Case 1", "thayi 3", "2013-05-25").withDetails(details); PNCClient expectedClient1 = createPNCClient("Entity Z", "Woman A", "Bherya", "thayi 3", "2013-05-25").withECNumber("EC Number 1").withHusbandName("Husband A").withChildren(EMPTY_LIST).withEntityIdToSavePhoto("EC Case 1"); PNCClient expectedClient2 = createPNCClient("Entity X", "Woman B", "kavalu_hosur", "thayi 1", "2013-05-25").withECNumber("EC Number 2").withHusbandName("Husband B").withChildren(EMPTY_LIST).withEntityIdToSavePhoto("EC Case 2"); PNCClient expectedClient3 = createPNCClient("Entity Y", "Woman C", "Bherya", "thayi 2", "2013-05-25").withECNumber("EC Number 3").withHusbandName("Husband C").withChildren(EMPTY_LIST).withEntityIdToSavePhoto("EC Case 3"); when(allBeneficiaries.allPNCsWithEC()).thenReturn(asList(Pair.of(m1, ec2), Pair.of(m2, ec3), Pair.of(m3, ec1))); when(preProcessor.preProcess(any(PNCClient.class))).thenReturn(expectedClient1, expectedClient2, expectedClient3); PNCClients clients = controller.getClients(); assertEquals(expectedClient1.wifeName(), clients.get(0).wifeName()); assertEquals(expectedClient2.wifeName(), clients.get(1).wifeName()); assertEquals(expectedClient3.wifeName(), clients.get(2).wifeName()); }
@Test public void shouldMapPNCToPNCClient() throws Exception { Map<String, String> ecDetails = create("wifeAge", "22") .put("currentMethod", "condom") .put("familyPlanningMethodChangeDate", "2013-01-02") .put("isHighPriority", Boolean.toString(false)) .put("deliveryDate", "2011-05-05") .put("womanDOB", "2011-05-05") .put("caste", "sc") .put("economicStatus", "bpl") .put("iudPlace", "iudPlace") .put("iudPerson", "iudPerson") .put("numberOfCondomsSupplied", "20") .put("numberOfCentchromanPillsDelivered", "10") .put("numberOfOCPDelivered", "5") .map(); Map<String, String> motherDetails = create("deliveryPlace", "PHC") .put("deliveryType", "live_birth") .put("deliveryComplications", "Headache") .put("otherDeliveryComplications", "Vomiting") .map(); EligibleCouple eligibleCouple = new EligibleCouple("entity id 1", "Woman A", "Husband A", "EC Number 1", "Bherya", null, ecDetails).asOutOfArea(); Mother mother = new Mother("Entity X", "entity id 1", "thayi 1", "2013-05-25").withDetails(motherDetails); when(allBeneficiaries.allPNCsWithEC()).thenReturn(asList(Pair.of(mother, eligibleCouple))); when(allBeneficiaries.findAllChildrenByMotherId("Entity X")).thenReturn(asList(new Child("child id 1", "Entity X", "male", mapOf("weight", "2.4")), new Child("child id 2", "Entity X", "female", mapOf("weight", "2.5")))); PNCClient expectedPNCClient = new PNCClient("Entity X", "Bherya", "Woman A", "thayi 1", "2013-05-25") .withECNumber("EC Number 1") .withIsHighPriority(false) .withAge("22") .withWomanDOB("2011-05-05") .withEconomicStatus("bpl") .withIUDPerson("iudPerson") .withIUDPlace("iudPlace") .withHusbandName("Husband A") .withIsOutOfArea(true) .withIsHighRisk(false) .withCaste("sc") .withFPMethod("condom") .withFamilyPlanningMethodChangeDate("2013-01-02") .withNumberOfCondomsSupplied("20") .withNumberOfCentchromanPillsDelivered("10") .withNumberOfOCPDelivered("5") .withDeliveryPlace("PHC") .withDeliveryType("live_birth") .withDeliveryComplications("Headache") .withOtherDeliveryComplications("Vomiting") .withPhotoPath("../../img/woman-placeholder.png") .withEntityIdToSavePhoto("entity id 1") .withAlerts(Collections.<AlertDTO>emptyList()) .withChildren(asList(new ChildClient("child id 1", "male", "2.4", "thayi 1"), new ChildClient("child id 2", "female", "2.5", "thayi 1"))) .withServicesProvided(Collections.<ServiceProvidedDTO>emptyList()); when(preProcessor.preProcess(any(PNCClient.class))).thenReturn(expectedPNCClient); PNCClients clients = controller.getClients(); assertEquals(expectedPNCClient, clients.get(0)); }
@Test public void shouldCreatePNCClientsWithPNC1Alert() throws Exception { EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 1", "Bherya", "Bherya SC", emptyMap); Mother mother = new Mother("Entity X", "entity id 1", "thayi 1", "2013-05-25"); Alert pnc1Alert = new Alert("entity id 1", "PNC", "PNC 1", normal, "2013-01-01", "2013-02-01"); when(allBeneficiaries.allPNCsWithEC()).thenReturn(asList(Pair.of(mother, ec))); when(alertService.findByEntityIdAndAlertNames("Entity X", PNC_ALERTS)).thenReturn(asList(pnc1Alert)); AlertDTO expectedAlertDto = new AlertDTO("PNC 1", "normal", "2013-01-01"); PNCClient expectedEC = createPNCClient("Entity X", "Woman C", "Bherya", "thayi 1", "2013-05-25") .withECNumber("EC Number 1") .withHusbandName("Husband C") .withEntityIdToSavePhoto("entity id 1") .withAlerts(asList(expectedAlertDto)) .withChildren(EMPTY_LIST) .withServiceToVisitMap(new HashMap<String, Visits>()); when(preProcessor.preProcess(any(PNCClient.class))).thenReturn(expectedEC); PNCClients clients = controller.getClients(); verify(alertService).findByEntityIdAndAlertNames("Entity X", PNC_ALERTS); assertEquals(asList(expectedEC), clients); }
@Test public void shouldCreatePNCClientsWithServicesProvided() throws Exception { EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 1", "Bherya", "Bherya SC", emptyMap); Mother mother = new Mother("Entity X", "entity id 1", "thayi 1", "2013-05-25"); when(allBeneficiaries.allPNCsWithEC()).thenReturn(asList(Pair.of(mother, ec))); when(alertService.findByEntityIdAndAlertNames("Entity X", PNC_ALERTS)).thenReturn(Collections.<Alert>emptyList()); when(serviceProvidedService.findByEntityIdAndServiceNames("Entity X", PNC_SERVICES)) .thenReturn(asList(new ServiceProvided("entity id 1", "PNC 1", "2013-01-01", mapOf("dose", "100")), new ServiceProvided("entity id 1", "PNC 1", "2013-02-01", emptyMap))); List<ServiceProvidedDTO> expectedServicesProvided = asList(new ServiceProvidedDTO("PNC 1", "2013-01-01", mapOf("dose", "100")), new ServiceProvidedDTO("PNC 1", "2013-02-01", emptyMap)); PNCClient expectedEC = createPNCClient("Entity X", "Woman C", "Bherya", "thayi 1", "2013-05-25") .withECNumber("EC Number 1") .withHusbandName("Husband C") .withEntityIdToSavePhoto("entity id 1") .withServicesProvided(expectedServicesProvided) .withChildren(EMPTY_LIST); when(preProcessor.preProcess(any(PNCClient.class))).thenReturn(expectedEC); PNCClients clients = controller.getClients(); verify(alertService).findByEntityIdAndAlertNames("Entity X", PNC_ALERTS); verify(serviceProvidedService).findByEntityIdAndServiceNames("Entity X", PNC_SERVICES); assertEquals(asList(expectedEC), clients); }