Skip to content

AMM-1168#64

Merged
helenKaryamsetty merged 5 commits intoPSMRI:developfrom
ravishanigarapu:develop
Apr 7, 2025
Merged

AMM-1168#64
helenKaryamsetty merged 5 commits intoPSMRI:developfrom
ravishanigarapu:develop

Conversation

@ravishanigarapu
Copy link
Copy Markdown
Contributor

@ravishanigarapu ravishanigarapu commented Dec 18, 2024

📋 Description

JIRA ID: AMM-1168

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

    • Introduced a setter method for teleconsultation service dependency in the ANC service.
    • Added a setter method for common doctor service dependency in the TeleConsultation service.
    • Added a new configuration property to allow bean definition overriding in the application context.
  • Bug Fixes

    • Improved SQL query syntax for date comparisons in the data sync repository, enhancing performance and clarity.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 18, 2024

Walkthrough

The pull request introduces setter methods for dependency injection in multiple service classes within the MMU (Mobile Medical Unit) project. Specifically, ANCServiceImpl has been updated to include a setter for TeleConsultationServiceImpl, while TeleConsultationServiceImpl now uses a setter for CommonDoctorServiceImpl. Additionally, the DataSyncRepositoryCentral class has modifications to its SQL query conditions for date comparisons, focusing on improving query syntax and performance without altering existing functionality.

Changes

File Change Summary
src/main/java/com/iemr/mmu/service/anc/ANCServiceImpl.java Added setter method setTeleConsultationServiceImpl() for dependency injection. Removed commented-out setter methods.
src/main/java/com/iemr/mmu/service/tele_consultation/TeleConsultationServiceImpl.java Added setter method setCommonDoctorServiceImpl() for dependency injection, replacing direct field injection.
src/main/java/com/iemr/mmu/service/dataSyncLayerCentral/DataSyncRepositoryCentral.java Modified SQL query conditions in getMasterDataFromTable() to directly compare LastModDate.
src/main/resources/application.properties Added property spring.main.allow-bean-definition-overriding=true to enable bean definition overriding.

Possibly related PRs

  • CI CD test #58: The changes in the main PR, which add a new setter method for dependency injection in the ANCServiceImpl class, are related to the modifications in the retrieved PR that also involve changes to the dependency injection strategy within the same ANCServiceImpl class.

Suggested reviewers

  • drtechie
  • devikasuresh20

Poem

🐰 In the realm of code, where services dance,
Setters arrive with a magical glance.
Injecting dependencies with rabbit-like grace,
No more field magic, a cleaner embrace.
MMU's services now sing a new song! 🌟


📜 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 34cff9c and ba1ae50.

