Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/environment/common_ci.properties
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ grievanceDataSyncDuration = @env.GRIEVANCE_DATA_SYNC_DURATION@
springdoc.api-docs.enabled=false
springdoc.swagger-ui.enabled=false

grievanceAllocationRetryConfiguration=1
grievanceAllocationRetryConfiguration=3


2 changes: 1 addition & 1 deletion src/main/environment/common_dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,4 @@ grievanceDataSyncDuration = <Enter Grievience Data Sync Duration>
springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true

grievanceAllocationRetryConfiguration=1
grievanceAllocationRetryConfiguration=3
2 changes: 1 addition & 1 deletion src/main/environment/common_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ grievanceDataSyncDuration = <Enter Grievience Data Sync Duration>
springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true

grievanceAllocationRetryConfiguration=1
grievanceAllocationRetryConfiguration=3



2 changes: 1 addition & 1 deletion src/main/environment/common_test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,4 @@ grievanceDataSyncDuration = <Enter Grievience Data Sync Duration>
springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true

grievanceAllocationRetryConfiguration=1
grievanceAllocationRetryConfiguration=3
2 changes: 1 addition & 1 deletion src/main/environment/common_uat.properties
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ grievanceDataSyncDuration = <Enter Grievience Data Sync Duration>
springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true

