Skip to content
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

AMM-1076 and AMM-1078 #146

Merged
merged 15 commits into from
Jan 7, 2025
Merged

Conversation

ravishanigarapu
Copy link
Member

@ravishanigarapu ravishanigarapu commented Jan 2, 2025

πŸ“‹ Description

JIRA ID: AMM-1076, AMM-1078

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

    • Added religionName field to beneficiary data models.
    • Enhanced beneficiary information tracking with new demographic details like occupation and education.
    • Improved phone number processing in call reporting system.
  • Bug Fixes

    • Updated phone number search to allow partial matching in call reports.
    • Added more robust null checking in beneficiary data retrieval.
  • Chores

    • Streamlined demographic data handling in service implementations.
    • Updated HTTP request interceptor to handle additional URI cases.

Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request introduces several enhancements to the beneficiary management system, focusing on improving data capture and processing. Changes span multiple components, including phone number handling, demographic data management, and request interceptor configurations. The modifications primarily involve adding new fields for beneficiary details, updating data mapping processes, and refining system interceptors to handle specific request types more flexibly.

Changes

File Change Summary
src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java Enhanced phone number processing by removing leading zeros for numbers exceeding 10 characters in detailedCallReport and getCallDetail methods.
src/main/java/com/iemr/common/dto/identity/CommonIdentityDTO.java Added religionName field to capture religious identification.
src/main/java/com/iemr/common/model/beneficiary/BeneficiaryModel.java Introduced new fields: occupation, education, and religionName, all annotated with @Expose.
src/main/java/com/iemr/common/repository/report/CallReportRepo.java Modified query in getBenCallDetailsBySessionIDAndPhone to use partial matching for phone numbers.
src/main/java/com/iemr/common/service/beneficiary/IEMRSearchUserServiceImpl.java Updated getBeneficiaryListFromMapper to enhance null checks and include new demographic details in mapping.
src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java Added methods setDemographicDetails and setSaveDemographicDetails to streamline demographic data handling.
src/main/java/com/iemr/common/utils/http/HTTPRequestInterceptor.java Added new URI cases in preHandle method to bypass validation for specific requests.

Poem

🐰 Hop, hop, through data's domain,
New fields bloom like springtime's refrain,
Phone numbers trimmed, details unfurled,
A rabbit's code, a richer world!
Intercepting paths with gentle care 🌈


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

🧹 Nitpick comments (6)
src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java (2)

65-67: Consolidate repeated phone number preprocessing.

Currently, the phone number preprocessing (removal of leading zeros) is handled inline. Consider extracting this logic into a helper method to avoid duplication and to ensure consistency across different parts of the codebase.


156-159: Avoid duplication of phone number parsing logic.

This block repeats the same phone number trimming logic. Calling a shared helper method (as suggested above) can reduce the risk of errors and make the code more maintainable.

src/main/java/com/iemr/common/service/beneficiary/IEMRSearchUserServiceImpl.java (1)

381-382: Consider validating the newly set fields.
If education and incomeStatus are restricted to a set of valid values, adding a lightweight validation or enumeration would reduce potential data inconsistencies.

src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (1)

133-154: Guard Against Confused Fallback Logic

In setDemographicDetails(...), the fallback checks for different religion fields (beneficiaryDetails.getReligion(), .getI_bendemographics().getReligion(), .getI_bendemographics().getReligionName()) may cause confusion or data inconsistency if these fields differ. Consider clarifying or documenting the priority of these fields to ensure the correct value is always set.

src/main/java/com/iemr/common/model/beneficiary/BeneficiaryModel.java (2)

216-217: Clarify Usage of occupation vs. occupationName

Having both occupation and occupationName can cause confusion or data mismatches. Provide clear documentation or rename one field to differentiate raw IDs or codes from user-friendly labels.


224-225: Avoid Potential Redundancy in education Fields

Similar to occupation, confirm whether education vs. educationName serve distinct purposes. If not, consider consolidating or clarifying these fields.

πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 5cc6822 and 39cc5ba.

