Skip to content

AMM-1206 : In closure screen language is not showing in the preferred language list#55

Merged
devikasuresh20 merged 12 commits into
PSMRI:developfrom
ravishanigarapu:develop
Jan 24, 2025
Merged

AMM-1206 : In closure screen language is not showing in the preferred language list#55
devikasuresh20 merged 12 commits into
PSMRI:developfrom
ravishanigarapu:develop

Conversation

@ravishanigarapu

@ravishanigarapu ravishanigarapu commented Jan 22, 2025

Copy link
Copy Markdown
Contributor

📋 Description

JIRA ID: AMM-1206

In closure screen language is not showing in the preferred language list.


✅ 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

Release Notes

  • New Features

    • Added ability to update allocation status for child and mother records.
    • Enhanced call closure process with improved language mapping logic.
  • Improvements

    • Streamlined code for managing preferred language updates.
    • Introduced more robust language mapping verification for calls.
  • Documentation Updates

    • Enabled API documentation and Swagger UI for enhanced visibility of API endpoints in development, test, and UAT environments.
    • Disabled API documentation and Swagger UI in the CI environment.

@coderabbitai

coderabbitai Bot commented Jan 22, 2025

Copy link
Copy Markdown

Walkthrough

The pull request introduces enhancements to the call closure and record allocation functionality in the ECD (Early Childhood Development) system. New methods are added to repository interfaces for updating the allocation status of child and mother records. In the CallClosureImpl service, language mapping logic is refined, with new methods added to check language mapping and update preferred languages. Additionally, properties for API documentation and Swagger UI are configured differently across various environments.

Changes

File Change Summary
.../ChildRecordRepo.java Added updateAllocatedStatus() method to update child record allocation status
.../MotherRecordRepo.java Added updateAllocatedStatus() method to update mother record allocation status
.../CallClosureImpl.java - Added masterServiceImpl field
- Introduced updatePreferredLanguage() method
- Added isLanguageMappedWithUser() method
- Modified closeCall() method to include language mapping checks
.../ecd_ci.properties Added properties to disable API documentation and Swagger UI
.../ecd_dev.properties Added properties to enable API documentation and Swagger UI
.../ecd_test.properties Added properties to enable API documentation and Swagger UI
.../ecd_uat.properties Added properties to enable API documentation and Swagger UI

Possibly related PRs

  • AMM-919 : Preferred Language Changes #44: The updateAllocatedStatus method in MotherRecordRepo is related to the updateAllocatedStatus method in ChildRecordRepo, as both methods are designed to update the allocation status for their respective records.
  • PreferredLanguage changes #45: The updatePreferredLanguage method added to ChildRecordRepo is directly related to the changes in the main PR, as both involve updating the preferred language for child records.
  • PreferredLanguage changes #45: The updatePreferredLanguage method in MotherRecordRepo is also related, as it parallels the functionality of updating the preferred language for mother records, similar to the changes made in the main PR.

Suggested reviewers

  • devikasuresh20
  • helenKaryamsetty

Poem

🐰 Hop, hop, through code so bright,
Language mapping now takes flight!
Repos dance with status new,
Allocation's path shines true,
Rabbit's code hops with delight! 🌈


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 00fda09 and 5486156.

📒 Files selected for processing (1)
  • src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (4)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (4)

280-298: Consider enhancing error handling in updatePreferredLanguage.

The method effectively handles both mother and child records. Consider adding error logging for failed updates to help with troubleshooting.

 private void updatePreferredLanguage(CallClosureDTO request,OutboundCalls callObj,boolean isLanguageMapped) {
     if (null != request.getPreferredLanguage()) {
         boolean isMother = callObj.getMotherId() != null;
         boolean isChild = callObj.getChildId() != null;
         
         if (isMother && !isChild) {
+            try {
                 motherRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getMotherId());
                 if (!isLanguageMapped) {
                     motherRecordRepo.updateAllocatedStatus(false, callObj.getMotherId());
                 }
+            } catch (Exception e) {
+                logger.error("Failed to update mother's preferred language: " + callObj.getMotherId(), e);
+                throw new ECDException("Failed to update mother's preferred language", e);
+            }
         }
         if (isChild) {
+            try {
                 childRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getChildId());
                 if (!isLanguageMapped) {
                     childRecordRepo.updateAllocatedStatus(false, callObj.getChildId());
                 }
+            } catch (Exception e) {
+                logger.error("Failed to update child's preferred language: " + callObj.getChildId(), e);
+                throw new ECDException("Failed to update child's preferred language", e);
+            }
         }
     }
 }

280-298: Consider enhancing error handling and logging.

