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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public GrievanceController(GrievanceHandlingService grievanceHandlingService, Gr
public String fetchUnallocatedGrievanceCount(@RequestBody UnallocationRequest request) {
OutputResponse responseData = new OutputResponse();
try {
responseData.setResponse(grievanceDataSync.fetchUnallocatedGrievanceCount(request.getPreferredLanguageName()));
responseData.setResponse(grievanceDataSync.fetchUnallocatedGrievanceCount(request.getPreferredLanguageName(), request.getFilterStartDate(), request.getFilterEndDate(), request.getProviderServiceMapID()));
} catch (IEMRException e) {
logger.error("Business logic error in UnallocatedGrievanceCount" + e.getMessage(), e);
responseData.setError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public class GrievanceAllocationRequest {

private Timestamp startDate; // Start date for filtering grievances
private Timestamp endDate; // End date for filtering grievances
private List<Integer> userID; // List of user IDs (agents) to whom grievances will be allocated
private List<Integer> touserID; // List of user IDs (agents) to whom grievances will be allocated
private Integer allocateNo; // Number of grievances to be allocated to each user
private String preferredLanguage;
private String language;

@Override
public String toString() {
return "GrievanceAllocationRequest{" + "startDate=" + startDate + ", endDate=" + endDate + ", userID=" + userID
+ ", allocateNo=" + allocateNo + ", language=" + preferredLanguage + '}';
return "GrievanceAllocationRequest{" + "startDate=" + startDate + ", endDate=" + endDate + ", touserID=" + touserID
+ ", allocateNo=" + allocateNo + ", language=" + language + '}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ public class GrievanceDetails {
@Column(name = "State")
private String state;

@Expose
@Column(name = "Agentid")
private String agentid;

@Expose
@Column(name = "userid")
private Integer userID;
Expand Down Expand Up @@ -169,7 +165,7 @@ public class GrievanceDetails {

public GrievanceDetails(Long gwid, Long grievanceId, Long beneficiaryRegID, Long benCallID,
Integer providerServiceMapID, String complaintID, String subjectOfComplaint, String complaint,
String primaryNumber, String severety, String state, String agentID, Integer userid, Boolean isAllocated,
String primaryNumber, String severety, String state, Integer userid, Boolean isAllocated,
Boolean retryNeeded, Boolean isRegistered, Integer callCounter, Integer preferredLanguageId,
String preferredLanguage, String complaintResolution, String remarks, Boolean deleted, Character processed, String createdBy, Timestamp createdDate,
String modifiedBy, Timestamp lastModDate, Integer vanSerialNo, Integer vanID, String vehicalNo,
Expand All @@ -186,7 +182,6 @@ public GrievanceDetails(Long gwid, Long grievanceId, Long beneficiaryRegID, Long
this.primaryNumber = primaryNumber;
this.severety = severety;
this.state = state;
this.agentid = agentID;
this.userID = userid;
this.isAllocated = isAllocated;
this.retryNeeded = retryNeeded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,52 @@ List<GrievanceDetails> findGrievancesByUserAndLanguage(@Param("userID") Integer

@Modifying
@Transactional
@Query("UPDATE GrievanceDetails g SET g.userID = NULL WHERE g.grievanceId = :grievanceId AND g.userID = :userID")
int unassignGrievance(@Param("grievanceId") Long grievanceId, @Param("userID") Integer userID);
@Query("UPDATE GrievanceDetails g SET g.userID = :userID WHERE g.gwid = :gwid")
int unassignGrievance(@Param("userID") Integer userID, @Param("gwid") Long gwid);

@Modifying
@Transactional
@Query("UPDATE GrievanceDetails g SET g.isAllocated = :isAllocated WHERE g.grievanceId = :grievanceId")
int updateGrievanceAllocationStatus(@Param("grievanceId") Long grievanceId,
@Query("UPDATE GrievanceDetails g SET g.isAllocated = :isAllocated WHERE g.gwid = :gwid")
int updateGrievanceAllocationStatus(@Param("gwid") Long gwid,
@Param("isAllocated") Boolean isAllocated);

@Query("Select grievance.preferredLanguage, count(grievance) from GrievanceDetails grievance where grievance.isAllocated=false group by grievance.preferredLanguage")
public Set<Object[]> fetchUnallocatedGrievanceCount();
@Query("Select grievance.preferredLanguage, count(grievance) from GrievanceDetails grievance where grievance.isAllocated=false "
+ "AND grievance.createdDate BETWEEN :filterStartDate AND :filterEndDate "
+ "group by grievance.preferredLanguage")
public Set<Object[]> fetchUnallocatedGrievanceCount(
@Param("filterStartDate") Timestamp filterStartDate,
@Param("filterEndDate") Timestamp filterEndDate);

@Modifying
@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"
@Query("UPDATE GrievanceDetails g SET g.complaintResolution = :complaintResolution, g.remarks = :remarks, g.modifiedBy = :modifiedBy, "
+ "g.benCallID = :benCallID "
+ "WHERE g.complaintID = :complaintID AND g.beneficiaryRegID = :beneficiaryRegID AND g.providerServiceMapID = :providerServiceMapID"
+ " AND g.userID = :userID")
@Transactional
int updateComplaintResolution(@Param("complaintResolution") String complaintResolution,
@Param("remarks") String remarks,
@Param("modifiedBy") String modifiedBy,
@Param("benCallID") Long benCallID,
@Param("complaintID") String complaintID,
@Param("beneficiaryRegID") Long beneficiaryRegID,
@Param("providerServiceMapID") Integer providerServiceMapID,
@Param("userID") Integer userID);

@Modifying
@Query("UPDATE GrievanceDetails g SET g.complaintResolution = :complaintResolution, g.modifiedBy = :modifiedBy "
+ "WHERE g.complaintID = :complaintID AND g.beneficiaryRegID = :beneficiaryRegID AND g.providerServiceMapID = :providerServiceMapID"
@Query("UPDATE GrievanceDetails g SET g.complaintResolution = :complaintResolution, g.modifiedBy = :modifiedBy, "
+ "g.benCallID = :benCallID "
+ "WHERE g.complaintID = :complaintID AND g.beneficiaryRegID = :beneficiaryRegID AND g.providerServiceMapID = :providerServiceMapID"
+ " AND g.userID = :userID")
@Transactional
int updateComplaintResolution(@Param("complaintResolution") String complaintResolution,
@Param("modifiedBy") String modifiedBy,
@Param("benCallID") Long benCallID,
@Param("complaintID") String complaintID,
@Param("beneficiaryRegID") Long beneficiaryRegID,
@Param("providerServiceMapID") Integer providerServiceMapID,
@Param("userID") Integer userID);

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

@Modifying
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.iemr.common.service.grievance;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

Expand All @@ -10,7 +11,8 @@
public interface GrievanceDataSync {
public List<Map<String, Object>> dataSyncToGrievance();

public String fetchUnallocatedGrievanceCount(String preferredLanguage) throws IEMRException, JSONException;
public String fetchUnallocatedGrievanceCount(String preferredLanguage, Timestamp filterStartDate,
Timestamp filterEndDate, Integer providerServiceMapID) throws IEMRException, JSONException;

public String completeGrievanceCall(String request) throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ public List<Map<String, Object>> dataSyncToGrievance() {
}

// Setting remaining grievance properties (similar to the existing code)
grievance.setAgentid(grievance.getAgentid());
grievance.setDeleted(grievance.getDeleted());
grievance.setCreatedBy(registeringUser);
grievance.setProcessed('N');
Expand Down Expand Up @@ -294,7 +293,6 @@ public List<Map<String, Object>> dataSyncToGrievance() {
combinedData.put("transaction", transactions);
combinedData.put("severity", grievance.getSeverety());
combinedData.put("state", grievance.getState());
combinedData.put("agentId", grievance.getAgentid());
combinedData.put("deleted", grievance.getDeleted());
combinedData.put("createdBy", grievance.getCreatedBy());
combinedData.put("createdDate", grievance.getCreatedDate());
Expand Down Expand Up @@ -413,11 +411,12 @@ private void generateGrievanceAuthToken() {
}
}

public String fetchUnallocatedGrievanceCount(String preferredLanguage) throws IEMRException, JSONException {
public String fetchUnallocatedGrievanceCount(String preferredLanguage, Timestamp filterStartDate,
Timestamp filterEndDate, Integer providerServiceMapID) throws IEMRException, JSONException {
logger.debug("Request received for fetchUnallocatedGrievanceCount");

// Fetch all unallocated grievances count from the database
Set<Object[]> resultSet = grievanceDataRepo.fetchUnallocatedGrievanceCount();
Set<Object[]> resultSet = grievanceDataRepo.fetchUnallocatedGrievanceCount(filterStartDate, filterEndDate);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

The providerServiceMapID parameter is not used in the repository call.

The method accepts providerServiceMapID as a parameter, but it's not passed to the repository method. This inconsistency may lead to bugs or confusion.

Consider updating the repository call to use the providerServiceMapID parameter:

-Set<Object[]> resultSet = grievanceDataRepo.fetchUnallocatedGrievanceCount(filterStartDate, filterEndDate);
+Set<Object[]> resultSet = grievanceDataRepo.fetchUnallocatedGrievanceCount(filterStartDate, filterEndDate, providerServiceMapID);

Also ensure that the corresponding repository method accepts this parameter.

πŸ“ 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
Set<Object[]> resultSet = grievanceDataRepo.fetchUnallocatedGrievanceCount(filterStartDate, filterEndDate);
Set<Object[]> resultSet = grievanceDataRepo.fetchUnallocatedGrievanceCount(filterStartDate, filterEndDate, providerServiceMapID);


// Initialize the result JSON object to hold counts
JSONObject result = new JSONObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public String allocateGrievances(String request) throws Exception {
// language
List<GrievanceDetails> grievances = grievanceDataRepo.findGrievancesInDateRangeAndLanguage(
allocationRequest.getStartDate(), allocationRequest.getEndDate(),
allocationRequest.getPreferredLanguage());
allocationRequest.getLanguage());

if (grievances.isEmpty()) {
throw new Exception("No grievances found in the given date range and language.");
Expand All @@ -85,7 +85,7 @@ public String allocateGrievances(String request) throws Exception {
// Step 4: Get the allocation parameters from the request
int totalAllocated = 0;
int userIndex = 0;
List<Integer> userIds = allocationRequest.getUserID();
List<Integer> userIds = allocationRequest.getTouserID();
int allocateNo = allocationRequest.getAllocateNo(); // Number of grievances to allocate per user

for (int i = 0; i < grievances.size(); i++) {
Expand Down Expand Up @@ -230,22 +230,22 @@ public String moveToBin(String request) throws Exception {
// Step 4: Unassign grievances from the user and "move them to bin"
int totalUnassigned = 0;
for (GrievanceDetails grievance : grievancesToMove) {
int rowsAffected = grievanceDataRepo.unassignGrievance(grievance.getGrievanceId(),
moveToBinRequest.getUserID());
grievance.setUserID(null);
int rowsAffected = grievanceDataRepo.unassignGrievance(grievance.getUserID(), grievance.getGwid());
if (rowsAffected > 0) {
grievance.setIsAllocated(false); // Assuming there's a setter for this flag
int updateFlagResult = grievanceDataRepo.updateGrievanceAllocationStatus(grievance.getGrievanceId(),
false);
int updateFlagResult = grievanceDataRepo.updateGrievanceAllocationStatus(grievance.getGwid(),
grievance.getIsAllocated());
if (updateFlagResult > 0) {
totalUnassigned++;
logger.debug("Unassigned grievance ID {} from user ID {}", grievance.getGrievanceId(),
logger.debug("Unassigned grievance gwid {} from user ID {}", grievance.getGwid(),
moveToBinRequest.getUserID());
} else {
logger.error("Failed to unassign grievance ID {} from user ID {}", grievance.getGrievanceId(),
logger.error("Failed to unassign grievance gwid {} from user ID {}", grievance.getGwid(),
moveToBinRequest.getUserID());
}
} else {
logger.error("Failed to unassign grievance ID {} from user ID {}", grievance.getGrievanceId(),
logger.error("Failed to unassign grievance gwid {} from user ID {}", grievance.getGwid(),
moveToBinRequest.getUserID());
}
}
Expand Down Expand Up @@ -368,6 +368,9 @@ public String saveComplaintResolution(String request) throws Exception {
if (grievanceRequest.getCreatedBy() == null) {
throw new IllegalArgumentException("CreatedBy is required");
}
if(grievanceRequest.getBenCallID() == null) {
throw new IllegalArgumentException("BencallId is required");
}
// Extract values from the request
String complaintID = grievanceRequest.getComplaintID();
String complaintResolution = grievanceRequest.getComplaintResolution();
Expand All @@ -376,17 +379,17 @@ public String saveComplaintResolution(String request) throws Exception {
Integer providerServiceMapID = grievanceRequest.getProviderServiceMapID();
Integer userID = grievanceRequest.getUserID();
String createdBy = grievanceRequest.getCreatedBy();

Long benCallID = grievanceRequest.getBenCallID();

String modifiedBy = createdBy;
int updateCount = 0;
if (remarks == null) {
updateCount = grievanceDataRepo.updateComplaintResolution(complaintResolution, modifiedBy, complaintID,
updateCount = grievanceDataRepo.updateComplaintResolution(complaintResolution, modifiedBy, benCallID, complaintID,
beneficiaryRegID, providerServiceMapID, userID);
logger.debug("updated complaint resolution without remarks for complaint id: {}", complaintID);
}
else {
updateCount = grievanceDataRepo.updateComplaintResolution(complaintResolution, remarks, modifiedBy, complaintID,
updateCount = grievanceDataRepo.updateComplaintResolution(complaintResolution, remarks, modifiedBy, benCallID, complaintID,
beneficiaryRegID, providerServiceMapID, userID);
logger.debug("updated complaint resolution with remarks for complaint id: {}", complaintID);

Expand Down
Loading