Skip to content

Commit 088a15b

Browse files
committed
Update Modification date of mother-child mapping in case of mobile change
1 parent 90ccb9b commit 088a15b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ public Subscription updateRchMotherSubscriber(Long msisdn, MctsMother motherUpda
400400
motherUpdate.setLastMenstrualPeriod(lmp);
401401
motherUpdate.setUpdatedDateNic(lastUpdatedDateNic);
402402
motherUpdate.setRegistrationDate(motherRegistrationDate);
403+
updateSubscriptionModificationDate(subscriberByRchId, SubscriptionPackType.CHILD);
403404
return latestDeactivatedSubscription;
404405
}
405406
}else {
@@ -464,6 +465,7 @@ public Subscription updateRchMotherSubscriber(Long msisdn, MctsMother motherUpda
464465
motherUpdate.setDateOfBirth(motherDOB);
465466
motherUpdate.setLastMenstrualPeriod(lmp);
466467
motherUpdate.setUpdatedDateNic(lastUpdatedDateNic);
468+
updateSubscriptionModificationDate(subscriberByRchId, SubscriptionPackType.CHILD);
467469
return latestDeactivatedSubscription;
468470

469471
} else if (status.equals(SubscriptionStatus.DEACTIVATED) && ((!DeactivationReason.LOW_LISTENERSHIP.equals(reason) && !DeactivationReason.WEEKLY_CALLS_NOT_ANSWERED.equals(reason)))) {
@@ -507,6 +509,7 @@ public Subscription updateRchMotherSubscriber(Long msisdn, MctsMother motherUpda
507509

508510
} else if (status.equals(SubscriptionStatus.COMPLETED) || (DeactivationReason.INVALID_NUMBER.equals(reason) && subscriberByRchId.getCallingNumber().equals(msisdn)) ) {
509511
subscriberByRchId.setModificationDate(DateTime.now());
512+
updateSubscriptionModificationDate(subscriberByRchId, SubscriptionPackType.CHILD);
510513
return latestDeactivatedSubscription;
511514
} else {
512515
subscription = latestDeactivatedSubscription;
@@ -743,8 +746,7 @@ public ChildImportRejection updateRchChildSubscriber(Long msisdn, MctsChild chil
743746
subscriberByRchId.setDateOfBirth(dob);
744747
subscriberByRchId.setModificationDate(DateTime.now());
745748
//Check for active mother subscription as well, we are modifying mobile number so it should impact mother
746-
updateMotherSubscriptionModificationDate(subscriberByRchId);
747-
LOGGER.debug("Returning from latest deactivated subscription");
749+
updateSubscriptionModificationDate(subscriberByRchId, SubscriptionPackType.PREGNANCY);
748750
return null;
749751
}else if(latestDeactivatedSubscription.getStatus().equals(SubscriptionStatus.DEACTIVATED) && (latestDeactivatedSubscription.getDeactivationReason().equals(DeactivationReason.INVALID_NUMBER))) {
750752
LOGGER.debug("Assigning the latest deactivated subscription to subscriptions");
@@ -815,7 +817,7 @@ public ChildImportRejection updateRchChildSubscriber(Long msisdn, MctsChild chil
815817
subscriberByRchId.setModificationDate(DateTime.now());
816818
//Check for active mother subscription as well, we are modifying mobile number so it should impact mother
817819
if (!Objects.equals(subscriberByRchId.getCallingNumber(), msisdn)) {
818-
updateMotherSubscriptionModificationDate(subscriberByRchId);
820+
updateSubscriptionModificationDate(subscriberByRchId, SubscriptionPackType.PREGNANCY);
819821
}
820822

821823
return null;
@@ -847,7 +849,7 @@ else if(childUpdate.getMother()!=null){
847849
subscriberByRchId.setModificationDate(DateTime.now());
848850

849851
if (!Objects.equals(subscriber.getCallingNumber(), msisdn)) {
850-
updateMotherSubscriptionModificationDate(subscriberByRchId);
852+
updateSubscriptionModificationDate(subscriberByRchId, SubscriptionPackType.PREGNANCY);
851853
}
852854
return null;
853855
} else if (status.equals(SubscriptionStatus.DEACTIVATED) && reason.equals(DeactivationReason.INVALID_NUMBER) && !Objects.equals(subscriber.getCallingNumber(), msisdn)) {
@@ -882,7 +884,7 @@ else if(childUpdate.getMother()!=null){
882884
subscriberByRchId.setModificationDate(DateTime.now());
883885
//Check for active mother subscription as well, we are modifying mobile number so it should impact mother
884886
if (!Objects.equals(subscriber.getCallingNumber(), msisdn)) {
885-
updateMotherSubscriptionModificationDate(subscriberByRchId);
887+
updateSubscriptionModificationDate(subscriberByRchId, SubscriptionPackType.PREGNANCY);
886888
}
887889
return null;
888890
}
@@ -917,7 +919,7 @@ else if(childUpdate.getMother()!=null){
917919
subscriberByRchId.setDateOfBirth(dob);
918920
subscriberByRchId.setModificationDate(DateTime.now());
919921
//Check for active mother subscription as well, we are modifying mobile number so it should impact mother
920-
updateMotherSubscriptionModificationDate(subscriberByRchId);
922+
updateSubscriptionModificationDate(subscriberByRchId, SubscriptionPackType.PREGNANCY);
921923
return null;
922924
}
923925
else if(latestDeactivatedSubscription.getStatus().equals(SubscriptionStatus.DEACTIVATED) && (latestDeactivatedSubscription.getDeactivationReason().equals(DeactivationReason.INVALID_NUMBER))) {
@@ -1241,11 +1243,10 @@ public List<Subscriber> execute(Query query) {
12411243
else return subscriber;
12421244
}
12431245
}
1244-
1245-
private void updateMotherSubscriptionModificationDate(Subscriber subscriber) {
1246-
Subscription motherActive = subscriptionService.getActiveSubscription(subscriber, SubscriptionPackType.PREGNANCY);
1247-
if (motherActive != null) {
1248-
motherActive.setModificationDate(DateTime.now());
1246+
private void updateSubscriptionModificationDate(Subscriber subscriber, SubscriptionPackType packType) {
1247+
Subscription activeSubscription = subscriptionService.getActiveSubscription(subscriber, packType);
1248+
if (activeSubscription != null) {
1249+
activeSubscription.setModificationDate(DateTime.now());
12491250
}
12501251
}
12511252

0 commit comments

Comments
 (0)