πŸ“’ Files selected for processing (7)
  • src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java (2 hunks)
  • src/main/java/com/iemr/common/dto/identity/CommonIdentityDTO.java (1 hunks)
  • src/main/java/com/iemr/common/model/beneficiary/BeneficiaryModel.java (2 hunks)
  • src/main/java/com/iemr/common/repository/report/CallReportRepo.java (1 hunks)
  • src/main/java/com/iemr/common/service/beneficiary/IEMRSearchUserServiceImpl.java (1 hunks)
  • src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (3 hunks)
  • src/main/java/com/iemr/common/utils/http/HTTPRequestInterceptor.java (1 hunks)
πŸ”‡ Additional comments (7)
src/main/java/com/iemr/common/utils/http/HTTPRequestInterceptor.java (1)

90-92: Ensure appropriateness of skipping authentication on these endpoints.

These cases disable validation for index.html, swagger-initializer.js, and swagger-config. Confirm whether these endpoints or assets must be publicly accessible. If any of them could expose sensitive data or become an attack surface, consider enforcing some level of protection.

src/main/java/com/iemr/common/service/beneficiary/IEMRSearchUserServiceImpl.java (2)

375-375: Nice usage of null checks to avoid NullPointerExceptions.
The explicit check for beneficiaryModel and its nested object helps prevent runtime errors.


377-380: Clarify the distinction between religion & religionName and occupation & occupationName.
Both field pairs are currently set to the same value. It might be more maintainable and less confusing if each pair held distinct data (e.g., a code vs. a descriptive label).

src/main/java/com/iemr/common/dto/identity/CommonIdentityDTO.java (1)

154-154: Ensure Consistent Usage of religionName

The addition of the religionName field is straightforward and enhances clarity. Verify that the new field is consistently set across the codebase, particularly within database operations, to prevent mismatches or null references if other fields (like religion) take precedence.

src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (2)

117-118: Centralization of Demographic Logic

Calling setDemographicDetails(...) within updateBenificiary is a good approach for consolidating demographic handling. This improves readability and helps keep the method focused on cohesive logic. Nice work!


171-174: Validate Null Handling for beneficiaryModel.getI_bendemographics()

In the save(...) method, you’re setting extra fields (religion, occupation, etc.) only if beneficiaryModel.getI_bendemographics() is non-null. This is correct. If future expansions require partial demographic data, ensure that each sub-field is also properly null-checked or defaults are provided.

src/main/java/com/iemr/common/model/beneficiary/BeneficiaryModel.java (1)

292-293: Maintain Consistency with religion vs. religionName

Adding a separate religionName field is beneficial when numeric IDs or codes differ from displayed text. However, ensure that downstream operations reference the correct field to avoid user-facing errors or incomplete updates.

@@ -42,7 +42,7 @@ public interface CallReportRepo extends CrudRepository<BeneficiaryCall, Integer>
+ "and report.createdDate >= :startDate and report.createdDate <= :endDate ")
public List<BeneficiaryCall> getAllBenCallIDetails(@Param("startDate") Timestamp startDate, @Param("endDate") Timestamp endDate);//start date and end date as param for x days.

@Query("SELECT call FROM BeneficiaryCall call WHERE call.callID = :sessionID and call.phoneNo = :phoneNo")
@Query("SELECT call FROM BeneficiaryCall call WHERE call.callID = :sessionID and call.phoneNo like %:phoneNo%")
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 2, 2025

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Consider clarifying matching requirements and potential performance trade-offs.

Switching from = to LIKE broadens the match criteria, which may risk unintended matches or degrade performance if the underlying column lacks an appropriate index. Evaluate whether partial matches are truly desired, and if so, ensure that phone numbers are sanitized and indexed appropriately to mitigate performance and accuracy concerns.

Copy link
Member Author

Choose a reason for hiding this comment

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

CTI server is maintaining 0 before the phone number resulting false for every search from our server Hence using like operator to match phonenumber
@coderabbitai

Copy link
Contributor

Choose a reason for hiding this comment

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

@ravishanigarapu I understand now - the LIKE operator is necessary to handle the phone number format discrepancy between the CTI server (which prepends zeros) and your server. Thank you for the clarification.


