From 7ec15e93c660c549803ed580144927c51a6ad3f9 Mon Sep 17 00:00:00 2001 From: Mandar-Beehyv Date: Thu, 3 Oct 2024 17:15:29 +0530 Subject: [PATCH 01/10] Two or more subscriber having same calling number and active, pending or hold subscriptions --- .../nms/kilkari/service/impl/SubscriptionServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java index 2980e36e6..140a94df0 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java @@ -311,7 +311,7 @@ public Boolean activeSubscriptionByMsisdnRch(List 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())); } } } @@ -326,7 +326,7 @@ public Boolean activeSubscriptionByMsisdnRch(List 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; From dcfff2ff579148d012d1b0abc323079baa574f4f Mon Sep 17 00:00:00 2001 From: Kantas2601 Date: Mon, 7 Oct 2024 11:53:15 +0530 Subject: [PATCH 02/10] Update for the record in their last 12 weeks should be accepted while any request for fresh subscription should get rejecetd straight away --- .../service/impl/MctsBeneficiaryImportServiceImpl.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java index e77f703fa..5e6355a30 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java @@ -144,6 +144,7 @@ public MotherImportRejection importMotherRecord(Map 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); @@ -153,6 +154,7 @@ public MotherImportRejection importMotherRecord(Map 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))); @@ -164,6 +166,7 @@ public MotherImportRejection importMotherRecord(Map 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) ; @@ -203,7 +206,7 @@ public MotherImportRejection importMotherRecord(Map 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); } @@ -289,7 +292,6 @@ public MotherImportRejection importMotherRecord(Map 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); @@ -463,7 +465,7 @@ public ChildImportRejection importChildRecord(Map 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); } From 33d68e157ea6e3ef15ae289a79d07468e6a8bb18 Mon Sep 17 00:00:00 2001 From: Kantas2601 Date: Wed, 25 Sep 2024 18:43:52 +0530 Subject: [PATCH 03/10] Time Slot optimization column in OBD files --- .../service/impl/TargetFileServiceImpl.java | 168 ++++++++++++++++-- .../resources/META-INF/spring/blueprint.xml | 3 + .../kilkari/domain/SubscriptionTimeSlot.java | 98 ++++++++++ .../SubscriptionTimeSlotDataService.java | 8 + .../service/SubscriptionTimeSlotService.java | 11 ++ .../impl/SubscriptionTimeSlotServiceImpl.java | 96 ++++++++++ .../resources/META-INF/spring/blueprint.xml | 6 + 7 files changed, 378 insertions(+), 12 deletions(-) create mode 100644 kilkari/src/main/java/org/motechproject/nms/kilkari/domain/SubscriptionTimeSlot.java create mode 100644 kilkari/src/main/java/org/motechproject/nms/kilkari/repository/SubscriptionTimeSlotDataService.java create mode 100644 kilkari/src/main/java/org/motechproject/nms/kilkari/service/SubscriptionTimeSlotService.java create mode 100644 kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionTimeSlotServiceImpl.java diff --git a/imi/src/main/java/org/motechproject/nms/imi/service/impl/TargetFileServiceImpl.java b/imi/src/main/java/org/motechproject/nms/imi/service/impl/TargetFileServiceImpl.java index ba64dc142..f3b75bb10 100644 --- a/imi/src/main/java/org/motechproject/nms/imi/service/impl/TargetFileServiceImpl.java +++ b/imi/src/main/java/org/motechproject/nms/imi/service/impl/TargetFileServiceImpl.java @@ -30,6 +30,7 @@ import org.motechproject.nms.kilkari.repository.WhatsAppOptSMSDataService; import org.motechproject.nms.kilkari.service.CallRetryService; import org.motechproject.nms.kilkari.service.SubscriptionService; +import org.motechproject.nms.kilkari.service.SubscriptionTimeSlotService; import org.motechproject.nms.kilkari.utils.KilkariConstants; import org.motechproject.nms.props.domain.DayOfTheWeek; import org.motechproject.nms.props.domain.RequestId; @@ -101,6 +102,7 @@ public class TargetFileServiceImpl implements TargetFileService { private MotechSchedulerService schedulerService; private AlertService alertService; private SubscriptionService subscriptionService; + private SubscriptionTimeSlotService subscriptionTimeSlotService; private CallRetryService callRetryService; private FileAuditRecordDataService fileAuditRecordDataService; private WhatsAppOptSMSDataService whatsAppOptSMSDataService; @@ -201,7 +203,8 @@ public TargetFileServiceImpl(@Qualifier("imiSettings") SettingsFacade settingsFa SubscriptionService subscriptionService, CallRetryService callRetryService, FileAuditRecordDataService fileAuditRecordDataService, - WhatsAppOptSMSDataService whatsAppOptSMSDataService) { + WhatsAppOptSMSDataService whatsAppOptSMSDataService, + SubscriptionTimeSlotService subscriptionTimeSlotService) { this.schedulerService = schedulerService; this.settingsFacade = settingsFacade; this.alertService = alertService; @@ -209,6 +212,7 @@ public TargetFileServiceImpl(@Qualifier("imiSettings") SettingsFacade settingsFa this.callRetryService = callRetryService; this.fileAuditRecordDataService = fileAuditRecordDataService; this.whatsAppOptSMSDataService = whatsAppOptSMSDataService; + this.subscriptionTimeSlotService = subscriptionTimeSlotService; scheduleTargetFileGeneration(); scheduleWhatsAppTargetFileGeneration(); @@ -412,6 +416,15 @@ private void writeHeader(OutputStreamWriter writer) throws IOException { * # WhatsApp OPT-IN Call need to be played at welcome prompt */ writer.write("opt_in_call_eligibility"); + writer.write(","); + + writer.write("time_stamp1"); + writer.write(","); + + writer.write("time_stamp2"); + writer.write(","); + + writer.write("time_stamp3"); writer.write("\n"); } @@ -421,9 +434,10 @@ private File wpLocalObdDir() { } private void writeSubscriptionRow(String requestId, String serviceId, // NO CHECKSTYLE More than 7 parameters - String msisdn, String priority, String callFlowUrl, String contentFileName, + String msisdn, String priority, String callFlowUrl, String contentFileName, String weekId, String languageLocationCode, String circle, - String subscriptionOrigin, OutputStreamWriter writer, Boolean needsWelcomeOptInForWP) throws IOException { + String subscriptionOrigin, OutputStreamWriter writer, Boolean needsWelcomeOptInForWP, + String timestamp1, String timestamp2, String timestamp3)throws IOException { /* * #1 RequestId * @@ -521,6 +535,32 @@ private void writeSubscriptionRow(String requestId, String serviceId, // NO CHEC writer.write((((contentFileName.equals("w1_1.wav") || contentFileName.equals("opt_in.wav")) && needsWelcomeOptInForWP != null) ? needsWelcomeOptInForWP : Boolean.FALSE).toString()); + writer.write(","); + + if (timestamp1 != null) { + writer.write(timestamp1); + } + writer.write(","); + + /* + * #14 Extra Column 2 + * + * Additional data from SubscriptionTimeSlot + */ + if (timestamp2 != null) { + writer.write(timestamp2); + } + writer.write(","); + + /* + * #15 Extra Column 3 + * + * Additional data from SubscriptionTimeSlot + */ + if (timestamp3 != null) { + writer.write(timestamp3); + } + writer.write("\n"); } @@ -545,8 +585,31 @@ private HashMap generateFreshCalls(DateTime timestamp, int maxQ break; } + List subscriptionIds = new ArrayList<>(); + for (Subscription subscription : subscriptions) { + subscriptionIds.add(subscription.getSubscriptionId()); + } + + List timeSlots = null; + + try { + timeSlots = subscriptionTimeSlotService.findTimeSlotsForSubscriptionsById(subscriptionIds); + + }catch (Exception e){ + LOGGER.error("Error finding time slots for subscriptions", e); + } + if(timeSlots==null){ + continue; + } + + + Map timeSlotMap = new HashMap<>(); + for (SubscriptionTimeSlot timeSlot : timeSlots) { + timeSlotMap.put(timeSlot.getSubscriptionId(), timeSlot); + } + for (Subscription subscription : subscriptions) { - LOGGER.debug("Handling Subscription " + subscription.getId()); +// LOGGER.debug("Handling Subscription " + subscription.getId()); offset = subscription.getId(); Subscriber subscriber = subscription.getSubscriber(); @@ -570,6 +633,14 @@ private HashMap generateFreshCalls(DateTime timestamp, int maxQ } SubscriptionPackMessage msg = subscription.nextScheduledMessage(timestamp); + + SubscriptionTimeSlot timeSlot = timeSlotMap.get(subscription.getSubscriptionId()); + String timeStamp1 = timeSlot != null ? timeSlot.getTimeStamp1() != null ? timeSlot.getTimeStamp1().toString() : "" : ""; + String timeStamp2 = timeSlot != null ? timeSlot.getTimeStamp2() != null ? timeSlot.getTimeStamp2().toString() : "" : ""; + String timeStamp3 = timeSlot != null ? timeSlot.getTimeStamp3() != null ? timeSlot.getTimeStamp3().toString() : "" : ""; + + + if(split && subscriptionIdsJh.contains(subscription.getSubscriptionId())) { writeSubscriptionRow( requestId.toString(), @@ -584,14 +655,17 @@ private HashMap generateFreshCalls(DateTime timestamp, int maxQ subscriber.getCircle() == null ? "" : subscriber.getCircle().getName(), subscription.getOrigin().getCode(), wr.get(Jh), - subscription.isNeedsWelcomeOptInForWP()); + subscription.isNeedsWelcomeOptInForWP(), + timeStamp1, + timeStamp2, + timeStamp3); recordsWrittenJh++; } else if(specificStateList.contains(stateID)){ - recordsWrittenSpecific = getRecordsWritten(callFlowUrl, wr, recordsWrittenSpecific, subscription, subscriber, requestId, msg, specific_non_Jh); + recordsWrittenSpecific = getRecordsWritten(callFlowUrl, wr, recordsWrittenSpecific, subscription, subscriber, requestId, msg, specific_non_Jh,timeStamp1,timeStamp2,timeStamp3); } else { - recordsWritten = getRecordsWritten(callFlowUrl, wr, recordsWritten, subscription, subscriber, requestId, msg, non_Jh); + recordsWritten = getRecordsWritten(callFlowUrl, wr, recordsWritten, subscription, subscriber, requestId, msg, non_Jh,timeStamp1,timeStamp2,timeStamp3); } } catch (IllegalStateException se) { @@ -614,7 +688,7 @@ else if(specificStateList.contains(stateID)){ return recordsMap; } - private int getRecordsWritten(String callFlowUrl, HashMap wr, int recordsWrittenJh, Subscription subscription, Subscriber subscriber, RequestId requestId, SubscriptionPackMessage msg, String specific_non_jh) throws IOException { + private int getRecordsWritten(String callFlowUrl, HashMap wr, int recordsWrittenJh, Subscription subscription, Subscriber subscriber, RequestId requestId, SubscriptionPackMessage msg, String specific_non_jh,String timeStamp1,String timeStamp2,String timeStamp3) throws IOException { writeSubscriptionRow( requestId.toString(), serviceIdFromOrigin(true, subscription.getOrigin()), @@ -628,7 +702,10 @@ private int getRecordsWritten(String callFlowUrl, HashMap generateRetryCalls(DateTime timestamp, int maxQ if (callRetries.size() == 0) { break; } + + List subscriptionIds = new ArrayList<>(); + for (CallRetry callRetry : callRetries) { + subscriptionIds.add(callRetry.getSubscriptionId()); + } + + + List timeSlots = null; + try { + timeSlots = subscriptionTimeSlotService.findTimeSlotsForSubscriptionsById(subscriptionIds); + } catch (Exception e) { + LOGGER.error("Error finding time slots for subscriptions", e); + } + + if (timeSlots == null) { + continue; + } + + Map timeSlotMap = new HashMap<>(); + for (SubscriptionTimeSlot timeSlot : timeSlots) { + timeSlotMap.put(timeSlot.getSubscriptionId(), timeSlot); + } + + for (CallRetry callRetry : callRetries) { offset = callRetry.getId(); RequestId requestId = new RequestId(callRetry.getSubscriptionId(), TIME_FORMATTER.print(timestamp)); + + SubscriptionTimeSlot timeSlot = timeSlotMap.get(callRetry.getSubscriptionId()); + String timeStamp1 = timeSlot != null ? timeSlot.getTimeStamp1() != null ? timeSlot.getTimeStamp1().toString() : "" : ""; + String timeStamp2 = timeSlot != null ? timeSlot.getTimeStamp2() != null ? timeSlot.getTimeStamp2().toString() : "" : ""; + String timeStamp3 = timeSlot != null ? timeSlot.getTimeStamp3() != null ? timeSlot.getTimeStamp3().toString() : "" : ""; + writeSubscriptionRow( requestId.toString(), serviceIdFromOrigin(false, callRetry.getSubscriptionOrigin()), @@ -749,7 +856,10 @@ private HashMap generateRetryCalls(DateTime timestamp, int maxQ callRetry.getCircle(), callRetry.getSubscriptionOrigin().getCode(), wr.get(specific_non_Jh), - callRetry.isOpt_in_call_eligibility()); + callRetry.isOpt_in_call_eligibility(), + timeStamp1, + timeStamp2, + timeStamp3); countSpecific++; } @@ -764,10 +874,38 @@ private HashMap generateRetryCalls(DateTime timestamp, int maxQ if (callRetries.size() == 0) { break; } + List subscriptionIds = new ArrayList<>(); + for (CallRetry callRetry : callRetries) { + subscriptionIds.add(callRetry.getSubscriptionId()); + } + + + List timeSlots = null; + try { + timeSlots = subscriptionTimeSlotService.findTimeSlotsForSubscriptionsById(subscriptionIds); + } catch (Exception e) { + LOGGER.error("Error finding time slots for subscriptions", e); + } + + if (timeSlots == null) { +// LOGGER.warn("No time slots found for subscriptions: {}", subscriptionIds); + continue; + } + + Map timeSlotMap = new HashMap<>(); + for (SubscriptionTimeSlot timeSlot : timeSlots) { + timeSlotMap.put(timeSlot.getSubscriptionId(), timeSlot); + } + for (CallRetry callRetry : callRetries) { offset = callRetry.getId(); RequestId requestId = new RequestId(callRetry.getSubscriptionId(), TIME_FORMATTER.print(timestamp)); + SubscriptionTimeSlot timeSlot = timeSlotMap.get(callRetry.getSubscriptionId()); + String timeStamp1 = timeSlot != null ? timeSlot.getTimeStamp1() != null ? timeSlot.getTimeStamp1().toString() : "" : ""; + String timeStamp2 = timeSlot != null ? timeSlot.getTimeStamp2() != null ? timeSlot.getTimeStamp2().toString() : "" : ""; + String timeStamp3 = timeSlot != null ? timeSlot.getTimeStamp3() != null ? timeSlot.getTimeStamp3().toString() : "" : ""; + if (split && subscriptionIdsJh.contains(callRetry.getSubscriptionId())) { writeSubscriptionRow( requestId.toString(), @@ -781,7 +919,10 @@ private HashMap generateRetryCalls(DateTime timestamp, int maxQ callRetry.getCircle(), callRetry.getSubscriptionOrigin().getCode(), wr.get(Jh), - callRetry.isOpt_in_call_eligibility()); + callRetry.isOpt_in_call_eligibility(), + timeStamp1, + timeStamp2, + timeStamp3); countJh++; } else { writeSubscriptionRow( @@ -796,7 +937,10 @@ private HashMap generateRetryCalls(DateTime timestamp, int maxQ callRetry.getCircle(), callRetry.getSubscriptionOrigin().getCode(), wr.get(non_Jh), - callRetry.isOpt_in_call_eligibility()); + callRetry.isOpt_in_call_eligibility(), + timeStamp1, + timeStamp2, + timeStamp3); count++; } } diff --git a/imi/src/main/resources/META-INF/spring/blueprint.xml b/imi/src/main/resources/META-INF/spring/blueprint.xml index ee226fd25..43d28cc88 100644 --- a/imi/src/main/resources/META-INF/spring/blueprint.xml +++ b/imi/src/main/resources/META-INF/spring/blueprint.xml @@ -56,6 +56,9 @@ + + diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/SubscriptionTimeSlot.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/SubscriptionTimeSlot.java new file mode 100644 index 000000000..e7708f004 --- /dev/null +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/SubscriptionTimeSlot.java @@ -0,0 +1,98 @@ +package org.motechproject.nms.kilkari.domain; + +import org.joda.time.DateTime; +import org.motechproject.mds.annotations.Entity; +import org.motechproject.mds.annotations.Field; + +import javax.persistence.Id; + +@Entity(tableName = "nms_subscriptions_time_slot") +public class SubscriptionTimeSlot { + + @Id + @Field + private Long subscription_id; + + @Field + private String subscriptionId; + + @Field + private Integer timeStamp1; + + @Field + private Integer timeStamp2; + + @Field + private Integer timeStamp3; + + @Field + private DateTime creationDate; + + @Field + private DateTime modificationDate; + + public SubscriptionTimeSlot() { + + } + + public DateTime getCreationDate() { + return creationDate; + } + + public void setCreationDate(DateTime creationDate) { + this.creationDate = creationDate; + } + + public DateTime getModificationDate() { + return modificationDate; + } + + public void setModificationDate(DateTime modificationDate) { + this.modificationDate = modificationDate; + } + + public Long getSubscription_id() {return subscription_id;} + + public void setSubscription_id(Long subscription_id) {this.subscription_id = subscription_id;} + + public void setSubscriptionId(String subscriptionId) {this.subscriptionId = subscriptionId;} + + public Integer getTimeStamp1() { + return timeStamp1; + } + + public void setTimeStamp1(Integer timeStamp1) { + this.timeStamp1 = timeStamp1; + } + + public Integer getTimeStamp2() { + return timeStamp2; + } + + public void setTimeStamp2(Integer timeStamp2) { + this.timeStamp2 = timeStamp2; + } + + public Integer getTimeStamp3() { + return timeStamp3; + } + + + public void setTimeStamp3(Integer timeStamp3) { + this.timeStamp3 = timeStamp3; + } + + public String getSubscriptionId() { + return subscriptionId; + } + + public SubscriptionTimeSlot(Integer timeStamp1, Integer timeStamp2, Integer timeStamp3, String subscriptionId, DateTime creationDate, DateTime modificationDate) { + this.timeStamp1 = timeStamp1; + this.timeStamp2 = timeStamp2; + this.timeStamp3 = timeStamp3; + this.subscriptionId = subscriptionId; + this.creationDate = creationDate; + this.modificationDate = modificationDate; + } + +} diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/repository/SubscriptionTimeSlotDataService.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/repository/SubscriptionTimeSlotDataService.java new file mode 100644 index 000000000..6d1f4ba11 --- /dev/null +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/repository/SubscriptionTimeSlotDataService.java @@ -0,0 +1,8 @@ +package org.motechproject.nms.kilkari.repository; + +import org.motechproject.mds.service.MotechDataService; +import org.motechproject.nms.kilkari.domain.SubscriptionTimeSlot; + +public interface SubscriptionTimeSlotDataService extends MotechDataService { + +} diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/SubscriptionTimeSlotService.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/SubscriptionTimeSlotService.java new file mode 100644 index 000000000..cefbbb875 --- /dev/null +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/SubscriptionTimeSlotService.java @@ -0,0 +1,11 @@ +package org.motechproject.nms.kilkari.service; + +import org.motechproject.nms.kilkari.domain.SubscriptionTimeSlot; + +import java.util.List; + +public interface SubscriptionTimeSlotService { + + List findTimeSlotsForSubscriptionsById(List subscriptionId); + +} diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionTimeSlotServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionTimeSlotServiceImpl.java new file mode 100644 index 000000000..857900071 --- /dev/null +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionTimeSlotServiceImpl.java @@ -0,0 +1,96 @@ +package org.motechproject.nms.kilkari.service.impl; + +import org.datanucleus.store.rdbms.query.ForwardQueryResult; +import org.motechproject.mds.query.SqlQueryExecution; +import org.motechproject.nms.kilkari.domain.SubscriptionTimeSlot; +import org.motechproject.nms.kilkari.repository.SubscriptionTimeSlotDataService; +import org.motechproject.nms.kilkari.service.SubscriptionTimeSlotService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +import javax.jdo.Query; +import java.util.*; + +@Service("subscriptionTimeSlotService") +@Component +public class SubscriptionTimeSlotServiceImpl implements SubscriptionTimeSlotService { + + private static final Logger LOGGER = LoggerFactory.getLogger(SubscriptionTimeSlotServiceImpl.class); + private final SubscriptionTimeSlotDataService subscriptionTimeSlotDataService; + + @Autowired + public SubscriptionTimeSlotServiceImpl(SubscriptionTimeSlotDataService subscriptionTimeSlotDataService) { + this.subscriptionTimeSlotDataService = subscriptionTimeSlotDataService; + } + + @Override + public List findTimeSlotsForSubscriptionsById(final List subscriptionIds) { + + if (subscriptionIds == null || subscriptionIds.isEmpty()) { + LOGGER.warn("No subscription IDs provided, returning empty list."); + return new ArrayList<>(); + } + + StringBuilder idsString = new StringBuilder(); + int i = 0; + while (i < subscriptionIds.size()) { + idsString.append("'").append(subscriptionIds.get(i)).append("'"); + if (i < subscriptionIds.size() - 1) { + idsString.append(","); + } + i++; + } + + String query = "SELECT ts.subscription_id, ts.subscriptionId, ts.timeStamp1, ts.timeStamp2, ts.timeStamp3 " + + "FROM nms_subscriptions_time_slot AS ts " + + "WHERE ts.subscriptionId IN (" + idsString + ")"; + + LOGGER.debug("Generated SQL query: {}", query); + + SqlQueryExecution> queryExecution = new SqlQueryExecution>() { + + @Override + public String getSqlQuery() { + return query; + } + + @Override + public List execute(Query query) { + ForwardQueryResult fqr = (ForwardQueryResult) query.execute(); + + List results = new ArrayList<>(); + if (fqr != null && !fqr.isEmpty()) { + for (Object result : fqr) { + results.add((Object[]) result); + } + } + + return results; + } + }; + + List rawResults = subscriptionTimeSlotDataService.executeSQLQuery(queryExecution); + + List subscriptionTimeSlots = new ArrayList<>(); + for (Object[] row : rawResults) { + + SubscriptionTimeSlot timeSlot = new SubscriptionTimeSlot(); + + timeSlot.setSubscription_id(((Number) row[0]).longValue()); + timeSlot.setSubscriptionId((String) row[1]); + timeSlot.setTimeStamp1((Integer) row[2]); + timeSlot.setTimeStamp2((Integer) row[3]); + timeSlot.setTimeStamp3((Integer) row[4]); + subscriptionTimeSlots.add(timeSlot); + } + if(subscriptionIds.isEmpty()) { + LOGGER.warn("No subscriptionTimeSlots found for fresh calls subscriptionIds:"); + } + + return subscriptionTimeSlots; + } + +} diff --git a/kilkari/src/main/resources/META-INF/spring/blueprint.xml b/kilkari/src/main/resources/META-INF/spring/blueprint.xml index cbd567486..b68013f8f 100644 --- a/kilkari/src/main/resources/META-INF/spring/blueprint.xml +++ b/kilkari/src/main/resources/META-INF/spring/blueprint.xml @@ -16,6 +16,9 @@ + + @@ -82,6 +85,9 @@ + + From 6b9a1a42317fc8e2c267f65bdcc25d33059aff06 Mon Sep 17 00:00:00 2001 From: Mandar-Beehyv Date: Wed, 9 Oct 2024 15:03:44 +0530 Subject: [PATCH 04/10] Two or more subscriber having same calling number and active, pending or hold subscriptions --- .../service/impl/SubscriberServiceImpl.java | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java index f1654dd34..ab40484f0 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java @@ -579,6 +579,17 @@ private void liveBirthChildDeathCheck(Subscription subscription, Map record, String action) { //NOPMD NcssMethodCount District district = childUpdate.getDistrict(); // district should never be null here since we validate upstream on setLocation @@ -609,10 +620,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) { @@ -624,7 +648,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()); subscriber.setCallingNumber(msisdn); subscriber.setDateOfBirth(dob); From c6052f4792d0b4a161d45542ffb7600289b96327 Mon Sep 17 00:00:00 2001 From: Mandar-Beehyv Date: Thu, 3 Oct 2024 17:15:29 +0530 Subject: [PATCH 05/10] Two or more subscriber having same calling number and active, pending or hold subscriptions --- .../nms/kilkari/service/impl/SubscriptionServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java index 2980e36e6..140a94df0 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java @@ -311,7 +311,7 @@ public Boolean activeSubscriptionByMsisdnRch(List 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())); } } } @@ -326,7 +326,7 @@ public Boolean activeSubscriptionByMsisdnRch(List 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; From f2ff01e7519301eda5519167ba36f4f411791fb5 Mon Sep 17 00:00:00 2001 From: Mandar-Beehyv Date: Wed, 9 Oct 2024 15:03:44 +0530 Subject: [PATCH 06/10] Two or more subscriber having same calling number and active, pending or hold subscriptions --- .../service/impl/SubscriberServiceImpl.java | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java index f1654dd34..ab40484f0 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java @@ -579,6 +579,17 @@ private void liveBirthChildDeathCheck(Subscription subscription, Map record, String action) { //NOPMD NcssMethodCount District district = childUpdate.getDistrict(); // district should never be null here since we validate upstream on setLocation @@ -609,10 +620,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) { @@ -624,7 +648,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()); subscriber.setCallingNumber(msisdn); subscriber.setDateOfBirth(dob); From fca96fbe9f80963a10afe96cdab6a9866f2bc1a5 Mon Sep 17 00:00:00 2001 From: Kantas2601 Date: Mon, 14 Oct 2024 18:36:23 +0530 Subject: [PATCH 07/10] priority healthBlock shifted to properties file of kilkari --- .../kilkari/service/impl/SubscriptionServiceImpl.java | 10 +++++++++- kilkari/src/main/resources/kilkari.properties | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java index 2980e36e6..eb639bc78 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java @@ -60,6 +60,7 @@ public class SubscriptionServiceImpl implements SubscriptionService { private DeactivatedBeneficiaryDataService deactivatedBeneficiaryDataService; private SubscriberMsisdnTrackerDataService subscriberMsisdnTrackerDataService; public static AtomicBoolean isCapacityAvailable = new AtomicBoolean(true); + private final String HIGH_PRIORITY_BLOCK = "kilkari.highPriority_blockId"; @Autowired @@ -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, " + @@ -1319,5 +1320,12 @@ private Set 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); + } } diff --git a/kilkari/src/main/resources/kilkari.properties b/kilkari/src/main/resources/kilkari.properties index afc8ad018..3102aee6f 100644 --- a/kilkari/src/main/resources/kilkari.properties +++ b/kilkari/src/main/resources/kilkari.properties @@ -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 \ No newline at end of file From 407066619acde3a2aa374812f07d95b8ed6a2e6a Mon Sep 17 00:00:00 2001 From: Mandar-Beehyv Date: Thu, 3 Oct 2024 17:15:29 +0530 Subject: [PATCH 08/10] Two or more subscriber having same calling number and active, pending or hold subscriptions --- .../nms/kilkari/service/impl/SubscriptionServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java index 488102956..4ecd1d290 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java @@ -312,7 +312,7 @@ public Boolean activeSubscriptionByMsisdnRch(List 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())); } } } @@ -327,7 +327,7 @@ public Boolean activeSubscriptionByMsisdnRch(List 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; From 12e16f7639176cd39a2acdbfe3d5dc42f41d7455 Mon Sep 17 00:00:00 2001 From: Mandar-Beehyv Date: Wed, 9 Oct 2024 15:03:44 +0530 Subject: [PATCH 09/10] Two or more subscriber having same calling number and active, pending or hold subscriptions --- .../service/impl/SubscriberServiceImpl.java | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java index 5dc6319ec..5588ae925 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java @@ -584,6 +584,17 @@ private void liveBirthChildDeathCheck(Subscription subscription, Map record, String action) { //NOPMD NcssMethodCount District district = childUpdate.getDistrict(); // district should never be null here since we validate upstream on setLocation @@ -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) { @@ -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){ From 06bb78db176da090fbf4dffab9a951b508984a0c Mon Sep 17 00:00:00 2001 From: Mandar-Beehyv Date: Fri, 18 Oct 2024 12:16:29 +0530 Subject: [PATCH 10/10] replacing '_' with '.' --- .../nms/kilkari/service/impl/SubscriptionServiceImpl.java | 2 +- kilkari/src/main/resources/kilkari.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java index 4ecd1d290..c568cb71d 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriptionServiceImpl.java @@ -60,7 +60,7 @@ public class SubscriptionServiceImpl implements SubscriptionService { private DeactivatedBeneficiaryDataService deactivatedBeneficiaryDataService; private SubscriberMsisdnTrackerDataService subscriberMsisdnTrackerDataService; public static AtomicBoolean isCapacityAvailable = new AtomicBoolean(true); - private final String HIGH_PRIORITY_BLOCK = "kilkari.highPriority_blockId"; + private static final String HIGH_PRIORITY_BLOCK = "kilkari.highPriority.blockId"; @Autowired diff --git a/kilkari/src/main/resources/kilkari.properties b/kilkari/src/main/resources/kilkari.properties index 3102aee6f..4e81f6c75 100644 --- a/kilkari/src/main/resources/kilkari.properties +++ b/kilkari/src/main/resources/kilkari.properties @@ -13,4 +13,4 @@ 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 \ No newline at end of file +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 \ No newline at end of file