Skip to content

Conversation

@ravishanigarapu
Copy link
Contributor

@ravishanigarapu ravishanigarapu commented May 28, 2025

πŸ“‹ Description

JIRA ID:

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

  • Bug Fixes
    • Improved error handling during patient resource processing to ensure that issues with one patient do not interrupt processing of others. Clearer error messages are now logged for failures.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 28, 2025

Walkthrough

The method processResourceOperation() in CommonServiceImpl was refactored to wrap the entire processing logic for each patient in a single try-catch block. This consolidates error handling, ensuring that exceptions for one patient do not affect the processing of others. No public interfaces or method signatures were changed.

Changes

File Change Summary
src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java Refactored processResourceOperation() to wrap per-patient logic in a single try-catch block, consolidating error handling for each patient. No changes to method signatures.

Poem

A rabbit hopped through Java code so neat,
Wrapping patient logic in a single error sheet.
Now if one should stumble or fall,
The others still hop, standing tall.
With logs and catches, all in place,
The process continuesβ€”no lost race!
πŸ‡βœ¨


πŸ“œ 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 80c2520 and f7b7d3b.

πŸ“’ Files selected for processing (1)
  • src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java (1 hunks)
✨ Finishing Touches
  • πŸ“ Generate Docstrings

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.

@sonarqubecloud
Copy link

@helenKaryamsetty helenKaryamsetty merged commit 0ab9d9d into PSMRI:develop May 28, 2025
6 of 7 checks passed
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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 3

πŸ›‘ Comments failed to post (3)
src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java (3)

186-209: ⚠️ Potential issue

Inconsistent exception handling logic.

The inner try-catch catches and logs exceptions but allows processing to continue, which may lead to unexpected behavior since subsequent operations depend on successful demographic fetching.

The current nested structure creates inconsistent behavior:

  • Inner catch: Logs error and continues processing
  • Outer catch: Logs error and moves to next patient

This could result in processing bundles without proper demographic data. Consider removing the nested try-catch as suggested in the previous comment to ensure consistent error handling.

πŸ€– Prompt for AI Agents
In src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java between
lines 186 and 209, the inner try-catch block catches exceptions and logs them
but allows processing to continue, which can cause issues since later code
depends on successful demographic fetching. To fix this, remove the inner
try-catch block entirely so that any exceptions propagate to the outer catch
block, ensuring consistent error handling and preventing processing of
incomplete data.

237-239: πŸ› οΈ Refactor suggestion

Enhance error logging with patient-specific context.

The error message should include patient-specific information to aid in debugging and monitoring.

Apply this diff to improve error logging:

-logger.error("Fhir Schedule run failed " +e.getMessage());
+logger.error("FHIR bundle creation failed for BenID: {} | BenRegID: {} | VisitCode: {} - {}", 
+        p.getBeneficiaryId(), p.getBeneficiaryRegID(), p.getVisitCode(), e.getMessage(), e);

This provides better context for debugging and includes the full stack trace.

πŸ“ 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.

        } catch (Exception e) {
-           logger.error("Fhir Schedule run failed " + e.getMessage());
+           logger.error("FHIR bundle creation failed for BenID: {} | BenRegID: {} | VisitCode: {} - {}",
+                   p.getBeneficiaryId(),
+                   p.getBeneficiaryRegID(),
+                   p.getVisitCode(),
+                   e.getMessage(),
+                   e);
        }
πŸ€– Prompt for AI Agents
In src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java around
lines 237 to 239, the error logging in the catch block only logs the exception
message without patient-specific context or the full stack trace. Modify the
logger.error call to include relevant patient information (such as patient ID or
name) along with the exception message, and pass the exception object itself to
log the full stack trace for better debugging and monitoring.

176-240: πŸ› οΈ Refactor suggestion

Good improvement to error handling, but consider simplifying the nested structure.

The addition of the outer try-catch block is a solid improvement that prevents exceptions from one patient's processing from affecting others. However, the nested try-catch structure could be simplified for better maintainability.