📒 Files selected for processing (1)
  • src/main/resources/application.properties (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
🔇 Additional comments (1)
src/main/resources/application.properties (1)

51-51: Enabling Bean Definition Overriding

The new property spring.main.allow-bean-definition-overriding=true is correctly added and aligns with the dependency injection strategy highlighted by the new setter methods in the service classes. This configuration enables the application context to override existing bean definitions, which is useful when multiple beans of the same type are defined. However, please verify that this behavior is acceptable for the overall project architecture since it could potentially mask unintended bean conflicts if not carefully monitored.


🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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
Copy Markdown

Copy link
Copy Markdown

@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 comments (1)
src/main/java/com/iemr/mmu/service/anc/ANCServiceImpl.java (1)

Line range hint 450-650: Consider breaking down large methods into smaller, focused methods

Methods like saveANCDoctorData() and updateANCDoctorData() are very long and handle multiple responsibilities. This makes the code harder to maintain and test. Consider:

  1. Extracting TC request handling into a separate method
  2. Moving investigation and prescription logic to separate helper methods
  3. Creating a common utility method for shared logic between save and update operations

Example structure:

private void handleTCRequest(JsonObject requestOBJ, String Authorization) {
    // TC request specific logic
}

private void handleInvestigations(JsonObject requestOBJ, Long prescriptionID) {
    // Investigation specific logic
}

private void handlePrescriptions(JsonObject requestOBJ, Long prescriptionID) {
    // Prescription specific logic
}
🧹 Nitpick comments (5)
src/main/java/com/iemr/mmu/service/tele_consultation/TeleConsultationServiceImpl.java (2)

73-76: Consider improving the dependency injection implementation

While moving to setter injection is good, consider these improvements for better encapsulation and thread safety:

  1. Mark the field as final
  2. Make the setter method package-private or protected
  3. Add null check in the setter
-  private CommonDoctorServiceImpl commonDoctorServiceImpl;
+  private final CommonDoctorServiceImpl commonDoctorServiceImpl;

-  @Autowired
-  public void setCommonDoctorServiceImpl(CommonDoctorServiceImpl commonDoctorServiceImpl) {
+  @Autowired
+  void setCommonDoctorServiceImpl(CommonDoctorServiceImpl commonDoctorServiceImpl) {
+    if (commonDoctorServiceImpl == null) {
+      throw new IllegalArgumentException("commonDoctorServiceImpl cannot be null");
+    }
     this.commonDoctorServiceImpl = commonDoctorServiceImpl;
   }

Line range hint 1-391: Consider architectural improvements for better maintainability

The class has multiple responsibilities and could benefit from the following improvements:

  1. Split into smaller, focused services:
    • TCRequestManagementService
    • BeneficiaryStatusService
    • SlotManagementService
  2. Externalize error messages to a properties file
  3. Extract common validation logic into a separate utility class

Example structure:

@Service
class TCRequestManagementService {
    private final BeneficiaryStatusService beneficiaryStatusService;
    private final SlotManagementService slotManagementService;
    private final ErrorMessageProvider errorMessageProvider;
    
    // TC request specific methods
}

@Service
class BeneficiaryStatusService {
    // Beneficiary status specific methods
}

@Service
class SlotManagementService {
    // Slot management specific methods
}
src/main/java/com/iemr/mmu/service/anc/ANCServiceImpl.java (2)

Line range hint 1-50: Consider standardizing dependency injection pattern

The class mixes field-level and setter-level dependency injection which reduces consistency. Consider using constructor injection for required dependencies and setter injection for optional dependencies as per Spring best practices.

@Service
public class ANCServiceImpl implements ANCService {
-    @Autowired
-    private ANCNurseServiceImpl ancNurseServiceImpl;
-    private ANCDoctorServiceImpl ancDoctorServiceImpl;
-    private CommonNurseServiceImpl commonNurseServiceImpl;
-    private CommonDoctorServiceImpl commonDoctorServiceImpl;
-    @Autowired
-    private CommonBenStatusFlowServiceImpl commonBenStatusFlowServiceImpl;
-    @Autowired
-    private LabTechnicianServiceImpl labTechnicianServiceImpl;
-    @Autowired
-    private TeleConsultationServiceImpl teleConsultationServiceImpl;

+    private final ANCNurseServiceImpl ancNurseServiceImpl;
+    private final CommonBenStatusFlowServiceImpl commonBenStatusFlowServiceImpl;
+    private final LabTechnicianServiceImpl labTechnicianServiceImpl;
+    private final TeleConsultationServiceImpl teleConsultationServiceImpl;
+    
+    @Autowired
+    public ANCServiceImpl(ANCNurseServiceImpl ancNurseServiceImpl,
+                         CommonBenStatusFlowServiceImpl commonBenStatusFlowServiceImpl,
+                         LabTechnicianServiceImpl labTechnicianServiceImpl,
+                         TeleConsultationServiceImpl teleConsultationServiceImpl) {
+        this.ancNurseServiceImpl = ancNurseServiceImpl;
+        this.commonBenStatusFlowServiceImpl = commonBenStatusFlowServiceImpl;
+        this.labTechnicianServiceImpl = labTechnicianServiceImpl;
+        this.teleConsultationServiceImpl = teleConsultationServiceImpl;
+    }

Line range hint 800-900: Consider implementing error handling for external service calls

The code makes several external service calls but lacks proper error handling and retry mechanisms. Consider:

  1. Adding circuit breakers for external service calls
  2. Implementing retry logic for transient failures
  3. Logging detailed error information for debugging
src/main/java/com/iemr/mmu/service/dataSyncLayerCentral/DataSyncRepositoryCentral.java (1)

182-182: Consider refactoring for better separation of concerns

While the query optimization is good, the method handles multiple sync scenarios (All/Van/Provider) which could be separated into distinct methods for better maintainability and testing.

Consider refactoring like this:

private List<Map<String, Object>> getAllRecords(String schema, String table, String columnNames, Timestamp lastDownloadDate)
private List<Map<String, Object>> getVanRecords(String schema, String table, String columnNames, Timestamp lastDownloadDate, Integer vanID)
private List<Map<String, Object>> getProviderRecords(String schema, String table, String columnNames, Timestamp lastDownloadDate, Integer psmID)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7036452 and 714205c.

📒 Files selected for processing (3)
  • src/main/java/com/iemr/mmu/service/anc/ANCServiceImpl.java (1 hunks)
  • src/main/java/com/iemr/mmu/service/dataSyncLayerCentral/DataSyncRepositoryCentral.java (1 hunks)
  • src/main/java/com/iemr/mmu/service/tele_consultation/TeleConsultationServiceImpl.java (1 hunks)
🔇 Additional comments (4)
src/main/java/com/iemr/mmu/service/tele_consultation/TeleConsultationServiceImpl.java (1)

Line range hint 316-318: LGTM: Proper usage of the injected dependency

The commonDoctorServiceImpl is correctly used within a transactional context with proper error handling.

src/main/java/com/iemr/mmu/service/anc/ANCServiceImpl.java (1)

124-127: LGTM!

The new setter method for TeleConsultationServiceImpl follows proper Spring dependency injection conventions.

src/main/java/com/iemr/mmu/service/dataSyncLayerCentral/DataSyncRepositoryCentral.java (2)

177-177: LGTM! Proper data isolation maintained

The query optimization maintains proper van-level data segregation while improving performance through direct timestamp comparison.


171-171: SQL query optimization looks good, verify timestamp handling

The removal of the Date() function wrapper improves query performance by enabling better index utilization. However, please verify that this change doesn't affect the time component handling in your timestamp comparisons.

✅ Verification successful

Timestamp handling is correctly implemented across the codebase

The removal of the Date() function wrapper in the SQL query is safe. The codebase consistently uses proper timestamp handling:

  • Entity classes use appropriate Date/Timestamp types for LastModDate
  • The only other Date() function usage with LastModDate is in ReistrarRepoBenSearch.java which is for a different use-case (current date comparison)
  • All timestamp comparisons in the data sync layer are properly parameterized
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any other timestamp comparisons in the codebase that might need similar optimization
rg -l "Date\(.*LastModDate\)" --type java

Length of output: 234


Script:

#!/bin/bash
# Let's check the actual usage context of Date() with LastModDate in these files
rg "Date.*LastModDate" --type java -C 2

Length of output: 7061

Comment on lines +171 to +182
+ " WHERE LastModDate >= ? ";
resultSetList = jdbcTemplate.queryForList(baseQuery,lastDownloadDate);

}
else if (masterType.equalsIgnoreCase("V")) {
baseQuery += " SELECT " + columnNames + " FROM " + schema + "." + table
+ " WHERE Date(LastModDate) >= ? AND VanID = ? ";
+ " WHERE LastModDate >= ? AND VanID = ? ";
resultSetList = jdbcTemplate.queryForList(baseQuery,lastDownloadDate,vanID);
}
else if (masterType.equalsIgnoreCase("P")) {
baseQuery += " SELECT " + columnNames + " FROM " + schema + "." + table
+ " WHERE Date(LastModDate) >= ? AND ProviderServiceMapID = ? ";
+ " WHERE LastModDate >= ? AND ProviderServiceMapID = ? ";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codebase verification

Security improvements needed for medical data handling

Based on the code analysis:

  1. Direct concatenation of schema and table names in SQL queries creates SQL injection vulnerabilities. These parameters should be validated or whitelisted before use.
  2. While logging is implemented using SLF4J throughout the application, the DataSyncRepositoryCentral class needs to add appropriate logging for sensitive operations with proper data sanitization.
  3. No input validation is found for schema and table parameters in the data sync operations.

Recommended actions:

  • Add a whitelist validation for allowed schema and table names
  • Implement parameterized queries instead of string concatenation for schema and table names
  • Add structured logging for sync operations with sanitized data
🔗 Analysis chain

Review security and logging practices for medical data handling

As this code handles sensitive medical records:

  1. Consider adding input validation for schema and table parameters to prevent SQL injection through these parameters
  2. Add error logging with appropriate sanitization of sensitive data
  3. Consider implementing rate limiting for sync operations to prevent DoS
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for input validation patterns in the codebase
rg "validateTableName|validateSchema" --type java

# Check for rate limiting implementations
rg "RateLimiter|@RateLimit" --type java

Length of output: 93


Script:

#!/bin/bash
# Let's check for SQL query construction and validation patterns
rg -A 3 "baseQuery.*=.*SELECT.*FROM" --type java

# Check for any existing security measures or input sanitization
rg -B 2 "jdbcTemplate\.query" --type java

# Look for logging implementations
rg "Logger|LogFactory|getLogger" --type java

Length of output: 25015

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 7, 2025

Copy link
Copy Markdown
Member

@helenKaryamsetty helenKaryamsetty 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

@helenKaryamsetty helenKaryamsetty merged commit f8fe7cc into PSMRI:develop Apr 7, 2025
7 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jul 15, 2025
1 task
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