Skip to content

Conversation

@vanitha1822
Copy link
Member

@vanitha1822 vanitha1822 commented Jun 5, 2025

📋 Description

JIRA ID:

AMM-1446

  • Add batch fetch using getIsNewAbhaBatch() instead of individual calls to getIsNewAbha().
  • Avoided multiple database round-trips by fetching all isNewAbha flags in a single query.
  • Improved average response time from ~600ms to ~280ms for typical data sets.

✅ Type of Change

  • 🚀 Performance (improves performance)

ℹ️ 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

  • Bug Fixes
    • Improved error messages and validation for missing parameters when creating a Health ID with mobile OTP.
  • New Features
    • Added support for batch retrieval of "new ABHA" status for multiple health IDs, enhancing performance and efficiency.
  • Refactor
    • Optimized backend processing to reduce redundant database calls and streamline response handling for Health ID queries.
  • Chores
    • Enhanced logging configuration with new log file settings and improved application properties formatting.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 5, 2025

Walkthrough

This change refactors the retrieval of beneficiary health IDs by introducing batch querying for the "new ABHA" status, updates error handling and validation in the controller, and adds a new repository method for batch status retrieval. The controller and service logic are streamlined for efficiency and clarity.

Changes

File(s) Change Summary
.../controller/healthID/CreateHealthIDWithMobileOTP.java Refactored request validation, error handling, and logging in getBenhealthID; removed @Param usage.
.../repo/healthID/BenHealthIDMappingRepo.java Changed getIsNewAbha return type to primitive boolean; added batch method getIsNewAbhaBatch.
.../service/healthID/HealthIDServiceImpl.java Refactored getBenHealthID to use batch query, map results, and serialize response more efficiently.
src/main/resources/application.properties Removed initial blank line; added spacing for readability; added logging path and file name properties.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller as CreateHealthIDWithMobileOTP
    participant Service as HealthIDServiceImpl
    participant Repo as BenHealthIDMappingRepo

    Client->>Controller: POST /getBenhealthID with benRegID
    Controller->>Service: getBenHealthID(benRegID)
    Service->>Repo: findByBenRegID(benRegID)
    Service->>Repo: getIsNewAbhaBatch(list of healthIdNumbers)
    Repo-->>Service: List of (healthIdNumber, isNewAbha)
    Service-->>Controller: JSON response with health IDs and newAbha flags
    Controller-->>Client: Response
Loading

Possibly related PRs

  • PSMRI/FHIR-API#85: Refactored getBenHealthID to use batch querying and updated handling of isNewAbha field, complementing the changes in this PR.

Suggested reviewers

  • ravishanigarapu
  • drtechie

Poem

In the warren of code, a batch call hops fast,
Health IDs gathered, old queries surpassed.
With careful new checks and a map for the way,
The rabbits ensure errors won’t lead us astray.
Now ABHA flags fetched in one swift leap—
Efficiency sown, and the carrots run deep! 🥕


📜 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 3e5accc and b1692c8.

📒 Files selected for processing (1)
  • src/main/resources/application.properties (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/resources/application.properties
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: style-check / checkstyle
  • GitHub Check: Analyze (java)
  • GitHub Check: Package-test
  • GitHub Check: Build

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.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need 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)

  • @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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@vanitha1822 vanitha1822 requested a review from drtechie June 5, 2025 04:47
@vanitha1822 vanitha1822 self-assigned this Jun 5, 2025
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: 2

🧹 Nitpick comments (1)
src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java (1)

139-166: Excellent batch processing optimization with minor null handling concern.

The refactored implementation successfully reduces the N+1 query problem by batching all isNewAbha lookups into a single database call. This should significantly improve performance as stated in the PR objectives.

However, consider the null handling behavior on line 159:

healthDetails.setNewAbha(Boolean.TRUE.equals(isNew));

This converts null values to false, which may differ from the original implementation's behavior. Verify that this is the intended behavior.

Alternative approach for explicit null handling:

-healthDetails.setNewAbha(Boolean.TRUE.equals(isNew));
+healthDetails.setNewAbha(isNew != null ? isNew : false); // or handle nulls differently if needed
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2b01db1 and c039754.

