Skip to content

AMM-1225 Query change required for different demographic details #85

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

Merged
merged 6 commits into from
Feb 17, 2025

Conversation

ravishanigarapu
Copy link
Member

@ravishanigarapu ravishanigarapu commented Feb 14, 2025

πŸ“‹ Description

JIRA ID: AMM-1225

Please provide a summary of the change and the motivation behind it. Include relevant context and details.


βœ… 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

    • Beneficiary profiles now pull in a more comprehensive set of details, enriching the data presented to users.
    • Enhanced identity management capabilities ensure more reliable and efficient data integration and query handling.
    • Expanded data retrieval for beneficiaries now includes additional related information, improving overall data accuracy.
    • Updated data retrieval logic allows for additional fields to be populated in beneficiary mappings, enhancing overall data richness.
  • Chores

    • Upgraded GitHub Actions workflow configuration for packaging to improve artifact handling.

Copy link

coderabbitai bot commented Feb 14, 2025

Walkthrough

The pull request updates the beneficiary mapping retrieval by modifying the getMapping method in the BenMappingRepo interface. The original query has been replaced with a more complex query utilizing multiple LEFT JOINs to fetch related beneficiary data. Additionally, the getBeneficiariesDTONew method in the IdentityService class has been enhanced to include logic for populating additional fields in the MBeneficiarymapping object from the RMNCH data source. Furthermore, the GitHub Actions workflow for packaging has been updated to use a newer version of the actions/upload-artifact action.

Changes

File(s) Change Summary
src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java Updated the getMapping method: replaced a simple query with a complex query using multiple LEFT JOINs for fetching comprehensive beneficiary information.
src/main/java/com/iemr/common/identity/service/IdentityService.java Modified the getBeneficiariesDTONew method to retrieve additional fields from RMNCHBeneficiaryDetailsRmnch, enriching the MBeneficiarymapping object.
.github/workflows/package.yml Updated the actions/upload-artifact action from version v3 to v4 in the GitHub Actions workflow for packaging.

Suggested reviewers

  • drtechie
  • devikasuresh20

Poem

I'm a little rabbit, hopping through code,
With queries so clever, on this data road.
LEFT JOINs are dancing, fetching details galore,
Enriching our mappings, oh, who could ask for more?
With each little change, we leap and we play,
In the fields of the database, brightening the day! πŸ‡βœ¨


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

@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/identity/service/IdentityService.java (2)

96-104: Remove unused EntityManager injection.

The EntityManager is injected but not used in any method. Either:

  1. Remove the unused injection, or
  2. Document the intended future use with a TODO comment

Apply this diff to remove the unused injection:

-import jakarta.persistence.EntityManager;
-import jakarta.persistence.criteria.CriteriaBuilder;
-import jakarta.persistence.criteria.CriteriaQuery;
-import jakarta.persistence.criteria.Join;
-import jakarta.persistence.criteria.JoinType;
-import jakarta.persistence.criteria.Predicate;
-import jakarta.persistence.criteria.Root;

-@Autowired
-private EntityManager entityManager;

Or add a TODO comment explaining the intended use:

@Autowired
private EntityManager entityManager;
+// TODO: Implement dynamic queries using JPA Criteria API for complex search operations

Also applies to: 113-114


62-62: Remove unused import.

The TBendataaccess class is imported but not used in the code.

Apply this diff to remove the unused import:

-import com.iemr.common.identity.domain.TBendataaccess;
πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 0ac92b3 and 9aa15cf.