✏️ Learnings added
Learnt from: ravishanigarapu
PR: PSMRI/Common-API#146
File: src/main/java/com/iemr/common/repository/report/CallReportRepo.java:45-45
Timestamp: 2025-01-07T11:10:32.956Z
Learning: The CTI server prepends '0' to phone numbers, requiring the use of LIKE operator instead of exact matching (=) when comparing phone numbers between CTI server and application server data.

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

πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 39cc5ba and 02c5e7c.

πŸ“’ Files selected for processing (1)
  • src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (java)
  • GitHub Check: Package-test
  • GitHub Check: Build
πŸ”‡ Additional comments (1)
src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (1)

117-118: LGTM! Good refactoring of demographic details.

The extraction of demographic details into a separate method improves code organization and maintainability.

Comment on lines 200 to 220
private void setSaveDemographicDetails(CommonIdentityDTO identityDTO, BeneficiaryModel beneficiaryModel) {
if(null != beneficiaryModel.getI_bendemographics()) {
identityDTO.setCommunity(beneficiaryModel.getI_bendemographics().getCommunityName());
if(null != beneficiaryModel.getReligion())
identityDTO.setReligion(beneficiaryModel.getReligion());
else if(null != beneficiaryModel.getI_bendemographics().getReligion())
identityDTO.setReligion(beneficiaryModel.getI_bendemographics().getReligion());
else
identityDTO.setReligion(beneficiaryModel.getI_bendemographics().getReligionName());
if(null != beneficiaryModel.getOccupation())
identityDTO.setOccupationName(beneficiaryModel.getOccupation());
else
identityDTO.setOccupationName(beneficiaryModel.getI_bendemographics().getOccupation());
identityDTO.setEducation(beneficiaryModel.getI_bendemographics().getEducationName());
if(null != beneficiaryModel.getIncomeStatus())
identityDTO.setIncomeStatus(beneficiaryModel.getIncomeStatus());
else
identityDTO.setIncomeStatus(beneficiaryModel.getI_bendemographics().getIncomeStatus());
}

}
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 6, 2025

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Reduce code duplication with setDemographicDetails.

This method largely duplicates the logic from setDemographicDetails. Consider creating a common helper method to handle the demographic data extraction.

Here's a suggested approach:

+ private static class DemographicData {
+     String community;
+     String religion;
+     String occupation;
+     String education;
+     String incomeStatus;
+ }
+
+ private DemographicData extractDemographicData(BeneficiaryModel beneficiaryModel) {
+     DemographicData data = new DemographicData();
+     if(beneficiaryModel.getI_bendemographics() != null) {
+         BeneficiaryDemographicsModel demographics = beneficiaryModel.getI_bendemographics();
+         
+         data.community = demographics.getCommunityName();
+         
+         data.religion = beneficiaryModel.getReligion();
+         if(data.religion == null) {
+             data.religion = demographics.getReligion();
+             if(data.religion == null) {
+                 data.religion = demographics.getReligionName();
+             }
+         }
+         
+         data.occupation = beneficiaryModel.getOccupation();
+         if(data.occupation == null) {
+             data.occupation = demographics.getOccupation();
+         }
+         
+         data.education = demographics.getEducationName();
+         
+         data.incomeStatus = beneficiaryModel.getIncomeStatus();
+         if(data.incomeStatus == null) {
+             data.incomeStatus = demographics.getIncomeStatus();
+         }
+     }
+     return data;
+ }
+
+ private void setDemographicDetails(IdentityEditDTO identityEditDTO, BeneficiaryModel beneficiaryModel) {
+     DemographicData data = extractDemographicData(beneficiaryModel);
+     if(data.community != null) {
+         identityEditDTO.setCommunity(data.community);
+         identityEditDTO.setCommunityName(data.community);
+     }
+     identityEditDTO.setReligion(data.religion);
+     identityEditDTO.setOccupationName(data.occupation);
+     identityEditDTO.setEducation(data.education);
+     identityEditDTO.setIncomeStatus(data.incomeStatus);
+ }
+
+ private void setSaveDemographicDetails(CommonIdentityDTO identityDTO, BeneficiaryModel beneficiaryModel) {
+     DemographicData data = extractDemographicData(beneficiaryModel);
+     identityDTO.setCommunity(data.community);
+     identityDTO.setReligion(data.religion);
+     identityDTO.setOccupationName(data.occupation);
+     identityDTO.setEducation(data.education);
+     identityDTO.setIncomeStatus(data.incomeStatus);
+ }