📒 Files selected for processing (3)
  • src/main/java/com/wipro/fhir/controller/healthID/CreateHealthIDWithMobileOTP.java (1 hunks)
  • src/main/java/com/wipro/fhir/repo/healthID/BenHealthIDMappingRepo.java (1 hunks)
  • src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java (2 hunks)
🔇 Additional comments (4)
src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java (2)

31-32: LGTM: Appropriate imports for stream processing.

The new imports support the batch processing implementation effectively.


163-163: Improved response format.

Good change to return the actual object list instead of calling toString() on the map, which provides cleaner JSON serialization.

src/main/java/com/wipro/fhir/controller/healthID/CreateHealthIDWithMobileOTP.java (2)

153-159: Improved error handling with specific error codes.

Excellent improvement to provide specific error code 4001 for missing beneficiaryRegID, making debugging easier compared to the generic validation in the original implementation.


160-163: Enhanced exception logging.

Good improvement to log the full stack trace and prepend "Error: " to the message, providing better debugging information.

Comment on lines 144 to 167
@Operation(summary = "Get Beneficiary ABHA details")
@PostMapping("/getBenhealthID")
public String getBenhealthID(@RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();

try {
logger.info("NDHM_FHIR Request to fetch ABHA details: {}", comingRequest);

JSONObject obj = new JSONObject(comingRequest);
if (obj.has("beneficiaryRegID")) {
Long benRegID = obj.getLong("beneficiaryRegID");
String res = healthIDService.getBenHealthID(benRegID);
response.setResponse(res);
} else {
response.setError(4001, "Missing 'beneficiaryRegID' in request");
}
} catch (Exception e) {
logger.error("NDHM_FHIR Error while getting beneficiary ABHA: ", e);
response.setError(5000, "Error: " + e.getMessage());
}

logger.info("NDHM_FHIR Response:", response);
return response.toString();
}
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

Good validation improvements but missing annotations and incomplete logging.

The refactored method provides better validation and error handling, specifically checking for the beneficiaryRegID key rather than just object length.

However, there are two issues to address:

  1. Missing @crossorigin annotation: The original method had this annotation which may be needed for CORS handling.

  2. Incomplete logging: Line 165 doesn't log the actual response content.

Apply these fixes:

+@CrossOrigin()
 @Operation(summary = "Get Beneficiary ABHA details")
 @PostMapping("/getBenhealthID")
 public String getBenhealthID(@RequestBody String comingRequest) {
     // ... existing code ...
     
-    logger.info("NDHM_FHIR Response:", response);
+    logger.info("NDHM_FHIR Response: {}", response.toString());
     return response.toString();
 }
📝 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
@Operation(summary = "Get Beneficiary ABHA details")
@PostMapping("/getBenhealthID")
public String getBenhealthID(@RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();
try {
logger.info("NDHM_FHIR Request to fetch ABHA details: {}", comingRequest);
JSONObject obj = new JSONObject(comingRequest);
if (obj.has("beneficiaryRegID")) {
Long benRegID = obj.getLong("beneficiaryRegID");
String res = healthIDService.getBenHealthID(benRegID);
response.setResponse(res);
} else {
response.setError(4001, "Missing 'beneficiaryRegID' in request");
}
} catch (Exception e) {
logger.error("NDHM_FHIR Error while getting beneficiary ABHA: ", e);
response.setError(5000, "Error: " + e.getMessage());
}
logger.info("NDHM_FHIR Response:", response);
return response.toString();
}
@CrossOrigin()
@Operation(summary = "Get Beneficiary ABHA details")
@PostMapping("/getBenhealthID")
public String getBenhealthID(@RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();
try {
logger.info("NDHM_FHIR Request to fetch ABHA details: {}", comingRequest);
JSONObject obj = new JSONObject(comingRequest);
if (obj.has("beneficiaryRegID")) {
Long benRegID = obj.getLong("beneficiaryRegID");
String res = healthIDService.getBenHealthID(benRegID);
response.setResponse(res);
} else {
response.setError(4001, "Missing 'beneficiaryRegID' in request");
}
} catch (Exception e) {
logger.error("NDHM_FHIR Error while getting beneficiary ABHA: ", e);
response.setError(5000, "Error: " + e.getMessage());
}
logger.info("NDHM_FHIR Response: {}", response.toString());
return response.toString();
}
🤖 Prompt for AI Agents
In
src/main/java/com/wipro/fhir/controller/healthID/CreateHealthIDWithMobileOTP.java
around lines 144 to 167, add the @CrossOrigin annotation above the
getBenhealthID method to enable CORS handling as in the original code. Also,
update the logger.info call on line 165 to include the actual response content
by passing response.toString() instead of just response, ensuring the response
details are properly logged.

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

