diff --git a/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java index a4e3212c..bf243f69 100644 --- a/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java +++ b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java @@ -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; @@ -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; @@ -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> 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 response = new ArrayList<>(); Map responseMap = new HashMap<>(); + ObjectMapper objectMapper = new ObjectMapper(); try { response = grievanceHandlingService.getFormattedGrievanceData(request); @@ -160,9 +168,17 @@ public ResponseEntity> 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() { + @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); } diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java b/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java index 628c9ca8..51232dcc 100644 --- a/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceTransaction.java @@ -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") diff --git a/src/main/java/com/iemr/common/dto/grivance/GrievanceWorklistDTO.java b/src/main/java/com/iemr/common/dto/grivance/GrievanceWorklistDTO.java index 365c76a3..b8184162 100644 --- a/src/main/java/com/iemr/common/dto/grivance/GrievanceWorklistDTO.java +++ b/src/main/java/com/iemr/common/dto/grivance/GrievanceWorklistDTO.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.NoArgsConstructor; @@ -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; @@ -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 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; @@ -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; diff --git a/src/main/java/com/iemr/common/repository/callhandling/BeneficiaryCallRepository.java b/src/main/java/com/iemr/common/repository/callhandling/BeneficiaryCallRepository.java index e48e8f9d..38c67f08 100644 --- a/src/main/java/com/iemr/common/repository/callhandling/BeneficiaryCallRepository.java +++ b/src/main/java/com/iemr/common/repository/callhandling/BeneficiaryCallRepository.java @@ -191,7 +191,7 @@ public ArrayList getExistingBCByCallIDAndAgentID(@Param("callID BeneficiaryCall findByBenCallID(Long benCallID); - @Query("SELECT b.remarks FROM BeneficiaryCall b WHERE b.beneficiaryRegID = :beneficiaryRegID") - List fetchBenCallRemarks(@Param("beneficiaryRegID") Long beneficiaryRegID); + @Query("SELECT b.remarks FROM BeneficiaryCall b WHERE b.benCallID = :benCallID") + List fetchBenCallRemarks(@Param("benCallID") Long benCallID); } diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java index 47b8e848..37d2f0dc 100644 --- a/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java @@ -49,7 +49,7 @@ public int allocateGrievance(@Param("grievanceId") Long grievanceId, + "group by grievance.preferredLanguage") public Set 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 findAllocatedGrievancesByUserAndLanguage(@Param("userID") Integer userID, @Param("language") String language); @@ -85,7 +85,7 @@ public Set 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, @@ -94,13 +94,12 @@ 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, @@ -108,41 +107,37 @@ 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); - @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 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 fetchGrievanceDetailsBasedOnParams( @Param("state") String state, @Param("complaintResolution") String complaintResolution, diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceTransactionRepo.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceTransactionRepo.java index 2c513836..b1d2d1a1 100644 --- a/src/main/java/com/iemr/common/repository/grievance/GrievanceTransactionRepo.java +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceTransactionRepo.java @@ -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 { + @Query(value = "select actionTakenBy,status,FileName,FileType,Redressed,createdAt,updatedAt,Comments from t_grievancetransaction t where t.grievanceId = :grievanceId",nativeQuery = true) + List getGrievanceTransaction(@Param("grievanceId") Long grievanceId); } diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java index e70a25e6..5a05b94f 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java @@ -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]); } } @@ -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 { @@ -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) { diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java index ded5322e..68e8e76e 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java @@ -1,17 +1,17 @@ package com.iemr.common.service.grievance; +import java.lang.reflect.Type; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Comparator; import java.util.Date; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; +import org.apache.commons.lang.StringUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -22,6 +22,11 @@ import org.springframework.stereotype.Service; 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.GetGrievanceWorklistRequest; import com.iemr.common.data.grievance.GrievanceAllocationRequest; import com.iemr.common.data.grievance.GrievanceDetails; @@ -33,6 +38,7 @@ import com.iemr.common.repository.callhandling.BeneficiaryCallRepository; import com.iemr.common.repository.grievance.GrievanceDataRepo; import com.iemr.common.repository.grievance.GrievanceOutboundRepository; +import com.iemr.common.repository.grievance.GrievanceTransactionRepo; import com.iemr.common.utils.exception.IEMRException; import com.iemr.common.utils.mapper.InputMapper; @@ -46,13 +52,15 @@ public class GrievanceHandlingServiceImpl implements GrievanceHandlingService { private final GrievanceDataRepo grievanceDataRepo; private final GrievanceOutboundRepository grievanceOutboundRepo; private final BeneficiaryCallRepository beneficiaryCallRepo; + private final GrievanceTransactionRepo grievanceTransactionRepo; @Autowired public GrievanceHandlingServiceImpl(GrievanceDataRepo grievanceDataRepo, GrievanceOutboundRepository grievanceOutboundRepo, - BeneficiaryCallRepository beneficiaryCallRepo) { + BeneficiaryCallRepository beneficiaryCallRepo,GrievanceTransactionRepo grievanceTransactionRepo) { this.grievanceDataRepo = grievanceDataRepo; this.grievanceOutboundRepo = grievanceOutboundRepo; this.beneficiaryCallRepo = beneficiaryCallRepo; + this.grievanceTransactionRepo = grievanceTransactionRepo; } @Value("${grievanceAllocationRetryConfiguration}") @@ -60,7 +68,6 @@ public GrievanceHandlingServiceImpl(GrievanceDataRepo grievanceDataRepo, Grievan // configure // retry logic - private InputMapper inputMapper = new InputMapper(); // InputMapper used to map the JSON request @Override public String allocateGrievances(String request) throws Exception { @@ -82,9 +89,7 @@ public String allocateGrievances(String request) throws Exception { int allocateNo = allocationRequest.getAllocateNo(); // Number of grievances to allocate per user // Step 4: Initialize counters - int totalAllocated = 0; int grievanceIndex = 0; // Start from the first grievance - int totalUsers = userIds.size(); int totalGrievances = grievances.size(); // Step 5: Allocate grievances to users, ensuring each user gets exactly 'allocateNo' grievances @@ -98,7 +103,6 @@ public String allocateGrievances(String request) throws Exception { // Allocate the grievance to the user int rowsAffected = grievanceDataRepo.allocateGrievance(grievance.getGrievanceId(), userId); if (rowsAffected > 0) { - totalAllocated++; logger.debug("Allocated grievance ID {} to user ID {}", grievance.getGrievanceId(), userId); } else { logger.error("Failed to allocate grievance ID {} to user ID {}", grievance.getGrievanceId(), userId); @@ -292,7 +296,7 @@ public List getFormattedGrievanceData(String request) thro // Loop through the worklist data and format the response for (Object[] row : worklistData) { - if (row == null || row.length < 30) + if (row == null || row.length < 22) { logger.warn("invalid row data received"); continue; @@ -300,56 +304,57 @@ public List getFormattedGrievanceData(String request) thro // Handle age conversion from Double to "x years" format String ageFormatted = null; // Default value for age if it's not available - if (row[25] != null) { - Long age = (Long) row[25]; + if (row[20] != null) { + Long age = (Long) row[20]; ageFormatted = age.intValue() + " years"; // Convert the age to integer and append " years" } GrievanceWorklistDTO grievance = new GrievanceWorklistDTO( (String) row[0], // complaintID - (String) row[1], // subjectOfComplaint - (String) row[2], // complaint - (Long) row[3], // beneficiaryRegID - (Integer) row[4],// providerServiceMapID - - (String) row[20], // firstName - (String) row[21], // lastName - (String) row[5], // primaryNumber - - new ArrayList<>(),// transactions (initially empty, will be populated later) - (String) row[12], // severety - (String) row[13], // state - (Integer) row[14],// userId - (Boolean) row[15],// deleted - (String) row[16],// createdBy - (Timestamp) row[17], // createdDate - (Timestamp) row[18], // lastModDate - (Boolean) row[19], // isCompleted - (String) row[22], // gender - (String) row[23], // district - (Long) row[24], // beneficiaryID - // (Double) row[25], // age + (Long) row[1], //grievanceId + (String) row[2], // subjectOfComplaint + (String) row[3], // complaint + (Long) row[4], // beneficiaryRegID + (Integer) row[5],// providerServiceMapID + (String) row[6], // primaryNumber + (String) row[7], // severety + (String) row[8], // state + (Integer) row[9],// userId + (Boolean) row[10],// deleted + (String) row[11],// createdBy + (Timestamp) row[12], // createdDate + (Timestamp) row[13], // lastModDate + (Boolean) row[14], // isCompleted + + (String) row[15], // firstName + (String) row[16], // lastName + (String) row[17], // gender + (String) row[18], // district + (Long) row[19], // beneficiaryID ageFormatted, - (Boolean) row[26], // retryNeeded - (Integer) row[27], // callCounter - (Timestamp) row[18] //lastCall yet to fill + (Boolean) row[21], // retryNeeded + (Integer) row[22], // callCounter + (Timestamp) row[13] //lastCall + ); // Extract transactions from the current row and add them to the grievance object - GrievanceTransactionDTO transaction = new GrievanceTransactionDTO( - (String) row[28], //actionTakenBy yet to fill - (String) row[29], //status yet to fill - (String) row[6], // fileName - (String) row[7], // fileType - (String) row[8], // redressed - (Timestamp) row[9], // createdAt - (Timestamp) row[10], // updatedAt - (String) row[11] // comment - ); + List transaction = grievanceTransactionRepo.getGrievanceTransaction((Long) row[1]); + List arrayList = new ArrayList<>(); + for (Object[] tras : transaction) { + String actionTakenBy = (tras[0]!=null)?(String) tras[0]:null; + String status = (tras[1]!=null)?(String) tras[1]:null; + String fileName = (tras[2]!=null)?(String) tras[2]:null; + String fileType = (tras[3]!=null)?(String) tras[3]:null; + String redressed = (tras[4]!=null)?(String) tras[4]:null; + Timestamp createdAt = (tras[5]!=null)?(Timestamp) tras[5]:null; + Timestamp updatedAt = (tras[6]!=null)?(Timestamp) tras[6]:null; + String comment = (tras[7]!=null)?(String) tras[7]:null; + GrievanceTransactionDTO grievanceTransactionDTO = new GrievanceTransactionDTO(actionTakenBy, status, fileName, fileType, redressed, createdAt, updatedAt,comment); + arrayList.add(grievanceTransactionDTO); + } + grievance.setTransactions(arrayList); - grievance.getTransactions().add(transaction); // Add the transaction to the grievance's list - - // Add the grievance to the result list formattedGrievances.add(grievance); } @@ -404,12 +409,12 @@ public String saveComplaintResolution(String request) throws Exception { int updateCount = 0; if (remarks == null) { updateCount = grievanceDataRepo.updateComplaintResolution(complaintResolution, modifiedBy, benCallID, complaintID, - beneficiaryRegID, providerServiceMapID, userID); + beneficiaryRegID, userID); logger.debug("updated complaint resolution without remarks for complaint id: {}", complaintID); } else { updateCount = grievanceDataRepo.updateComplaintResolution(complaintResolution, remarks, modifiedBy, benCallID, complaintID, - beneficiaryRegID, providerServiceMapID, userID); + beneficiaryRegID, userID); logger.debug("updated complaint resolution with remarks for complaint id: {}", complaintID); } @@ -476,32 +481,29 @@ public String getGrievanceDetailsWithRemarks(String request) throws Exception { // Fetch and set remarks based on complaintResolution value String remarks = ""; - if ("unresolved".equalsIgnoreCase(complaintResolution)) { - // Fetch remarks from t_bencall by joining with t_grievanceworklist based on benRegId - remarks = fetchRemarksFromBenCallByComplaint(grievance.getComplaintID()); - } else if ("resolved".equalsIgnoreCase(complaintResolution)) { - // Fetch remarks from t_grievanceworklist - remarks = fetchRemarksFromGrievanceWorklist(grievance.getComplaintID()); - } else { - // Default: Fetch remarks based on the grievance's specific conditions (no specific resolution status) - String callRemarks = fetchRemarksFromBenCallByComplaint(grievance.getComplaintID()); - if(remarks != null && !remarks.startsWith("No remarks found")) { - remarks = callRemarks; - } - else { - remarks = fetchRemarksFromGrievanceWorklist(grievance.getComplaintID()); - - } + if(!StringUtils.isEmpty(grievance.getRemarks())) { + remarks = grievance.getRemarks(); + }else { + remarks = fetchRemarksFromBenCallByComplaint(grievance.getComplaintID()); } + grievanceResponse.setRemarks(remarks); // Add to response list grievanceResponseList.add(grievanceResponse); } - - // Convert the list of GrievanceResponse objects to JSON and return as a string - return objectMapper.writeValueAsString(grievanceResponseList); + Gson gson = new GsonBuilder() + .serializeNulls() + .registerTypeAdapter(Date.class, new JsonSerializer() { + @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(grievanceResponseList); } catch (Exception e) { logger.error("Error while getting grievance details with remarks: " + e.getMessage(), e); @@ -518,16 +520,17 @@ private String fetchRemarksFromBenCallByComplaint(String complaintID) throws Exc if (grievanceWorklist != null && !grievanceWorklist.isEmpty()) { GrievanceDetails grievance = grievanceWorklist.get(0); Long beneficiaryRegID = grievance.getBeneficiaryRegID(); // Fetch the beneficiaryRegID from the grievance - + Long benCallID = grievance.getBenCallID(); // Query t_bencall to fetch remarks based on benRegId - List benCallResults = beneficiaryCallRepo.fetchBenCallRemarks(beneficiaryRegID); + List benCallResults = beneficiaryCallRepo.fetchBenCallRemarks(benCallID); if (benCallResults != null && !benCallResults.isEmpty()) { - return (String) benCallResults.get(0)[0]; // Fetch the remarks + if(null != benCallResults.get(0) && null != benCallResults.get(0)[0]) + return (String) benCallResults.get(0)[0]; // Fetch the remarks } } - return "No remarks found in t_bencall"; + return "No remarks found"; } private String fetchRemarksFromGrievanceWorklist(String complaintID) throws JSONException {