Skip to content

Conversation

srishtigrp78
Copy link
Contributor

@srishtigrp78 srishtigrp78 commented Feb 20, 2025

πŸ“‹ Description

JIRA ID: AMM-1145

Please provide a summary of the change and the motivation behind it. Include relevant context and details.
API to fetch grievance outbound worklist

βœ… Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • πŸ”₯ Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • πŸ›  Refactor (change that is neither a fix nor a new feature)
  • βš™οΈ Config change (configuration file or build script updates)
  • πŸ“š Documentation (updates to docs or readme)
  • πŸ§ͺ Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • πŸš€ Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.

Summary by CodeRabbit

  • New Features

    • Introduced a new API endpoint that returns detailed grievance worklist information along with transaction data.
    • Added a new class for processing grievance worklist requests and new DTOs for grievance transactions and worklists.
    • Enhanced the organization of grievance data for improved clarity and tracking.
    • Added robust error handling to provide reliable feedback in case of processing issues.
  • Bug Fixes

    • Improved error handling for grievance data processing to ensure stability.

SR20290919 and others added 30 commits October 15, 2024 23:34
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

coderabbitai bot commented Feb 20, 2025

Walkthrough

This pull request introduces a new POST endpoint in the grievance controller to fetch a formatted grievance worklist. It adds new DTO classes, a request model, and a repository interface to execute a stored procedure. Additionally, the service interface and its implementation are updated to process and structure grievance data retrieved from the repository, with added error handling and logging.

Changes

File(s) Change Summary
src/main/java/com/iemr/common/controller/grievance/GrievanceController.java Added getGrievanceOutboundWorklist method with logging, request handling, service delegation, and error handling. New imports included.
src/main/java/com/iemr/common/data/grievance/GetGrievanceWorklistRequest.java Introduced a new POJO with Lombok @Data to encapsulate providerServiceMapID and userId.
src/main/java/com/iemr/common/dto/grivance/GrievanceTransactionDTO.java,
src/main/java/com/iemr/common/dto/grivance/GrievanceWorklistDTO.java
Added two DTO classes. GrievanceTransactionDTO encapsulates file and transaction details; GrievanceWorklistDTO holds detailed grievance information and includes a parameterized constructor and list initialization.
src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java Added a repository interface extending JpaRepository with a method to call the stored procedure "Pr_Grievanceworklist" for retrieving grievance worklist data.
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingService.java,
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java
Updated the service layer by adding the method getFormattedGrievanceData(String request) and its implementation. The implementation deserializes the request, retrieves data from the repository, formats it into DTOs, and includes transactional handling.

Possibly related PRs

  • AMM-1139 | Scheduler for fetching L3 to L5 grievance detailsΒ #148: The changes in the main PR, specifically the addition of the getGrievanceOutboundWorklist method in the GrievanceController, are related to the modifications in the retrieved PR, which includes the getFormattedGrievanceData method in the GrievanceHandlingService interface that returns a list of GrievanceWorklistDTO objects, as both involve handling grievance data and utilize the GrievanceWorklistDTO class.
  • Grievances API changesΒ #159: The changes in the main PR, specifically the addition of the getGrievanceOutboundWorklist method in the GrievanceController, are related to the modifications in the retrieved PR, which also involves changes to the GrievanceController class, including the addition of new methods for grievance handling.
  • AMM-1141 | Allocate API for allocating grievance records to agentsΒ #156: The changes in the main PR, which add a new method to the GrievanceController for handling grievances, are related to the retrieved PR as both modify the GrievanceController class and introduce new methods that handle grievance-related requests.

Suggested reviewers

  • ravishanigarapu

Poem

Hop along the code lane,
Where endpoints and DTOs reign,
A stored proc’s beat, a service fine,
Logging each hop in a graceful line,
Bugs may scurry, but our code’s on trackβ€”
A happy rabbit’s code, never looking back! πŸ‡βœ¨

✨ Finishing Touches
  • πŸ“ Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (9)
src/main/java/com/iemr/common/data/grievance/GetGrievanceWorklistRequest.java (1)

7-8: Maintain consistent field naming conventions.

The field names are inconsistent - one uses ID suffix while the other doesn't. Consider renaming for consistency:

-    private Integer providerServiceMapID;
-    private Integer userId;
+    private Integer providerServiceMapId;
+    private Integer userId;
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingService.java (1)

