Skip to content

Conversation

ravishanigarapu
Copy link
Member

@ravishanigarapu ravishanigarapu commented Oct 25, 2024

different-2 service line in single provider

πŸ“‹ Description

JIRA ID: AMM-1002

Preprod- Unable to separate a Customization field for different 2 service line in single provider


βœ… 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 projectId field to enhance data mapping for sections and fields.
    • Updated methods to filter and handle data based on projectId, improving specificity in operations related to project and section mappings.
  • Bug Fixes

    • Implemented checks to ensure projectId is provided when saving section and field mappings, enhancing data integrity.
    • Added validation for projectId in data retrieval processes to prevent errors.
  • Documentation

    • Updated response formats to include projectId for clearer context in returned data.

different-2 service line in single provider
Copy link
Contributor

coderabbitai bot commented Oct 25, 2024

Walkthrough

This pull request introduces a new field, projectId, to both the SectionAndFieldsMapping and SectionFieldsMappingDTO classes. It also modifies the SectionAndFieldsMappingRepo interface to include projectId as a parameter in relevant query methods. Additionally, the CustomizationServiceImpl class has been updated to ensure that projectId is handled appropriately during save and fetch operations, enhancing the overall data integrity and specificity of project-related mappings.

Changes

File Path Change Summary
src/main/java/com/iemr/common/data/customization/SectionAndFieldsMapping.java - Added new field: private Integer projectId annotated with @Column(name = "ProjectID") and @Expose.
src/main/java/com/iemr/common/data/customization/SectionFieldsMappingDTO.java - Added variable: private Integer projectId;.
src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java - Updated method findSectionIdAndSectionNameAndServiceProviderId to include projectId as a parameter.
- Updated method getByFieldName to include projectId as a parameter.
src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java - Modified saveSectionAndFields to check for projectId.
- Updated fetchMappedFields to include projectId in the query.
- Updated updateSectionAndFields to conditionally set projectId on the response object.

Possibly related PRs

  • Unnable to seperate fields for different providersΒ #126: The changes in this PR involve updating the SectionAndFieldsMappingRepo interface to include projectId in the query methods, which directly relates to the addition of the projectId field in the main PR's SectionAndFieldsMapping class.
  • Customization Changes EditΒ #128: This PR modifies the CustomizationServiceImpl class to include null checks for serviceProviderId, which is relevant as the main PR also introduces a new field (projectId) that may require similar validation in related service methods.
  • logic modified save section-fields APIΒ #125: This PR modifies the saveSectionAndFields method in CustomizationServiceImpl, which is relevant because the main PR's changes to SectionAndFieldsMapping will likely affect how fields are saved, including the new projectId.

Suggested reviewers

  • devikasuresh20
  • helenKaryamsetty

πŸ‡ In the fields where we play,
A new ID comes to stay.
Project dreams now take their flight,
Mapping paths both day and night.
With each save, we hold it dear,
Hop along, the change is here! 🌟


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 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: 4

🧹 Outside diff range and nitpick comments (3)
src/main/java/com/iemr/common/data/customization/SectionFieldsMappingDTO.java (1)

17-17: LGTM! Consider adding documentation and validation.

The addition of projectId aligns with the requirement to separate customization fields. However, consider these improvements:

+ /** Project identifier used to separate customization fields for different service lines */
+ @JsonProperty(required = false) // if nullable
+ @Min(value = 1, message = "Project ID must be positive")
 private Integer projectId;
src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java (1)

19-21: Document the fallback behavior for projectId=0.

The query correctly implements a fallback mechanism where projectId=0 represents global settings. This aligns with the PR objective of separating customization fields while maintaining backward compatibility.

Add a comment explaining the fallback behavior:

+// Fetches mappings for specific project/provider or falls back to global settings (projectId=0/serviceProviderId=0)
@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.sectionId = :sectionId AND (sfm.serviceProviderId = :serviceProviderId OR sfm.serviceProviderId= 0) AND (sfm.projectId = :projectId OR sfm.projectId= 0)")
src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java (1)

Line range hint 183-377: Consider adding transaction boundaries

The changes effectively solve the field separation issue by introducing projectId context. However, consider adding @transactional annotations to methods that perform multiple database operations (save, update) to ensure data consistency in case of failures.

πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

πŸ“₯ Commits

Files that changed from the base of the PR and between 72361d5 and 5d9edff.

πŸ“’ Files selected for processing (4)
  • src/main/java/com/iemr/common/data/customization/SectionAndFieldsMapping.java (1 hunks)
  • src/main/java/com/iemr/common/data/customization/SectionFieldsMappingDTO.java (1 hunks)
  • src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java (1 hunks)
  • src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java (3 hunks)
πŸ”‡ Additional comments (6)
src/main/java/com/iemr/common/data/customization/SectionFieldsMappingDTO.java (1)

