-
Notifications
You must be signed in to change notification settings - Fork 31
Optimize HealthID existence check using existsByHealthIdNumber() #110
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
β¦ByHealthIdNumber()
WalkthroughThis update introduces an Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant HealthIDServiceImpl
participant BenHealthIDMappingRepo
participant HealthIDRepo
Client->>HealthIDServiceImpl: mapHealthIDToBeneficiary(request)
HealthIDServiceImpl->>BenHealthIDMappingRepo: existsByHealthIdNumber(healthIdNumber)
alt Health ID already linked
HealthIDServiceImpl-->>Client: Throw "Health ID already linked" error
else Not linked
HealthIDServiceImpl->>BenHealthIDMappingRepo: save(mapping)
HealthIDServiceImpl->>HealthIDRepo: existsByHealthIdNumber(healthIdNumber)
alt Health ID record does not exist
HealthIDServiceImpl->>HealthIDRepo: save(new HealthID record)
end
HealthIDServiceImpl-->>Client: Return saved mapping as JSON
end
Possibly related PRs
Suggested reviewers
Poem
β¨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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
π§Ή Nitpick comments (1)
src/main/java/com/wipro/fhir/repo/healthID/HealthIDRepo.java (1)
27-28: Parameter name inconsistency with query condition.The parameter is named
healthIdbut the query checkshealthIdNumber. This inconsistency could lead to confusion.Consider renaming the parameter to match the field being queried:
-public Integer getCountOfHealthIdNumber(@Param("healthId") String healthId); +public Integer getCountOfHealthIdNumber(@Param("healthIdNumber") String healthIdNumber);
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (3)
src/main/java/com/wipro/fhir/repo/healthID/BenHealthIDMappingRepo.java(1 hunks)src/main/java/com/wipro/fhir/repo/healthID/HealthIDRepo.java(1 hunks)src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java(2 hunks)
π§° Additional context used
π§ Learnings (1)
src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java (1)
Learnt from: helenKaryamsetty
PR: PSMRI/FHIR-API#68
File: src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java:0-0
Timestamp: 2025-04-08T10:35:30.482Z
Learning: When no beneficiary IDs are found in the getMappedBenIdForHealthId method, returning "No Beneficiary Found" as a string response is the expected behavior rather than treating it as an error condition.
β° Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: style-check / checkstyle
- GitHub Check: Package-test
- GitHub Check: Analyze (java)
- GitHub Check: Build
π Additional comments (9)
src/main/java/com/wipro/fhir/repo/healthID/HealthIDRepo.java (1)
30-30: LGTM! Efficient existence check method added.The
existsByHealthIdNumbermethod follows Spring Data JPA conventions and provides a more efficient way to check existence compared to count-based approaches.src/main/java/com/wipro/fhir/repo/healthID/BenHealthIDMappingRepo.java (1)
91-91: LGTM! Consistent with the optimization approach.The
existsByHealthIdNumbermethod provides an efficient existence check, consistent with the similar addition inHealthIDRepo.src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java (7)
52-55: Good modernization with Java 8+ APIs.Excellent choice using
java.timeAPI for date handling and streams for functional operations.
73-80: Well-structured input validation and parsing.Good improvements:
- Single JSON parsing operation
- Clear extraction of ABHAProfile object
- Explicit validation with meaningful error message
86-89: Excellent optimization using existence check.The refactored code efficiently checks existence without fetching unnecessary data, which is the main objective of this PR. The error message is also clear and accurate.
108-111: Clean stream-based string concatenation.Good use of
IntStreamfor indexed iteration andCollectors.joining()for building the comma-separated address string.
114-118: Robust name concatenation with null safety.Excellent implementation:
- Checks field existence before access
- Filters out empty strings
- Properly trims the final result
135-140: Improved exception handling with proper logging.Good practice:
- Re-throwing domain-specific exceptions as-is
- Logging unexpected exceptions with context
- Wrapping with meaningful error messages
121-124: Modern date parsing with proper formatting.Good use of
LocalDateAPI with explicit zero-padding for month and day values.Ensure the date format "dd-MM-yyyy" is consistently used across the codebase:
#!/bin/bash # Description: Check for consistency in date format usage across the codebase # Search for date format patterns in the codebase rg -A 2 -B 2 'dd-MM-yyyy|MM-dd-yyyy|yyyy-MM-dd' --type java



π Description
JIRA ID: AMM-1609
Improves the performance and readability of the health ID mapping flow by replacing a count-based existence check with a direct boolean existence check.
β 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