-
Notifications
You must be signed in to change notification settings - Fork 45
AMM-1149 | API to push back Grievance data to the GR team #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
affa900
b2fff57
ce472ee
f5ca14c
b95e4cc
50afdf9
e1465d9
057734c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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<GrievanceDetails> fetchGrievanceDetailsBasedOnParams( | ||||||||||||||||||||||||||||||||||||||||
@Param("state") String state, | ||||||||||||||||||||||||||||||||||||||||
@Param("complaintResolution") String complaintResolution, | ||||||||||||||||||||||||||||||||||||||||
@Param("startDate") Date startDate, | ||||||||||||||||||||||||||||||||||||||||
@Param("endDate") Date endDate); | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+128
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Good query design but consider including deleted filter. The query handles optional parameters well, but it doesn't filter out deleted records. Based on other repository methods (like line 41), it appears that @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.deleted = false") π Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not required There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @srishtigrp78 I understand that filtering out deleted records is not required for this query. I'll respect your decision on this implementation choice. βοΈ Learnings added
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
@Query("SELECT g FROM GrievanceDetails g WHERE g.complaintID = :complaintID") | ||||||||||||||||||||||||||||||||||||||||
List<GrievanceDetails> fetchGrievanceWorklistByComplaintID(@Param("complaintID") String complaintID); | ||||||||||||||||||||||||||||||||||||||||
srishtigrp78 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
@Query("SELECT g.remarks FROM GrievanceDetails g WHERE g.complaintID = :complaintID") | ||||||||||||||||||||||||||||||||||||||||
List<Object[]> fetchGrievanceWorklistRemarks(@Param("complaintID") String complaintID); | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+143
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Simplify return type and add deleted filter. The query selects only one column (remarks) but returns -@Query("SELECT g.remarks FROM GrievanceDetails g WHERE g.complaintID = :complaintID")
-List<Object[]> fetchGrievanceWorklistRemarks(@Param("complaintID") String complaintID);
+@Query("SELECT g.remarks FROM GrievanceDetails g WHERE g.complaintID = :complaintID AND g.deleted = false")
+List<String> fetchGrievanceWorklistRemarks(@Param("complaintID") String complaintID); π Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not required There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @srishtigrp78 I understand that you don't want to implement this change. Thank you for letting me know - I'll respect your decision and won't pursue this suggestion further. |
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -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,16 @@ | |||||||||||||||||
import org.springframework.beans.factory.annotation.Value; | ||||||||||||||||||
import org.springframework.stereotype.Service; | ||||||||||||||||||
|
||||||||||||||||||
import com.fasterxml.jackson.databind.ObjectMapper; | ||||||||||||||||||
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.grievance.GrievanceDataRepo; | ||||||||||||||||||
import com.iemr.common.repository.grievance.GrievanceOutboundRepository; | ||||||||||||||||||
import com.iemr.common.utils.exception.IEMRException; | ||||||||||||||||||
|
@@ -37,11 +45,14 @@ public class GrievanceHandlingServiceImpl implements GrievanceHandlingService { | |||||||||||||||||
|
||||||||||||||||||
private final GrievanceDataRepo grievanceDataRepo; | ||||||||||||||||||
private final GrievanceOutboundRepository grievanceOutboundRepo; | ||||||||||||||||||
private final BeneficiaryCallRepository beneficiaryCallRepo; | ||||||||||||||||||
|
||||||||||||||||||
@Autowired | ||||||||||||||||||
public GrievanceHandlingServiceImpl(GrievanceDataRepo grievanceDataRepo, GrievanceOutboundRepository grievanceOutboundRepo) { | ||||||||||||||||||
public GrievanceHandlingServiceImpl(GrievanceDataRepo grievanceDataRepo, GrievanceOutboundRepository grievanceOutboundRepo, | ||||||||||||||||||
BeneficiaryCallRepository beneficiaryCallRepo) { | ||||||||||||||||||
this.grievanceDataRepo = grievanceDataRepo; | ||||||||||||||||||
this.grievanceOutboundRepo = grievanceOutboundRepo; | ||||||||||||||||||
this.beneficiaryCallRepo = beneficiaryCallRepo; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
@Value("${grievanceAllocationRetryConfiguration}") | ||||||||||||||||||
|
@@ -386,5 +397,128 @@ public String saveComplaintResolution(String request) throws Exception { | |||||||||||||||||
throw new Exception("Failed to update complaint resolution"); | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
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); | ||||||||||||||||||
throw new IllegalArgumentException("Invalid date format in request:"+ dateStr); | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
@Override | ||||||||||||||||||
public String getGrievanceDetailsWithRemarks(String request) throws Exception { | ||||||||||||||||||
ObjectMapper objectMapper = new ObjectMapper(); | ||||||||||||||||||
|
||||||||||||||||||
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"); | ||||||||||||||||||
|
||||||||||||||||||
srishtigrp78 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
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); | ||||||||||||||||||
|
||||||||||||||||||
Comment on lines
+431
to
+433
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential NullPointerException for date parsing. The method doesn't check if -Date startDateStr = parseDate(fromDate);
-Date endDateStr = parseDate(toDate);
+if (fromDate == null || toDate == null) {
+ throw new IllegalArgumentException("StartDate and EndDate are required");
+}
+Date startDateStr = parseDate(fromDate);
+Date endDateStr = parseDate(toDate); π Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @srishtigrp78 Thank you for confirming! I can see that you've implemented the null check for the date parameters before attempting to parse them. This change will prevent potential NullPointerExceptions and improve the error handling in your code. Good work! If you found this review helpful, would you consider giving us a shout-out on X? |
||||||||||||||||||
List<GrievanceDetails> 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<GrievanceResponse> 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) | ||||||||||||||||||
String callRemarks = fetchRemarksFromBenCallByComplaint(grievance.getComplaintID()); | ||||||||||||||||||
if(remarks != null && !remarks.startsWith("No remarks found")) { | ||||||||||||||||||
remarks = callRemarks; | ||||||||||||||||||
} | ||||||||||||||||||
else { | ||||||||||||||||||
remarks = fetchRemarksFromGrievanceWorklist(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); | ||||||||||||||||||
|
||||||||||||||||||
} catch (Exception e) { | ||||||||||||||||||
logger.error("Error while getting grievance details with remarks: " + e.getMessage(), e); | ||||||||||||||||||
throw new Exception("Error processing grievance request"); | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
private String fetchRemarksFromBenCallByComplaint(String complaintID) throws Exception { | ||||||||||||||||||
// Query t_grievanceworklist to fetch the benRegId based on complaintID | ||||||||||||||||||
List<GrievanceDetails> 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<Object[]> 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<Object[]> 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"; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
} | ||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.