Line range hint 1-19: Verify data migration strategy.

Since this appears to be a schema change, ensure there's a plan for handling existing records in the database.

src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java (1)

19-27: Verify the impact of projectId changes.

The addition of projectId parameter affects multiple queries. Let's verify that all callers are updated accordingly.

βœ… Verification successful

Based on the search results, I can generate the final response as we have sufficient information:

All callers are properly updated with projectId parameter

The code search shows that both repository methods findSectionIdAndSectionNameAndServiceProviderId and getByFieldName are called correctly in CustomizationServiceImpl.java with the projectId parameter being passed appropriately:

  • getByFieldName is called with sectionFieldsMappingDTO.getProjectId()
  • findSectionIdAndSectionNameAndServiceProviderId is called with sectionAndFieldsMapping.getProjectId()
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for method calls to ensure all callers are updated with projectId parameter
rg -A 2 "findSectionIdAndSectionNameAndServiceProviderId|getByFieldName" --type java

# Search for any remaining queries in the repo that might need projectId
ast-grep --pattern 'SELECT sfm FROM SectionAndFieldsMapping sfm WHERE $$$'

Length of output: 2036

src/main/java/com/iemr/common/data/customization/SectionAndFieldsMapping.java (2)

99-102: LGTM! The projectId field implementation looks correct.

The field follows consistent patterns with other ID fields in the class and will help separate customization fields per project.

Let's verify the database schema changes:

#!/bin/bash
# Description: Check if database migration scripts exist for the ProjectID column

# Look for migration files containing ProjectID
rg -i "projectid|project_id" --type sql

99-102: Verify impact on existing records.

Since this is a new column in an existing table, ensure there's a strategy for handling existing records.

βœ… Verification successful

Based on the shell script results, I can now generate the final response since I have sufficient information about how projectId is handled in the codebase.

The projectId column addition is properly handled with fallback mechanisms

The codebase shows proper handling of the projectId column through:

  • Default fallback to projectId=0 in queries (e.g. OR sp.projectId = 0)
  • Null checks and initialization of projectId in service layer
  • Consistent usage across related entities (ServicelineCustomization, SectionProjectMapping, etc.)

The existing records are safely handled through the OR conditions in repository queries that fall back to projectId=0 when querying data:

(sfm.projectId = :projectId OR sfm.projectId= 0)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Look for repository and service layer handling of projectId

# Check repository methods using projectId
ast-grep --pattern 'interface $_ extends JpaRepository<$_, $_> {
  $$$
  findBy$$$ProjectId$$$
  $$$
}'

# Check service layer handling
rg -A 5 "projectId" --type java

Length of output: 12446

src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java (2)

183-188: LGTM: Proper validation and uniqueness check for projectId

The changes correctly enforce projectId presence and ensure field name uniqueness within each project context, which addresses the core issue of separating customization fields.


191-191: LGTM: Proper projectId assignment

The projectId is correctly assigned from the DTO to the mapping object.

Comment on lines +26 to +27
@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName and sfm.serviceProviderId = :serviceProviderId and sfm.projectId = :projectId")
List<SectionAndFieldsMapping> getByFieldName(@Param("fieldName") String fieldName,@Param("serviceProviderId") Integer serviceProviderId,@Param("projectId") Integer projectId);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent fallback behavior between queries.

While the first query allows fallback to global settings (projectId=0), this query enforces strict matching. This inconsistency could lead to unexpected behavior where some queries find global settings and others don't.

Consider applying the same fallback pattern:

-@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName and sfm.serviceProviderId = :serviceProviderId and sfm.projectId = :projectId")
+@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName AND (sfm.serviceProviderId = :serviceProviderId OR sfm.serviceProviderId = 0) AND (sfm.projectId = :projectId OR sfm.projectId = 0)")
πŸ“ 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
@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName and sfm.serviceProviderId = :serviceProviderId and sfm.projectId = :projectId")
List<SectionAndFieldsMapping> getByFieldName(@Param("fieldName") String fieldName,@Param("serviceProviderId") Integer serviceProviderId,@Param("projectId") Integer projectId);
@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName AND (sfm.serviceProviderId = :serviceProviderId OR sfm.serviceProviderId = 0) AND (sfm.projectId = :projectId OR sfm.projectId = 0)")
List<SectionAndFieldsMapping> getByFieldName(@Param("fieldName") String fieldName,@Param("serviceProviderId") Integer serviceProviderId,@Param("projectId") Integer projectId);

Comment on lines 99 to 102
@Column(name = "ProjectID")
@Expose
private Integer projectId;

Copy link
Contributor

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Consider adding validation constraints.

To ensure data integrity, consider adding validation annotations:

 @Column(name = "ProjectID")
 @Expose
+@NotNull(message = "Project ID is required")
+@Min(value = 1, message = "Project ID must be positive")
 private Integer projectId;