22-22: Remove commented out code.

Commented out code should be removed if it's not being used. If this is planned for future implementation, consider tracking it in the issue tracker instead.

-//	public Map<String, Object> getGrievanceOutboundWorklist(String request) throws Exception;
src/main/java/com/iemr/common/dto/grivance/GrievanceTransactionDTO.java (2)

13-14: Remove or implement commented fields.

The commented fields suggest incomplete implementation. Either:

  1. Remove them if they're not needed, or
  2. Implement them if they're required for the feature

24-37: Clean up constructor implementation.

The constructor contains commented parameters and unnecessary super() call.

-    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;
-				this.createdAt = createdAt;
-				this.updatedAt = updatedAt;
-				this.comment = comment;
-			}
+    public GrievanceTransactionDTO(
+        String fileName,
+        String fileType,
+        String redressed,
+        Timestamp createdAt,
+        Timestamp updatedAt,
+        String comment
+    ) {
+        this.fileName = fileName;
+        this.fileType = fileType;
+        this.redressed = redressed;
+        this.createdAt = createdAt;
+        this.updatedAt = updatedAt;
+        this.comment = comment;
+    }
src/main/java/com/iemr/common/dto/grivance/GrievanceWorklistDTO.java (2)

26-26: Fix typo in field name.

The field name 'severety' is misspelled. It should be 'severity'.

-    private String severety;
+    private String severity;

40-40: Remove commented code.

The commented field 'lastCall' should either be implemented or removed to maintain clean code.

src/main/java/com/iemr/common/controller/grievance/GrievanceController.java (2)

131-131: Fix operation summary description.

The operation summary is incomplete and contains a typo (extra parenthesis).

-  @Operation(summary = "get grievance outbound worklist)")
+  @Operation(summary = "Get grievance outbound worklist")

142-152: Enhance error handling with specific exceptions.

The catch block catches all exceptions generically. Consider catching specific exceptions (e.g., IllegalArgumentException, JsonProcessingException) to provide more targeted error handling.

-catch (Exception e) {
+catch (IllegalArgumentException e) {
+    logger.error("Invalid argument in grievanceOutboundWorklist: " + e.getMessage(), e);
+    List<GrievanceWorklistDTO> errorResponse = new ArrayList<>();
+    GrievanceWorklistDTO errorDTO = new GrievanceWorklistDTO();
+    errorDTO.setComplaint("Invalid request parameters");
+    errorDTO.setSubjectOfComplaint(e.getMessage());
+    errorResponse.add(errorDTO);
+    return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorResponse);
+} catch (Exception e) {
     logger.error("grievanceOutboundWorklist failed with error " + e.getMessage(), e);
     List<GrievanceWorklistDTO> errorResponse = new ArrayList<>();
     GrievanceWorklistDTO errorDTO = new GrievanceWorklistDTO();
     errorDTO.setComplaint("Error fetching grievance data");
     errorDTO.setSubjectOfComplaint(e.getMessage());
     errorResponse.add(errorDTO);
     return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse);
 }
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (1)

292-301: Clean up commented code and add validation.

The transaction creation has commented fields and lacks validation.

     GrievanceTransactionDTO transaction = new GrievanceTransactionDTO(
-        //     (String) row[23], // actionTakenBy
-        //     (String) row[24], // status
+        // Add validation for required fields
+        validateField(row[22], "fileName"),
+        validateField(row[6], "fileType"),
         // ... continue with other fields
     );

+    private String validateField(Object value, String fieldName) {
+        if (value == null) {
+            logger.warn("Missing required field: {}", fieldName);
+            return "";
+        }
+        return (String) value;
+    }
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 1cd7d6f and e6acf34.

πŸ“’ Files selected for processing (7)
  • src/main/java/com/iemr/common/controller/grievance/GrievanceController.java (2 hunks)
  • src/main/java/com/iemr/common/data/grievance/GetGrievanceWorklistRequest.java (1 hunks)
  • src/main/java/com/iemr/common/dto/grivance/GrievanceTransactionDTO.java (1 hunks)
  • src/main/java/com/iemr/common/dto/grivance/GrievanceWorklistDTO.java (1 hunks)
  • src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java (1 hunks)
  • src/main/java/com/iemr/common/service/grievance/GrievanceHandlingService.java (2 hunks)
  • src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: style-check / checkstyle
  • GitHub Check: Package-test
  • GitHub Check: Build
  • GitHub Check: Analyze (java)