This refactoring:

  1. Eliminates code duplication
  2. Centralizes null checks
  3. Makes the code more maintainable
  4. Reduces the risk of inconsistencies between the two methods

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Member Author

Choose a reason for hiding this comment

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

Its unnessory to crate a new class for small cchanges
@coderabbitai

Copy link
Contributor

Choose a reason for hiding this comment

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

@ravishanigarapu I understand your point. You're right - creating a new class would be overengineering for these small changes. The current implementation is more straightforward and easier to maintain.


✏️ Learnings added
Learnt from: ravishanigarapu
PR: PSMRI/Common-API#146
File: src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java:200-220
Timestamp: 2025-01-07T11:12:41.730Z
Learning: For small changes with limited code duplication, prefer simpler and straightforward implementations over creating new abstractions like helper classes. This keeps the code more maintainable and avoids overengineering.

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.

Comment on lines +133 to +154
private void setDemographicDetails(IdentityEditDTO identityEditDTO, BeneficiaryModel benificiaryDetails) {
if(null != benificiaryDetails.getI_bendemographics()) {
identityEditDTO.setCommunity(benificiaryDetails.getI_bendemographics().getCommunityName());
identityEditDTO.setCommunityName(benificiaryDetails.getI_bendemographics().getCommunityName());
if(null != benificiaryDetails.getReligion())
identityEditDTO.setReligion(benificiaryDetails.getReligion());
else if(null != benificiaryDetails.getI_bendemographics().getReligion())
identityEditDTO.setReligion(benificiaryDetails.getI_bendemographics().getReligion());
else
identityEditDTO.setReligion(benificiaryDetails.getI_bendemographics().getReligionName());
if(null != benificiaryDetails.getOccupation())
identityEditDTO.setOccupationName(benificiaryDetails.getOccupation());
else
identityEditDTO.setOccupationName(benificiaryDetails.getI_bendemographics().getOccupation());
identityEditDTO.setEducation(benificiaryDetails.getI_bendemographics().getEducationName());
if(null != benificiaryDetails.getIncomeStatus())
identityEditDTO.setIncomeStatus(benificiaryDetails.getIncomeStatus());
else
identityEditDTO.setIncomeStatus(benificiaryDetails.getI_bendemographics().getIncomeStatus());
}

}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add consistent null checks to prevent NPEs.

The method has several potential null pointer issues:

  1. Missing null check for educationName on line 147
  2. Complex nested logic for religion field could be simplified

Consider this safer implementation:

 private void setDemographicDetails(IdentityEditDTO identityEditDTO, BeneficiaryModel benificiaryDetails) {
     if(null != benificiaryDetails.getI_bendemographics()) {
         BeneficiaryDemographicsModel demographics = benificiaryDetails.getI_bendemographics();
         
         String communityName = demographics.getCommunityName();
         if(communityName != null) {
             identityEditDTO.setCommunity(communityName);
             identityEditDTO.setCommunityName(communityName);
         }
         
         // Simplified religion logic
         String religion = benificiaryDetails.getReligion();
         if(religion == null) {
             religion = demographics.getReligion();
             if(religion == null) {
                 religion = demographics.getReligionName();
             }
         }
         identityEditDTO.setReligion(religion);
         
         String occupation = benificiaryDetails.getOccupation();
         identityEditDTO.setOccupationName(occupation != null ? occupation : demographics.getOccupation());
         
         String education = demographics.getEducationName();
         if(education != null) {
             identityEditDTO.setEducation(education);
         }
         
         String incomeStatus = benificiaryDetails.getIncomeStatus();
         identityEditDTO.setIncomeStatus(incomeStatus != null ? incomeStatus : demographics.getIncomeStatus());
     }
 }
