@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()); }
private void makeMctsSubscription( MctsBeneficiary beneficiary, DateTime startDate, SubscriptionPackType packType, Long number) { subscriptionHelper.mksub(SubscriptionOrigin.MCTS_IMPORT, startDate, packType, number); Subscriber subscriber = subscriberDataService.findByCallingNumber(number); if (packType == SubscriptionPackType.CHILD) { subscriber.setChild((MctsChild) beneficiary); subscriber.setDateOfBirth(startDate); } else { subscriber.setMother((MctsMother) beneficiary); subscriber.setLastMenstrualPeriod(startDate.minusDays(90)); } subscriberDataService.update(subscriber); }