πŸ“ 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
@Column(name = "ProjectID")
@Expose
private Integer projectId;
@Column(name = "ProjectID")
@Expose
@NotNull(message = "Project ID is required")
@Min(value = 1, message = "Project ID must be positive")
private Integer projectId;

Comment on lines +290 to +297
sectionAndFieldsMapping.getServiceProviderId(), sectionAndFieldsMapping.getProjectId());

String sectionName = sectionMasterCustomizationRepo.findSectionName(sectionAndFieldsMapping.getSectionId());
Map<String, Object> responseMap = new HashMap<>();
responseMap.put("sectionId", sectionAndFieldsMapping.getSectionId());
responseMap.put("sectionName", sectionName);
responseMap.put("serviceProviderId", sectionAndFieldsMapping.getServiceProviderId());

responseMap.put("projectId", sectionAndFieldsMapping.getProjectId());
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null check for projectId

While the changes correctly include projectId in the query and response, consider adding a null check for projectId to prevent potential NullPointerException.

- .findSectionIdAndSectionNameAndServiceProviderId(sectionAndFieldsMapping.getSectionId(),
-   sectionAndFieldsMapping.getServiceProviderId(), sectionAndFieldsMapping.getProjectId());
+ if (sectionAndFieldsMapping.getProjectId() == null) {
+   throw new IllegalArgumentException("ProjectId is required");
+ }
+ .findSectionIdAndSectionNameAndServiceProviderId(sectionAndFieldsMapping.getSectionId(),
+   sectionAndFieldsMapping.getServiceProviderId(), sectionAndFieldsMapping.getProjectId());

Committable suggestion was skipped due to low confidence.

Comment on lines 376 to 377
if(sectionAndFieldsMapping.getProjectId() != null)
response.setProjectId(sectionAndFieldsMapping.getProjectId());
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Validate projectId before update

While the conditional update of projectId is correct, consider validating that the new projectId exists in the projects table to maintain data integrity.

- if(sectionAndFieldsMapping.getProjectId() != null)
-   response.setProjectId(sectionAndFieldsMapping.getProjectId());
+ if(sectionAndFieldsMapping.getProjectId() != null) {
+   // Validate projectId exists
+   ProjectCustomization project = projectCustomizationRepo.findById(sectionAndFieldsMapping.getProjectId())
+     .orElseThrow(() -> new IllegalArgumentException("Invalid projectId"));
+   response.setProjectId(sectionAndFieldsMapping.getProjectId());
+ }

Committable suggestion was skipped due to low confidence.

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: 1

🧹 Outside diff range and nitpick comments (1)
src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java (1)

19-28: Consider adding documentation about project-service line relationship.

The addition of projectId effectively solves the service line separation issue. However, consider adding documentation (either in code comments or README) explaining:

  1. The relationship between projects and service lines
  2. The significance of projectId=0 as a fallback
  3. When and how the fallback mechanism should be used
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

πŸ“₯ Commits

Files that changed from the base of the PR and between 5d9edff and a55221a.

πŸ“’ Files selected for processing (3)
  • src/main/java/com/iemr/common/data/customization/SectionAndFieldsMapping.java (2 hunks)
  • src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java (1 hunks)
  • src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/com/iemr/common/data/customization/SectionAndFieldsMapping.java
  • src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java
πŸ”‡ Additional comments (1)
src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java (1)

27-28: Reference existing comment about inconsistent fallback behavior.

The inconsistency in fallback behavior between queries is still present, as noted in the previous review. The first query allows fallback to global settings (projectId=0) while this one doesn't.

Comment on lines +20 to +22
@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName AND (sfm.serviceProviderId = :serviceProviderId OR sfm.serviceProviderId = 0) AND (sfm.projectId = :projectId OR sfm.projectId = 0)")
List<SectionAndFieldsMapping> findSectionIdAndSectionNameAndServiceProviderId(
@Param("sectionId") Integer sectionId, @Param("serviceProviderId") Integer serviceProviderId);
@Param("sectionId") Integer sectionId, @Param("serviceProviderId") Integer serviceProviderId, @Param("projectId") Integer projectId);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Method name doesn't match its implementation.

The method name suggests it finds by sectionId and sectionName, but the query filters by fieldName. This mismatch could lead to confusion. Consider renaming the method to better reflect its functionality.

-List<SectionAndFieldsMapping> findSectionIdAndSectionNameAndServiceProviderId(
+List<SectionAndFieldsMapping> findByFieldNameWithFallback(

Committable suggestion was skipped due to low confidence.

Copy link
Contributor

@devikasuresh20 devikasuresh20 left a comment

Choose a reason for hiding this comment

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

looks fine

@devikasuresh20 devikasuresh20 merged commit 81877b1 into PSMRI:develop Oct 29, 2024
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 18, 2024
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