πŸ“ 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
private void setDemographicDetails(IdentityEditDTO identityEditDTO, BeneficiaryModel benificiaryDetails) {
if(null != benificiaryDetails.getI_bendemographics()) {
identityEditDTO.setCommunity(benificiaryDetails.getI_bendemographics().getCommunityName());
identityEditDTO.setCommunityName(benificiaryDetails.getI_bendemographics().getCommunityName());
if(null != benificiaryDetails.getReligion())
identityEditDTO.setReligion(benificiaryDetails.getReligion());
else if(null != benificiaryDetails.getI_bendemographics().getReligion())
identityEditDTO.setReligion(benificiaryDetails.getI_bendemographics().getReligion());
else
identityEditDTO.setReligion(benificiaryDetails.getI_bendemographics().getReligionName());
if(null != benificiaryDetails.getOccupation())
identityEditDTO.setOccupationName(benificiaryDetails.getOccupation());
else
identityEditDTO.setOccupationName(benificiaryDetails.getI_bendemographics().getOccupation());
identityEditDTO.setEducation(benificiaryDetails.getI_bendemographics().getEducationName());
if(null != benificiaryDetails.getIncomeStatus())
identityEditDTO.setIncomeStatus(benificiaryDetails.getIncomeStatus());
else
identityEditDTO.setIncomeStatus(benificiaryDetails.getI_bendemographics().getIncomeStatus());
}
}
private void setDemographicDetails(IdentityEditDTO identityEditDTO, BeneficiaryModel benificiaryDetails) {
if(null != benificiaryDetails.getI_bendemographics()) {
BeneficiaryDemographicsModel demographics = benificiaryDetails.getI_bendemographics();
String communityName = demographics.getCommunityName();
if(communityName != null) {
identityEditDTO.setCommunity(communityName);
identityEditDTO.setCommunityName(communityName);
}
// Simplified religion logic
String religion = benificiaryDetails.getReligion();
if(religion == null) {
religion = demographics.getReligion();
if(religion == null) {
religion = demographics.getReligionName();
}
}
identityEditDTO.setReligion(religion);
String occupation = benificiaryDetails.getOccupation();
identityEditDTO.setOccupationName(occupation != null ? occupation : demographics.getOccupation());
String education = demographics.getEducationName();
if(education != null) {
identityEditDTO.setEducation(education);
}
String incomeStatus = benificiaryDetails.getIncomeStatus();
identityEditDTO.setIncomeStatus(incomeStatus != null ? incomeStatus : demographics.getIncomeStatus());
}
}

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

🧹 Nitpick comments (1)
src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (1)

200-221: Consider consolidating duplicate demographic setting logic.

This method shares significant logic with setDemographicDetails. While the previous feedback about avoiding helper classes is noted, we can still reduce duplication by extracting the common null-checking logic into private methods within this class.

Example approach:

private String getReligion(BeneficiaryModel model) {
    if(null != model.getReligion())
        return model.getReligion();
    if(null != model.getI_bendemographics().getReligion())
        return model.getI_bendemographics().getReligion();
    return model.getI_bendemographics().getReligionName();
}

private String getOccupation(BeneficiaryModel model) {
    return null != model.getOccupation() 
        ? model.getOccupation() 
        : model.getI_bendemographics().getOccupation();
}
πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 02c5e7c and fe20b68.

πŸ“’ Files selected for processing (1)
  • src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (4 hunks)
🧰 Additional context used
πŸ““ Learnings (1)
src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (1)
Learnt from: ravishanigarapu
PR: PSMRI/Common-API#146
File: src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java:200-220
Timestamp: 2025-01-07T11:12:41.885Z
Learning: For small changes with limited code duplication, prefer simpler and straightforward implementations over creating new abstractions like helper classes. This keeps the code more maintainable and avoids overengineering.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (java)
  • GitHub Check: Package-test
  • GitHub Check: Build
πŸ”‡ Additional comments (3)
src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (3)

117-118: LGTM! Good separation of concerns.

The extraction of demographic details setting logic into a separate method improves code organization and readability.


133-154: Add consistent null checks to prevent NPEs.

Similar to previous feedback, there are several potential null pointer issues:

  1. Missing null check for communityName before setting
  2. Missing null check for educationName
  3. Complex nested logic for religion field could be simplified

169-169: LGTM! Good separation of concerns.

The extraction of demographic details setting logic into a separate method improves code organization and readability.

