diff --git a/src/main/environment/ecd_ci.properties b/src/main/environment/ecd_ci.properties index dfcfdb0..9df17e4 100644 --- a/src/main/environment/ecd_ci.properties +++ b/src/main/environment/ecd_ci.properties @@ -25,6 +25,6 @@ beneficiaryEditUrl =@env.COMMON_API@/beneficiary/update logging.file.name=@env.ECD_API_LOGGING_FILE_NAME@ -springdoc.api-docs.enabled=false -springdoc.swagger-ui.enabled=false +springdoc.api-docs.enabled=@env.SWAGGER_DOC_ENABLED@ +springdoc.swagger-ui.enabled=@env.SWAGGER_DOC_ENABLED@ diff --git a/src/main/environment/ecd_example.properties b/src/main/environment/ecd_example.properties index bf43a4d..dd037f5 100644 --- a/src/main/environment/ecd_example.properties +++ b/src/main/environment/ecd_example.properties @@ -16,3 +16,7 @@ registerBeneficiaryUrl=https:localhost:8083/beneficiary/create ##Beneficiary Edit Url beneficiaryEditUrl =https:localhost:8083/beneficiary/update + +springdoc.api-docs.enabled=true +springdoc.swagger-ui.enabled=true + diff --git a/src/main/environment/ecd_uat.properties b/src/main/environment/ecd_uat.properties index 779e08f..b00f99b 100644 --- a/src/main/environment/ecd_uat.properties +++ b/src/main/environment/ecd_uat.properties @@ -22,3 +22,4 @@ jwt.secret= springdoc.api-docs.enabled=true springdoc.swagger-ui.enabled=true + diff --git a/src/main/java/com/iemr/ecd/repo/call_conf_allocation/ChildRecordRepo.java b/src/main/java/com/iemr/ecd/repo/call_conf_allocation/ChildRecordRepo.java index edb6eca..8308c01 100644 --- a/src/main/java/com/iemr/ecd/repo/call_conf_allocation/ChildRecordRepo.java +++ b/src/main/java/com/iemr/ecd/repo/call_conf_allocation/ChildRecordRepo.java @@ -40,12 +40,18 @@ public interface ChildRecordRepo extends CrudRepository { public List findByIsAllocatedAndWhomPhoneNoAndCreatedDateBetween(Boolean isAllocated, String phoneType, Timestamp fromDate, Timestamp toDate); + @Query(value = " SELECT * FROM t_childvaliddata WHERE IsAllocated is false AND " + + " CreatedDate BETWEEN :fDate AND :tDate AND Phone_No_of =:phoneType AND preferredLanguage =:preferredLanguage LIMIT :recordLimit ", nativeQuery = true) + public List getChildRecordForAllocation(@Param("fDate") Timestamp fDate, + @Param("tDate") Timestamp tDate, @Param("phoneType") String phoneType, + @Param("recordLimit") int recordLimit, @Param("preferredLanguage") String preferredLanguage); + @Query(value = " SELECT * FROM t_childvaliddata WHERE IsAllocated is false AND " + " CreatedDate BETWEEN :fDate AND :tDate AND Phone_No_of =:phoneType LIMIT :recordLimit ", nativeQuery = true) public List getChildRecordForAllocation(@Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("phoneType") String phoneType, @Param("recordLimit") int recordLimit); - + @Modifying @Transactional @Query(" UPDATE ChildRecord SET isAllocated = true WHERE ecdIdNoChildId IN :childId ") diff --git a/src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java b/src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java index 8f7c167..784e8ac 100644 --- a/src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java +++ b/src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java @@ -45,12 +45,18 @@ public interface MotherRecordRepo extends CrudRepository { public List findByIsAllocatedAndWhomPhoneNoAndCreatedDateBetween(Boolean isAllocated, String phoneType, Timestamp fromDate, Timestamp toDate); + @Query(value = " SELECT * FROM t_mothervalidrecord WHERE IsAllocated is false AND " + + " CreatedDate BETWEEN :fDate AND :tDate AND PhoneNo_Of_Whom =:phoneType AND preferredLanguage = :preferredLanguage LIMIT :recordLimit ", nativeQuery = true) + public List getMotherRecordForAllocation(@Param("fDate") Timestamp fDate, + @Param("tDate") Timestamp tDate, @Param("phoneType") String phoneType, + @Param("recordLimit") int recordLimit, @Param("preferredLanguage") String preferredLanguage); + @Query(value = " SELECT * FROM t_mothervalidrecord WHERE IsAllocated is false AND " + " CreatedDate BETWEEN :fDate AND :tDate AND PhoneNo_Of_Whom =:phoneType LIMIT :recordLimit ", nativeQuery = true) public List getMotherRecordForAllocation(@Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("phoneType") String phoneType, @Param("recordLimit") int recordLimit); - + @Modifying @Transactional @Query(" UPDATE MotherRecord SET isAllocated = true WHERE ecdIdNo IN :motherId ") diff --git a/src/main/java/com/iemr/ecd/repo/call_conf_allocation/OutboundCallsRepo.java b/src/main/java/com/iemr/ecd/repo/call_conf_allocation/OutboundCallsRepo.java index 21f80d3..64de2c6 100644 --- a/src/main/java/com/iemr/ecd/repo/call_conf_allocation/OutboundCallsRepo.java +++ b/src/main/java/com/iemr/ecd/repo/call_conf_allocation/OutboundCallsRepo.java @@ -61,13 +61,23 @@ public interface OutboundCallsRepo extends CrudRepository { + " t.childId IS NULL AND t.motherId IS NOT NULL AND (t.isHighRisk = false OR t.isHighRisk IS NULL ) AND mv.preferredLanguage = :preferredLanguage") Page getMotherRecordsForANM(Pageable pageable, @Param("allocationStatus") String allocationStatus, @Param("psmId") Integer psmId, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("preferredLanguage") String preferredLanguage); + + @Query(value = " SELECT t FROM OutboundCalls AS t INNER JOIN MotherRecord mv ON t.motherId = mv.ecdIdNo WHERE t.allocationStatus =:allocationStatus AND " + + " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND " + + " t.childId IS NULL AND t.motherId IS NOT NULL AND (t.isHighRisk = false OR t.isHighRisk IS NULL ) AND mv.preferredLanguage = :preferredLanguage") + Page getMotherRecordsForAssociate(Pageable pageable,@Param("allocationStatus") String allocationStatus, + @Param("psmId") Integer psmId, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("preferredLanguage") String preferredLanguage); @Query(value = " SELECT t FROM OutboundCalls AS t INNER JOIN ChildRecord cv ON t.childId = cv.ecdIdNoChildId WHERE t.allocationStatus =:allocationStatus AND " + " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND " + " t.childId IS NOT NULL AND (t.isHrni = false OR t.isHrni IS NULL ) AND cv.preferredLanguage = :preferredLanguage") Page getChildRecordsForANM(Pageable pageable, @Param("allocationStatus") String allocationStatus, @Param("psmId") Integer psmId, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("preferredLanguage") String preferredLanguage); - + @Query(value = " SELECT t FROM OutboundCalls AS t INNER JOIN ChildRecord cv ON t.childId = cv.ecdIdNoChildId WHERE t.allocationStatus =:allocationStatus AND " + + " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND " + + " t.childId IS NOT NULL AND (t.isHrni = false OR t.isHrni IS NULL ) AND cv.preferredLanguage = :preferredLanguage") + Page getChildRecordsForAssociate(Pageable pageable, @Param("allocationStatus") String allocationStatus, + @Param("psmId") Integer psmId, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("preferredLanguage") String preferredLanguage); @Query(value = " SELECT t FROM OutboundCalls AS t WHERE t.allocationStatus =:allocationStatus AND " + " t.psmId=:psmId AND " + " t.childId IS NULL AND t.motherId IS NOT NULL AND t.isHighRisk = true ") @@ -152,6 +162,20 @@ int getAllocatedRecordsCountMotherUser(@Param("allocatedUserId") Integer allocat int getAllocatedRecordsCountMotherUserANM(@Param("allocatedUserId") Integer allocatedUserId, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("callStatus") String callStatus, @Param("phoneNoType") String phoneNoType,@Param("preferredLanguage") String preferredLanguage); + + @Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t INNER JOIN MotherRecord AS mv ON t.motherId = mv.ecdIdNo WHERE t.allocatedUserId=:allocatedUserId AND " + + " ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND t.callStatus=:callStatus " + + " AND t.phoneNumberType=:phoneNoType AND t.childId IS NULL AND t.motherId IS NOT NULL AND mv.preferredLanguage = :preferredLanguage") + int getAllocatedRecordsCountMotherUserAssociateWithPreferredLanguage(@Param("allocatedUserId") Integer allocatedUserId, + @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("callStatus") String callStatus, + @Param("phoneNoType") String phoneNoType,@Param("preferredLanguage") String preferredLanguage); + + @Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t INNER JOIN MotherRecord AS mv ON t.motherId = mv.ecdIdNo WHERE t.allocatedUserId=:allocatedUserId AND " + + " ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND t.callStatus=:callStatus " + + " AND t.phoneNumberType=:phoneNoType AND t.childId IS NULL AND t.motherId IS NOT NULL") + int getAllocatedRecordsCountMotherUserAssociate(@Param("allocatedUserId") Integer allocatedUserId, + @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("callStatus") String callStatus, + @Param("phoneNoType") String phoneNoType); // get users allocated calls count mother , not completed // @Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t WHERE t.allocatedUserId=:allocatedUserId AND " @@ -173,7 +197,20 @@ int getAllocatedRecordsCountChildUser(@Param("allocatedUserId") Integer allocate int getAllocatedRecordsCountChildUserANM(@Param("allocatedUserId") Integer allocatedUserId, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("callStatus") String callStatus, @Param("phoneNoType") String phoneNoType, @Param("preferredLanguage") String preferredLanguage); + + @Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t INNER JOIN ChildRecord AS cv ON t.childId = cv.ecdIdNoChildId WHERE t.allocatedUserId=:allocatedUserId AND " + + " ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND t.callStatus=:callStatus " + + " AND t.phoneNumberType=:phoneNoType AND t.childId IS NOT NULL AND cv.preferredLanguage = :preferredLanguage ") + int getAllocatedRecordsCountChildUserAssociate(@Param("allocatedUserId") Integer allocatedUserId, + @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("callStatus") String callStatus, + @Param("phoneNoType") String phoneNoType, @Param("preferredLanguage") String preferredLanguage); + @Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t INNER JOIN ChildRecord AS cv ON t.childId = cv.ecdIdNoChildId WHERE t.allocatedUserId=:allocatedUserId AND " + + " ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND t.callStatus=:callStatus " + + " AND t.phoneNumberType=:phoneNoType AND t.childId IS NOT NULL ") + int getAllocatedRecordsCountChildUserAssociate(@Param("allocatedUserId") Integer allocatedUserId, + @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("callStatus") String callStatus, + @Param("phoneNoType") String phoneNoType); // users allocated calls, Mother, by RecordType And PhoneType // @Query(value = " SELECT t FROM OutboundCalls AS t WHERE t.allocatedUserId=:allocatedUserId AND " // + " t.callStatus=:callStatus AND t.phoneNumberType=:phoneNoType AND t.callDateFrom >= :fDate " @@ -197,7 +234,22 @@ Page getAllocatedRecordsUserByRecordTypeAndPhoneTypeMotherANM(Pag @Param("allocatedUserId") Integer allocatedUserId, @Param("callStatus") String callStatus, @Param("phoneNoType") String phoneNoType, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("preferredLanguage") String preferredLanguage); -// // users allocated calls, Child, by RecordType And PhoneType + @Query(value = " SELECT t FROM OutboundCalls AS t INNER JOIN MotherRecord AS mv ON t.motherId = mv.ecdIdNo WHERE t.allocatedUserId=:allocatedUserId AND " + + " t.callStatus=:callStatus AND t.phoneNumberType=:phoneNoType " + + " AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND " + + " t.childId IS NULL AND t.motherId IS NOT NULL AND mv.preferredLanguage = :preferredLanguage") + Page getAllocatedRecordsUserByRecordTypeAndPhoneTypeMotherAssociate(Pageable pageable, + @Param("allocatedUserId") Integer allocatedUserId, @Param("callStatus") String callStatus, + @Param("phoneNoType") String phoneNoType, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("preferredLanguage") String preferredLanguage); + + @Query(value = " SELECT t FROM OutboundCalls AS t INNER JOIN MotherRecord AS mv ON t.motherId = mv.ecdIdNo WHERE t.allocatedUserId=:allocatedUserId AND " + + " t.callStatus=:callStatus AND t.phoneNumberType=:phoneNoType " + + " AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND " + + " t.childId IS NULL AND t.motherId IS NOT NULL ") + Page getAllocatedRecordsUserByRecordTypeAndPhoneTypeMotherAssociate(Pageable pageable, + @Param("allocatedUserId") Integer allocatedUserId, @Param("callStatus") String callStatus, + @Param("phoneNoType") String phoneNoType, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate); + // // users allocated calls, Child, by RecordType And PhoneType // @Query(value = " SELECT t FROM OutboundCalls AS t WHERE t.allocatedUserId=:allocatedUserId AND " // + " t.callStatus=:callStatus AND t.phoneNumberType=:phoneNoType " // + " AND t.callDateFrom >= :fDate AND t.callDateTo <= :tDate AND t.childId IS NOT NULL ") @@ -217,7 +269,21 @@ Page getAllocatedRecordsUserByRecordTypeAndPhoneTypeChild(Pageabl Page getAllocatedRecordsUserByRecordTypeAndPhoneTypeChildANM(Pageable pageable, @Param("allocatedUserId") Integer allocatedUserId, @Param("callStatus") String callStatus, @Param("phoneNoType") String phoneNoType, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate,@Param("preferredLanguage") String preferredLanguage); + + @Query(value = " SELECT t FROM OutboundCalls AS t INNER JOIN ChildRecord AS cv ON t.childId = cv.ecdIdNoChildId WHERE t.allocatedUserId=:allocatedUserId AND " + + " t.callStatus=:callStatus AND t.phoneNumberType=:phoneNoType " + + " AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND t.childId IS NOT NULL AND cv.preferredLanguage = :preferredLanguage ") + Page getAllocatedRecordsUserByRecordTypeAndPhoneTypeChildAssociate(Pageable pageable, + @Param("allocatedUserId") Integer allocatedUserId, @Param("callStatus") String callStatus, + @Param("phoneNoType") String phoneNoType, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate,@Param("preferredLanguage") String preferredLanguage); + @Query(value = " SELECT t FROM OutboundCalls AS t INNER JOIN ChildRecord AS cv ON t.childId = cv.ecdIdNoChildId WHERE t.allocatedUserId=:allocatedUserId AND " + + " t.callStatus=:callStatus AND t.phoneNumberType=:phoneNoType " + + " AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND t.childId IS NOT NULL ") + Page getAllocatedRecordsUserByRecordTypeAndPhoneTypeChildAssociate(Pageable pageable, + @Param("allocatedUserId") Integer allocatedUserId, @Param("callStatus") String callStatus, + @Param("phoneNoType") String phoneNoType, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate); + @Modifying @Transactional @Query(" UPDATE OutboundCalls obc SET beneficiaryRegId = :beneficiaryRegId, phoneNumberType = :phoneNumberType WHERE motherId = :motherId AND childId IS NULL ") diff --git a/src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java b/src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java index cd578a3..7ad1e88 100644 --- a/src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java +++ b/src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java @@ -37,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; import com.google.gson.Gson; import com.iemr.ecd.dao.CallConfiguration; @@ -156,17 +157,20 @@ public String closeCall(CallClosureDTO request) { callConfigurationDetail = callConfigurationDetails.get(0); } - if (obj.getIsCallAnswered() != null && obj.getIsCallAnswered()) { - callObj.setCallStatus("Completed"); + if ("introductory".equalsIgnoreCase(callObj.getEcdCallType()) && Boolean.TRUE.equals(obj.getIsCallDisconnected()) && StringUtils.hasText(request.getPreferredLanguage())) { + callObj.setCallStatus(Constants.OPEN); + callObj.setAllocationStatus(Constants.UNALLOCATED); + }else if(Boolean.TRUE.equals(obj.getIsCallAnswered())){ + callObj.setCallStatus(Constants.COMPLETED); } if (obj.getIsFurtherCallRequired() != null && !obj.getIsFurtherCallRequired()) { - callObj.setCallStatus("Completed"); + callObj.setCallStatus(Constants.COMPLETED); } else { if (obj.getIsCallDisconnected() != null && obj.getIsCallDisconnected()) { - callObj.setCallStatus("Open"); + callObj.setCallStatus(Constants.OPEN); } else { - callObj.setCallStatus("Completed"); + callObj.setCallStatus(Constants.COMPLETED); createEcdCallRecordsInOutboundCalls(request, callConfigurationDetails, callObj.getPhoneNumberType()); } @@ -210,6 +214,9 @@ public String closeCall(CallClosureDTO request) { callObj.setIsHighRisk(request.getIsHrp()); if(obj.getReceivedRoleName().equalsIgnoreCase(Constants.ANM)){ callObj.setCallStatus(Constants.OPEN); + callObj.setAllocatedUserId(null); + callObj.setAllocationStatus(Constants.UNALLOCATED); + callObj.setCallAttemptNo(0); } } outboundCallsRepo.save(callObj); diff --git a/src/main/java/com/iemr/ecd/service/call_conf_allocation/CallAllocationImpl.java b/src/main/java/com/iemr/ecd/service/call_conf_allocation/CallAllocationImpl.java index 2dc6115..a16dd26 100644 --- a/src/main/java/com/iemr/ecd/service/call_conf_allocation/CallAllocationImpl.java +++ b/src/main/java/com/iemr/ecd/service/call_conf_allocation/CallAllocationImpl.java @@ -97,96 +97,108 @@ public String allocateCalls(RequestCallAllocationDTO callAllocationDto) { } + private String allocateMotherRecordsAssociates(RequestCallAllocationDTO callAllocationDto) throws ParseException { - List outBoundCallList = new ArrayList<>(); - int totalRecordToAllocate = 0; - if (callAllocationDto != null && callAllocationDto.getToUserIds() != null - && callAllocationDto.getToUserIds().length > 0 && callAllocationDto.getNoOfCalls() > 0) - totalRecordToAllocate = (callAllocationDto.getToUserIds().length) * (callAllocationDto.getNoOfCalls()); - else - throw new InvalidRequestException(); - - if (totalRecordToAllocate <= 0) - throw new InvalidRequestException(); - else { - - Timestamp tempFDateStamp = null; - Timestamp tempTDateStamp = null; - if (callAllocationDto.getFDate() != null && callAllocationDto.getTDate() != null) { - tempFDateStamp = getTimestampFromString( - callAllocationDto.getFDate().split(Constants.T)[0].concat(Constants.TIME_FORMAT_START_TIME)); - tempTDateStamp = getTimestampFromString( - callAllocationDto.getTDate().split(Constants.T)[0].concat(Constants.TIME_FORMAT_END_TIME)); - } else - throw new InvalidRequestException(Constants.FROM_DATE_TO_DATE_IS_NULL); - - List resultSet = motherRecordRepo.getMotherRecordForAllocation(tempFDateStamp, tempTDateStamp, - callAllocationDto.getPhoneNoType(), totalRecordToAllocate); - - OutboundCalls outboundCalls; - - int callCountPointer = 0; - if (resultSet != null && resultSet.size() > 0) { - List motherIds = new ArrayList<>(); - for (MotherRecord motherRecord : resultSet) { - try { - - outboundCalls = new OutboundCalls(); - - if (motherRecord.getEcdIdNo() != null) - outboundCalls.setMotherId(motherRecord.getEcdIdNo()); - if (motherRecord.getBeneficiaryRegID() != null) - outboundCalls.setBeneficiaryRegId(motherRecord.getBeneficiaryRegID()); - if (callAllocationDto.getPsmId() != null) - outboundCalls.setPsmId(callAllocationDto.getPsmId()); - - if (motherRecord.getWhomPhoneNo() != null) - outboundCalls.setPhoneNumberType(motherRecord.getWhomPhoneNo()); - - outboundCalls.setEcdCallType("introductory"); - outboundCalls.setDisplayEcdCallType("introductory"); - outboundCalls.setCallStatus("Open"); - outboundCalls.setAllocationStatus(Constants.ALLOCATED); - outboundCalls.setAllocatedUserId( - callAllocationDto.getToUserIds()[callCountPointer / callAllocationDto.getNoOfCalls()]); - - outboundCalls.setCreatedBy(callAllocationDto.getCreatedBy()); - if (motherRecord.getHighRisk() != null) - outboundCalls.setIsHighRisk(motherRecord.getHighRisk()); - - if (motherRecord.getHighRiskReason() != null) - outboundCalls.setHighRiskReason(motherRecord.getHighRiskReason()); - - if (motherRecord.getCreatedDate() != null) - outboundCalls.setCallDateFrom(getTimestampDaysLater(motherRecord.getCreatedDate(), 0)); - - outboundCalls.setCallDateTo(getTimestampDaysLater(motherRecord.getCreatedDate(), 30)); - - outboundCalls.setCallAttemptNo(0); - - outBoundCallList.add(outboundCalls); - - callCountPointer++; - - motherIds.add(motherRecord.getEcdIdNo()); - } catch (Exception e) { - // log - callCountPointer++; - } - } - outboundCallsRepo.saveAll(outBoundCallList); - - int i = motherRecordRepo.updateIsAllocatedStatus(motherIds); - - Map responseMap = new HashMap<>(); - responseMap.put("response", outBoundCallList.size() + " mother record allocated successfully"); - return new Gson().toJson(responseMap); - } else - throw new ECDException("no eligible record available to allocate, please contact administrator"); - - } + if (callAllocationDto == null || callAllocationDto.getToUserIds() == null || + callAllocationDto.getToUserIds().length == 0 || callAllocationDto.getNoOfCalls() <= 0) { + throw new InvalidRequestException(); + } + + int totalRecordToAllocate = callAllocationDto.getToUserIds().length * callAllocationDto.getNoOfCalls(); + + if (totalRecordToAllocate <= 0) { + throw new InvalidRequestException(); + } + + if (callAllocationDto.getFDate() == null || callAllocationDto.getTDate() == null) { + throw new InvalidRequestException(Constants.FROM_DATE_TO_DATE_IS_NULL); + } + + Timestamp fromDate = getTimestampFromString( + callAllocationDto.getFDate().split(Constants.T)[0] + Constants.TIME_FORMAT_START_TIME); + Timestamp toDate = getTimestampFromString( + callAllocationDto.getTDate().split(Constants.T)[0] + Constants.TIME_FORMAT_END_TIME); + + List outBoundCallList = new ArrayList<>(); + int callCountPointer = 0; + + if (callAllocationDto.getPreferredLanguage() != null) { + Page page = outboundCallsRepo.getMotherRecordsForAssociate( + PageRequest.of(0, totalRecordToAllocate), + "unallocated", + callAllocationDto.getPsmId(), + fromDate, + toDate, + callAllocationDto.getPreferredLanguage() + ); + + if (page == null || page.isEmpty()) { + throw new ECDException("No eligible record available to allocate, please contact administrator"); + } + + outBoundCallList = page.getContent(); + for (OutboundCalls call : outBoundCallList) { + try { + call.setAllocationStatus(Constants.ALLOCATED); + call.setAllocatedUserId(callAllocationDto.getToUserIds()[callCountPointer / callAllocationDto.getNoOfCalls()]); + call.setCallAttemptNo(0); + callCountPointer++; + } catch (Exception e) { + callCountPointer++; + } + } + + } else { + List motherRecords = motherRecordRepo.getMotherRecordForAllocation( + fromDate, toDate, callAllocationDto.getPhoneNoType(), totalRecordToAllocate); + + if (motherRecords == null || motherRecords.isEmpty()) { + throw new ECDException("No eligible record available to allocate, please contact administrator"); + } + + List motherIds = new ArrayList<>(); + for (MotherRecord mr : motherRecords) { + try { + OutboundCalls call = new OutboundCalls(); + call.setMotherId(mr.getEcdIdNo()); + call.setBeneficiaryRegId(mr.getBeneficiaryRegID()); + call.setPsmId(callAllocationDto.getPsmId()); + call.setPhoneNumberType(mr.getWhomPhoneNo()); + call.setEcdCallType("introductory"); + call.setDisplayEcdCallType("introductory"); + call.setCallStatus("Open"); + call.setAllocationStatus(Constants.ALLOCATED); + call.setAllocatedUserId(callAllocationDto.getToUserIds()[callCountPointer / callAllocationDto.getNoOfCalls()]); + call.setCreatedBy(callAllocationDto.getCreatedBy()); + call.setIsHighRisk(mr.getHighRisk()); + call.setHighRiskReason(mr.getHighRiskReason()); + call.setCallDateFrom(getTimestampDaysLater(mr.getCreatedDate(), 0)); + call.setCallDateTo(getTimestampDaysLater(mr.getCreatedDate(), 30)); + call.setCallAttemptNo(0); + + outBoundCallList.add(call); + motherIds.add(mr.getEcdIdNo()); + + callCountPointer++; + } catch (Exception e) { + callCountPointer++; + } + } + + outboundCallsRepo.saveAll(outBoundCallList); + motherRecordRepo.updateIsAllocatedStatus(motherIds); + // Assuming updateIsAllocatedStatus updates all in one batch + } + + outboundCallsRepo.saveAll(outBoundCallList); + + Map responseMap = new HashMap<>(); + responseMap.put("response", outBoundCallList.size() + " mother record(s) allocated successfully"); + + return new Gson().toJson(responseMap); } + private String allocateChildRecordsAssociates(RequestCallAllocationDTO callAllocationDto) throws ParseException { List outBoundCallList = new ArrayList<>(); int totalRecordToAllocate = 0; @@ -210,10 +222,17 @@ private String allocateChildRecordsAssociates(RequestCallAllocationDTO callAlloc callAllocationDto.getTDate().split(Constants.T)[0].concat(Constants.TIME_FORMAT_END_TIME)); } else throw new InvalidRequestException(Constants.FROM_DATE_TO_DATE_IS_NULL); - - List resultSet = childRecordRepo.getChildRecordForAllocation(tempFDateStamp, tempTDateStamp, - callAllocationDto.getPhoneNoType(), totalRecordToAllocate); - + List resultSet = null; + Page childRecordsForAssociate = null; + Pageable pageable = PageRequest.of(0, totalRecordToAllocate); + if (null != callAllocationDto.getPreferredLanguage()) { + childRecordsForAssociate = outboundCallsRepo.getChildRecordsForAssociate(pageable, "unallocated", + callAllocationDto.getPsmId(), tempFDateStamp, tempTDateStamp, + callAllocationDto.getPreferredLanguage()); + } else { + resultSet = childRecordRepo.getChildRecordForAllocation(tempFDateStamp, tempTDateStamp, + callAllocationDto.getPhoneNoType(), totalRecordToAllocate); + } OutboundCalls outboundCalls; int callCountPointer = 0; @@ -243,19 +262,14 @@ private String allocateChildRecordsAssociates(RequestCallAllocationDTO callAlloc outboundCalls.setAllocationStatus(Constants.ALLOCATED); outboundCalls.setAllocatedUserId( callAllocationDto.getToUserIds()[callCountPointer / callAllocationDto.getNoOfCalls()]); - outboundCalls.setCreatedBy(callAllocationDto.getCreatedBy()); - outboundCalls.setIsHrni(childRecord.getIsHrni()); outboundCalls.setHrniReason(childRecord.getHrni_Reason()); - if (childRecord.getCreatedDate() != null) outboundCalls.setCallDateFrom(getTimestampDaysLater(childRecord.getCreatedDate(), 0)); - outboundCalls.setCallDateTo(getTimestampDaysLater(childRecord.getCreatedDate(), 30)); - outboundCalls.setCallAttemptNo(0); - + outBoundCallList.add(outboundCalls); childIds.add(childRecord.getEcdIdNoChildId()); @@ -264,19 +278,37 @@ private String allocateChildRecordsAssociates(RequestCallAllocationDTO callAlloc callCountPointer++; // log } - } outboundCallsRepo.saveAll(outBoundCallList); int i = childRecordRepo.updateIsAllocatedStatus(childIds); - Map responseMap = new HashMap<>(); - responseMap.put("response", outBoundCallList.size() + " child record allocated successfully"); - return new Gson().toJson(responseMap); + } else if (null != childRecordsForAssociate && !childRecordsForAssociate.isEmpty()) { + outBoundCallList = childRecordsForAssociate.getContent(); + if (!outBoundCallList.isEmpty()) { + for (OutboundCalls outboundCall : outBoundCallList) { + try { + outboundCall.setAllocationStatus(Constants.ALLOCATED); + outboundCall.setAllocatedUserId(callAllocationDto.getToUserIds()[callCountPointer + / callAllocationDto.getNoOfCalls()]); + + outboundCall.setCallAttemptNo(0); + + callCountPointer++; + } catch (Exception e) { + callCountPointer++; + } + } + outboundCallsRepo.saveAll(outBoundCallList); + } + } else { + throw new ECDException("no eligible record available to allocate, please contact administrator"); } - throw new ECDException("no eligible record available to allocate, please contact administrator"); } + Map responseMap = new HashMap<>(); + responseMap.put("response", outBoundCallList.size() + " child record allocated successfully"); + return new Gson().toJson(responseMap); } private String allocateMotherRecordsToANM(RequestCallAllocationDTO callAllocationDto) throws ParseException { @@ -577,7 +609,12 @@ public String moveAllocatedCallsToBin(RequestCallAllocationDTO callAllocationDto outboundCallsPage = outboundCallsRepo.getAllocatedRecordsUserByRecordTypeAndPhoneTypeMotherANM( pageable, callAllocationDto.getUserId(), "open", callAllocationDto.getPhoneNoType(), tempFDateStamp, tempTDateStamp, callAllocationDto.getPreferredLanguage()); - } else { + } else if(null != callAllocationDto.getRoleName() + && callAllocationDto.getRoleName().equalsIgnoreCase("associate")){ + outboundCallsPage = getOutboundCallsForMotherAssociate(pageable,callAllocationDto,tempFDateStamp,tempTDateStamp); + + } + else { outboundCallsPage = outboundCallsRepo.getAllocatedRecordsUserByRecordTypeAndPhoneTypeMother( pageable, callAllocationDto.getUserId(), "open", callAllocationDto.getPhoneNoType(), tempFDateStamp, tempTDateStamp); @@ -588,7 +625,11 @@ public String moveAllocatedCallsToBin(RequestCallAllocationDTO callAllocationDto outboundCallsPage = outboundCallsRepo.getAllocatedRecordsUserByRecordTypeAndPhoneTypeChildANM( pageable, callAllocationDto.getUserId(), "open", callAllocationDto.getPhoneNoType(), tempFDateStamp, tempTDateStamp, callAllocationDto.getPreferredLanguage()); - } else { + }else if(null != callAllocationDto.getRoleName() + && callAllocationDto.getRoleName().equalsIgnoreCase("associate")) { + outboundCallsPage = getOutboundcallsForChildAssociate(pageable,callAllocationDto,tempFDateStamp,tempTDateStamp); + } + else { outboundCallsPage = outboundCallsRepo.getAllocatedRecordsUserByRecordTypeAndPhoneTypeChild( pageable, callAllocationDto.getUserId(), "open", callAllocationDto.getPhoneNoType(), tempFDateStamp, tempTDateStamp); @@ -639,6 +680,38 @@ else if (outboundCalls.getMotherId() != null) } + private Page getOutboundCallsForMotherAssociate(Pageable pageable, + RequestCallAllocationDTO callAllocationDto, Timestamp tempFDateStamp, Timestamp tempTDateStamp) { + Page outboundCallsPage = null; + if(null != callAllocationDto.getPreferredLanguage()) { + outboundCallsPage = outboundCallsRepo.getAllocatedRecordsUserByRecordTypeAndPhoneTypeMotherAssociate( + pageable, callAllocationDto.getUserId(), "open", callAllocationDto.getPhoneNoType(), + tempFDateStamp, tempTDateStamp, callAllocationDto.getPreferredLanguage()); + }else { + outboundCallsPage = outboundCallsRepo.getAllocatedRecordsUserByRecordTypeAndPhoneTypeMotherAssociate( + pageable, callAllocationDto.getUserId(), "open", callAllocationDto.getPhoneNoType(), + tempFDateStamp, tempTDateStamp); + } + return outboundCallsPage; + } + + private Page getOutboundcallsForChildAssociate(Pageable pageable, + RequestCallAllocationDTO callAllocationDto, Timestamp tempFDateStamp, Timestamp tempTDateStamp) { + Page outboundCallsPage = null; + if (null != callAllocationDto.getPreferredLanguage()) { + outboundCallsPage = outboundCallsRepo + .getAllocatedRecordsUserByRecordTypeAndPhoneTypeChildAssociate(pageable, + callAllocationDto.getUserId(), "open", callAllocationDto.getPhoneNoType(), + tempFDateStamp, tempTDateStamp, callAllocationDto.getPreferredLanguage()); + } else { + outboundCallsPage = outboundCallsRepo + .getAllocatedRecordsUserByRecordTypeAndPhoneTypeChildAssociate(pageable, + callAllocationDto.getUserId(), "open", callAllocationDto.getPhoneNoType(), + tempFDateStamp, tempTDateStamp); + } + return outboundCallsPage; + } + public String getAllocatedCallCountUser(RequestCallAllocationDTO callAllocationDto) { Map responseMap = new HashMap<>(); try { @@ -660,7 +733,15 @@ public String getAllocatedCallCountUser(RequestCallAllocationDTO callAllocationD if(null != callAllocationDto.getRoleName() && callAllocationDto.getRoleName().equalsIgnoreCase(Constants.ANM)) { cnt = outboundCallsRepo.getAllocatedRecordsCountMotherUserANM(callAllocationDto.getUserId(), tempFDateStamp, tempTDateStamp, Constants.OPEN, callAllocationDto.getPhoneNoType(),callAllocationDto.getPreferredLanguage()); - }else { + }else if(null != callAllocationDto.getRoleName() && callAllocationDto.getRoleName().equalsIgnoreCase(Constants.ASSOCIATE)){ + if(null != callAllocationDto.getPreferredLanguage()) { + cnt = outboundCallsRepo.getAllocatedRecordsCountMotherUserAssociateWithPreferredLanguage(callAllocationDto.getUserId(), + tempFDateStamp, tempTDateStamp, Constants.OPEN, callAllocationDto.getPhoneNoType(),callAllocationDto.getPreferredLanguage()); + }else { + cnt = outboundCallsRepo.getAllocatedRecordsCountMotherUserAssociate(callAllocationDto.getUserId(), + tempFDateStamp, tempTDateStamp, Constants.OPEN, callAllocationDto.getPhoneNoType()); + } + }else{ cnt = outboundCallsRepo.getAllocatedRecordsCountMotherUser(callAllocationDto.getUserId(), tempFDateStamp, tempTDateStamp, Constants.OPEN, callAllocationDto.getPhoneNoType()); } @@ -668,7 +749,16 @@ public String getAllocatedCallCountUser(RequestCallAllocationDTO callAllocationD if(null != callAllocationDto.getRoleName() && callAllocationDto.getRoleName().equalsIgnoreCase(Constants.ANM)) { cnt = outboundCallsRepo.getAllocatedRecordsCountChildUserANM(callAllocationDto.getUserId(), tempFDateStamp, tempTDateStamp, Constants.OPEN, callAllocationDto.getPhoneNoType(), callAllocationDto.getPreferredLanguage()); - }else { + }else if(null != callAllocationDto.getRoleName() && callAllocationDto.getRoleName().equalsIgnoreCase(Constants.ASSOCIATE)) { + if(null != callAllocationDto.getPreferredLanguage()) { + cnt = outboundCallsRepo.getAllocatedRecordsCountChildUserAssociate(callAllocationDto.getUserId(), + tempFDateStamp, tempTDateStamp, Constants.OPEN, callAllocationDto.getPhoneNoType(), callAllocationDto.getPreferredLanguage()); + }else { + cnt = outboundCallsRepo.getAllocatedRecordsCountChildUserAssociate(callAllocationDto.getUserId(), + tempFDateStamp, tempTDateStamp, Constants.OPEN, callAllocationDto.getPhoneNoType()); + } + } + else { cnt = outboundCallsRepo.getAllocatedRecordsCountChildUser(callAllocationDto.getUserId(), tempFDateStamp, tempTDateStamp, Constants.OPEN, callAllocationDto.getPhoneNoType()); } diff --git a/src/main/java/com/iemr/ecd/utils/mapper/JwtUserIdValidationFilter.java b/src/main/java/com/iemr/ecd/utils/mapper/JwtUserIdValidationFilter.java index d7d1c09..e7d0115 100644 --- a/src/main/java/com/iemr/ecd/utils/mapper/JwtUserIdValidationFilter.java +++ b/src/main/java/com/iemr/ecd/utils/mapper/JwtUserIdValidationFilter.java @@ -55,6 +55,9 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo // Skip login and public endpoints if (path.equals(contextPath + "/user/userAuthenticate") || path.equalsIgnoreCase(contextPath + "/user/logOutUserFromConcurrentSession") + || path.startsWith(contextPath + "/swagger-ui") + || path.startsWith(contextPath + "/v3/api-docs") + || path.startsWith(contextPath + "/user/refreshToken") || path.startsWith(contextPath + "/public")) { logger.info("Skipping filter for path: " + path); filterChain.doFilter(servletRequest, servletResponse);