@Test public void testUpdateLMP() throws Exception { createLocationData(); Long msisdn = subscriptionHelper.makeNumber(); String motherId = "0123456789"; DateTime originalLMP = DateTime.now().minusDays(100); DateTime updatedLMP = originalLMP.minusDays(200); subscriptionHelper.mksub( SubscriptionOrigin.MCTS_IMPORT, originalLMP, SubscriptionPackType.PREGNANCY, msisdn); Subscriber subscriber = subscriberDataService.findByCallingNumber(msisdn); subscriber.setLastMenstrualPeriod(originalLMP); MctsMother mother = new MctsMother(motherId); mother.setState(stateDataService.findByCode(21L)); mother.setDistrict(districtService.findByStateAndCode(mother.getState(), 3L)); subscriber.setMother(mother); subscriberDataService.update(subscriber); Reader reader = createUpdateReaderWithHeaders( "1," + motherId + ",,," + getDateString(updatedLMP) + ",,,,,,,,,,"); mctsBeneficiaryUpdateService.updateBeneficiaryData(reader); Subscriber updatedSubscriber = subscriberDataService.findByCallingNumber(msisdn); assertEquals( getDateString(updatedLMP), getDateString(updatedSubscriber.getLastMenstrualPeriod())); Subscription updatedSubscription = updatedSubscriber.getActiveAndPendingSubscriptions().iterator().next(); assertEquals( getDateString(updatedLMP.plusDays(90)), getDateString(updatedSubscription.getStartDate())); assertEquals(SubscriptionStatus.ACTIVE, updatedSubscription.getStatus()); }
@Test public void testUpdateBeneficiariesFromFile() throws Exception { createLocationData(); // ----Create 4 beneficiaries:---- String child1id = "1234567890"; MctsChild child1 = new MctsChild(child1id); child1.setState(stateDataService.findByCode(21L)); child1.setDistrict(districtService.findByStateAndCode(child1.getState(), 3L)); Long child1msisdn = subscriptionHelper.makeNumber(); makeMctsSubscription( child1, DateTime.now().minusDays(100), SubscriptionPackType.CHILD, child1msisdn); String mother2id = "1234567899"; MctsMother mother2 = new MctsMother(mother2id); mother2.setState(stateDataService.findByCode(21L)); mother2.setDistrict(districtService.findByStateAndCode(mother2.getState(), 3L)); Long mother2msisdn = subscriptionHelper.makeNumber(); makeMctsSubscription( mother2, DateTime.now().minusDays(100), SubscriptionPackType.PREGNANCY, mother2msisdn); String mother3id = "9876543210"; MctsMother mother3 = new MctsMother(mother3id); mother3.setState(stateDataService.findByCode(21L)); mother3.setDistrict(districtService.findByStateAndCode(mother3.getState(), 3L)); makeMctsSubscription( mother3, DateTime.now().minusDays(100), SubscriptionPackType.PREGNANCY, subscriptionHelper.makeNumber()); Long child4msisdn = subscriptionHelper.makeNumber(); MctsChild child4 = new MctsChild("9876543211"); child4.setState(stateDataService.findByCode(21L)); child4.setDistrict(districtService.findByStateAndCode(child4.getState(), 3L)); makeMctsSubscription( child4, DateTime.now().minusDays(100), SubscriptionPackType.CHILD, child4msisdn); // ----Update all 4 via CSV:---- mctsBeneficiaryUpdateService.updateBeneficiaryData(read("csv/mcts_beneficiary_update.csv")); // ----Validate updates to each:---- // MSISDN update: Subscriber oldSubscriber1 = subscriberDataService.findByCallingNumber(child1msisdn); assertNull(oldSubscriber1.getChild()); assertEquals(0, oldSubscriber1.getAllSubscriptions().size()); Subscriber subscriber1 = subscriberDataService.findByCallingNumber(9439986187L); assertNotNull(subscriber1); assertEquals(child1id, subscriber1.getChild().getBeneficiaryId()); // MSISDN update: Subscriber oldSubscriber2 = subscriberDataService.findByCallingNumber(mother2msisdn); assertNull(oldSubscriber2.getMother()); assertEquals(0, oldSubscriber2.getAllSubscriptions().size()); Subscriber subscriber2 = subscriberDataService.findByCallingNumber(9439986188L); assertNotNull(subscriber2); assertEquals(mother2id, subscriber2.getMother().getBeneficiaryId()); // Location update: MctsMother updatedMother3 = mctsMotherDataService.findByBeneficiaryId(mother3id); assertEquals(21L, (long) updatedMother3.getState().getCode()); assertEquals(3L, (long) updatedMother3.getDistrict().getCode()); assertEquals("0026", updatedMother3.getTaluka().getCode()); assertEquals(453L, (long) updatedMother3.getHealthBlock().getCode()); // DOB update: String updatedDOB = "01-07-2015"; Subscriber subscriber4 = subscriberDataService.findByCallingNumber(child4msisdn); assertEquals(updatedDOB, getDateString(subscriber4.getDateOfBirth())); Subscription updatedSubscription = subscriber4.getActiveAndPendingSubscriptions().iterator().next(); assertEquals(updatedDOB, getDateString(updatedSubscription.getStartDate())); assertEquals(SubscriptionStatus.ACTIVE, updatedSubscription.getStatus()); }