grievanceAllocationRetryConfiguration=1
grievanceAllocationRetryConfiguration=3
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,35 @@ public String saveComplaintResolution( @Param(value = "{\"complaintID\":\"
return response.toString();
}


// Controller method to handle reattempt logic
@Operation(summary = "Check reattempt logic for grievance")
@PostMapping(value = "/completeGrievanceCall", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization")
public String completeGrievanceCall(
@Param(value = "{\"complaintID\":\"String - ComplaintID\", "
+ "\"userID\":\"Integer - Assigned UserID\", "
+ "\"isCompleted\":\"Boolean - completion status of call\", "
+ "\"beneficiaryRegId\":\"Long - Beneficiary Registration ID\", "
+ "\"callTypeID\":\"Integer - Call Type ID\", "
+ "\"benCallID\":\"Long - Beneficiary Call ID\", "
+"\"callID\":\"String - call ID by czentrix\", "
+ "\"providerServiceMapID\":\"Integer - providerServiceMapID\", "
+ "\"createdBy\":\"String - Creator\"}")
@RequestBody String request) {

OutputResponse response = new OutputResponse();

try {
String s = grievanceDataSync.completeGrievanceCall(request);
response.setResponse(s);

} catch (Exception e) {
logger.error("complete grievance outbound call failed with error " + e.getMessage(), e);
response.setError(e);
}
return response.toString();
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.iemr.common.data.grievance;

import lombok.Data;

@Data
public class GrievanceCallRequest {

String complaintID;
Integer userID;
Boolean isCompleted;
Long beneficiaryRegID;
Integer callTypeID;
Long benCallID;
Integer providerServiceMapId;
String createdBy;

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@ Set<Object[]> getOutboundCallTypes(@Param("providerServiceMapID") Integer provid
@Query("select callType from CallType callType where deleted = false and callTypeID = :callTypeID")
CallType getCallTypeDetails(@Param("callTypeID") Integer callTypeID);


@Query("select callType, callGroupType from CallType "
+ "where callTypeID = :callTypeID")
Set<Object[]> getCallDetails(@Param("callTypeID") Integer callTypeID);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int updateGrievanceAllocationStatus(@Param("grievanceId") Long grievanceId,
public Set<Object[]> fetchUnallocatedGrievanceCount();

@Modifying
@Query("UPDATE GrievanceDetails g SET g.complaintResolution = :complaintResolution, g.remarks = :remarks, g.modifiedBy = :modifiedBy, "
@Query("UPDATE GrievanceDetails g SET g.complaintResolution = :complaintResolution, g.remarks = :remarks, g.modifiedBy = :modifiedBy "
+ "WHERE g.complaintID = :complaintID AND g.beneficiaryRegID = :beneficiaryRegID AND g.providerServiceMapID = :providerServiceMapID"
+ " AND g.userID = :userID")
@Transactional
Expand All @@ -85,7 +85,7 @@ int updateComplaintResolution(@Param("complaintResolution") String complaintReso
@Param("userID") Integer userID);

@Modifying
@Query("UPDATE GrievanceDetails g SET g.complaintResolution = :complaintResolution, g.modifiedBy = :modifiedBy, "
@Query("UPDATE GrievanceDetails g SET g.complaintResolution = :complaintResolution, g.modifiedBy = :modifiedBy "
+ "WHERE g.complaintID = :complaintID AND g.beneficiaryRegID = :beneficiaryRegID AND g.providerServiceMapID = :providerServiceMapID"
+ " AND g.userID = :userID")
@Transactional
Expand All @@ -95,5 +95,33 @@ int updateComplaintResolution(@Param("complaintResolution") String complaintReso
@Param("beneficiaryRegID") Long beneficiaryRegID,
@Param("providerServiceMapID") Integer providerServiceMapID,
@Param("userID") Integer userID);

@Query(" Select grievance.callCounter, grievance.retryNeeded FROM GrievanceDetails grievance where complaintID = :complaintID")
public List<Object[]> getCallCounter(@Param("complaintID") String complaintID);

@Modifying
@Query("UPDATE GrievanceDetails g SET g.isCompleted = :isCompleted, g. g.retryNeeded = :retryNeeded "
+ "WHERE g.complaintID = :complaintID AND g.userID = :userID AND g.beneficiaryRegID = :beneficiaryRegID "
+ "AND g.providerServiceMapID = :providerServiceMapID")
@Transactional
public int updateCompletedStatusInCall(@Param("isCompleted") Boolean isCompleted,
@Param("retryNeeded") Boolean retryNeeded,
@Param("complaintID") String complaintID,
@Param("userID") Integer userID,
@Param("beneficiaryRegID") Long beneficiaryRegID,
@Param("providerServiceMapID") Integer providerServiceMapID);


@Modifying
@Query("UPDATE GrievanceDetails g SET g.callCounter = :callCounter, g.retryNeeded = :retryNeeded "
+ "WHERE g.complaintID = :complaintID AND g.beneficiaryRegID = :beneficiaryRegID AND g.providerServiceMapID = :providerServiceMapID"
+ " AND g.userID = :userID")
@Transactional
public int updateCallCounter(@Param("callCounter") Integer callCounter,
@Param("retryNeeded") Boolean retryNeeded,
@Param("complaintID") String complaintID,
@Param("beneficiaryRegID") Long beneficiaryRegID,
@Param("providerServiceMapID") Integer providerServiceMapID,
@Param("userID") Integer userID);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface GrievanceDataSync {

public String fetchUnallocatedGrievanceCount(String preferredLanguage) throws IEMRException, JSONException;

public String completeGrievanceCall(String request) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand All @@ -32,16 +33,21 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.iemr.common.data.callhandling.CallType;
import com.iemr.common.data.everwell.EverwellDetails;
import com.iemr.common.data.grievance.GrievanceCallRequest;
import com.iemr.common.data.grievance.GrievanceDetails;
import com.iemr.common.data.grievance.GrievanceTransaction;

import com.iemr.common.repository.callhandling.IEMRCalltypeRepositoryImplCustom;
import com.iemr.common.repository.grievance.GrievanceDataRepo;
import com.iemr.common.repository.grievance.GrievanceFetchBenDetailsRepo;
import com.iemr.common.repository.grievance.GrievanceTransactionRepo;
import com.iemr.common.repository.location.LocationStateRepository;
import com.iemr.common.utils.exception.IEMRException;
import com.iemr.common.utils.mapper.InputMapper;

import jakarta.transaction.Transactional;

@Service
@PropertySource("classpath:application.properties")
public class GrievanceDataSyncImpl implements GrievanceDataSync {
Expand All @@ -62,16 +68,18 @@ public class GrievanceDataSyncImpl implements GrievanceDataSync {
private final GrievanceTransactionRepo grievanceTransactionRepo;
private final GrievanceFetchBenDetailsRepo grievanceFetchBenDetailsRepo;
private final LocationStateRepository locationStateRepository;
private final IEMRCalltypeRepositoryImplCustom iEMRCalltypeRepositoryImplCustom;

// Constructor-based injection
@Autowired
public GrievanceDataSyncImpl(GrievanceDataRepo grievanceDataRepo, GrievanceTransactionRepo grievanceTransactionRepo,
GrievanceFetchBenDetailsRepo grievanceFetchBenDetailsRepo,
LocationStateRepository locationStateRepository) {
LocationStateRepository locationStateRepository, IEMRCalltypeRepositoryImplCustom iEMRCalltypeRepositoryImplCustom) {
this.grievanceDataRepo = grievanceDataRepo;
this.grievanceTransactionRepo = grievanceTransactionRepo;
this.grievanceFetchBenDetailsRepo = grievanceFetchBenDetailsRepo;
this.locationStateRepository = locationStateRepository;
this.iEMRCalltypeRepositoryImplCustom = iEMRCalltypeRepositoryImplCustom;
}

@Value("${grievanceUserAuthenticate}")
Expand All @@ -92,6 +100,9 @@ public GrievanceDataSyncImpl(GrievanceDataRepo grievanceDataRepo, GrievanceTrans
@Value("${grievanceDataSyncDuration}")
private String grievanceDataSyncDuration;

@Value("${grievanceAllocationRetryConfiguration}")
private int grievanceAllocationRetryConfiguration;

private String GRIEVANCE_AUTH_TOKEN;
private Long GRIEVANCE_TOKEN_EXP;

Expand Down Expand Up @@ -468,4 +479,105 @@ public String fetchUnallocatedGrievanceCount(String preferredLanguage) throws IE

return resultArray.toString();
}



@Override
@Transactional
public String completeGrievanceCall(String request) throws Exception {

GrievanceCallRequest grievanceCallRequest = InputMapper.gson().fromJson(request, GrievanceCallRequest.class);
String complaintID = grievanceCallRequest.getComplaintID();
Integer userID = grievanceCallRequest.getUserID();
Boolean isCompleted = grievanceCallRequest.getIsCompleted();
Long beneficiaryRegID = grievanceCallRequest.getBeneficiaryRegID();
Integer callTypeID = grievanceCallRequest.getCallTypeID();
Integer providerServiceMapId = grievanceCallRequest.getProviderServiceMapId();

CallType callTypeObj = new CallType();
String response = "failure";
int updateCount = 0;
int updateCallCounter = 0;
int callCounter = 0;
try {

GrievanceDetails grievanceCallStatus = new GrievanceDetails();

List<Object[]> lists = grievanceDataRepo.getCallCounter(complaintID);
for (Object[] objects : lists) {
if (objects != null && objects.length >= 2) {
grievanceCallStatus.setCallCounter((Integer) objects[0]);
grievanceCallStatus.setRetryNeeded((Boolean)objects[1]);
}
}

// Fetching CallDetails using BenCallID and CallTypeID
Set<Object[]> callTypesArray = new HashSet<Object[]>();
callTypesArray = iEMRCalltypeRepositoryImplCustom.getCallDetails(callTypeID);
for (Object[] object : callTypesArray)
{
if (object != null && object.length >= 2)
{
callTypeObj.setCallGroupType((String) object[0]);
callTypeObj.setCallType((String) object[1]);

}

}

String callGroupType = callTypeObj.getCallGroupType();
String callType = callTypeObj.getCallType();


// Logic for reattempt based on call group type and call type

boolean isRetryNeeded = grievanceCallStatus.getRetryNeeded();
if (callGroupType.equals("Valid")) {
// Conditions when no reattempt is needed
if (callType.equals("Valid") || callType.equals("Wrong Number") || callType.equals("Test Call")) {
isRetryNeeded = false;
} else if (callType.equals("Disconnected Call") || callType.equals("Serviced Call") ||
callType.equals("Silent Call") || callType.equals("Call Back")) {
// Reattempt is needed for these call subtypes
isRetryNeeded = true;
}
}

// Check if max attempts (3) are reached
if (isRetryNeeded == true && callCounter < grievanceAllocationRetryConfiguration) {
// Increment the call counter for reattempt
Comment on lines +547 to +548
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the call counter comparison logic.

The current code compares the local variable callCounter (initialized to 0 and never updated) instead of using the actual counter from grievanceCallStatus.

- if (isRetryNeeded == true && callCounter < grievanceAllocationRetryConfiguration) {
+ if (isRetryNeeded == true && grievanceCallStatus.getCallCounter() < grievanceAllocationRetryConfiguration) {
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (isRetryNeeded == true && callCounter < grievanceAllocationRetryConfiguration) {
// Increment the call counter for reattempt
if (isRetryNeeded == true && grievanceCallStatus.getCallCounter() < grievanceAllocationRetryConfiguration) {
// Increment the call counter for reattempt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not requird

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srishtigrp78 Understood. I'll close this comment without the suggested change.

grievanceCallStatus.setCallCounter(grievanceCallStatus.getCallCounter() + 1);
// Update the retryNeeded flag
grievanceCallStatus.setRetryNeeded(true);
updateCallCounter = grievanceDataRepo.updateCallCounter(callCounter, grievanceCallStatus.getRetryNeeded(), grievanceCallRequest.getComplaintID(),
grievanceCallRequest.getBeneficiaryRegID(), grievanceCallRequest.getProviderServiceMapId(),
grievanceCallRequest.getUserID());
// response = "Successfully closing call."; // Return success when reattempt logic is applied successfully. The grievance call needs to be retried, and a reattempt is performed.
if (updateCallCounter > 0)
response = "Successfully closing call";
else {
response = "failure";
}
} else if (callCounter == grievanceAllocationRetryConfiguration) {
// Max attempts reached, no further reattempt
grievanceCallStatus.setRetryNeeded(false);
updateCount = grievanceDataRepo.updateCompletedStatusInCall(isCompleted, grievanceCallStatus.getRetryNeeded(), complaintID, userID, beneficiaryRegID, providerServiceMapId);
response = "max_attempts_reached"; // Indicate that max attempts are reached


} else {

response = "no_reattempt_needed"; // No reattempt needed
}



}
catch (Exception e) {
response = "error: " + e.getMessage();
}

return response; // Return the response (either success or error message)
}

}
Loading