While the logic is correct, consider adding:

  1. Logging statements for debugging language mapping updates
  2. Error handling for database operations
 private void updatePreferredLanguage(CallClosureDTO request,OutboundCalls callObj,boolean isLanguageMapped) {
+    logger.debug("Updating preferred language for request: {}", request);
     if (null != request.getPreferredLanguage()) {
         boolean isMother = callObj.getMotherId() != null;
         boolean isChild = callObj.getChildId() != null;
         
         if (isMother && !isChild) {
+            try {
                 motherRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getMotherId());
                 if (!isLanguageMapped) {
                     motherRecordRepo.updateAllocatedStatus(false, callObj.getMotherId());
                 }
+                logger.info("Successfully updated mother record language preferences for motherId: {}", callObj.getMotherId());
+            } catch (Exception e) {
+                logger.error("Failed to update mother record language preferences for motherId: {}", callObj.getMotherId(), e);
+                throw new ECDException("Failed to update mother record language preferences", e);
+            }
         }
         if (isChild) {
+            try {
                 childRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getChildId());
                 if (!isLanguageMapped) {
                     childRecordRepo.updateAllocatedStatus(false, callObj.getChildId());
                 }
+                logger.info("Successfully updated child record language preferences for childId: {}", callObj.getChildId());
+            } catch (Exception e) {
+                logger.error("Failed to update child record language preferences for childId: {}", callObj.getChildId(), e);
+                throw new ECDException("Failed to update child record language preferences", e);
+            }
         }
     }
 }

280-298: Consider adding error handling for database operations.

While the method is well-structured and handles both mother and child records appropriately, it should include try-catch blocks for database operations to handle potential failures gracefully.

 private void updatePreferredLanguage(CallClosureDTO request,OutboundCalls callObj,boolean isLanguageMapped) {
     if (null != request.getPreferredLanguage()) {
         boolean isMother = callObj.getMotherId() != null;
         boolean isChild = callObj.getChildId() != null;
         
+        try {
             if (isMother && !isChild) {
                 motherRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getMotherId());
                 if (!isLanguageMapped) {
                     motherRecordRepo.updateAllocatedStatus(false, callObj.getMotherId());
                 }
             }
             if (isChild) {
                 childRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getChildId());
                 if (!isLanguageMapped) {
                     childRecordRepo.updateAllocatedStatus(false, callObj.getChildId());
                 }
             }
+        } catch (Exception e) {
+            logger.error("Failed to update preferred language", e);
+            throw new ECDException("Failed to update preferred language: " + e.getMessage());
+        }
     }
 }

300-313: Consider caching language mappings for better performance.

The method makes a database call to retrieve language mappings on every call closure. Consider caching the language mappings at the user level to reduce database load.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c28b648 and 15aace3.

📒 Files selected for processing (3)
  • src/main/java/com/iemr/ecd/repo/call_conf_allocation/ChildRecordRepo.java (1 hunks)
  • src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java (1 hunks)
  • src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (6 hunks)
👮 Files not reviewed due to content moderation or server errors (2)
  • src/main/java/com/iemr/ecd/repo/call_conf_allocation/ChildRecordRepo.java
  • src/main/java/com/iemr/ecd/repo/call_conf_allocation/MotherRecordRepo.java
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (java)
  • GitHub Check: Package-test
🔇 Additional comments (5)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (5)

148-148: LGTM! Language mapping check is well integrated.

The language mapping verification is properly integrated into the call closure flow, with appropriate updates to the allocation status.

Also applies to: 210-213


300-313: LGTM! Robust language mapping verification.

The method effectively verifies user's language mappings with proper null checks using ObjectUtils.isEmpty.


210-213: LGTM! Language mapping check is well integrated.

The code properly checks if the user has the required language mapping and updates the allocation status accordingly.


300-313: LGTM! Well-structured language mapping check.

The method effectively retrieves and validates user language mappings using null-safe collection checks.


148-148: LGTM! Language mapping check is well integrated.

The code properly handles language mapping verification and updates the allocation status accordingly.

Also applies to: 210-213

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 15aace3 and 445476a.

