ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()) .withHusbandName(ec.husbandName()) .withAge(ec.age()) .withECNumber(ec.ecNumber()) .withANCNumber(anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()) .withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus(ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath) .withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts) .withAshaPhoneNumber(anc.getDetail(AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided) .withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService,
                                      AllBeneficiaries allBeneficiaries,
                                      Cache<String> cache, Cache<ANCClients> ancClientsCache); ANCClients getClients();  }
@Test public void shouldSortANCsByWifeName() 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); Map<String, Visits> serviceToVisitsMap = EasyMap.create("tt", new Visits()).put("pnc", new Visits()).put("ifa", new Visits()).put("delivery_plan", new Visits()).put("anc", new Visits()).put("hb", new Visits()).map(); ANCClient expectedClient1 = createANCClient("Entity Z", "Woman A", "Bherya", "thayi 3", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 1").withHusbandName("Husband A").withEntityIdToSavePhoto("EC Case 1").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); ANCClient expectedClient2 = createANCClient("Entity X", "Woman B", "kavalu_hosur", "thayi 1", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 2").withHusbandName("Husband B").withEntityIdToSavePhoto("EC Case 2").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); ANCClient expectedClient3 = createANCClient("Entity Y", "Woman C", "Bherya", "thayi 2", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 3").withHusbandName("Husband C").withEntityIdToSavePhoto("EC Case 3").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); when(allBeneficiaries.allANCsWithEC()).thenReturn(asList(Pair.of(m1, ec2), Pair.of(m2, ec3), Pair.of(m3, ec1))); ANCClients actualClients = controller.getClients(); assertEquals(asList(expectedClient1, expectedClient2, expectedClient3), actualClients); }
@Test public void shouldGetANCClientsListWithSortedANCsByWifeName() 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); Map<String, Visits> serviceToVisitsMap = EasyMap.create("tt", new Visits()).put("pnc", new Visits()).put("ifa", new Visits()).put("delivery_plan", new Visits()).put("anc", new Visits()).put("hb", new Visits()).map(); ANCClient expectedClient1 = createANCClient("Entity Z", "Woman A", "Bherya", "thayi 3", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 1").withHusbandName("Husband A").withEntityIdToSavePhoto("EC Case 1").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); ANCClient expectedClient2 = createANCClient("Entity X", "Woman B", "kavalu_hosur", "thayi 1", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 2").withHusbandName("Husband B").withEntityIdToSavePhoto("EC Case 2").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); ANCClient expectedClient3 = createANCClient("Entity Y", "Woman C", "Bherya", "thayi 2", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 3").withHusbandName("Husband C").withEntityIdToSavePhoto("EC Case 3").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); when(allBeneficiaries.allANCsWithEC()).thenReturn(asList(Pair.of(m1, ec2), Pair.of(m2, ec3), Pair.of(m3, ec1))); SmartRegisterClients actualClients = controller.getClients(); assertEquals(asList(expectedClient1, expectedClient2, expectedClient3), actualClients); }
@Test public void shouldMapANCToANCClient() throws Exception { Map<String, String> details = create("edd", "Tue, 25 Feb 2014 00:00:00 GMT") .put("isHighRisk", "yes") .put("ancNumber", "ANC X") .put("highRiskReason", "Headache") .put("riskObservedDuringANC", "Headache") .put("ashaPhoneNumber", "Asha phone number 1") .map(); EligibleCouple eligibleCouple = new EligibleCouple("ec id 1", "Woman A", "Husband A", "EC Number 1", "Bherya", null, create("wifeAge", "23") .put("isHighPriority", Boolean.toString(false)) .put("caste", "other") .put("economicStatus", "bpl") .map() ).asOutOfArea(); Mother mother = new Mother("Entity X", "ec id 1", "thayi 1", "2013-05-25").withDetails(details); Map<String, Visits> serviceToVisitsMap = EasyMap.create("tt", new Visits()).put("pnc", new Visits()).put("ifa", new Visits()).put("delivery_plan", new Visits()).put("anc", new Visits()).put("hb", new Visits()).map(); when(allBeneficiaries.allANCsWithEC()).thenReturn(asList(Pair.of(mother, eligibleCouple))); ANCClient expectedANCClient = new ANCClient("Entity X", "Bherya", "Woman A", "thayi 1", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25") .withECNumber("EC Number 1") .withIsHighPriority(false) .withAge("23") .withHusbandName("Husband A") .withIsOutOfArea(true) .withIsHighRisk(true) .withCaste("other") .withANCNumber("ANC X") .withHighRiskReason("Headache") .withPhotoPath("../../img/woman-placeholder.png") .withEconomicStatus("bpl") .withEntityIdToSavePhoto("ec id 1") .withAlerts(Collections.<AlertDTO>emptyList()) .withAshaPhoneNumber("Asha phone number 1") .withServicesProvided(Collections.<ServiceProvidedDTO>emptyList()) .withServiceToVisitMap(serviceToVisitsMap); ANCClients actualClients = controller.getClients(); assertEquals(asList(expectedANCClient), actualClients); }
@Test public void shouldCreateANCClientsWithANC1AlertAndDeliveryPlanAlert() throws Exception { Map<String, String> details = mapOf("edd", "Tue, 25 Feb 2014 00:00:00 GMT"); 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", "2012-10-25").withDetails(details); Alert anc1Alert = new Alert("entity id 1", "ANC", "ANC 1", normal, "2013-01-01", "2013-02-01"); Alert deliveryPlanAlert = new Alert("entity id 1", "Delivery Plan", "Delivery Plan", normal, "2012-10-25", "2013-08-25"); when(allBeneficiaries.allANCsWithEC()).thenReturn(asList(Pair.of(mother, ec))); when(alertService.findByEntityIdAndAlertNames("Entity X", ANC_ALERTS)).thenReturn(asList(anc1Alert, deliveryPlanAlert)); ANCClients actualClients = controller.getClients(); verify(alertService).findByEntityIdAndAlertNames("Entity X", ANC_ALERTS); AlertDTO expectedANC1AlertDto = new AlertDTO("ANC 1", "normal", "2013-01-01"); AlertDTO expectedDeliveryPlanAlertDto = new AlertDTO("Delivery Plan", "normal", "2012-10-25"); Visits emptyVisit = new Visits(); Visits expectedANCVisit = new Visits(); expectedANCVisit.toProvide = expectedANC1AlertDto; Visits expectedDeliveryPlanVisit = new Visits(); expectedDeliveryPlanVisit.toProvide = expectedDeliveryPlanAlertDto; Map<String, Visits> serviceToVisitsMap = EasyMap.create("tt", emptyVisit).put("pnc", emptyVisit).put("ifa", emptyVisit).put("delivery_plan", expectedDeliveryPlanVisit).put("anc", expectedANCVisit).put("hb", emptyVisit).map(); ANCClient expectedEC = createANCClient("Entity X", "Woman C", "Bherya", "thayi 1", "Tue, 25 Feb 2014 00:00:00 GMT", "2012-10-25") .withECNumber("EC Number 1") .withHusbandName("Husband C") .withEntityIdToSavePhoto("entity id 1") .withAlerts(asList(expectedANC1AlertDto, expectedDeliveryPlanAlertDto)) .withServiceToVisitMap(serviceToVisitsMap) .withHighRiskReason(""); assertEquals(asList(expectedEC), actualClients); }
@Test public void shouldCreateANCClientsWithServicesProvided() throws Exception { Map<String, String> details = mapOf("edd", "Tue, 25 Feb 2014 00:00:00 GMT"); 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").withDetails(details); when(allBeneficiaries.allANCsWithEC()).thenReturn(asList(Pair.of(mother, ec))); when(alertService.findByEntityIdAndAlertNames("Entity X", ANC_ALERTS)).thenReturn(Collections.<Alert>emptyList()); when(sericeProvidedService.findByEntityIdAndServiceNames("Entity X", ANC_SERVICES)) .thenReturn(asList(new ServiceProvided("entity id 1", "IFA", "2013-01-01", mapOf("dose", "100")), new ServiceProvided("entity id 1", "TT 1", "2013-02-01", emptyMap), new ServiceProvided("entity id 1", "Delivery Plan", "2013-02-01", emptyMap) )); ANCClients actualClients = controller.getClients(); verify(alertService).findByEntityIdAndAlertNames("Entity X", ANC_ALERTS); verify(sericeProvidedService).findByEntityIdAndServiceNames("Entity X", ANC_SERVICES); ServiceProvidedDTO IFAServiceProvidedDTO = new ServiceProvidedDTO("IFA", "2013-01-01", mapOf("dose", "100")); ServiceProvidedDTO deliveryPlanServiceProvidedDTO = new ServiceProvidedDTO("Delivery Plan", "2013-02-01", emptyMap); ServiceProvidedDTO ttServiceProvidedDTO = new ServiceProvidedDTO("TT 1", "2013-02-01", emptyMap); List<ServiceProvidedDTO> expectedServicesProvided = asList(IFAServiceProvidedDTO, ttServiceProvidedDTO, deliveryPlanServiceProvidedDTO); Visits emptyVisit = new Visits(); Visits expectedIFAServiceProvided = new Visits(); expectedIFAServiceProvided.provided = IFAServiceProvidedDTO; Visits expectedDeliveryPlanServiceProvided = new Visits(); expectedDeliveryPlanServiceProvided.provided = deliveryPlanServiceProvidedDTO; Visits expectedTTServiceProvided = new Visits(); expectedTTServiceProvided.provided = ttServiceProvidedDTO; Map<String, Visits> serviceToVisitsMap = EasyMap.create("tt", expectedTTServiceProvided).put("pnc", emptyVisit).put("ifa", expectedIFAServiceProvided).put("delivery_plan", expectedDeliveryPlanServiceProvided).put("anc", emptyVisit).put("hb", emptyVisit).map(); ANCClient expectedEC = createANCClient("Entity X", "Woman C", "Bherya", "thayi 1", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25") .withECNumber("EC Number 1") .withHusbandName("Husband C") .withEntityIdToSavePhoto("entity id 1") .withServicesProvided(expectedServicesProvided) .withServiceToVisitMap(serviceToVisitsMap) .withHighRiskReason(""); assertEquals(asList(expectedEC), actualClients); }