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
@@ -1,6 +1,9 @@
package com.iemr.common.controller.grievance;

import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -12,13 +15,17 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.iemr.common.data.grievance.UnallocationRequest;
import com.iemr.common.dto.grivance.GrievanceWorklistDTO;
import com.iemr.common.service.grievance.GrievanceDataSync;
Expand Down Expand Up @@ -130,11 +137,12 @@ public String moveToBin(@RequestBody String request) {

@Operation(summary = "get grievance outbound worklist)")
@PostMapping(value = "/getGrievanceOutboundWorklist", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization")
public ResponseEntity<Map<String, Object>> getGrievanceOutboundWorklist(@Param(value = "{\"providerServiceMapId\":\" called service ID integer\", "
+ "\"userId\":\"Optional - Integer ID of user that is assigned to\"}") @RequestBody String request) {
public String getGrievanceOutboundWorklist(@Param(value = "{\"providerServiceMapId\":\" called service ID integer\", "
+ "\"userId\":\"Optional - Integer ID of user that is assigned to\"}") @RequestBody String request) throws JsonProcessingException {
logger.info("Request received for grievance worklist");
List<GrievanceWorklistDTO> response = new ArrayList<>();
Map<String, Object> responseMap = new HashMap<>();
ObjectMapper objectMapper = new ObjectMapper();

try {
response = grievanceHandlingService.getFormattedGrievanceData(request);
Expand All @@ -160,9 +168,17 @@ public ResponseEntity<Map<String, Object>> getGrievanceOutboundWorklist(@Param(v
responseMap.put("errorMessage", e.getMessage());
responseMap.put("status", "Error");
}


return ResponseEntity.ok(responseMap);
Gson gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
@Override
public JsonElement serialize(Date date, Type typeOfSrc, JsonSerializationContext context) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return context.serialize(sdf.format(date)); // Format date
}
})
.create();

return gson.toJson(responseMap);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package com.iemr.common.data.grievance;


import jakarta.persistence.*;
import java.util.Date;

import com.google.gson.annotations.Expose;

import jakarta.validation.constraints.NotBlank;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Size;
import lombok.Data;

import java.util.Date;

@Entity
@Data
@Table(name = "t_grievancetransaction")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;

import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -15,6 +16,7 @@ public class GrievanceWorklistDTO implements Serializable {
private static final long serialVersionUID = 1L;

private String complaintID;
private Long grievanceId;
private String subjectOfComplaint;
private String complaint;
private Long beneficiaryRegID;
Expand All @@ -39,22 +41,19 @@ public class GrievanceWorklistDTO implements Serializable {
private Integer callCounter;
private Timestamp lastCall;

public GrievanceWorklistDTO(String complaintID, String subjectOfComplaint, String complaint,
Long beneficiaryRegID, Integer providerServiceMapID, String firstName, String lastName,
String primaryNumber, List<GrievanceTransactionDTO> transactions, String severety, String state,
public GrievanceWorklistDTO(String complaintID,Long grievanceId, String subjectOfComplaint, String complaint,
Long beneficiaryRegID, Integer providerServiceMapID,String primaryNumber,String severety,String state,
Integer userId, Boolean deleted, String createdBy, Timestamp createdDate, Timestamp lastModDate,
Boolean isCompleted, String gender, String district, Long beneficiaryID, String age,
Boolean isCompleted,String firstName, String lastName, String gender, String district, Long beneficiaryID, String age,
Boolean retryNeeded, Integer callCounter, Timestamp lastCall) {
super();
this.complaintID = complaintID;
this.grievanceId = grievanceId;
this.subjectOfComplaint = subjectOfComplaint;
this.complaint = complaint;
this.beneficiaryRegID = beneficiaryRegID;
this.providerServiceMapID = providerServiceMapID;
this.firstName = firstName;
this.lastName = lastName;
this.primaryNumber = primaryNumber;
this.transactions = transactions;
this.severety = severety;
this.state = state;
this.userId = userId;
Expand All @@ -63,6 +62,8 @@ public GrievanceWorklistDTO(String complaintID, String subjectOfComplaint, Strin
this.createdDate = createdDate;
this.lastModDate = lastModDate;
this.isCompleted = isCompleted;
this.firstName = firstName;
this.lastName = lastName;
this.gender = gender;
this.district = district;
this.beneficiaryID = beneficiaryID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public ArrayList<BeneficiaryCall> getExistingBCByCallIDAndAgentID(@Param("callID

BeneficiaryCall findByBenCallID(Long benCallID);

@Query("SELECT b.remarks FROM BeneficiaryCall b WHERE b.beneficiaryRegID = :beneficiaryRegID")
List<Object[]> fetchBenCallRemarks(@Param("beneficiaryRegID") Long beneficiaryRegID);
@Query("SELECT b.remarks FROM BeneficiaryCall b WHERE b.benCallID = :benCallID")
List<Object[]> fetchBenCallRemarks(@Param("benCallID") Long benCallID);

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public int allocateGrievance(@Param("grievanceId") Long grievanceId,
+ "group by grievance.preferredLanguage")
public Set<Object[]> fetchGrievanceRecordsCount(@Param("userID") Integer userID);

@Query("SELECT g FROM GrievanceDetails g WHERE g.userID = :userID AND g.preferredLanguage = :language AND g.isAllocated = true")
@Query("SELECT g FROM GrievanceDetails g WHERE g.userID = :userID AND g.preferredLanguage = :language AND g.isAllocated = true AND g.isCompleted = false")
List<GrievanceDetails> findAllocatedGrievancesByUserAndLanguage(@Param("userID") Integer userID,
@Param("language") String language);

Expand Down Expand Up @@ -85,7 +85,7 @@ public Set<Object[]> fetchUnallocatedGrievanceCount(
@Modifying
@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"
+ "WHERE g.complaintID = :complaintID AND g.beneficiaryRegID = :beneficiaryRegID "
+ " AND g.userID = :userID")
@Transactional
int updateComplaintResolution(@Param("complaintResolution") String complaintResolution,
Expand All @@ -94,55 +94,50 @@ int updateComplaintResolution(@Param("complaintResolution") String complaintReso
@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, "
+ "g.benCallID = :benCallID "
+ "WHERE g.complaintID = :complaintID AND g.beneficiaryRegID = :beneficiaryRegID AND g.providerServiceMapID = :providerServiceMapID"
+ "WHERE g.complaintID = :complaintID AND g.beneficiaryRegID = :beneficiaryRegID "
+ " 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 grievance.complaintID = :complaintID")
@Query(" Select grievance.callCounter, grievance.retryNeeded,grievance.complaintResolution FROM GrievanceDetails grievance where grievance.complaintID = :complaintID")
public List<Object[]> getCallCounter(@Param("complaintID") String complaintID);

@Modifying
@Query("UPDATE GrievanceDetails g SET g.isCompleted = :isCompleted, g.retryNeeded = :retryNeeded "
+ "WHERE g.complaintID = :complaintID AND g.userID = :userID AND g.beneficiaryRegID = :beneficiaryRegID "
+ "AND g.providerServiceMapID = :providerServiceMapID")
+ "WHERE g.complaintID = :complaintID AND g.userID = :userID AND g.beneficiaryRegID = :beneficiaryRegID ")
@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);
@Param("beneficiaryRegID") Long beneficiaryRegID);


@Modifying
@Query("UPDATE GrievanceDetails g SET g.callCounter = :callCounter, g.retryNeeded = :retryNeeded "
+ "WHERE g.complaintID = :complaintID AND g.beneficiaryRegID = :beneficiaryRegID AND g.providerServiceMapID = :providerServiceMapID"
+ "WHERE g.complaintID = :complaintID AND g.beneficiaryRegID = :beneficiaryRegID "
+ " 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);

@Query("SELECT g FROM GrievanceDetails g WHERE "
+ "(g.state = :state OR :state IS NULL) "
+ "AND (g.complaintResolution = :complaintResolution OR :complaintResolution IS NULL) "
+ "AND g.createdDate BETWEEN :startDate AND :endDate")
+ "AND g.createdDate BETWEEN :startDate AND :endDate AND g.isCompleted = true")
List<GrievanceDetails> fetchGrievanceDetailsBasedOnParams(
@Param("state") String state,
@Param("complaintResolution") String complaintResolution,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.iemr.common.repository.grievance;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.iemr.common.data.grievance.GrievanceTransaction;

@Repository
public interface GrievanceTransactionRepo extends CrudRepository<GrievanceTransaction, Long> {
@Query(value = "select actionTakenBy,status,FileName,FileType,Redressed,createdAt,updatedAt,Comments from t_grievancetransaction t where t.grievanceId = :grievanceId",nativeQuery = true)
List<Object[]> getGrievanceTransaction(@Param("grievanceId") Long grievanceId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ public String completeGrievanceCall(String request) throws Exception {
if (objects != null && objects.length >= 2) {
grievanceCallStatus.setCallCounter((Integer) objects[0]);
grievanceCallStatus.setRetryNeeded((Boolean) objects[1]);
grievanceCallStatus.setComplaintResolution((String) objects[2]);
}
}

Expand All @@ -577,38 +578,28 @@ public String completeGrievanceCall(String request) throws Exception {
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("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;
}
if ((null != grievanceCallStatus.getComplaintResolution()
&& grievanceCallStatus.getComplaintResolution().equalsIgnoreCase("Resolved")) || (callGroupType.equalsIgnoreCase("Valid") && (callType.equalsIgnoreCase("Valid") || callType.equals("Test Call")))) {
isRetryNeeded = false;
updateCount = grievanceDataRepo.updateCompletedStatusInCall(true, false, complaintID, userID, beneficiaryRegID);
}
if (callGroupType.equals("Invalid") && callType.equals("Wrong Number")) {
else if (callGroupType.equalsIgnoreCase("Invalid") && (callType.equalsIgnoreCase("Wrong Number") || callType.equalsIgnoreCase("Invalid Call"))) {
isRetryNeeded = false;
// isCompleted = true;
grievanceDataRepo.updateCompletedStatusInCall(isCompleted, isRetryNeeded, complaintID, userID,
beneficiaryRegID, providerServiceMapID);
updateCount = grievanceDataRepo.updateCompletedStatusInCall(true, isRetryNeeded, complaintID, userID,
beneficiaryRegID);
}else {
isRetryNeeded = true;
updateCount = grievanceDataRepo.updateCompletedStatusInCall(false, isRetryNeeded, complaintID,
userID, beneficiaryRegID);
}

// Check if max attempts (3) are reached
if (isRetryNeeded == true && grievanceCallStatus.getCallCounter() < grievanceAllocationRetryConfiguration) {
// Increment the call counter for reattempt
if (isRetryNeeded && grievanceCallStatus.getCallCounter() < grievanceAllocationRetryConfiguration) {
grievanceCallStatus.setCallCounter(grievanceCallStatus.getCallCounter() + 1);
// Update the retryNeeded flag
isRetryNeeded = true;
// isCompleted = false;
updateCallCounter = grievanceDataRepo.updateCallCounter(grievanceCallStatus.getCallCounter(),
isRetryNeeded, grievanceCallRequest.getComplaintID(),
grievanceCallRequest.getBeneficiaryRegID(), grievanceCallRequest.getProviderServiceMapID(),
grievanceCallRequest.getBeneficiaryRegID(),
grievanceCallRequest.getUserID());
// 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 {
Expand All @@ -619,12 +610,11 @@ public String completeGrievanceCall(String request) throws Exception {
isRetryNeeded = false;
// isCompleted = true;
updateCount = grievanceDataRepo.updateCompletedStatusInCall(isCompleted, isRetryNeeded, complaintID,
userID, beneficiaryRegID, providerServiceMapID);
userID, beneficiaryRegID);
response = "max_attempts_reached"; // Indicate that max attempts are reached

} else {

response = "no_reattempt_needed"; // No reattempt needed
}else if(updateCount > 0) {
response = "Successfully closing call";
}

} catch (Exception e) {
Expand Down
Loading
Loading