πŸ”‡ Additional comments (3)
src/main/java/com/iemr/common/data/grievance/GetGrievanceWorklistRequest.java (1)

11-14: LGTM! Constructor implementation is clean and follows best practices.

The constructor properly initializes all fields and follows good practices.

src/main/java/com/iemr/common/service/grievance/GrievanceHandlingService.java (1)

24-24: LGTM! Method signature is clear and follows interface design principles.

The new method signature is well-defined and follows the pattern of other methods in the interface.

src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java (1)

19-22: LGTM! Stored procedure implementation follows best practices.

The stored procedure implementation is well-structured with:

  • Proper transaction management
  • Clear parameter naming
  • Appropriate return type for procedure results

import com.iemr.common.data.grievance.GrievanceWorklist;
import com.iemr.common.dto.grivance.GrievanceWorklistDTO;

import io.lettuce.core.dynamic.annotation.Param;
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incorrect @param import.

The code is using Lettuce's @param annotation instead of Spring's. This could cause issues with parameter binding.

-import io.lettuce.core.dynamic.annotation.Param;
+import org.springframework.data.repository.query.Param;
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.repository.query.Param;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Comment on lines 261 to 289
for (Object[] row : worklistData) {
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[19], // firstName
(String) row[20], // lastName

new ArrayList<>(),// transactions (initially empty, will be populated later)
(String) row[11], // severety
(String) row[12], // state
(Integer) row[13],// userId
(Boolean) row[14],// deleted
(String) row[15],// createdBy
(Timestamp) row[16], // createdDate
(Timestamp) row[17], // lastModDate
(Boolean) row[18], // isCompleted
(String) row[21], // gender
(String) row[22], // district
(Long) row[23], // beneficiaryID
(String) row[24], // age
(Boolean) row[25], // retryNeeded
(Integer) row[26] // callCounter
//(String) row[22] // lastCall
);
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

Add null checks and use constants for array indices.

The direct array index access without null checks is error-prone. Consider:

  1. Adding null checks for each field
  2. Using constants for array indices
  3. Adding documentation for the array structure