πŸ“’ Files selected for processing (2)
  • src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java (1 hunks)
  • src/main/java/com/iemr/common/identity/service/IdentityService.java (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (java)
  • GitHub Check: Build_and_analyse
πŸ”‡ Additional comments (1)
src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java (1)

127-137:

❓ Verification inconclusive

Verify join conditions for data consistency.

The join conditions use a mix of direct ID matches and vanSerialNo matches. Ensure that:

  1. The vanSerialNo values are consistent across tables
  2. The vanID matches maintain data integrity
  3. The LEFT JOINs don't unintentionally exclude records

Run the following script to check for potential data inconsistencies:


🏁 Script executed:

#!/bin/bash
# Description: Check for data inconsistencies in join conditions

echo "Checking for mismatched vanSerialNo values..."
mysql -e "
SELECT 
  'Mismatched vanSerialNo' as Issue,
  COUNT(*) as Count
FROM MBeneficiarymapping bm
LEFT JOIN MBeneficiaryregidmapping brm 
  ON brm.benRegId = bm.benRegId 
  AND brm.vanID = bm.vanID
WHERE brm.benRegId IS NULL
UNION ALL
SELECT 
  'Mismatched vanID',
  COUNT(*)
FROM MBeneficiarymapping bm
LEFT JOIN MBeneficiaryregidmapping brm 
  ON brm.benRegId = bm.benRegId 
  AND brm.vanID = bm.vanID
WHERE brm.vanID IS NULL;
"

Length of output: 647


Manual Verification Needed for JOIN Conditions

The automated check using the provided MySQL script encountered a "mysql: command not found" error, so please manually verify that:

  • The join conditions correctly compare the correct identifier types (direct IDs versus vanSerialNo) across the tables.
  • The consistency of vanSerialNo values and the integrity of vanID relationships is maintained.
  • The LEFT JOINs are structured so that no essential records are unexpectedly excluded.

Comment on lines +125 to +138
//@Query("SELECT t FROM MBeneficiarymapping t WHERE t.vanSerialNo =:vanSerialNo AND t.vanID=:vanID")
@Query(value = "select bm FROM MBeneficiarymapping bm "
+"LEFT JOIN MBeneficiaryregidmapping brm ON brm.benRegId=bm.benRegId and brm.vanID=bm.vanID "
+"LEFT JOIN MBeneficiarycontact bc ON bc.vanSerialNo = bm.benContactsId and bm.vanID=bc.vanID "
+"LEFT JOIN MBeneficiarydetail bd on bm.benDetailsId = bd.vanSerialNo and bm.vanID=bd.vanID "
+"LEFT JOIN MBeneficiaryaddress ba ON ba.vanSerialNo = bm.benAddressId and bm.vanID=ba.vanID "
+"LEFT JOIN MBeneficiaryconsent bt on bt.vanSerialNo=bm.benConsentId and bm.vanID=bt.vanID "
//+"LEFT JOIN MBensecurestack bs on bs.benSecureStackId=bm.benSecureStackId and bm.vanID=bs.vanID "
+"LEFT JOIN MBeneficiaryImage bi on bi.vanSerialNo=bm.benImageId and bm.vanID=bi.vanID "
+"LEFT JOIN MBeneficiaryAccount bac on bac.vanSerialNo=bm.benAccountID and bm.vanID=bac.vanID "
+"LEFT JOIN MBeneficiaryidentity bid on bid.vanSerialNo=bm.benMapId and bm.vanID=bid.vanID "
+"LEFT JOIN MBeneficiaryfamilymapping bfm on bfm.vanSerialNo=bm.benMapId and bm.vanID=bfm.vanID "
+"LEFT JOIN MBeneficiaryservicemapping bsm on bsm.vanSerialNo=bm.benMapId and bm.vanID=bsm.vanID "
+"where bm.vanSerialNo=:vanSerialNo and bm.vanID=:vanID")
Copy link

@coderabbitai coderabbitai bot Feb 14, 2025

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

❓ Verification inconclusive

Consider performance implications of the complex query.

The query joins 10 tables which could impact performance, especially with large datasets. Consider the following improvements:

  1. Add appropriate indexes on join columns (vanID, vanSerialNo) in all tables
  2. Implement pagination to limit result set size
  3. Consider splitting into multiple queries if not all data is always needed

Run the following script to check if indexes exist on the join columns:


🏁 Script executed:

#!/bin/bash
# Description: Check for missing indexes on join columns
# Note: This assumes MySQL/MariaDB. Adjust for other databases.

echo "Checking indexes on join columns..."
mysql -e "
SELECT DISTINCT
  CONCAT(TABLE_NAME, '.', COLUMN_NAME) as 'Table.Column',
  CASE WHEN INDEX_NAME IS NULL THEN 'Missing Index' ELSE 'Has Index' END as 'Index Status'
FROM INFORMATION_SCHEMA.COLUMNS c
LEFT JOIN INFORMATION_SCHEMA.STATISTICS s 
  ON c.TABLE_NAME = s.TABLE_NAME 
  AND c.COLUMN_NAME = s.COLUMN_NAME
WHERE c.TABLE_SCHEMA = 'your_db_name'
  AND c.TABLE_NAME IN (
    'MBeneficiaryregidmapping',
    'MBeneficiarycontact',
    'MBeneficiarydetail',
    'MBeneficiaryaddress',
    'MBeneficiaryconsent',
    'MBeneficiaryImage',
    'MBeneficiaryAccount',
    'MBeneficiaryidentity',
    'MBeneficiaryfamilymapping',
    'MBeneficiaryservicemapping'
  )
  AND c.COLUMN_NAME IN ('vanID', 'vanSerialNo')
ORDER BY 2 DESC, 1;
"

Length of output: 1030


Attention: Performance Considerations & Index Verification Needed

This query now performs complex LEFT JOINs across 10 related tables, which could significantly affect performance on large datasets. Please address the following:

  • Index Validation: Ensure that proper indexes exist on the join columns (vanID, vanSerialNo) in all involved tables. Our automated index check did not produce output (mysql command not found), so please manually verify that these indexes are in place.
  • Pagination: Consider adding pagination to limit the result set size if all joined data isn't required at once.
  • N+1 Query Risk: Review the data fetching design for potential N+1 query issues when accessing related entities.
  • Join Conditions: Confirm that all join conditions (especially the vanID criteria) consistently maintain data integrity.

Copy link
Member

Choose a reason for hiding this comment

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

@ravishanigarapu please confirm this.

Copy link

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!

Copy link
Member Author

Choose a reason for hiding this comment

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

@coderabbitai yes we have already created indexes for the all the tables.Fetching data based on filterations.

Copy link

Choose a reason for hiding this comment

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

@ravishanigarapu Thank you for confirming. With proper indexes in place and filtered data retrieval, the query's performance should be well-optimized.


✏️ Learnings added
Learnt from: ravishanigarapu
PR: PSMRI/Identity-API#85
File: src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java:125-138
Timestamp: 2025-02-17T07:29:04.989Z
Learning: In the Identity-API project, tables involved in beneficiary mapping queries (MBeneficiaryregidmapping, MBeneficiarycontact, MBeneficiarydetail, MBeneficiaryaddress, MBeneficiaryconsent, MBeneficiaryImage, MBeneficiaryAccount, MBeneficiaryidentity, MBeneficiaryfamilymapping, MBeneficiaryservicemapping) have indexes created on join columns (vanID, vanSerialNo) to optimize query performance.

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.


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

@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 (1)
.github/workflows/package.yml (1)

45-45: Update Artifact Upload Action and Remove Trailing Spaces

The upgrade to actions/upload-artifact@v4 is a positive change that ensures the workflow uses the latest features and improvements in the artifact upload process. However, YAMLlint has flagged trailing spaces on this line. Please remove the extra spaces at the end of the line to comply with best practices and avoid potential parsing issues.

-      uses: actions/upload-artifact@v4 
+      uses: actions/upload-artifact@v4
🧰 Tools
πŸͺ› YAMLlint (1.35.1)

[error] 45-45: trailing spaces

(trailing-spaces)

πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between a5a88bc and 887eee3.

πŸ“’ Files selected for processing (1)
  • .github/workflows/package.yml (1 hunks)
🧰 Additional context used
πŸͺ› YAMLlint (1.35.1)
.github/workflows/package.yml

[error] 45-45: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (java)
  • GitHub Check: Build_and_analyse

@helenKaryamsetty helenKaryamsetty merged commit 7e746a0 into PSMRI:develop Feb 17, 2025
7 checks passed
mohan-bee added a commit to mohan-bee/Identity-API that referenced this pull request Apr 17, 2025
Implemented Commit Message Linting and Automation for TM-API
mohan-bee added a commit to mohan-bee/Identity-API that referenced this pull request Apr 17, 2025
Implement Commit Message Linting and Automation for TM-API PSMRI#85
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.

3 participants