♻️ Duplicate comments (1)
src/main/java/com/wipro/fhir/controller/healthID/CreateHealthIDWithMobileOTP.java (1)

143-165: ⚠️ Potential issue

Response never logged due to missing {} placeholder

logger.info("NDHM_FHIR Response:", response); passes the response as an extra argument but the format string contains no {} token, so SLF4J will discard it. Use parameterised logging or explicit concatenation:

-logger.info("NDHM_FHIR Response:", response);
+logger.info("NDHM_FHIR Response: {}", response);
🧹 Nitpick comments (4)
src/main/resources/application.properties (2)

49-50: Clinical atom-feed parser now always on

start-parsing-atom-feed-clinical-scheduler=true enables the job in all environments. If this was previously disabled in prod/stage we may unintentionally ingest duplicate data. Consider guarding with a profile flag.


64-68: Log file path settings conflict

logging.path and logging.file.name are mutually exclusive; Spring Boot ignores logging.path when logging.file.name is present. If the intent is to keep the directory configurable, drop logging.path.

src/main/java/com/wipro/fhir/controller/healthID/CreateHealthIDWithMobileOTP.java (2)

150-157: Consider early validation for empty payload

obj.has("beneficiaryRegID") guards the happy path, but an empty body triggers a JSON parsing exception that is mapped to a generic 5000 error. A quick null/blank check before parsing would return the clearer 4001 code and avoid stack-trace noise.


143-165: Opportunity to exploit new batch API

The service now supports batch retrieval (getIsNewAbhaBatch), yet the controller still handles only a single beneficiaryRegID. Accepting a list (e.g., beneficiaryRegIDs: [1,2,3]) would surface the performance win all the way to the REST layer.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c039754 and 0b2348a.

📒 Files selected for processing (3)
  • src/main/java/com/wipro/fhir/controller/healthID/CreateHealthIDWithMobileOTP.java (1 hunks)
  • src/main/java/com/wipro/fhir/repo/healthID/BenHealthIDMappingRepo.java (1 hunks)
  • src/main/resources/application.properties (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/wipro/fhir/repo/healthID/BenHealthIDMappingRepo.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
🔇 Additional comments (1)
src/main/resources/application.properties (1)

34-35: 1-minute cron may overload downstream jobs

Changing the FHIR bundle scheduler from every 5 min to every 1 min increases DB, network and CPU utilisation 5×. Confirm that the job is idempotent and that the infrastructure sizing and rate limits can cope.

spring.session.store-type=redis
spring.redis.host=localhost
spring.redis.host=172.17.0.1
spring.redis.password=
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

Hard-coding Redis host reduces deploy portability

spring.redis.host=172.17.0.1 bakes an environment-specific IP into the JAR. Externalise via an environment variable or profile-specific properties so CI/CD pipelines and k8s pods don’t require code changes when the endpoint moves.

🤖 Prompt for AI Agents
In src/main/resources/application.properties at line 23, the Redis host is
hard-coded as 172.17.0.1, which reduces deployment flexibility. Replace this
static IP with a placeholder that references an environment variable or a
profile-specific property, such as using Spring's ${} syntax to externalize the
host configuration. This allows the Redis host to be set dynamically via
environment variables or different profiles without modifying the code or JAR.

@sonarqubecloud
Copy link

@vanitha1822 vanitha1822 merged commit 7476ed0 into develop Jun 13, 2025
7 of 8 checks passed
@vanitha1822 vanitha1822 deleted the nd-vs/AMM-1446 branch June 13, 2025 06:18
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