Consider refactoring to eliminate the nested try-catch blocks:

 for (PatientEligibleForResourceCreation p : pList) {
     try {
         logger.info("Bundle creation is started for BenID : " + p.getBeneficiaryId() + " | BenRegID : "
                 + p.getBeneficiaryRegID() + " | VisitCode : " + p.getVisitCode());

         resourceRequestHandler = new ResourceRequestHandler();
         resourceRequestHandler.setBeneficiaryID(p.getBeneficiaryId());
         resourceRequestHandler.setVisitCode(p.getVisitCode());
         resourceRequestHandler.setBeneficiaryRegID(p.getBeneficiaryRegID());

-        try {
-            logger.info("*****Fetch beneficiary Id: " + resourceRequestHandler.getBeneficiaryRegID());
-            List<Object[]> rsObjList = patientEligibleForResourceCreationRepo
-                    .callPatientDemographicSP(resourceRequestHandler.getBeneficiaryRegID());
-            logger.info("*****Fetch beneficiary Id response recevied :", rsObjList);
-
-            PatientDemographic patientDemographicOBJ = patientDemographic.getPatientDemographic(rsObjList);
-            logger.info("*****Fetch patient after fetching demographics");
-            if (patientDemographicOBJ != null) {
-                addCareContextToMongo(patientDemographicOBJ, p);
-                logger.info("*****Add to mongo success done");
-                if (patientDemographicOBJ.getPreferredPhoneNo() != null)
-                    sendAbdmAdvSMS(patientDemographicOBJ.getPreferredPhoneNo());
-                else
-                    logger.error(
-                            "Advertisement sms could not be sent as beneficiary phone no not found");
-            } else
-                throw new FHIRException(
-                        "Beneficiary not found, benRegId = " + resourceRequestHandler.getBeneficiaryRegID());
-
-        } catch (Exception e) {
-            logger.error(e.getMessage());
-        }
+        logger.info("*****Fetch beneficiary Id: " + resourceRequestHandler.getBeneficiaryRegID());
+        List<Object[]> rsObjList = patientEligibleForResourceCreationRepo
+                .callPatientDemographicSP(resourceRequestHandler.getBeneficiaryRegID());
+        logger.info("*****Fetch beneficiary Id response recevied :", rsObjList);
+
+        PatientDemographic patientDemographicOBJ = patientDemographic.getPatientDemographic(rsObjList);
+        logger.info("*****Fetch patient after fetching demographics");
+        if (patientDemographicOBJ == null) {
+            throw new FHIRException(
+                    "Beneficiary not found, benRegId = " + resourceRequestHandler.getBeneficiaryRegID());
+        }
+        
+        addCareContextToMongo(patientDemographicOBJ, p);
+        logger.info("*****Add to mongo success done");
+        if (patientDemographicOBJ.getPreferredPhoneNo() != null) {
+            sendAbdmAdvSMS(patientDemographicOBJ.getPreferredPhoneNo());
+        } else {
+            logger.error("Advertisement sms could not be sent as beneficiary phone no not found");
+        }

         // Bundle processing logic...
         
     } catch (Exception e) {
-        logger.error("Fhir Schedule run failed " +e.getMessage());
+        logger.error("FHIR bundle creation failed for BenID: {} | BenRegID: {} | VisitCode: {} - {}", 
+                p.getBeneficiaryId(), p.getBeneficiaryRegID(), p.getVisitCode(), e.getMessage());
     }
 }
πŸ“ 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.

			try {
				logger.info("Bundle creation is started for BenID : " + p.getBeneficiaryId() + " | BenRegID : "
						+ p.getBeneficiaryRegID() + " | VisitCode : " + p.getVisitCode());

				resourceRequestHandler = new ResourceRequestHandler();
				resourceRequestHandler.setBeneficiaryID(p.getBeneficiaryId());
				resourceRequestHandler.setVisitCode(p.getVisitCode());
				resourceRequestHandler.setBeneficiaryRegID(p.getBeneficiaryRegID());

				// fetch demographics (no more nested try/catch)
				logger.info("*****Fetch beneficiary Id: " + resourceRequestHandler.getBeneficiaryRegID());
				List<Object[]> rsObjList = patientEligibleForResourceCreationRepo
						.callPatientDemographicSP(resourceRequestHandler.getBeneficiaryRegID());
				logger.info("*****Fetch beneficiary Id response received: {}", rsObjList);

				PatientDemographic patientDemographicOBJ = patientDemographic.getPatientDemographic(rsObjList);
				logger.info("*****Fetch patient after fetching demographics");
				if (patientDemographicOBJ == null) {
					throw new FHIRException(
							"Beneficiary not found, benRegId = " + resourceRequestHandler.getBeneficiaryRegID());
				}

				addCareContextToMongo(patientDemographicOBJ, p);
				logger.info("*****Add to mongo success done");
				if (patientDemographicOBJ.getPreferredPhoneNo() != null) {
					sendAbdmAdvSMS(patientDemographicOBJ.getPreferredPhoneNo());
				} else {
					logger.error("Advertisement sms could not be sent as beneficiary phone no not found");
				}

				// 1. OP consult resource bundle
				int i = oPConsultRecordBundle.processOPConsultRecordBundle(resourceRequestHandler, p);
				// 2. diagnostic report record bundle
				int j = diagnosticReportRecordBundle.processDiagnosticReportRecordBundle(resourceRequestHandler, p);
				// 3. prescription Bundle
				int k = prescriptionBundle.processPrescriptionRecordBundle(resourceRequestHandler, p);

				logger.info("The value of i: {} The value of j: {} The value of k: {}", i, j, k);

				if (i > 0 && j > 0 && k > 0) {
					// update the processed flag in trigger table
					p.setProcessed(true);
					PatientEligibleForResourceCreation resultSet = patientEligibleForResourceCreationRepo.save(p);
					if (resultSet != null && resultSet.getId().compareTo(BigInteger.ZERO) > 0) {
						logger.info("processed flag updated successfully after FHIR resource creation");
					}

					response = "Bundle creation is success for BenID : " + p.getBeneficiaryId() + " | BenRegID : "
							+ p.getBeneficiaryRegID() + " | VisitCode : " + p.getVisitCode();

					logger.info("Bundle creation is success for BenID : {} | BenRegID : {} | VisitCode : {}",
							p.getBeneficiaryId(), p.getBeneficiaryRegID(), p.getVisitCode());
				}

				// adv SMS - ABDM notify2 API
			} catch (Exception e) {
				logger.error("FHIR bundle creation failed for BenID: {} | BenRegID: {} | VisitCode: {} - {}",
						p.getBeneficiaryId(), p.getBeneficiaryRegID(), p.getVisitCode(), e.getMessage());
			}
πŸ€– Prompt for AI Agents
In src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java around
lines 176 to 240, the nested try-catch blocks inside the main try block make the
code harder to maintain. Refactor by merging the inner try-catch into the outer
one, handling all exceptions in a single catch block. This will simplify the
control flow and improve readability while preserving the error handling
behavior.

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