Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less than12 week #865

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
7ec15e9
Two or more subscriber having same calling number and active, pending…
Mandar-Beehyv Oct 3, 2024
dcfff2f
Update for the record in their last 12 weeks should be accepted while…
Kantas2601 Oct 7, 2024
33d68e1
Time Slot optimization column in OBD files
Kantas2601 Sep 25, 2024
6b9a1a4
Two or more subscriber having same calling number and active, pending…
Mandar-Beehyv Oct 9, 2024
c6052f4
Two or more subscriber having same calling number and active, pending…
Mandar-Beehyv Oct 3, 2024
f2ff01e
Two or more subscriber having same calling number and active, pending…
Mandar-Beehyv Oct 9, 2024
a34312e
Merge remote-tracking branch 'origin/same-calling-number-issue' into …
Mandar-Beehyv Oct 9, 2024
9443205
Merge pull request #862 from motech-implementations/master
Kantas2601 Oct 14, 2024
fca96fb
priority healthBlock shifted to properties file of kilkari
Kantas2601 Oct 14, 2024
49d95a9
Merge remote-tracking branch 'origin/lessThan12Week' into lessThan12Week
Kantas2601 Oct 14, 2024
544bce3
Merge pull request #863 from motech-implementations/master
Mandar-Beehyv Oct 15, 2024
4070666
Two or more subscriber having same calling number and active, pending…
Mandar-Beehyv Oct 3, 2024
12e16f7
Two or more subscriber having same calling number and active, pending…
Mandar-Beehyv Oct 9, 2024
916a24f
Merge pull request #864 from motech-implementations/same-calling-numb…
Mandar-Beehyv Oct 18, 2024
de75f3f
Merge remote-tracking branch 'origin/lessThan12Week' into lessThan12Week
Mandar-Beehyv Oct 18, 2024
06bb78d
replacing '_' with '.'
Mandar-Beehyv Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public MotherImportRejection importMotherRecord(Map<String, Object> record, Subs
String action = "";
Boolean flagForMcts = true;
String ashaId ;
Long caseNo;
if (importOrigin.equals(SubscriptionOrigin.MCTS_IMPORT)) {
action = actionFinderService.motherActionFinder(convertMapToMother(record));
beneficiaryId = (String) record.get(KilkariConstants.BENEFICIARY_ID);
Expand All @@ -153,6 +154,7 @@ public MotherImportRejection importMotherRecord(Map<String, Object> record, Subs
stillBirth = (Boolean) record.get(KilkariConstants.STILLBIRTH);
lastUpdatedDateNic = (LocalDate) record.get(KilkariConstants.LAST_UPDATE_DATE);
ashaId = (String) record.get(KilkariConstants.KILKARI_ASHA_ID);
caseNo = (Long) record.get(KilkariConstants.CASE_NO);
} else {
flagForMcts = false;
action = actionFinderService.rchMotherActionFinder((convertMapToRchMother(record)));
Expand All @@ -164,6 +166,7 @@ public MotherImportRejection importMotherRecord(Map<String, Object> record, Subs
stillBirth = (Boolean) record.get(KilkariConstants.DELIVERY_OUTCOMES);
lastUpdatedDateNic = (LocalDate) record.get(KilkariConstants.EXECUTION_DATE);
ashaId = (String) record.get(KilkariConstants.KILKARI_ASHA_ID);
caseNo = (Long) record.get(KilkariConstants.CASE_NO);
}

LOGGER.trace("MotherImportRejection::importMotherRecord Start " + beneficiaryId) ;
Expand Down Expand Up @@ -203,7 +206,7 @@ public MotherImportRejection importMotherRecord(Map<String, Object> record, Subs
//new rejection reason less_than_12_week
boolean isServiceable=validateIsServiceable(lmp, SubscriptionPackType.PREGNANCY, msisdn, beneficiaryId, importOrigin);

if (!isServiceable) {
if (!isServiceable && (action.equals("CREATE") || mother.getMaxCaseNo() < caseNo)) {
return createUpdateMotherRejections(flagForMcts, record, action, RejectionReasons.LESS_THAN_12_WEEK, false);
}

Expand Down Expand Up @@ -289,7 +292,6 @@ public MotherImportRejection importMotherRecord(Map<String, Object> record, Subs
return createUpdateMotherRejections(flagForMcts, record, action, RejectionReasons.ACTIVE_CHILD_PRESENT, false);
}

Long caseNo = (Long) record.get(KilkariConstants.CASE_NO);
// validate caseNo
if (!validateCaseNo(caseNo, mother)) {
LOGGER.debug("MotherImportRejection::importMotherRecord End synchronized block " + beneficiaryId);
Expand Down Expand Up @@ -463,7 +465,7 @@ public ChildImportRejection importChildRecord(Map<String, Object> record, Subscr
//new rejection reason less_than_12_week
boolean isServiceable=validateIsServiceable(dob, SubscriptionPackType.CHILD, msisdn, childId, importOrigin);

if (!isServiceable) {
if (!isServiceable && action.equals("CREATE")) {
return createUpdateChildRejections(flagForMcts, record, action, RejectionReasons.LESS_THAN_12_WEEK, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,17 @@ private void liveBirthChildDeathCheck(Subscription subscription, Map<String, Obj
}
}

private void liveBirthChildCheck(Subscription subscription) {
// a child subscription was created -- deactivate mother's pregnancy subscription if she has one
Subscriber subscriber = subscription != null ? subscription.getSubscriber() : null;
Subscription pregnancySubscription = subscriptionService.getActiveSubscription(subscriber,
SubscriptionPackType.PREGNANCY);
if (pregnancySubscription != null) {
subscriptionService.deactivateSubscription(pregnancySubscription, DeactivationReason.LIVE_BIRTH);
}

}

@Override // NO CHECKSTYLE Cyclomatic Complexity
public ChildImportRejection updateRchChildSubscriber(Long msisdn, MctsChild childUpdate, DateTime dob, Map<String, Object> record, String action) { //NOPMD NcssMethodCount
District district = childUpdate.getDistrict(); // district should never be null here since we validate upstream on setLocation
Expand Down Expand Up @@ -614,10 +625,23 @@ public ChildImportRejection updateRchChildSubscriber(Long msisdn, MctsChild chil
}
}

if(subscriberByRchId!=null && childUpdate.getMother()!=null && childUpdate.getMother().getId() != null && getSubscriberListByMother(childUpdate.getMother().getId()) != null){
Subscriber motherSubscriberByRchId = getSubscriberListByMother(childUpdate.getMother().getId());
Subscription subscription = subscriptionService.getActiveSubscription(motherSubscriberByRchId, pack.getType());
if(!Objects.equals(motherSubscriberByRchId.getId(), subscriberByRchId.getId()) && subscription!=null){
return childRejectionRch(convertMapToRchChild(record), false, RejectionReasons.ALREADY_SUBSCRIBED.toString(), action);
}
}

if (subscriberByRchId != null) { //subscriber exists with the provided RCH id
if (subscribersByMsisdn.isEmpty()) { //no subscriber with provided msisdn
//subscriber's number has changed
//update msisdn in subscriber and delete msisdn from blocked list
if(subscriberByRchId.getMother()==null && childUpdate.getMother()!= null){
Subscriber motherSubscriber = getSubscriberListByMother(childUpdate.getMother().getId());
Subscription motherSubscription = subscriptionService.getActiveSubscription(motherSubscriber,SubscriptionPackType.PREGNANCY);
liveBirthChildCheck(motherSubscription);
}
subscriptionService.deleteBlockedMsisdn(childUpdate.getId(), subscriberByRchId.getCallingNumber(), msisdn);
subscriberByRchId.setCallingNumber(msisdn);
if (subscriberByRchId.getMother() == null) {
Expand All @@ -631,7 +655,43 @@ public ChildImportRejection updateRchChildSubscriber(Long msisdn, MctsChild chil
finalSubscription = updateOrCreateSubscription(subscriberByRchId, subscription, dob, pack, language, circle, SubscriptionOrigin.RCH_IMPORT, false);
} else {
//subscriber found with provided msisdn
if(childUpdate.getMother()!=null){
if(subscriberByRchId.getMother()==null && childUpdate.getMother()!= null){
Boolean isSameSubscriber = true;
Subscriber motherSubscriber = getSubscriberListByMother(childUpdate.getMother().getId());
Subscription motherSubscription = subscriptionService.getActiveSubscription(motherSubscriber,SubscriptionPackType.PREGNANCY);
liveBirthChildCheck(motherSubscription);

for (Subscriber subscriber : subscribersByMsisdn) {

if (subscriber.getId().equals(subscriberByRchId.getId())) {
Subscription subscription = subscriptionService.getActiveSubscription(subscriberByRchId, pack.getType());
if (subscriberByRchId.getMother() == null) {
subscriberByRchId.setMother(childUpdate.getMother());
}
subscriberByRchId.setDateOfBirth(dob);
subscriberByRchId.setModificationDate(DateTime.now());
finalSubscription = updateOrCreateSubscription(subscriberByRchId, subscription, dob, pack, language, circle, SubscriptionOrigin.RCH_IMPORT, false);
} else {
//A different subscriber found with same mobile number
isSameSubscriber = false;
}
}
if (!isSameSubscriber) {
if (subscriptionService.activeSubscriptionByMsisdnRch(subscribersByMsisdn, msisdn, SubscriptionPackType.CHILD, motherRchId, childUpdate.getRchId())) {
return childRejectionRch(convertMapToRchChild(record), false, RejectionReasons.MOBILE_NUMBER_ALREADY_SUBSCRIBED.toString(), action);
} else {
subscriberByRchId.setCallingNumber(msisdn);
if (subscriberByRchId.getMother() == null) {
subscriberByRchId.setMother(childUpdate.getMother());
}
Subscription subscription = subscriptionService.getActiveSubscription(subscriberByRchId, pack.getType());
subscriberByRchId.setDateOfBirth(dob);
subscriberByRchId.setModificationDate(DateTime.now());
finalSubscription = updateOrCreateSubscription(subscriberByRchId, subscription, dob, pack, language, circle, SubscriptionOrigin.RCH_IMPORT, false);
}
}
}
else if(childUpdate.getMother()!=null){
Subscriber subscriber = getSubscriberListByMother(childUpdate.getMother().getId());
Subscription subscription = subscriptionService.getActiveSubscription(subscriber, pack.getType());
if ((!Objects.equals(subscriber.getCallingNumber(), msisdn) || subscriber.getDateOfBirth().getDayOfYear() != dob.getDayOfYear()) && subscription!=null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class SubscriptionServiceImpl implements SubscriptionService {
private DeactivatedBeneficiaryDataService deactivatedBeneficiaryDataService;
private SubscriberMsisdnTrackerDataService subscriberMsisdnTrackerDataService;
public static AtomicBoolean isCapacityAvailable = new AtomicBoolean(true);
private static final String HIGH_PRIORITY_BLOCK = "kilkari.highPriority.blockId";


@Autowired
Expand Down Expand Up @@ -311,7 +312,7 @@ public Boolean activeSubscriptionByMsisdnRch(List<Subscriber> subscribers,Long m
return (subscriber.getMother() != null && subscriber.getMother().getRchId() != null && !motherRchId.equals(subscriber.getMother().getRchId()));
}
} else {
return (subscriber.getMother() != null && !motherRchId.equals(subscriber.getMother().getRchId()));
return (subscriber.getMother() == null || !motherRchId.equals(subscriber.getMother().getRchId()));
}
}
}
Expand All @@ -326,7 +327,7 @@ public Boolean activeSubscriptionByMsisdnRch(List<Subscriber> subscribers,Long m
subscriptionsSize = subscriptions.size();
if (subscriptionsSize != 0) {
if (subscriptionsSize == 1) {
if (SubscriptionPackType.PREGNANCY.equals(subscriptions.get(0).getSubscriptionPack().getType()) && subscriber.getMother() != null && subscriber.getMother().getRchId() != null && motherRchId != null && !motherRchId.equals(subscriber.getMother().getRchId())) {
if (SubscriptionPackType.PREGNANCY.equals(subscriptions.get(0).getSubscriptionPack().getType()) && subscriber.getMother() != null && subscriber.getMother().getRchId() != null && (motherRchId == null || !motherRchId.equals(subscriber.getMother().getRchId()))) {
return true;
} else if (SubscriptionPackType.PREGNANCY.equals(subscriptions.get(0).getSubscriptionPack().getType()) && subscriber.getMother() != null && subscriber.getMother().getRchId() != null && motherRchId != null && motherRchId.equals(subscriber.getMother().getRchId())) {
return false;
Expand Down Expand Up @@ -886,7 +887,7 @@ public String getSqlQuery() {
"JOIN nms_subscription_packs AS sp ON ss.subscriptionPack_id_OID = sp.id " +
"JOIN nms_subscribers AS s ON ss.subscriber_id_OID = s.id " +
"JOIN nms_mcts_mothers m ON s.mother_id_OID = m.id " +
"WHERE ss.status = 'HOLD' AND m.healthBlock_id_OID IN (3122, 3139, 3144, 1669, 3027, 3240, 3251, 3252, 3266, 3322, 3331, 3340) AND origin in ('MCTS_IMPORT', 'RCH_IMPORT')) AS res1 " +
"WHERE ss.status = 'HOLD' AND m.healthBlock_id_OID IN ( " + highPriorityBlocks() + " ) AND origin in ('MCTS_IMPORT', 'RCH_IMPORT')) AS res1 " +
"UNION " +
"SELECT res.id as id, res.activationDate, res.deactivationReason, res.endDate, res.firstMessageDayOfWeek, res.needsWelcomeMessageViaObd, " +
"res.origin, res.secondMessageDayOfWeek, res.startDate, res.status, res.subscriber_id_OID, res.subscriptionId, res.subscriptionPack_id_OID, " +
Expand Down Expand Up @@ -1320,5 +1321,12 @@ private Set<Long> getWhatsAppStateFilter(){
}
return states;
}

private String highPriorityBlocks(){
if (settingsFacade.getProperty(HIGH_PRIORITY_BLOCK)==null || settingsFacade.getProperty(HIGH_PRIORITY_BLOCK).trim().isEmpty()){
return "0";
}
return settingsFacade.getProperty(HIGH_PRIORITY_BLOCK);
}

}
2 changes: 2 additions & 0 deletions kilkari/src/main/resources/kilkari.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ kilkari.accept_new_subscription_for_blocked_msisdn=true

kilkari.chunk.size=1000
kilkari.thread.size=10000

kilkari.highPriority.blockId=3257999, 3258000, 3258001, 3258002, 3258003, 3258004, 3258005, 3258006, 3258007, 3258008, 3258009, 3258010, 3258011, 3258012, 3258013, 3258014, 3258015, 3258016, 3258017, 3258018, 3258019, 3258020, 3258021, 3258022, 3258023, 3258024, 3258025, 3258026, 3258027, 3258028, 3258029, 3258030, 3258031, 3258032, 3258033, 3258034, 3258035, 3258036, 3258037, 3258038, 3258039, 3258040, 3258041, 3258042, 3258043, 3258044, 3258045, 3258046, 3258047, 3258048, 3258049, 3258050, 3258051, 3258052, 3258053, 3258054, 3258055, 3258056, 3258057, 3258058, 3258059, 3258060, 3258061, 3258062, 3258063, 3258064, 3258065, 3258066, 3258067, 3258068, 3258069, 3258070, 3258071, 3258072, 3258073, 3258074, 3258075, 3258076, 3258077, 3258078, 3258079, 3258080, 3258081, 3258082, 3258083, 3258084, 3258085, 3258086, 3258087, 3258088, 3258089, 3258090, 3258091, 3258092, 3258093, 3258094, 3258095, 3258096, 3258097, 3258098, 3258099, 3258100, 3258101, 3258102, 3258103, 3258104, 3258105, 3258106, 3258107, 3258108, 3258109, 3258110, 3258111, 3258112, 3258113, 3258114, 3258115, 3258116, 3258117, 3258118, 3258119, 3258120, 3258121, 3258122, 3258123, 3258124, 3258125, 3258126, 3258127, 3258128, 3258129, 3258130, 3258131, 3258132, 3258133, 3258134, 3258135, 3258136, 3258137, 3258138, 3258139, 3258140, 3258141, 3258142, 3258143, 3258144, 3258145, 3258146, 3258147, 3258148, 3258149, 3258150, 3258151, 3258152, 3258153, 3258154, 3258155, 3258156, 3258157, 3258158, 3258159, 3258160, 3258161, 3258162, 3258163, 3258164, 3258165, 3258166, 3258167, 3258168, 3258169, 3258170, 3258171, 3258172, 3258173, 3258174, 3258175, 3258176, 3258177, 3258178, 3258179, 3258180, 3257859, 3257860, 3257861, 3257862, 3257863, 3257864, 3257865, 3257866, 3257867, 3257868, 3257869, 3257870, 3257871, 3257872, 3257873, 3257874, 3257875, 3257876, 3122, 3139, 3144, 1669, 3027, 3240, 3251, 3252, 3266, 3322, 3331, 3340