From b2fff5741233809fb6ef6142e8e1631eb7a585b1 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 3 Mar 2025 10:20:42 +0530 Subject: [PATCH 1/7] adding code for API to push back grievance data to GR team --- .../grievance/GrievanceController.java | 14 +- .../data/grievance/GrievanceResponse.java | 70 ++++ .../BeneficiaryCallRepository.java | 6 + .../grievance/GrievanceDataRepo.java | 21 ++ .../grievance/GrievanceHandlingService.java | 2 + .../GrievanceHandlingServiceImpl.java | 301 +++++++++++++++++- 6 files changed, 412 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/iemr/common/data/grievance/GrievanceResponse.java 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 d364338c..0311fc2a 100644 --- a/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java +++ b/src/main/java/com/iemr/common/controller/grievance/GrievanceController.java @@ -207,6 +207,18 @@ public String completeGrievanceCall( return response.toString(); } - + + @Operation(summary = "Get Grievance Details with Remarks") + @PostMapping(value = "/getCompleteGrievanceDetails", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization") + public String getGrievanceDetailsWithRemarks(@RequestBody String request) { + OutputResponse response = new OutputResponse(); + try { + response.setResponse(grievanceHandlingService.getGrievanceDetailsWithRemarks(request)); + } catch (Exception e) { + logger.error("getGrievanceDetailsWithRemarks failed with error " + e.getMessage(), e); + response.setError(e); + } + return response.toString(); + } } diff --git a/src/main/java/com/iemr/common/data/grievance/GrievanceResponse.java b/src/main/java/com/iemr/common/data/grievance/GrievanceResponse.java new file mode 100644 index 00000000..516df3dd --- /dev/null +++ b/src/main/java/com/iemr/common/data/grievance/GrievanceResponse.java @@ -0,0 +1,70 @@ +package com.iemr.common.data.grievance; + +import java.sql.Timestamp; + +public class GrievanceResponse { + private Long grievanceId; + private String complaintID; + private String primaryNumber; + private String complaintResolution; + private String remarks; + private Timestamp createdDate; + private Timestamp lastModDate; + + // Getters and Setters + public Long getGrievanceId() { + return grievanceId; + } + + public void setGrievanceId(Long grievanceId) { + this.grievanceId = grievanceId; + } + + public String getComplaintID() { + return complaintID; + } + + public void setComplaintID(String complaintID) { + this.complaintID = complaintID; + } + + public String getPrimaryNumber() { + return primaryNumber; + } + + public void setPrimaryNumber(String primaryNumber) { + this.primaryNumber = primaryNumber; + } + + public String getComplaintResolution() { + return complaintResolution; + } + + public void setComplaintResolution(String complaintResolution) { + this.complaintResolution = complaintResolution; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public Timestamp getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Timestamp createdDate) { + this.createdDate = createdDate; + } + + public Timestamp getLastModDate() { + return lastModDate; + } + + public void setLastModDate(Timestamp lastModDate) { + this.lastModDate = lastModDate; + } +} 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 60ec1b71..9e20b70d 100644 --- a/src/main/java/com/iemr/common/repository/callhandling/BeneficiaryCallRepository.java +++ b/src/main/java/com/iemr/common/repository/callhandling/BeneficiaryCallRepository.java @@ -190,5 +190,11 @@ public ArrayList getExistingBCByCallIDAndAgentID(@Param("callID public int updateBeneficiaryRegIDInCall(@Param("benCallID") Long benCallID, @Param("beneficiaryRegID") Long beneficiaryRegID); BeneficiaryCall findByBenCallID(Long benCallID); + + @Query("SELECT b.remarks FROM BeneficiaryCall b WHERE b.beneficiaryRegID = :beneficiaryRegID") + List fetchBenCallRemarks(@Param("beneficiaryRegID") Long beneficiaryRegID); + + @Query("SELECT b.callTypeID FROM BeneficiaryCall b WHERE b.beneficiaryRegID = :beneficiaryRegID") + Integer fetchCallTypeID(@Param("beneficiaryRegID") Long beneficiaryRegID); } 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 f51083c2..35f1e124 100644 --- a/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java @@ -2,6 +2,7 @@ import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Set; @@ -123,5 +124,25 @@ public int updateCallCounter(@Param("callCounter") Integer callCounter, @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") + List fetchGrievanceDetailsBasedOnParams( + @Param("state") String state, + @Param("complaintResolution") String complaintResolution, + @Param("startDate") Date startDate, + @Param("endDate") Date endDate); + + + @Query("SELECT g FROM GrievanceDetails g WHERE g.complaintID = :complaintID") + List fetchGrievanceWorklistByComplaintID(@Param("complaintID") String complaintID); + + +@Query("SELECT g.remarks FROM GrievanceDetails g WHERE g.complaintID = :complaintID") +List fetchGrievanceWorklistRemarks(@Param("complaintID") String complaintID); + + } diff --git a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingService.java b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingService.java index 1eba9801..c1a19866 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingService.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingService.java @@ -21,6 +21,8 @@ public interface GrievanceHandlingService { public List getFormattedGrievanceData(String request) throws Exception; public String saveComplaintResolution(String request) throws Exception; + + public String getGrievanceDetailsWithRemarks(String request) throws Exception; } 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 094183db..14c9e2c7 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java @@ -1,8 +1,13 @@ package com.iemr.common.service.grievance; 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; @@ -16,13 +21,19 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.iemr.common.data.callhandling.CallType; import com.iemr.common.data.grievance.GetGrievanceWorklistRequest; import com.iemr.common.data.grievance.GrievanceAllocationRequest; import com.iemr.common.data.grievance.GrievanceDetails; import com.iemr.common.data.grievance.GrievanceReallocationRequest; +import com.iemr.common.data.grievance.GrievanceResponse; import com.iemr.common.data.grievance.MoveToBinRequest; import com.iemr.common.dto.grivance.GrievanceTransactionDTO; import com.iemr.common.dto.grivance.GrievanceWorklistDTO; +import com.iemr.common.repository.callhandling.BeneficiaryCallRepository; +import com.iemr.common.repository.callhandling.IEMRCalltypeRepositoryImplCustom; import com.iemr.common.repository.grievance.GrievanceDataRepo; import com.iemr.common.repository.grievance.GrievanceOutboundRepository; import com.iemr.common.utils.exception.IEMRException; @@ -37,11 +48,16 @@ public class GrievanceHandlingServiceImpl implements GrievanceHandlingService { private final GrievanceDataRepo grievanceDataRepo; private final GrievanceOutboundRepository grievanceOutboundRepo; + private final BeneficiaryCallRepository beneficiaryCallRepo; + private final IEMRCalltypeRepositoryImplCustom iEMRCalltypeRepositoryImplCustom; @Autowired - public GrievanceHandlingServiceImpl(GrievanceDataRepo grievanceDataRepo, GrievanceOutboundRepository grievanceOutboundRepo) { + public GrievanceHandlingServiceImpl(GrievanceDataRepo grievanceDataRepo, GrievanceOutboundRepository grievanceOutboundRepo, + BeneficiaryCallRepository beneficiaryCallRepo, IEMRCalltypeRepositoryImplCustom iEMRCalltypeRepositoryImplCustom) { this.grievanceDataRepo = grievanceDataRepo; this.grievanceOutboundRepo = grievanceOutboundRepo; + this.beneficiaryCallRepo = beneficiaryCallRepo; + this.iEMRCalltypeRepositoryImplCustom = iEMRCalltypeRepositoryImplCustom; } @Value("${grievanceAllocationRetryConfiguration}") @@ -386,5 +402,288 @@ public String saveComplaintResolution(String request) throws Exception { throw new Exception("Failed to update complaint resolution"); } } + + public List fetchGrievanceDetailsFromRequest(String request) { + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = null; + + try { + // Parse the request JSON + jsonNode = objectMapper.readTree(request); + } catch (Exception e) { + logger.error("Error parsing request: " + e.getMessage(), e); + return null; + } + + // Extract parameters from the request + String state = jsonNode.has("State") ? jsonNode.get("State").asText() : null; + String complaintResolution = jsonNode.has("ComplaintResolution") ? jsonNode.get("ComplaintResolution").asText() : null; + String startDateStr = jsonNode.get("StartDate").asText(); + String endDateStr = jsonNode.get("EndDate").asText(); + + // Convert StartDate and EndDate to Date objects + Date startDate = parseDate(startDateStr); + Date endDate = parseDate(endDateStr); + + // Construct the query dynamically based on available parameters + return grievanceDataRepo.fetchGrievanceDetailsBasedOnParams(state, complaintResolution, startDate, endDate); + } + + + private Date parseDate(String dateStr) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + return dateFormat.parse(dateStr); + } catch (ParseException e) { + logger.error("Error parsing date for grievance: " + dateStr, e); + return null; + } +} + + + @Override + public String getGrievanceDetailsWithRemarks(String request) throws Exception { + ObjectMapper objectMapper = new ObjectMapper(); +// JsonNode jsonNode = null; +// +// try { +// // Parse the request JSON +// jsonNode = objectMapper.readTree(request); +// } catch (Exception e) { +// logger.error("Error parsing request: " + e.getMessage(), e); +// return null; +// } +// +// // Extract parameters from the request +// String state = jsonNode.has("State") ? jsonNode.get("State").asText() : null; +// String complaintResolution = jsonNode.has("ComplaintResolution") ? jsonNode.get("ComplaintResolution").asText() : null; +// String startDate = jsonNode.get("StartDate").asText(); +// String endDate = jsonNode.get("EndDate").asText(); + + + try { + // Parsing request to get the filter parameters (State, ComplaintResolution, StartDate, EndDate) + JSONObject requestObj = new JSONObject(request); + String complaintResolution = requestObj.optString("ComplaintResolution", null); + String state = requestObj.optString("State", null); + String fromDate = requestObj.optString("StartDate"); + String toDate = requestObj.optString("EndDate"); + + // Convert StartDate and EndDate to Date objects + Date startDateStr = parseDate(fromDate); + Date endDateStr = parseDate(toDate); + + List grievanceDetailsList = grievanceDataRepo.fetchGrievanceDetailsBasedOnParams(state, complaintResolution, startDateStr, endDateStr); // Fetch grievance details based on the request + + if (grievanceDetailsList == null || grievanceDetailsList.isEmpty()) { + return "No grievance details found for the provided request."; + } + + List grievanceResponseList = new ArrayList<>(); + + + // Determine if the complaintResolution is "resolved" or "unresolved" + for (GrievanceDetails grievance : grievanceDetailsList) { + GrievanceResponse grievanceResponse = new GrievanceResponse(); + + // Set basic grievance details + grievanceResponse.setGrievanceId(grievance.getGrievanceId()); + grievanceResponse.setComplaintID(grievance.getComplaintID()); + grievanceResponse.setPrimaryNumber(grievance.getPrimaryNumber()); + grievanceResponse.setComplaintResolution(grievance.getComplaintResolution()); + grievanceResponse.setCreatedDate(grievance.getCreatedDate()); + grievanceResponse.setLastModDate(grievance.getLastModDate()); + + // 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) + remarks = fetchRemarksBasedOnConditions(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 + // ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.writeValueAsString(grievanceResponseList); + + } catch (Exception e) { + logger.error("Error while getting grievance details with remarks: " + e.getMessage(), e); + return "Error fetching grievance details with remarks: " + e.getMessage(); + } + } + +// @Override +// public String getGrievanceDetailsWithRemarks(String request) throws Exception { +// ObjectMapper objectMapper = new ObjectMapper(); +// JsonNode jsonNode = null; +// +// try { +// // Parse the request JSON +// jsonNode = objectMapper.readTree(request); +// } catch (Exception e) { +// logger.error("Error parsing request: " + e.getMessage(), e); +// return null; +// } +// +// // Extract parameters from the request +// String state = jsonNode.has("State") ? jsonNode.get("State").asText() : null; +// String complaintResolution = jsonNode.has("ComplaintResolution") ? jsonNode.get("ComplaintResolution").asText() : null; +// String startDate = jsonNode.get("StartDate").asText(); +// String endDate = jsonNode.get("EndDate").asText(); +// +// // Convert StartDate and EndDate to Date objects +// Date startDateStr = parseDate(startDate); +// Date endDateStr = parseDate(endDate); +// +// List grievanceDetailsList = grievanceDataRepo.fetchGrievanceDetailsBasedOnParams(state, complaintResolution, startDateStr, endDateStr); // Fetch grievance details based on the request +// +// if (grievanceDetailsList == null || grievanceDetailsList.isEmpty()) { +// return "No grievance details found for the provided request."; +// } +// +// List grievanceResponseList = new ArrayList<>(); +// +// try { +// // Parsing request to get the filter parameters (State, ComplaintResolution, StartDate, EndDate) +// // JSONObject requestObj = new JSONObject(request); +// // String complaintResolution = requestObj.optString("ComplaintResolution", null); +// // String state = requestObj.optString("State", null); +// // String fromDate = requestObj.optString("StartDate"); +// // String toDate = requestObj.optString("EndDate"); +// +// +// +// // Determine if the complaintResolution is "resolved" or "unresolved" +// for (GrievanceDetails grievance : grievanceDetailsList) { +// GrievanceResponse grievanceResponse = new GrievanceResponse(); +// +// // Set basic grievance details +// grievanceResponse.setGrievanceId(grievance.getGrievanceId()); +// grievanceResponse.setComplaintID(grievance.getComplaintID()); +// grievanceResponse.setPrimaryNumber(grievance.getPrimaryNumber()); +// grievanceResponse.setComplaintResolution(grievance.getComplaintResolution()); +// grievanceResponse.setCreatedDate(grievance.getCreatedDate()); +// grievanceResponse.setLastModDate(grievance.getLastModDate()); +// +// // 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) +// remarks = fetchRemarksBasedOnConditions(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 +// // ObjectMapper objectMapper = new ObjectMapper(); +// return objectMapper.writeValueAsString(grievanceResponseList); +// +// } catch (Exception e) { +// logger.error("Error while getting grievance details with remarks: " + e.getMessage(), e); +// return "Error fetching grievance details with remarks: " + e.getMessage(); +// } +// } + + private String fetchRemarksFromBenCallByComplaint(String complaintID) throws JSONException { + // Query t_grievanceworklist to fetch the benRegId based on complaintID + List grievanceWorklist = grievanceDataRepo.fetchGrievanceWorklistByComplaintID(complaintID); + + if (grievanceWorklist != null && !grievanceWorklist.isEmpty()) { + GrievanceDetails grievance = grievanceWorklist.get(0); + Long beneficiaryRegID = grievance.getBeneficiaryRegID(); // Fetch the beneficiaryRegID from the grievance + + // Query t_bencall to fetch remarks based on benRegId + List benCallResults = beneficiaryCallRepo.fetchBenCallRemarks(beneficiaryRegID); + + if (benCallResults != null && !benCallResults.isEmpty()) { + return (String) benCallResults.get(0)[0]; // Fetch the remarks + } + } + + return "No remarks found in t_bencall"; + } + private String fetchRemarksFromGrievanceWorklist(String complaintID) throws JSONException { + // Query t_grievanceworklist to fetch remarks based on complaintID + List grievanceWorklistResults = grievanceDataRepo.fetchGrievanceWorklistRemarks(complaintID); + + if (grievanceWorklistResults != null && !grievanceWorklistResults.isEmpty()) { + // Assuming grievanceWorklistResults has a format like [remarks] for simplicity + return (String) grievanceWorklistResults.get(0)[0]; // Fetch the remarks + } + return "No remarks found in t_grievanceworklist"; + } + + +private String fetchRemarksBasedOnConditions(String complaintID) throws JSONException { + String remarks = ""; + // Query t_grievanceworklist to fetch the benRegId based on complaintID + List grievanceWorklist = grievanceDataRepo.fetchGrievanceWorklistByComplaintID(complaintID); + CallType callTypeObj = new CallType(); + + + if (grievanceWorklist != null && !grievanceWorklist.isEmpty()) { + GrievanceDetails grievance = grievanceWorklist.get(0); + Long beneficiaryRegID = grievance.getBeneficiaryRegID(); // Fetch the beneficiaryRegID from the grievance + + Integer benCall = beneficiaryCallRepo.fetchCallTypeID(beneficiaryRegID); + + // Fetching CallDetails using BenCallID and CallTypeID + Set callTypesArray = new HashSet(); + callTypesArray = iEMRCalltypeRepositoryImplCustom.getCallDetails(benCall); + for (Object[] object : callTypesArray) + { + if (object != null && object.length >= 2) + { + callTypeObj.setCallGroupType((String) object[0]); + callTypeObj.setCallType((String) object[1]); + + } + + } + + String callGroupType = callTypeObj.getCallGroupType(); + String callType = callTypeObj.getCallType(); + + // Scenario 1: if callGroupType is "invalid" and callType is "wrong number" + if ("invalid".equalsIgnoreCase(callGroupType) && "wrong number".equalsIgnoreCase(callType)) { + remarks = fetchRemarksFromBenCallByComplaint(complaintID); + } + // Scenario 2: if callCounter is 3 and callType is one of the specified types + else if (grievance.getCallCounter() == 3 && + (Arrays.asList("Switch off", "Not Reachable", "Silent Call", "Disconnected Call").contains(callType))) { + remarks = fetchRemarksFromBenCallByComplaint(complaintID);; + } + // Default case: fetch remarks from t_grievanceworklist based on complaintID + else { + remarks = fetchRemarksFromGrievanceWorklist(grievance.getComplaintID()); + } + + + } + return remarks; + } + } + From ce472ee3cf39e1bf917fffbe458051d839d38667 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 3 Mar 2025 10:57:52 +0530 Subject: [PATCH 2/7] removed unnecessary conditions --- .../BeneficiaryCallRepository.java | 3 - .../GrievanceHandlingServiceImpl.java | 134 +----------------- 2 files changed, 3 insertions(+), 134 deletions(-) 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 9e20b70d..e48e8f9d 100644 --- a/src/main/java/com/iemr/common/repository/callhandling/BeneficiaryCallRepository.java +++ b/src/main/java/com/iemr/common/repository/callhandling/BeneficiaryCallRepository.java @@ -194,7 +194,4 @@ public ArrayList getExistingBCByCallIDAndAgentID(@Param("callID @Query("SELECT b.remarks FROM BeneficiaryCall b WHERE b.beneficiaryRegID = :beneficiaryRegID") List fetchBenCallRemarks(@Param("beneficiaryRegID") Long beneficiaryRegID); - @Query("SELECT b.callTypeID FROM BeneficiaryCall b WHERE b.beneficiaryRegID = :beneficiaryRegID") - Integer fetchCallTypeID(@Param("beneficiaryRegID") Long beneficiaryRegID); - } 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 14c9e2c7..dcb2a68d 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java @@ -504,7 +504,8 @@ public String getGrievanceDetailsWithRemarks(String request) throws Exception { remarks = fetchRemarksFromGrievanceWorklist(grievance.getComplaintID()); } else { // Default: Fetch remarks based on the grievance's specific conditions (no specific resolution status) - remarks = fetchRemarksBasedOnConditions(grievance.getComplaintID()); + // remarks = fetchRemarksBasedOnConditions(grievance.getComplaintID()); + remarks = fetchRemarksFromBenCallByComplaint(grievance.getComplaintID()); } grievanceResponse.setRemarks(remarks); @@ -523,87 +524,7 @@ public String getGrievanceDetailsWithRemarks(String request) throws Exception { } } -// @Override -// public String getGrievanceDetailsWithRemarks(String request) throws Exception { -// ObjectMapper objectMapper = new ObjectMapper(); -// JsonNode jsonNode = null; -// -// try { -// // Parse the request JSON -// jsonNode = objectMapper.readTree(request); -// } catch (Exception e) { -// logger.error("Error parsing request: " + e.getMessage(), e); -// return null; -// } -// -// // Extract parameters from the request -// String state = jsonNode.has("State") ? jsonNode.get("State").asText() : null; -// String complaintResolution = jsonNode.has("ComplaintResolution") ? jsonNode.get("ComplaintResolution").asText() : null; -// String startDate = jsonNode.get("StartDate").asText(); -// String endDate = jsonNode.get("EndDate").asText(); -// -// // Convert StartDate and EndDate to Date objects -// Date startDateStr = parseDate(startDate); -// Date endDateStr = parseDate(endDate); -// -// List grievanceDetailsList = grievanceDataRepo.fetchGrievanceDetailsBasedOnParams(state, complaintResolution, startDateStr, endDateStr); // Fetch grievance details based on the request -// -// if (grievanceDetailsList == null || grievanceDetailsList.isEmpty()) { -// return "No grievance details found for the provided request."; -// } -// -// List grievanceResponseList = new ArrayList<>(); -// -// try { -// // Parsing request to get the filter parameters (State, ComplaintResolution, StartDate, EndDate) -// // JSONObject requestObj = new JSONObject(request); -// // String complaintResolution = requestObj.optString("ComplaintResolution", null); -// // String state = requestObj.optString("State", null); -// // String fromDate = requestObj.optString("StartDate"); -// // String toDate = requestObj.optString("EndDate"); -// -// -// -// // Determine if the complaintResolution is "resolved" or "unresolved" -// for (GrievanceDetails grievance : grievanceDetailsList) { -// GrievanceResponse grievanceResponse = new GrievanceResponse(); -// -// // Set basic grievance details -// grievanceResponse.setGrievanceId(grievance.getGrievanceId()); -// grievanceResponse.setComplaintID(grievance.getComplaintID()); -// grievanceResponse.setPrimaryNumber(grievance.getPrimaryNumber()); -// grievanceResponse.setComplaintResolution(grievance.getComplaintResolution()); -// grievanceResponse.setCreatedDate(grievance.getCreatedDate()); -// grievanceResponse.setLastModDate(grievance.getLastModDate()); -// -// // 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) -// remarks = fetchRemarksBasedOnConditions(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 -// // ObjectMapper objectMapper = new ObjectMapper(); -// return objectMapper.writeValueAsString(grievanceResponseList); -// -// } catch (Exception e) { -// logger.error("Error while getting grievance details with remarks: " + e.getMessage(), e); -// return "Error fetching grievance details with remarks: " + e.getMessage(); -// } -// } + private String fetchRemarksFromBenCallByComplaint(String complaintID) throws JSONException { // Query t_grievanceworklist to fetch the benRegId based on complaintID @@ -635,55 +556,6 @@ private String fetchRemarksFromGrievanceWorklist(String complaintID) throws JSON return "No remarks found in t_grievanceworklist"; } - -private String fetchRemarksBasedOnConditions(String complaintID) throws JSONException { - String remarks = ""; - // Query t_grievanceworklist to fetch the benRegId based on complaintID - List grievanceWorklist = grievanceDataRepo.fetchGrievanceWorklistByComplaintID(complaintID); - CallType callTypeObj = new CallType(); - - - if (grievanceWorklist != null && !grievanceWorklist.isEmpty()) { - GrievanceDetails grievance = grievanceWorklist.get(0); - Long beneficiaryRegID = grievance.getBeneficiaryRegID(); // Fetch the beneficiaryRegID from the grievance - - Integer benCall = beneficiaryCallRepo.fetchCallTypeID(beneficiaryRegID); - - // Fetching CallDetails using BenCallID and CallTypeID - Set callTypesArray = new HashSet(); - callTypesArray = iEMRCalltypeRepositoryImplCustom.getCallDetails(benCall); - for (Object[] object : callTypesArray) - { - if (object != null && object.length >= 2) - { - callTypeObj.setCallGroupType((String) object[0]); - callTypeObj.setCallType((String) object[1]); - - } - - } - - String callGroupType = callTypeObj.getCallGroupType(); - String callType = callTypeObj.getCallType(); - - // Scenario 1: if callGroupType is "invalid" and callType is "wrong number" - if ("invalid".equalsIgnoreCase(callGroupType) && "wrong number".equalsIgnoreCase(callType)) { - remarks = fetchRemarksFromBenCallByComplaint(complaintID); - } - // Scenario 2: if callCounter is 3 and callType is one of the specified types - else if (grievance.getCallCounter() == 3 && - (Arrays.asList("Switch off", "Not Reachable", "Silent Call", "Disconnected Call").contains(callType))) { - remarks = fetchRemarksFromBenCallByComplaint(complaintID);; - } - // Default case: fetch remarks from t_grievanceworklist based on complaintID - else { - remarks = fetchRemarksFromGrievanceWorklist(grievance.getComplaintID()); - } - - - } - return remarks; - } } From f5ca14c304c160b5f01234ca98ba0031a1a3ce73 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 3 Mar 2025 11:03:37 +0530 Subject: [PATCH 3/7] adding code rabbit changes --- .../GrievanceHandlingServiceImpl.java | 44 +------------------ 1 file changed, 2 insertions(+), 42 deletions(-) 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 dcb2a68d..63f1460d 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java @@ -403,31 +403,7 @@ public String saveComplaintResolution(String request) throws Exception { } } - public List fetchGrievanceDetailsFromRequest(String request) { - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode jsonNode = null; - - try { - // Parse the request JSON - jsonNode = objectMapper.readTree(request); - } catch (Exception e) { - logger.error("Error parsing request: " + e.getMessage(), e); - return null; - } - - // Extract parameters from the request - String state = jsonNode.has("State") ? jsonNode.get("State").asText() : null; - String complaintResolution = jsonNode.has("ComplaintResolution") ? jsonNode.get("ComplaintResolution").asText() : null; - String startDateStr = jsonNode.get("StartDate").asText(); - String endDateStr = jsonNode.get("EndDate").asText(); - - // Convert StartDate and EndDate to Date objects - Date startDate = parseDate(startDateStr); - Date endDate = parseDate(endDateStr); - - // Construct the query dynamically based on available parameters - return grievanceDataRepo.fetchGrievanceDetailsBasedOnParams(state, complaintResolution, startDate, endDate); - } + private Date parseDate(String dateStr) { @@ -436,7 +412,7 @@ private Date parseDate(String dateStr) { return dateFormat.parse(dateStr); } catch (ParseException e) { logger.error("Error parsing date for grievance: " + dateStr, e); - return null; + throw new IllegalArgumentException("Invalid JSON format in request"); } } @@ -444,22 +420,6 @@ private Date parseDate(String dateStr) { @Override public String getGrievanceDetailsWithRemarks(String request) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); -// JsonNode jsonNode = null; -// -// try { -// // Parse the request JSON -// jsonNode = objectMapper.readTree(request); -// } catch (Exception e) { -// logger.error("Error parsing request: " + e.getMessage(), e); -// return null; -// } -// -// // Extract parameters from the request -// String state = jsonNode.has("State") ? jsonNode.get("State").asText() : null; -// String complaintResolution = jsonNode.has("ComplaintResolution") ? jsonNode.get("ComplaintResolution").asText() : null; -// String startDate = jsonNode.get("StartDate").asText(); -// String endDate = jsonNode.get("EndDate").asText(); - try { // Parsing request to get the filter parameters (State, ComplaintResolution, StartDate, EndDate) From b95e4ccde6f00ba9082be02baf4e47c36f86546f Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 3 Mar 2025 11:09:14 +0530 Subject: [PATCH 4/7] adding code rabbit suggestions --- .../grievance/GrievanceHandlingServiceImpl.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 63f1460d..59e82ea0 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java @@ -464,8 +464,14 @@ public String getGrievanceDetailsWithRemarks(String request) throws Exception { remarks = fetchRemarksFromGrievanceWorklist(grievance.getComplaintID()); } else { // Default: Fetch remarks based on the grievance's specific conditions (no specific resolution status) - // remarks = fetchRemarksBasedOnConditions(grievance.getComplaintID()); - remarks = fetchRemarksFromBenCallByComplaint(grievance.getComplaintID()); + String callRemarks = fetchRemarksFromBenCallByComplaint(grievance.getComplaintID()); + if(remarks != null && !remarks.startsWith("No remarks found")) { + remarks = callRemarks; + } + else { + remarks = fetchRemarksFromGrievanceWorklist(grievance.getComplaintID()); + + } } grievanceResponse.setRemarks(remarks); @@ -475,12 +481,11 @@ public String getGrievanceDetailsWithRemarks(String request) throws Exception { } // Convert the list of GrievanceResponse objects to JSON and return as a string - // ObjectMapper objectMapper = new ObjectMapper(); return objectMapper.writeValueAsString(grievanceResponseList); } catch (Exception e) { logger.error("Error while getting grievance details with remarks: " + e.getMessage(), e); - return "Error fetching grievance details with remarks: " + e.getMessage(); + throw new Exception("Error processing grievance request"); } } From 50afdf96c4eab2f1ae789263ae3d7e0aae9dc6e7 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 3 Mar 2025 11:12:04 +0530 Subject: [PATCH 5/7] adding required null checks --- .../common/service/grievance/GrievanceHandlingServiceImpl.java | 3 +++ 1 file changed, 3 insertions(+) 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 59e82ea0..85e0fa4e 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java @@ -429,6 +429,9 @@ public String getGrievanceDetailsWithRemarks(String request) throws Exception { String fromDate = requestObj.optString("StartDate"); String toDate = requestObj.optString("EndDate"); + if (fromDate == null || toDate == null) { + throw new IllegalArgumentException("fromDate and toDate are required"); + } // Convert StartDate and EndDate to Date objects Date startDateStr = parseDate(fromDate); Date endDateStr = parseDate(toDate); From e1465d92eca6fcffd5e98489b5ee17ed5c73ee2c Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 3 Mar 2025 11:16:48 +0530 Subject: [PATCH 6/7] adding code rabbit suggested changes --- .../service/grievance/GrievanceHandlingServiceImpl.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) 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 85e0fa4e..3d48927e 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java @@ -21,9 +21,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.iemr.common.data.callhandling.CallType; import com.iemr.common.data.grievance.GetGrievanceWorklistRequest; import com.iemr.common.data.grievance.GrievanceAllocationRequest; import com.iemr.common.data.grievance.GrievanceDetails; @@ -33,7 +31,6 @@ import com.iemr.common.dto.grivance.GrievanceTransactionDTO; import com.iemr.common.dto.grivance.GrievanceWorklistDTO; import com.iemr.common.repository.callhandling.BeneficiaryCallRepository; -import com.iemr.common.repository.callhandling.IEMRCalltypeRepositoryImplCustom; import com.iemr.common.repository.grievance.GrievanceDataRepo; import com.iemr.common.repository.grievance.GrievanceOutboundRepository; import com.iemr.common.utils.exception.IEMRException; @@ -49,15 +46,13 @@ public class GrievanceHandlingServiceImpl implements GrievanceHandlingService { private final GrievanceDataRepo grievanceDataRepo; private final GrievanceOutboundRepository grievanceOutboundRepo; private final BeneficiaryCallRepository beneficiaryCallRepo; - private final IEMRCalltypeRepositoryImplCustom iEMRCalltypeRepositoryImplCustom; @Autowired public GrievanceHandlingServiceImpl(GrievanceDataRepo grievanceDataRepo, GrievanceOutboundRepository grievanceOutboundRepo, - BeneficiaryCallRepository beneficiaryCallRepo, IEMRCalltypeRepositoryImplCustom iEMRCalltypeRepositoryImplCustom) { + BeneficiaryCallRepository beneficiaryCallRepo) { this.grievanceDataRepo = grievanceDataRepo; this.grievanceOutboundRepo = grievanceOutboundRepo; this.beneficiaryCallRepo = beneficiaryCallRepo; - this.iEMRCalltypeRepositoryImplCustom = iEMRCalltypeRepositoryImplCustom; } @Value("${grievanceAllocationRetryConfiguration}") @@ -412,7 +407,7 @@ private Date parseDate(String dateStr) { return dateFormat.parse(dateStr); } catch (ParseException e) { logger.error("Error parsing date for grievance: " + dateStr, e); - throw new IllegalArgumentException("Invalid JSON format in request"); + throw new IllegalArgumentException("Invalid date format in request:"+ dateStr); } } From 057734cca17fd2b0b9265d4c50240518ff008e65 Mon Sep 17 00:00:00 2001 From: SR20290919 Date: Mon, 3 Mar 2025 11:19:10 +0530 Subject: [PATCH 7/7] removing unnecessary Exception --- .../common/service/grievance/GrievanceHandlingServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3d48927e..bc77cae2 100644 --- a/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java +++ b/src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java @@ -489,7 +489,7 @@ public String getGrievanceDetailsWithRemarks(String request) throws Exception { - private String fetchRemarksFromBenCallByComplaint(String complaintID) throws JSONException { + private String fetchRemarksFromBenCallByComplaint(String complaintID) throws Exception { // Query t_grievanceworklist to fetch the benRegId based on complaintID List grievanceWorklist = grievanceDataRepo.fetchGrievanceWorklistByComplaintID(complaintID);