From c88ad773ba6d0f2a9302849a9ad43a0ead9bc9af Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Thu, 6 Mar 2025 16:35:37 +0530 Subject: [PATCH 1/3] adding code changes for grievance issues --- .../grievance/GrievanceController.java | 2 +- .../grievance/GrievanceAllocationRequest.java | 8 ++--- .../data/grievance/GrievanceDetails.java | 7 +---- .../grievance/GrievanceDataRepo.java | 30 ++++++++++++------- .../service/grievance/GrievanceDataSync.java | 4 ++- .../grievance/GrievanceDataSyncImpl.java | 7 ++--- .../GrievanceHandlingServiceImpl.java | 27 +++++++++-------- 7 files changed, 46 insertions(+), 39 deletions(-) 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 0311fc2a..8ac8a8d4 100644 --- a/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java +++ b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java @@ -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); diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceAllocationRequest.java b/src/main/java/com/iemr/common/data/grievance/GrievanceAllocationRequest.java index 8dc30cc1..3f182548 100644 --- a/src/main/java/com/iemr/common/data/grievance/GrievanceAllocationRequest.java +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceAllocationRequest.java @@ -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 userID; // List of user IDs (agents) to whom grievances will be allocated + private List 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 + '}'; } } diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java b/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java index 910ab886..809a4e5d 100644 --- a/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceDetails.java @@ -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; @@ -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, @@ -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; 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 35f1e124..75a77d5e 100644 --- a/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java @@ -60,44 +60,52 @@ List 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 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 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 getCallCounter(@Param("complaintID") String complaintID); @Modifying diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java index d0d32f2e..9cb4537d 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSync.java @@ -1,5 +1,6 @@ package com.iemr.common.service.grievance; +import java.sql.Timestamp; import java.util.List; import java.util.Map; @@ -10,7 +11,8 @@ public interface GrievanceDataSync { public List> 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; 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 dd4d6baa..0d4e810c 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceDataSyncImpl.java @@ -251,7 +251,6 @@ public List> dataSyncToGrievance() { } // Setting remaining grievance properties (similar to the existing code) - grievance.setAgentid(grievance.getAgentid()); grievance.setDeleted(grievance.getDeleted()); grievance.setCreatedBy(registeringUser); grievance.setProcessed('N'); @@ -294,7 +293,6 @@ public List> 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()); @@ -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 resultSet = grievanceDataRepo.fetchUnallocatedGrievanceCount(); + Set resultSet = grievanceDataRepo.fetchUnallocatedGrievanceCount(filterStartDate, filterEndDate); // Initialize the result JSON object to hold counts JSONObject result = new JSONObject(); 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 bc77cae2..6db4b497 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java @@ -73,7 +73,7 @@ public String allocateGrievances(String request) throws Exception { // language List 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."); @@ -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 userIds = allocationRequest.getUserID(); + List userIds = allocationRequest.getTouserID(); int allocateNo = allocationRequest.getAllocateNo(); // Number of grievances to allocate per user for (int i = 0; i < grievances.size(); i++) { @@ -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()); } } @@ -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(); @@ -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); From 474d9ecf2db1a7dcd6bd6b40b647700c127d0804 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 10 Mar 2025 14:59:48 +0530 Subject: [PATCH 2/3] adding fixes related to grievance related APIs --- .../grievance/GrievanceController.java | 19 +- .../dto/grivance/GrievanceTransactionDTO.java | 7 +- .../dto/grivance/GrievanceWorklistDTO.java | 6 +- .../GrievanceOutboundRepository.java | 13 +- .../GrievanceHandlingServiceImpl.java | 186 ++++++++++-------- 5 files changed, 136 insertions(+), 95 deletions(-) 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 8ac8a8d4..71acde86 100644 --- a/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java +++ b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java @@ -130,13 +130,19 @@ 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\", " + public ResponseEntity> getGrievanceOutboundWorklist(@Param(value = "{\"providerServiceMapId\":\" called service ID integer\", " + "\"userId\":\"Optional - Integer ID of user that is assigned to\"}") @RequestBody String request) { logger.info("Request received for grievance worklist"); List response = new ArrayList<>(); + Map responseMap = new HashMap<>(); + try { response = grievanceHandlingService.getFormattedGrievanceData(request); - + // Prepare the success response structure + responseMap.put("data", response); + responseMap.put("statusCode", HttpStatus.OK.value()); + responseMap.put("errorMessage", "Success"); + responseMap.put("status", "Success"); } catch (Exception e) { @@ -148,11 +154,16 @@ public ResponseEntity> getGrievanceOutboundWorklist(@ // Return error response with empty list and error message errorResponse.add(errorDTO); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); + + responseMap.put("data", errorResponse); + responseMap.put("statusCode", HttpStatus.INTERNAL_SERVER_ERROR.value()); + responseMap.put("errorMessage", e.getMessage()); + responseMap.put("status", "Error"); + // return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); } - return ResponseEntity.ok(response); + return ResponseEntity.ok(responseMap); } diff --git a/src/main/java/com/iemr/common/dto/grivance/GrievanceTransactionDTO.java b/src/main/java/com/iemr/common/dto/grivance/GrievanceTransactionDTO.java index 6243e001..48d25b7e 100644 --- a/src/main/java/com/iemr/common/dto/grivance/GrievanceTransactionDTO.java +++ b/src/main/java/com/iemr/common/dto/grivance/GrievanceTransactionDTO.java @@ -9,7 +9,9 @@ @Data public class GrievanceTransactionDTO implements Serializable { private static final long serialVersionUID = 1L; - + + private String actionTakenBy; + private String status; private String fileName; private String fileType; private String redressed; @@ -20,9 +22,12 @@ public class GrievanceTransactionDTO implements Serializable { // Constructor, Getters, and Setters public GrievanceTransactionDTO( + String actionTakenBy, String status, String fileName, String fileType, String redressed, Timestamp createdAt, Timestamp updatedAt, String comment) { super(); + this.actionTakenBy = actionTakenBy; + this.status = status; this.fileName = fileName; this.fileType = fileType; this.redressed = redressed; 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 6e4b1604..365c76a3 100644 --- a/src/main/java/com/iemr/common/dto/grivance/GrievanceWorklistDTO.java +++ b/src/main/java/com/iemr/common/dto/grivance/GrievanceWorklistDTO.java @@ -37,15 +37,14 @@ public class GrievanceWorklistDTO implements Serializable { private String age; private Boolean retryNeeded; private Integer callCounter; - // private String lastCall; // Add this field if you want - + 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, Integer userId, Boolean deleted, String createdBy, Timestamp createdDate, Timestamp lastModDate, Boolean isCompleted, String gender, String district, Long beneficiaryID, String age, - Boolean retryNeeded, Integer callCounter) { + Boolean retryNeeded, Integer callCounter, Timestamp lastCall) { super(); this.complaintID = complaintID; this.subjectOfComplaint = subjectOfComplaint; @@ -70,6 +69,7 @@ public GrievanceWorklistDTO(String complaintID, String subjectOfComplaint, Strin this.age = age; this.retryNeeded = retryNeeded; this.callCounter = callCounter; + this.lastCall = lastCall; } diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java index 88c50d66..4cf62e82 100644 --- a/src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java @@ -3,6 +3,7 @@ import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.query.Procedure; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -15,9 +16,13 @@ @Repository public interface GrievanceOutboundRepository extends JpaRepository { - @Transactional - @Procedure(procedureName = "Pr_Grievanceworklist") - List getGrievanceWorklistData(@Param("providerServiceMapId") Integer providerServiceMapId, - @Param("userId") Integer userId); +// @Transactional +// @Procedure(procedureName = "Pr_Grievanceworklist") +// List getGrievanceWorklistData(@Param("providerServiceMapId") Integer providerServiceMapId, +// @Param("userId") Integer userId); + + @Query(value =" call db_iemr.Pr_Grievanceworklist(:providerServiceMapID, :userId)", nativeQuery = true) + List getGrievanceWorklistData(@Param("providerServiceMapID") Integer providerServiceMapID, + @Param("userId") Integer userId); } 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 6db4b497..b170a474 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java @@ -61,55 +61,60 @@ public GrievanceHandlingServiceImpl(GrievanceDataRepo grievanceDataRepo, Grievan // retry logic private InputMapper inputMapper = new InputMapper(); // InputMapper used to map the JSON request - + @Override public String allocateGrievances(String request) throws Exception { - // Step 1: Parse the request string into the appropriate - // GrievanceAllocationRequest object - GrievanceAllocationRequest allocationRequest = InputMapper.gson().fromJson(request, - GrievanceAllocationRequest.class); - - // Step 2: Fetch grievances based on the start date, end date range, and - // language - List grievances = grievanceDataRepo.findGrievancesInDateRangeAndLanguage( - allocationRequest.getStartDate(), allocationRequest.getEndDate(), - allocationRequest.getLanguage()); - - if (grievances.isEmpty()) { - throw new Exception("No grievances found in the given date range and language."); - } + // Step 1: Parse the request string into the appropriate GrievanceAllocationRequest object + GrievanceAllocationRequest allocationRequest = InputMapper.gson().fromJson(request, GrievanceAllocationRequest.class); - // Step 3: Sort grievances in ascending order based on creation date - grievances.sort(Comparator.comparing(GrievanceDetails::getCreatedDate)); + // Step 2: Fetch grievances based on the start date, end date range, and language + List grievances = grievanceDataRepo.findGrievancesInDateRangeAndLanguage( + allocationRequest.getStartDate(), allocationRequest.getEndDate(), + allocationRequest.getLanguage()); - // Step 4: Get the allocation parameters from the request - int totalAllocated = 0; - int userIndex = 0; - List userIds = allocationRequest.getTouserID(); - int allocateNo = allocationRequest.getAllocateNo(); // Number of grievances to allocate per user + if (grievances.isEmpty()) { + throw new Exception("No grievances found in the given date range and language."); + } - for (int i = 0; i < grievances.size(); i++) { - Integer userId = userIds.get(userIndex); - GrievanceDetails grievance = grievances.get(i); + // Step 3: Get the allocation parameters from the request + List userIds = allocationRequest.getTouserID(); + int allocateNo = allocationRequest.getAllocateNo(); // Number of grievances to allocate per 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); - } + // 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 + for (Integer userId : userIds) { + int allocatedToCurrentUser = 0; + + // Allocate 'allocateNo' grievances to the current user + while (allocatedToCurrentUser < allocateNo && grievanceIndex < totalGrievances) { + GrievanceDetails grievance = grievances.get(grievanceIndex); + + // 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); + } + + grievanceIndex++; // Move to the next grievance + allocatedToCurrentUser++; // Increment the number of grievances allocated to the current user + } - // Move to the next user after allocateNo grievances - if ((i + 1) % allocateNo == 0) { - userIndex = (userIndex + 1) % userIds.size(); - } - } + // If we have allocated the specified number of grievances, move on to the next user + } - // Step 6: Return a message with the total number of grievances allocated - return "Successfully allocated " + totalAllocated + " grievances to users."; + // Step 6: Return a message with the total number of grievances allocated + return "Successfully allocated " + allocateNo + " grievance to each user."; } + @Override public String allocatedGrievanceRecordsCount(String request) throws IEMRException, JSONException { GrievanceDetails grievanceRequest = InputMapper.gson().fromJson(request, GrievanceDetails.class); @@ -146,57 +151,61 @@ public String allocatedGrievanceRecordsCount(String request) throws IEMRExceptio return resultArray.toString(); } + + @Override public String reallocateGrievances(String request) throws Exception { - // Step 1: Parse the request string into the appropriate - // GrievanceReallocationRequest object - GrievanceReallocationRequest reallocationRequest = InputMapper.gson().fromJson(request, - GrievanceReallocationRequest.class); + // Step 1: Parse the request string into the appropriate GrievanceReallocationRequest object + GrievanceReallocationRequest reallocationRequest = InputMapper.gson().fromJson(request, GrievanceReallocationRequest.class); - // Step 2: Fetch grievances that are allocated to the 'fromUserId' and match the - // criteria - List grievances = grievanceDataRepo.findAllocatedGrievancesByUserAndLanguage( - reallocationRequest.getFromUserId(), reallocationRequest.getLanguage()); + // Step 2: Fetch grievances that are allocated to the 'fromUserId' and match the criteria + List grievances = grievanceDataRepo.findAllocatedGrievancesByUserAndLanguage( + reallocationRequest.getFromUserId(), reallocationRequest.getLanguage()); - if (grievances.isEmpty()) { - throw new Exception("No grievances found for the given user and language."); - } + if (grievances.isEmpty()) { + throw new Exception("No grievances found for the given user and language."); + } - // Step 3: Sort grievances in ascending order based on creation date - grievances.sort(Comparator.comparing(GrievanceDetails::getCreatedDate)); + // Step 3: Sort grievances in ascending order based on creation date + grievances.sort(Comparator.comparing(GrievanceDetails::getCreatedDate)); - // Step 4: Get the allocation parameters from the request - int totalReallocated = 0; - int userIndex = 0; - List toUserIds = reallocationRequest.getTouserID(); - int allocateNo = reallocationRequest.getAllocateNo(); // Number of grievances to reallocate per user + // Step 4: Get the allocation parameters from the request + int totalReallocated = 0; + int grievanceIndex = 0; // Start from the first grievance + List toUserIds = reallocationRequest.getTouserID(); + int allocateNo = reallocationRequest.getAllocateNo(); // Number of grievances to reallocate per user - // Step 5: Reallocate grievances to users in a round-robin fashion - for (int i = 0; i < grievances.size(); i++) { - if (i % allocateNo == 0 && userIndex < toUserIds.size()) { - // Reallocate to the next user when reaching the allocateNo threshold - Integer toUserId = toUserIds.get(userIndex); - GrievanceDetails grievance = grievances.get(i); + // Step 5: Reallocate grievances to users + for (Integer toUserId : toUserIds) { + int allocatedToCurrentUser = 0; - // Call the repository method to reallocate the grievance to the new user - int rowsAffected = grievanceDataRepo.reallocateGrievance(grievance.getGrievanceId(), toUserId); + // Reallocate 'allocateNo' grievances to the current user + while (allocatedToCurrentUser < allocateNo && grievanceIndex < grievances.size()) { + GrievanceDetails grievance = grievances.get(grievanceIndex); - if (rowsAffected > 0) { - totalReallocated++; - logger.debug("Reallocated grievance ID " + grievance.getGrievanceId() + " to user ID " + toUserId); - } else { - logger.error("Failed to reallocate grievance ID " + grievance.getGrievanceId() + " to user ID " - + toUserId); - } + // Call the repository method to reallocate the grievance to the new user + int rowsAffected = grievanceDataRepo.reallocateGrievance(grievance.getGrievanceId(), toUserId); - userIndex = (userIndex + 1) % toUserIds.size(); - } - } + if (rowsAffected > 0) { + totalReallocated++; + logger.debug("Reallocated grievance ID {} to user ID {}", grievance.getGrievanceId(), toUserId); + } else { + logger.error("Failed to reallocate grievance ID {} to user ID {}", grievance.getGrievanceId(), toUserId); + } - // Step 6: Return a message with the total number of grievances reallocated - return "Successfully reallocated " + totalReallocated + " grievances to users."; + grievanceIndex++; // Move to the next grievance + allocatedToCurrentUser++; // Increment the number of grievances reallocated to the current user + } + + // If the current user is allocated the specified number of grievances, move to the next user + } + + // Step 6: Return a message with the total number of grievances reallocated + return "Successfully reallocated " + totalReallocated + " grievance to user."; } + + @Override public String moveToBin(String request) throws Exception { // Step 1: Parse the request string into the appropriate MoveToBinRequest object @@ -284,22 +293,30 @@ public List getFormattedGrievanceData(String request) thro // Loop through the worklist data and format the response for (Object[] row : worklistData) { - if (row == null || row.length < 28) + if (row == null || row.length < 30) { logger.warn("invalid row data received"); continue; } + + // Handle age conversion from Double to "x years" format + String ageFormatted = "N/A"; // Default value for age if it's not available + if (row[25] != null) { + Double age = (Double) row[25]; + 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[5], // primaryNumber (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 @@ -312,14 +329,17 @@ public List getFormattedGrievanceData(String request) thro (String) row[22], // gender (String) row[23], // district (Long) row[24], // beneficiaryID - (String) row[25], // age + // (Double) row[25], // age + ageFormatted, (Boolean) row[26], // retryNeeded - (Integer) row[27] // callCounter + (Integer) row[27], // callCounter + (Timestamp) row[17] //lastCall yet to fill ); // 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 From c31f0b44641067b71dbe714edb87452cda04733f Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 10 Mar 2025 15:22:01 +0530 Subject: [PATCH 3/3] fixing code rabbit issues --- .../common/controller/grievance/GrievanceController.java | 1 - .../repository/grievance/GrievanceOutboundRepository.java | 6 ------ 2 files changed, 7 deletions(-) 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 71acde86..a4e3212c 100644 --- a/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java +++ b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java @@ -159,7 +159,6 @@ public ResponseEntity> getGrievanceOutboundWorklist(@Param(v responseMap.put("statusCode", HttpStatus.INTERNAL_SERVER_ERROR.value()); responseMap.put("errorMessage", e.getMessage()); responseMap.put("status", "Error"); - // return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); } diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java index 4cf62e82..88c8dfa9 100644 --- a/src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java @@ -4,22 +4,16 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import org.springframework.data.jpa.repository.query.Procedure; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import com.iemr.common.data.grievance.GrievanceDetails; -import jakarta.transaction.Transactional; @Repository public interface GrievanceOutboundRepository extends JpaRepository { -// @Transactional -// @Procedure(procedureName = "Pr_Grievanceworklist") -// List getGrievanceWorklistData(@Param("providerServiceMapId") Integer providerServiceMapId, -// @Param("userId") Integer userId); @Query(value =" call db_iemr.Pr_Grievanceworklist(:providerServiceMapID, :userId)", nativeQuery = true) List getGrievanceWorklistData(@Param("providerServiceMapID") Integer providerServiceMapID,