diff --git a/src/main/java/com/iemr/ecd/dao_temp/FetchMotherOutboundWorklist.java b/src/main/java/com/iemr/ecd/dao_temp/FetchMotherOutboundWorklist.java index 78e7717..0bd66c0 100644 --- a/src/main/java/com/iemr/ecd/dao_temp/FetchMotherOutboundWorklist.java +++ b/src/main/java/com/iemr/ecd/dao_temp/FetchMotherOutboundWorklist.java @@ -48,6 +48,7 @@ public class FetchMotherOutboundWorklist { private String phoneNoOfWhom; private String whomPhoneNo; private Boolean highRisk; + private String highRiskReason; private String husbandName; private String address; 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 ef52d53..9c993fc 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 @@ -41,6 +41,9 @@ public interface OutboundCallsRepo extends CrudRepository { OutboundCalls findByObCallId(Long obCallId); + @Query("SELECT ob.obCallId, ob.highRiskReason FROM OutboundCalls ob WHERE ob.obCallId IN :obCallIds AND ob.highRiskReason IS NOT NULL") + List getHighRiskReasonByObCallIds(@Param("obCallIds") List obCallIds); + @Query(value = "call PR_FetchECDMotherOutboundWorklist(:allocatedUserID)", nativeQuery = true) List getAgentAllocatedMotherList(@Param("allocatedUserID") Integer allocatedUserID); @@ -371,8 +374,8 @@ List getIntroductoryRecordsUser(@Param("psmId") Integer psmId, @Modifying @Transactional - @Query(" UPDATE OutboundCalls SET isHighRisk = :isHighRisk WHERE motherId = :motherId AND childId IS NULL AND callDateTo>current_date()") - public int updateHRPForUpcomingCall(@Param("motherId") Long motherId, @Param("isHighRisk") Boolean isHighRisk); + @Query(" UPDATE OutboundCalls SET isHighRisk = :isHighRisk, highRiskReason = :highRiskReason WHERE motherId = :motherId AND childId IS NULL AND callDateTo>current_date()") + public int updateHRPForUpcomingCall(@Param("motherId") Long motherId, @Param("isHighRisk") Boolean isHighRisk, @Param("highRiskReason") String highRiskReason); @Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t INNER JOIN MotherRecord AS 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 " diff --git a/src/main/java/com/iemr/ecd/repository/ecd/ECDCallResponseRepo.java b/src/main/java/com/iemr/ecd/repository/ecd/ECDCallResponseRepo.java index bdc4294..33c3e6c 100644 --- a/src/main/java/com/iemr/ecd/repository/ecd/ECDCallResponseRepo.java +++ b/src/main/java/com/iemr/ecd/repository/ecd/ECDCallResponseRepo.java @@ -38,10 +38,10 @@ public interface ECDCallResponseRepo extends JpaRepository getHrpHrniDetailsOld(@Param("motherId") Long motherId, @Param("childId") Long childId); - @Query(value = " SELECT t FROM ECDCallResponse t WHERE t.motherId=:motherId AND t.reasonsForHrpDB IS NOT NULL ORDER BY 1 DESC ") + @Query(value = " SELECT t FROM ECDCallResponse t WHERE t.motherId=:motherId AND t.reasonsForHrpDB IS NOT NULL ORDER BY t.createdDate DESC ") Page getHrpDetailsMother(Pageable pageable, @Param("motherId") Long motherId); - @Query(value = " SELECT t FROM ECDCallResponse t WHERE t.childId=:childId AND t.reasonsForHrniDB IS NOT NULL ORDER BY 1 DESC ") + @Query(value = " SELECT t FROM ECDCallResponse t WHERE t.childId=:childId AND t.reasonsForHrniDB IS NOT NULL ORDER BY t.createdDate DESC ") Page getHrniDetailsChild(Pageable pageable, @Param("childId") Long childId); @Query(value = "call PR_UpdateHRP_HRniReasons(:benCallId, :obCallId)", nativeQuery = true) diff --git a/src/main/java/com/iemr/ecd/service/associate/BeneficiaryCallHistoryImpl.java b/src/main/java/com/iemr/ecd/service/associate/BeneficiaryCallHistoryImpl.java index 743fef1..c8f7d99 100644 --- a/src/main/java/com/iemr/ecd/service/associate/BeneficiaryCallHistoryImpl.java +++ b/src/main/java/com/iemr/ecd/service/associate/BeneficiaryCallHistoryImpl.java @@ -193,17 +193,13 @@ public ECDCallResponse getHrpHrniDetails(Long motherId, Long childId) { if (childId != null) { Page page = ecdCallResponseRepo.getHrniDetailsChild(pageable, childId); - if (page.getSize() > 0) { - List objLIst = page.getContent(); - obj = objLIst.get(0); - + if (page.hasContent()) { + obj = page.getContent().get(0); } } else if (motherId != null) { Page page = ecdCallResponseRepo.getHrpDetailsMother(pageable, motherId); - if (page.getSize() > 0) { - List objLIst = page.getContent(); - obj = objLIst.get(0); - + if (page.hasContent()) { + obj = page.getContent().get(0); } } else throw new InvalidRequestException("NULL motherId/childId", "send valid motherId or childId"); 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 e1719b0..8d94a7b 100644 --- a/src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java +++ b/src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java @@ -211,7 +211,7 @@ public String closeCall(CallClosureDTO request) { boolean isHrp = request.getIsHrp(); callObj.setIsHighRisk(isHrp); - // Check if the role should be changed to MO + // ANM marks HRP = true → move to MO (high risk) bucket if (isHrp && obj.getReceivedRoleName().equalsIgnoreCase(Constants.ANM)) { callObj.setCallStatus(Constants.OPEN); callObj.setAllocatedUserId(null); @@ -219,12 +219,33 @@ public String closeCall(CallClosureDTO request) { callObj.setCallAttemptNo(0); } + // MO marks HRP = false → move to ANM (low risk) bucket + else if (!isHrp && obj.getReceivedRoleName().equalsIgnoreCase("MO")) { + callObj.setCallStatus(Constants.OPEN); + callObj.setAllocatedUserId(null); + callObj.setAllocationStatus(Constants.UNALLOCATED); + callObj.setCallAttemptNo(0); + } + else if (!isHrp && !obj.getIsCallDisconnected()) { callObj.setCallStatus(Constants.COMPLETED); } } - + if (request.getIsHrni() != null) { + boolean isHrni = request.getIsHrni(); + callObj.setIsHrni(isHrni); + + // MO marks HRNI = false → move to ANM (low risk) bucket + if (!isHrni && obj.getReceivedRoleName().equalsIgnoreCase("MO")) { + callObj.setCallStatus(Constants.OPEN); + callObj.setAllocatedUserId(null); + callObj.setAllocationStatus(Constants.UNALLOCATED); + callObj.setCallAttemptNo(0); + } + } + + outboundCallsRepo.save(callObj); } else throw new ECDException( @@ -238,7 +259,7 @@ else if (!isHrp && !obj.getIsCallDisconnected()) { } else if (callObj.getMotherId() != null && callObj.getChildId() == null && callObj.getIsHighRisk() != null) { // Mother - outboundCallsRepo.updateHRPForUpcomingCall(callObj.getMotherId(), callObj.getIsHighRisk()); + outboundCallsRepo.updateHRPForUpcomingCall(callObj.getMotherId(), callObj.getIsHighRisk(), callObj.getHighRiskReason()); } } if (null != obj.getIsFurtherCallRequired()) { diff --git a/src/main/java/com/iemr/ecd/service/outbound_worklist/OutboundWorkListServiceImpl.java b/src/main/java/com/iemr/ecd/service/outbound_worklist/OutboundWorkListServiceImpl.java index a109f1e..bc100fb 100644 --- a/src/main/java/com/iemr/ecd/service/outbound_worklist/OutboundWorkListServiceImpl.java +++ b/src/main/java/com/iemr/ecd/service/outbound_worklist/OutboundWorkListServiceImpl.java @@ -43,7 +43,6 @@ public class OutboundWorkListServiceImpl { public List getMotherWorkList(Integer userId) { try { List motherList = outboundCallsRepo.getAgentAllocatedMotherList(userId); - return getMotherDtoList(motherList); } catch (Exception e) { throw new ECDException(e);