identityDTO.setOccupationName(beneficiaryModel.getOccupation());
else
identityDTO.setOccupationName(beneficiaryModel.getI_bendemographics().getOccupation());
if(null != beneficiaryModel.getI_bendemographics())
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

Remove redundant null check.

The null check for beneficiaryModel.getI_bendemographics() is redundant as it's already checked at line 201.

-			if(null != beneficiaryModel.getI_bendemographics())
				identityDTO.setEducation(beneficiaryModel.getI_bendemographics().getEducationName());
+			identityDTO.setEducation(beneficiaryModel.getI_bendemographics().getEducationName());
πŸ“ 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
if(null != beneficiaryModel.getI_bendemographics())
identityDTO.setEducation(beneficiaryModel.getI_bendemographics().getEducationName());

Copy link

sonarqubecloud bot commented Jan 7, 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: 0

🧹 Nitpick comments (2)
src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (2)

137-142: Simplify religion field logic.

The nested if-else logic for religion can be simplified using a more concise approach.

-			if(null != benificiaryDetails.getReligion())
-				identityEditDTO.setReligion(benificiaryDetails.getReligion());
-			else if(null != benificiaryDetails.getI_bendemographics().getReligion())
-				identityEditDTO.setReligion(benificiaryDetails.getI_bendemographics().getReligion());
-			else 
-				identityEditDTO.setReligion(benificiaryDetails.getI_bendemographics().getReligionName());
+			String religion = benificiaryDetails.getReligion();
+			if(religion == null) {
+				religion = benificiaryDetails.getI_bendemographics().getReligion();
+				if(religion == null) {
+					religion = benificiaryDetails.getI_bendemographics().getReligionName();
+				}
+			}
+			identityEditDTO.setReligion(religion);

203-208: Maintain consistency with setDemographicDetails religion logic.

For better maintainability, the religion logic should follow the same pattern in both methods. Consider applying the same simplified approach suggested for setDemographicDetails.

-			if(null != beneficiaryModel.getReligion())
-				identityDTO.setReligion(beneficiaryModel.getReligion());
-			else if(null != beneficiaryModel.getI_bendemographics().getReligion())
-				identityDTO.setReligion(beneficiaryModel.getI_bendemographics().getReligion());
-			else 
-				identityDTO.setReligion(beneficiaryModel.getI_bendemographics().getReligionName());
+			String religion = beneficiaryModel.getReligion();
+			if(religion == null) {
+				religion = beneficiaryModel.getI_bendemographics().getReligion();
+				if(religion == null) {
+					religion = beneficiaryModel.getI_bendemographics().getReligionName();
+				}
+			}
+			identityDTO.setReligion(religion);
πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between fe20b68 and 7c01677.

πŸ“’ Files selected for processing (1)
  • src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (4 hunks)
🧰 Additional context used
πŸ““ Learnings (1)
src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (1)
Learnt from: ravishanigarapu
PR: PSMRI/Common-API#146
File: src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java:200-220
Timestamp: 2025-01-07T11:12:41.885Z
Learning: For small changes with limited code duplication, prefer simpler and straightforward implementations over creating new abstractions like helper classes. This keeps the code more maintainable and avoids overengineering.
πŸ”‡ Additional comments (3)
src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java (3)

117-118: LGTM! Method call placement is appropriate.

The setDemographicDetails call is well-placed, occurring before identity handling.


169-169: LGTM! Method call placement is appropriate.

The setSaveDemographicDetails call is well-placed, occurring before setting additional fields.


147-147: ⚠️ Potential issue

Add null check for educationName to prevent NPE.

The educationName field is accessed without a null check, which could lead to a NullPointerException.

-			identityEditDTO.setEducation(benificiaryDetails.getI_bendemographics().getEducationName());
+			if(null != benificiaryDetails.getI_bendemographics().getEducationName())
+				identityEditDTO.setEducation(benificiaryDetails.getI_bendemographics().getEducationName());

Likely invalid or redundant comment.

@helenKaryamsetty helenKaryamsetty merged commit cc77f01 into PSMRI:develop Jan 7, 2025
6 checks passed
srishtigrp78 added a commit to srishtigrp78/Common-API that referenced this pull request Jan 8, 2025
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