📒 Files selected for processing (4)
  • src/main/environment/ecd_ci.properties (1 hunks)
  • src/main/environment/ecd_dev.properties (1 hunks)
  • src/main/environment/ecd_test.properties (1 hunks)
  • src/main/environment/ecd_uat.properties (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
🔇 Additional comments (3)
src/main/environment/ecd_ci.properties (1)

22-23: LGTM! Appropriate configuration for CI environment.

Disabling Swagger UI and API docs in CI environment aligns with security best practices.

src/main/environment/ecd_test.properties (1)

19-20: LGTM! Appropriate configuration for test environment.

Enabling Swagger UI and API docs in test environment facilitates API testing and documentation.

src/main/environment/ecd_dev.properties (1)

19-20: LGTM! Appropriate configuration for dev environment.

Enabling Swagger UI and API docs in dev environment supports development workflow.

Comment on lines +19 to +20
springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true No newline at end of file

@coderabbitai coderabbitai Bot Jan 22, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider disabling Swagger UI in UAT environment.

UAT environment should mirror production configuration. Enabling Swagger UI and API docs in UAT might pose security risks.

Apply this diff to align with production security practices:

-springdoc.api-docs.enabled=true
-springdoc.swagger-ui.enabled=true
+springdoc.api-docs.enabled=false
+springdoc.swagger-ui.enabled=false
📝 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
springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true
springdoc.api-docs.enabled=false
springdoc.swagger-ui.enabled=false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@coderabbitai we need to enable swagger in all the lower environments so we need to keep it as TRUE

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@ravishanigarapu Understood, I'll note this requirement about keeping Swagger UI enabled in all lower environments. Thank you for the clarification.


✏️ Learnings added
Learnt from: ravishanigarapu
PR: PSMRI/ECD-API#55
File: src/main/environment/ecd_uat.properties:19-20
Timestamp: 2025-01-22T12:20:25.594Z
Learning: In the ECD-API project, Swagger UI and API docs should be enabled (set to true) in all lower environments (DEV, TEST, UAT) to facilitate API testing and documentation. Only the production environment should have these disabled.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (3)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (3)

148-148: Consider using constants for status values.

The logic for handling unmapped languages is correct, but consider extracting the magic strings into constants for better maintainability.

-                    callObj.setCallStatus(Constants.OPEN);
-                    callObj.setCallAttemptNo(0);
-                    callObj.setAllocationStatus(Constants.UNALLOCATED);
+                    callObj.setCallStatus(Constants.CALL_STATUS_OPEN);
+                    callObj.setCallAttemptNo(Constants.INITIAL_CALL_ATTEMPT);
+                    callObj.setAllocationStatus(Constants.ALLOCATION_STATUS_UNALLOCATED);

Also applies to: 210-216


284-302: Consider more descriptive boolean variable names.

The method logic is clear, but the boolean variables could be more descriptive for better readability.

-    boolean isMother = callObj.getMotherId() != null;
-    boolean isChild = callObj.getChildId() != null;
+    boolean hasMotherRecord = callObj.getMotherId() != null;
+    boolean hasChildRecord = callObj.getChildId() != null;

304-317: Consider using early return pattern for better readability.

The method can be simplified using the early return pattern.

 private boolean isLanguageMappedWithUser(CallClosureDTO request) {
-    boolean isLanguageMapped = false;
     Integer userId = request.getUserId();
     List<String> language = new ArrayList<>();
     List<V_GetUserlangmapping> languageByUserId = masterServiceImpl.getLanguageByUserId(userId);
     for (V_GetUserlangmapping v_GetUserlangmapping : languageByUserId) {
         String languageName = v_GetUserlangmapping.getLanguageName();
         language.add(languageName);
     }
-    if(!ObjectUtils.isEmpty(language)) {
-        isLanguageMapped = language.contains(request.getPreferredLanguage());
-    }
-    return isLanguageMapped;
+    if(ObjectUtils.isEmpty(language)) {
+        return false;
+    }
+    return language.contains(request.getPreferredLanguage());
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 445476a and 96e566a.

📒 Files selected for processing (1)
  • src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
🔇 Additional comments (2)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (2)

37-37: LGTM! Dependencies are properly configured.

The new imports and autowired field for MasterServiceImpl are correctly added.

Also applies to: 45-45, 52-52, 79-81


264-265: Verify error handling for updatePreferredLanguage.

The method is called without try-catch. Consider adding error handling to prevent potential runtime exceptions.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (1)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (1)

305-318: Improve isLanguageMappedWithUser using Java 8 Stream API.

The method can be simplified and made more robust with proper null checks and Stream API.

 private boolean isLanguageMappedWithUser(CallClosureDTO request) {
-    boolean isLanguageMapped = false;
     Integer userId = request.getUserId();
-    List<String> language = new ArrayList<>();
+    if (userId == null) {
+        return false;
+    }
+    
+    String preferredLanguage = request.getPreferredLanguage();
+    if (preferredLanguage == null || preferredLanguage.trim().isEmpty()) {
+        return false;
+    }
+    
     List<V_GetUserlangmapping> languageByUserId = masterServiceImpl.getLanguageByUserId(userId);
-    for (V_GetUserlangmapping v_GetUserlangmapping : languageByUserId) {
-        String languageName = v_GetUserlangmapping.getLanguageName();
-        language.add(languageName);
-    }
-    if(!ObjectUtils.isEmpty(language)) {
-        isLanguageMapped = language.contains(request.getPreferredLanguage());
-    }
-    return isLanguageMapped;
+    return !ObjectUtils.isEmpty(languageByUserId) &&
+           languageByUserId.stream()
+                          .map(V_GetUserlangmapping::getLanguageName)
+                          .anyMatch(lang -> lang.equals(preferredLanguage));
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 96e566a and 00fda09.

📒 Files selected for processing (1)
  • src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
🔇 Additional comments (2)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (2)

37-37: LGTM! Dependencies are properly imported and autowired.

The new imports and autowired field are correctly added to support the language mapping functionality.

Also applies to: 45-45, 52-52, 79-81


148-148: LGTM! Language mapping validation is properly implemented.

The code correctly handles cases where the user's preferred language is not mapped:

  1. For introductory calls, it:
    • Sets the call status to "OPEN"
    • Resets the call attempt counter
    • Updates the allocation status to "UNALLOCATED"
  2. This ensures that calls are properly reallocated when language preferences don't match.

Also applies to: 210-217

Comment on lines +285 to +303
private void updatePreferredLanguage(CallClosureDTO request,OutboundCalls callObj,boolean isLanguageMapped) {
if (null != request.getPreferredLanguage()) {
boolean isMother = callObj.getMotherId() != null;
boolean isChild = callObj.getChildId() != null;

if (isMother && !isChild) {
motherRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getMotherId());
if (!isLanguageMapped) {
motherRecordRepo.updateAllocatedStatus(false, callObj.getMotherId());
}
}
if (isChild) {
childRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getChildId());
if (!isLanguageMapped) {
childRecordRepo.updateAllocatedStatus(false, callObj.getChildId());
}
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance error handling and null checks in updatePreferredLanguage.

  1. Add null checks for request.getPreferredLanguage()
  2. Wrap database operations in try-catch blocks
 private void updatePreferredLanguage(CallClosureDTO request,OutboundCalls callObj,boolean isLanguageMapped) {
-    if (null != request.getPreferredLanguage()) {
+    String preferredLanguage = request.getPreferredLanguage();
+    if (preferredLanguage == null || preferredLanguage.trim().isEmpty()) {
+        return;
+    }
     boolean isMother = callObj.getMotherId() != null;
     boolean isChild = callObj.getChildId() != null;
     
     if (isMother && !isChild) {
+        try {
-            motherRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getMotherId());
+            motherRecordRepo.updatePreferredLanguage(preferredLanguage, callObj.getMotherId());
             if (!isLanguageMapped) {
                 motherRecordRepo.updateAllocatedStatus(false, callObj.getMotherId());
             }
+        } catch (Exception e) {
+            logger.error("Failed to update mother's preferred language", e);
+            throw new ECDException("Failed to update mother's preferred language: " + e.getMessage());
+        }
     }
     if (isChild) {
+        try {
-            childRecordRepo.updatePreferredLanguage(request.getPreferredLanguage(), callObj.getChildId());
+            childRecordRepo.updatePreferredLanguage(preferredLanguage, callObj.getChildId());
             if (!isLanguageMapped) {
                 childRecordRepo.updateAllocatedStatus(false, callObj.getChildId());
             }
+        } catch (Exception e) {
+            logger.error("Failed to update child's preferred language", e);
+            throw new ECDException("Failed to update child's preferred language: " + e.getMessage());
+        }
     }
-    }
 }

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

Comment on lines +265 to +266
updatePreferredLanguage(request,callObj,isLanguageMapped);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codebase verification

Add error handling for database operations in updatePreferredLanguage

The method makes database calls through repository methods that should be protected with error handling, following the established patterns in the codebase. The suggested try-catch implementation is appropriate as it:

  • Matches the error handling pattern used for similar database operations in the file
  • Uses the existing ECDException class for error propagation
  • Includes proper error logging
🔗 Analysis chain

Verify error handling for updatePreferredLanguage.

The method call should be wrapped in a try-catch block to handle potential database errors when updating the preferred language.

-updatePreferredLanguage(request,callObj,isLanguageMapped);
+try {
+    updatePreferredLanguage(request,callObj,isLanguageMapped);
+} catch (Exception e) {
+    logger.error("Failed to update preferred language", e);
+    throw new ECDException("Failed to update preferred language: " + e.getMessage());
+}
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash

# Find updatePreferredLanguage method implementation
echo "=== Searching for updatePreferredLanguage method ==="
ast-grep --pattern 'private $_ updatePreferredLanguage($$$) { $$$ }'

# Look for similar method calls with try-catch blocks in the same file
echo -e "\n=== Checking error handling patterns in CallClosureImpl.java ==="
rg "try\s*\{" "src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java" -A 5

# Verify ECDException exists
echo -e "\n=== Checking for ECDException class ==="
fd "ECDException.java"

Length of output: 3997

@sonarqubecloud

Copy link
Copy Markdown

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