+    // Constants for array indices
+    private static final int COMPLAINT_ID_INDEX = 0;
+    private static final int SUBJECT_INDEX = 1;
+    // ... add other indices

     for (Object[] row : worklistData) {
+        // Add null checks
+        if (row == null || row.length < 27) {
+            logger.warn("Invalid row data received");
+            continue;
+        }
         GrievanceWorklistDTO grievance = new GrievanceWorklistDTO(
-            (String) row[0],
+            (String) row[COMPLAINT_ID_INDEX],
             // ... continue with other fields
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for (Object[] row : worklistData) {
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[19], // firstName
(String) row[20], // lastName
new ArrayList<>(),// transactions (initially empty, will be populated later)
(String) row[11], // severety
(String) row[12], // state
(Integer) row[13],// userId
(Boolean) row[14],// deleted
(String) row[15],// createdBy
(Timestamp) row[16], // createdDate
(Timestamp) row[17], // lastModDate
(Boolean) row[18], // isCompleted
(String) row[21], // gender
(String) row[22], // district
(Long) row[23], // beneficiaryID
(String) row[24], // age
(Boolean) row[25], // retryNeeded
(Integer) row[26] // callCounter
//(String) row[22] // lastCall
);
// Constants for array indices
private static final int COMPLAINT_ID_INDEX = 0;
private static final int SUBJECT_OF_COMPLAINT_INDEX = 1;
private static final int COMPLAINT_INDEX = 2;
private static final int BENEFICIARY_REG_ID_INDEX = 3;
private static final int PROVIDER_SERVICE_MAP_ID_INDEX = 4;
private static final int PRIMARY_NUMBER_INDEX = 5;
// ... add additional constant definitions for all needed indices ...
private static final int SEVERETY_INDEX = 11;
private static final int STATE_INDEX = 12;
private static final int USER_ID_INDEX = 13;
private static final int DELETED_INDEX = 14;
private static final int CREATED_BY_INDEX = 15;
private static final int CREATED_DATE_INDEX = 16;
private static final int LAST_MOD_DATE_INDEX = 17;
private static final int IS_COMPLETED_INDEX = 18;
private static final int FIRST_NAME_INDEX = 19;
private static final int LAST_NAME_INDEX = 20;
private static final int GENDER_INDEX = 21;
private static final int DISTRICT_INDEX = 22;
private static final int BENEFICIARY_ID_INDEX = 23;
private static final int AGE_INDEX = 24;
private static final int RETRY_NEEDED_INDEX = 25;
private static final int CALL_COUNTER_INDEX = 26;
for (Object[] row : worklistData) {
// Add null checks for row validity
if (row == null || row.length < 27) {
logger.warn("Invalid row data received");
continue;
}
GrievanceWorklistDTO grievance = new GrievanceWorklistDTO(
(String) row[COMPLAINT_ID_INDEX], // complaintID
(String) row[SUBJECT_OF_COMPLAINT_INDEX], // subjectOfComplaint
(String) row[COMPLAINT_INDEX], // complaint
(Long) row[BENEFICIARY_REG_ID_INDEX], // beneficiaryRegID
(Integer) row[PROVIDER_SERVICE_MAP_ID_INDEX], // providerServiceMapID
(String) row[PRIMARY_NUMBER_INDEX], // primaryNumber
(String) row[FIRST_NAME_INDEX], // firstName
(String) row[LAST_NAME_INDEX], // lastName
new ArrayList<>(), // transactions (initially empty, will be populated later)
(String) row[SEVERETY_INDEX], // severety
(String) row[STATE_INDEX], // state
(Integer) row[USER_ID_INDEX], // userId
(Boolean) row[DELETED_INDEX], // deleted
(String) row[CREATED_BY_INDEX], // createdBy
(Timestamp) row[CREATED_DATE_INDEX], // createdDate
(Timestamp) row[LAST_MOD_DATE_INDEX], // lastModDate
(Boolean) row[IS_COMPLETED_INDEX], // isCompleted
(String) row[GENDER_INDEX], // gender
(String) row[DISTRICT_INDEX], // district
(Long) row[BENEFICIARY_ID_INDEX], // beneficiaryID
(String) row[AGE_INDEX], // age
(Boolean) row[RETRY_NEEDED_INDEX], // retryNeeded
(Integer) row[CALL_COUNTER_INDEX] // callCounter
//(String) row[22] // lastCall
);
// ... rest of the processing ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srishtigrp78 Great! Thank you for implementing the suggested improvements. This will make the code more maintainable and robust.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

♻️ Duplicate comments (1)
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (1)

262-288: πŸ› οΈ Refactor suggestion

Use constants for array indices to improve maintainability.

The hardcoded array indices make the code error-prone and difficult to maintain.

+    // Constants for array indices
+    private static final class GrievanceIndices {
+        static final int COMPLAINT_ID = 0;
+        static final int SUBJECT = 1;
+        static final int COMPLAINT = 2;
+        static final int BENEFICIARY_REG_ID = 3;
+        // ... add other indices
+    }

     GrievanceWorklistDTO grievance = new GrievanceWorklistDTO(
-        (String) row[0], // complaintID
-        (String) row[1], // subjectOfComplaint
+        (String) row[GrievanceIndices.COMPLAINT_ID],
+        (String) row[GrievanceIndices.SUBJECT],
         // ... continue with other fields
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between e6acf34 and 584f97e.

πŸ“’ Files selected for processing (4)
  • src/main/java/com/iemr/common/dto/grivance/GrievanceTransactionDTO.java (1 hunks)
  • src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java (1 hunks)
  • src/main/java/com/iemr/common/service/grievance/GrievanceHandlingService.java (2 hunks)
  • src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/java/com/iemr/common/repository/grievance/GrievanceOutboundRepository.java
  • src/main/java/com/iemr/common/service/grievance/GrievanceHandlingService.java
  • src/main/java/com/iemr/common/dto/grivance/GrievanceTransactionDTO.java
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: style-check / checkstyle
  • GitHub Check: Package-test
  • GitHub Check: Build
  • GitHub Check: Analyze (java)
πŸ”‡ Additional comments (1)
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (1)

3-45: LGTM! Clean dependency injection setup.

The imports are well-organized, and the constructor properly injects the new repository dependency.

Comment on lines 252 to 254
// Fetch grievance worklist data using @Procedure annotation
List<Object[]> worklistData = grievanceOutboundRepo.getGrievanceWorklistData(getGrievanceWorklistRequest.getProviderServiceMapID(), getGrievanceWorklistRequest.getUserId());

Copy link
Contributor

@coderabbitai coderabbitai bot Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

Add error handling for database operation.

The stored procedure call should be wrapped in a try-catch block to handle potential database errors.

     // Fetch grievance worklist data using @Procedure annotation
+    List<Object[]> worklistData;
+    try {
         worklistData = grievanceOutboundRepo.getGrievanceWorklistData(
             getGrievanceWorklistRequest.getProviderServiceMapID(), 
             getGrievanceWorklistRequest.getUserId()
         );
+        if (worklistData == null || worklistData.isEmpty()) {
+            logger.info("No grievance data found for the given criteria");
+            return new ArrayList<>();
+        }
+    } catch (Exception e) {
+        logger.error("Failed to fetch grievance data: {}", e.getMessage());
+        throw new Exception("Failed to retrieve grievance data", e);
+    }
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Fetch grievance worklist data using @Procedure annotation
List<Object[]> worklistData = grievanceOutboundRepo.getGrievanceWorklistData(getGrievanceWorklistRequest.getProviderServiceMapID(), getGrievanceWorklistRequest.getUserId());
// Fetch grievance worklist data using @Procedure annotation
List<Object[]> worklistData;
try {
worklistData = grievanceOutboundRepo.getGrievanceWorklistData(
getGrievanceWorklistRequest.getProviderServiceMapID(),
getGrievanceWorklistRequest.getUserId()
);
if (worklistData == null || worklistData.isEmpty()) {
logger.info("No grievance data found for the given criteria");
return new ArrayList<>();
}
} catch (Exception e) {
logger.error("Failed to fetch grievance data: {}", e.getMessage());
throw new Exception("Failed to retrieve grievance data", e);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srishtigrp78 Thank you for implementing the error handling! This will make the code more robust and maintainable.

(ο½€βˆ€Β΄)ゝ"


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Comment on lines 291 to 301
GrievanceTransactionDTO transaction = new GrievanceTransactionDTO(

(String) row[22], // fileName
(String) row[6], // fileType
(String) row[7], // redressed
(Timestamp) row[8], // createdAt
(Timestamp) row[9], // updatedAt
(String) row[10] // comment
);

grievance.getTransactions().add(transaction); // Add the transaction to the grievance's list
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incorrect field mapping in transaction DTO.

The district field is incorrectly mapped to fileName in the transaction DTO.

     GrievanceTransactionDTO transaction = new GrievanceTransactionDTO(
-        (String) row[22], // fileName
+        (String) row[6], // fileName
         (String) row[6], // fileType
         (String) row[7], // redressed
         (Timestamp) row[8], // createdAt
         (Timestamp) row[9], // updatedAt
         (String) row[10] // comment
     );

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srishtigrp78 Thanks for fixing the field mapping!


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (2)

274-307: Consider extracting mapping logic to a separate method.

The mapping of array values to DTO fields is quite long and could be moved to a dedicated method for better readability and maintainability.

+    private GrievanceWorklistDTO mapToGrievanceDTO(Object[] row) {
+        return new GrievanceWorklistDTO(
+            (String) row[0],
+            (String) row[1],
+            // ... rest of the mapping
+        );
+    }

     for (Object[] row : worklistData) {
         if (row == null || row.length < 27) {
             logger.warn("invalid row data received");
             continue;
         }
-        GrievanceWorklistDTO grievance = new GrievanceWorklistDTO(
-            // ... current mapping
-        );
+        GrievanceWorklistDTO grievance = mapToGrievanceDTO(row);

309-321: Consider extracting transaction mapping to a separate method.

Similar to the grievance mapping, the transaction mapping could be moved to a dedicated method.

+    private GrievanceTransactionDTO mapToTransactionDTO(Object[] row) {
+        return new GrievanceTransactionDTO(
+            (String) row[6],
+            (String) row[7],
+            // ... rest of the mapping
+        );
+    }

-    GrievanceTransactionDTO transaction = new GrievanceTransactionDTO(
-        // ... current mapping
-    );
+    GrievanceTransactionDTO transaction = mapToTransactionDTO(row);
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 584f97e and 4a4de76.

πŸ“’ Files selected for processing (1)
  • src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (1)
Learnt from: srishtigrp78
PR: PSMRI/Common-API#161
File: src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java:256-261
Timestamp: 2025-02-21T05:55:17.989Z
Learning: Type safety checks for array values from stored procedure 'Pr_Grievanceworklist' are not required as the data types are guaranteed by the procedure contract.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Package-test
  • GitHub Check: Build
  • GitHub Check: Analyze (java)
πŸ”‡ Additional comments (3)
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (3)

3-3: LGTM! Clean import organization and dependency injection.

The imports are well-organized, and the constructor-based dependency injection follows best practices.

Also applies to: 19-25, 27-27, 31-31, 39-39, 42-44


246-252: LGTM! Robust input validation.

The method includes thorough input validation for the request string and required fields.


256-272: LGTM! Comprehensive error handling.

The implementation includes proper error handling with:

  • Null checks for required fields
  • Try-catch block for database operations
  • Appropriate logging
  • Empty result handling

Comment on lines 311 to 314

(String) row[6], // fileName
(String) row[6], // fileType
(String) row[7], // redressed
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix duplicate file value assignment in transaction DTO.

The same value row[6] is used for both fileName and fileType.

-                (String) row[6], // fileName
-                (String) row[6], // fileType
+                (String) row[6], // fileName
+                (String) row[7], // fileType

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added one more field file name so had to fix row no

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srishtigrp78 Thanks for fixing the row numbers! The implementation now correctly maps the fields.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (2)

275-280: Consider using a constant for the expected row length.

The magic number 28 in the row length validation could be extracted to a constant for better maintainability.

+    private static final int EXPECTED_ROW_LENGTH = 28;
     for (Object[] row : worklistData) {
-        if (row == null || row.length < 28)
+        if (row == null || row.length < EXPECTED_ROW_LENGTH)

281-307: Consider using a builder pattern for complex object construction.

The GrievanceWorklistDTO constructor has many parameters which makes it hard to maintain. Consider using a builder pattern to improve readability and maintainability.

-    GrievanceWorklistDTO grievance = new GrievanceWorklistDTO(
-        (String) row[0], // complaintID
-        // ... other parameters
-        (Integer) row[27] // callCounter
-    );
+    GrievanceWorklistDTO grievance = GrievanceWorklistDTO.builder()
+        .complaintID((String) row[0])
+        // ... other parameters
+        .callCounter((Integer) row[27])
+        .build();
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 4a4de76 and 650e573.

πŸ“’ Files selected for processing (1)
  • src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (1)
Learnt from: srishtigrp78
PR: PSMRI/Common-API#161
File: src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java:256-261
Timestamp: 2025-02-21T05:55:17.989Z
Learning: Type safety checks for array values from stored procedure 'Pr_Grievanceworklist' are not required as the data types are guaranteed by the procedure contract.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Package-test
  • GitHub Check: Build
  • GitHub Check: Analyze (java)
πŸ”‡ Additional comments (4)
src/main/java/com/iemr/common/service/grievance/GrievanceHandlingServiceImpl.java (4)

38-45: LGTM! Constructor dependency injection is properly implemented.

The new repository dependency is correctly injected through constructor injection, following best practices for dependency management.


246-272: LGTM! Input validation and error handling are well implemented.

The method includes:

  • Null/empty request validation
  • Required field validation
  • Database error handling with proper logging

310-318: LGTM! Transaction mapping is correctly implemented.

The transaction data is properly mapped from the result set to the DTO.


320-324: Consider validating transaction data before adding to list.

While the transaction is added to the list without validation, it might be worth checking if any essential transaction fields are null before adding it.

+    if (transaction.getCreatedAt() != null) {  // or any other essential field
         grievance.getTransactions().add(transaction);
+    } else {
+        logger.warn("Skipping transaction with null created date for complaint: {}", grievance.getComplaintID());
+    }

Copy link
Member

@ravishanigarapu ravishanigarapu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks Ok

@ravishanigarapu ravishanigarapu merged commit e70fc25 into PSMRI:develop Feb 21, 2025
7 checks passed
srishtigrp78 added a commit to srishtigrp78/Common-API that referenced this pull request Feb 21, 2025
AMM-1145 | API to fetch grievance outbound worklist (PSMRI#161)
@coderabbitai coderabbitai bot mentioned this pull request Mar 10, 2025
10 tasks
@coderabbitai coderabbitai bot mentioned this pull request Mar 29, 2025
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants