-
Notifications
You must be signed in to change notification settings - Fork 45
Unnable to seperate fields for different providers #126
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
Conversation
WalkthroughThe pull request introduces modifications to the Changes
Possibly related PRs
Suggested reviewers
Poem
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? πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this 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
π§Ή Outside diff range and nitpick comments (4)
src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java (1)
Line range hint
1-30
: Summary: Changes align with PR objective, consider broader impactThe modifications to
SectionAndFieldsMappingRepo
align well with the PR objective of separating fields for different providers. The addition ofserviceProviderId
to queries will allow for provider-specific data retrieval.However, to ensure a complete implementation:
- Review the entire codebase for any other occurrences of provider-specific data retrieval that might need similar updates.
- Update and test all code that calls the modified
getByFieldName
method to ensure it provides the newserviceProviderId
parameter.- Consider adding unit tests to verify the behavior of the new and modified methods, especially the fallback behavior when
serviceProviderId = 0
.To help identify other areas that might need updates, you can search for similar patterns in the codebase:
rg -t java "serviceProviderId"
This will help identify other locations where provider-specific logic might need to be implemented or updated.
src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java (3)
Line range hint
188-210
: Optimize database calls in thesaveSectionAndFields
methodIn the
saveSectionAndFields
method, the database call togetByFieldName
is inside a loop, which can lead to performance issues due to multiple database hits.Consider fetching all existing fields in a single query before the loop to minimize database interactions. This can be achieved by retrieving all
SectionAndFieldsMapping
entries for the givensectionId
andserviceProviderId
and storing them in a map for quick lookup.Additionally, ensure that the method is thread-safe and handles potential race conditions that could lead to duplicate entries.
Proposed refactor:
Refactor the code to fetch existing field names in a single query:
// Fetch existing field names for the section and service provider Set<String> existingFieldNames = sectionAndFieldsMappingRepo .findFieldNamesBySectionIdAndServiceProviderId( sectionFieldsMappingDTO.getSectionId(), sectionFieldsMappingDTO.getServiceProviderId() ); List<SectionAndFieldsMapping> sectionAndFieldsMappingList = new ArrayList<>(); for (SectionAndFieldsMapping sectionFieldsMapping : sectionFieldsMappingDTO.getFields()) { if (!existingFieldNames.contains(sectionFieldsMapping.getFieldName())) { // Proceed to set properties and add to the list // [Remaining code unchanged] } else { throw new IllegalArgumentException("Field name '" + sectionFieldsMapping.getFieldName() + "' already exists"); } }Also, consider adding a unique constraint at the database level on
fieldName
,sectionId
, andserviceProviderId
to enforce uniqueness and prevent duplicates even in concurrent scenarios.
Line range hint
205-210
: Preserve the stack trace in exception handlingCurrently, the catch block catches a generic
Exception
and rethrows a newException
with only the message. This practice discards the original stack trace, making debugging difficult.Suggested fix:
Replace the catch block to preserve the original exception:
} catch (Exception e) { - throw new Exception(e.getMessage()); + throw e; // Re-throw the original exception to preserve the stack trace }If you need to throw a custom exception, include the original exception as the cause:
} catch (Exception e) { - throw new Exception(e.getMessage()); + throw new CustomException("An error occurred while saving section and fields", e); }Ensure that
CustomException
is a meaningful exception type in your application that extends fromException
or a more specific superclass.
Line range hint
188-210
: Enhance error messages for better clarityThe error message
"Invalid request: Field name already exists"
may not provide sufficient context to the user.Suggestion:
Include the conflicting
fieldName
in the error message to improve clarity:... } else { - throw new IllegalArgumentException("Invalid request: Field name already exists"); + throw new IllegalArgumentException("Invalid request: Field name '" + sectionFieldsMapping.getFieldName() + "' already exists for Service Provider ID " + sectionFieldsMapping.getServiceProviderId()); }
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
π Files selected for processing (2)
- src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java (1 hunks)
- src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java (1 hunks)
π§° Additional context used
π Additional comments (3)
src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java (2)
Line range hint
20-22
: Consider renaming the method and clarify the serviceProviderId = 0 conditionThe method name
findSectionIdAndSectionNameAndServiceProviderId
doesn't accurately reflect its functionality, as it doesn't involve finding by sectionName. Consider renaming it tofindBySectionIdAndServiceProviderId
for clarity.Additionally, please clarify the purpose of the
OR sfm.serviceProviderId = 0
condition in the query. Is this intended to retrieve default or global mappings when serviceProviderId is 0? If so, it might be helpful to add a comment explaining this behavior.To ensure this is the only occurrence of this method, run the following command:
β Verification successful
Method Usage Verified
The method
findSectionIdAndSectionNameAndServiceProviderId
is only used withinSectionAndFieldsMappingRepo.java
andCustomizationServiceImpl.java
, ensuring that renaming it tofindBySectionIdAndServiceProviderId
will not affect other parts of the codebase.π Scripts executed
The following scripts were executed for the analysis:
Script:
rg -t java "findSectionIdAndSectionNameAndServiceProviderId"
Length of output: 398
26-27
: Approve change with suggestions for improvementThe addition of the
serviceProviderId
parameter to thegetByFieldName
method aligns well with the PR objective of separating fields for different providers. However, consider the following suggestions:
The method name
getByFieldName
is now slightly misleading as it retrieves by both fieldName and serviceProviderId. Consider renaming it togetByFieldNameAndServiceProviderId
for clarity.This change might affect existing code that calls this method. Ensure all callers of this method are updated accordingly.
To check for potential impacts on existing code, run the following command to find all occurrences of
getByFieldName
:Review the results to ensure all callers of this method are updated with the new serviceProviderId parameter.
β Verification successful
Change Verified and Approved with Recommendations
The only existing caller of the
getByFieldName
method has been updated to include the newserviceProviderId
parameter, ensuring consistent usage across the codebase.Recommendation:
- Rename the method to
getByFieldNameAndServiceProviderId
for enhanced clarity.π Scripts executed
The following scripts were executed for the analysis:
Script:
rg -t java "getByFieldName"
Length of output: 435
src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java (1)
188-188
: Verify the method signature change forgetByFieldName
The method
getByFieldName
now includes an additional parameterserviceProviderId
. Ensure that all other calls to this method have been updated accordingly throughout the codebase to preventMethodNotFoundException
or runtime errors.Run the following script to find all usages of
getByFieldName
:This script uses
rg
to search for all instances wheregetByFieldName
is called and displays the subsequent lines to check for the correct parameters.β Verification successful
Verification Successful: All calls to
getByFieldName
include the requiredserviceProviderId
parameter.π Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Find all calls to `getByFieldName` to verify they include the new parameter. rg --type java 'getByFieldName\(' -A 1Length of output: 679
π Description
JIRA ID: AMM-1006
Unable to seperate fields for different providers.
β Type of Change
βΉοΈ 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
fieldName
andserviceProviderId
.Bug Fixes
Documentation