Skip to content

Conversation

@helenKaryamsetty
Copy link
Member

@helenKaryamsetty helenKaryamsetty commented Jun 4, 2025

📋 Description

JIRA ID: AMM-1452


✅ 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 stability and error handling across multiple data models by adding null checks and safer type conversions, reducing the risk of runtime errors during data assignment.
  • New Features
    • Enhanced user data handling to gracefully ignore unknown information during processing, improving compatibility with varied data sources.

KA40094929 and others added 26 commits May 21, 2025 01:09
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 4, 2025

Walkthrough

Null checks and safer casting have been added to the constructors of multiple data model classes, ensuring that fields are only assigned if the corresponding input array elements are non-null. Numeric conversions now use Number casting and longValue() for BigInteger fields. The User class now ignores unknown JSON properties during deserialization.

Changes

File(s) Change Summary
.../AllergyIntoleranceDataModel.java
.../AppointmentDataModel.java
.../ConditionDiagnosisDataModel.java
.../DiagnosticReportDataModel.java
.../EncounterDataModel.java
.../FamilyMemberHistoryDataModel.java
.../LabTestAndComponentModel.java
.../MedicationRequestDataModel.java
.../VitalsAnthropometryModel.java
Constructors updated to add null checks for each array element before assignment; numeric fields now use safer casting via Number and longValue() for BigInteger conversions.
.../users/User.java Added @JsonIgnoreProperties(ignoreUnknown = true) annotation to ignore unknown JSON properties.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant DataModel
    Caller->>DataModel: new DataModel(Object[] objArr)
    alt For each field in DataModel
        DataModel->>DataModel: if objArr[i] != null assign/cast value
        else DataModel->>DataModel: assign null
    end
    Caller-->>DataModel: Receives safely constructed object
Loading

Suggested reviewers

  • ravishanigarapu
  • drtechie

Poem

In fields of code where nulls once crept,
Constructors now with caution stepped.
Each value checked, each cast made right,
No more surprises late at night!
And User, too, now wise and keen,
Ignores stray fields it’s never seen.
🐇✨


📜 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 f90f001 and f27d531.

📒 Files selected for processing (1)
  • src/main/java/com/wipro/fhir/data/resource_model/VitalsAnthropometryModel.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/wipro/fhir/data/resource_model/VitalsAnthropometryModel.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
✨ 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.

ravishanigarapu
ravishanigarapu previously approved these changes Jun 4, 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: 13

🔭 Outside diff range comments (4)
src/main/java/com/wipro/fhir/data/resource_model/VitalsAnthropometryModel.java (4)

62-96: 🛠️ Refactor suggestion

Add array bounds validation to prevent ArrayIndexOutOfBoundsException.

The constructor assumes the input array has at least 19 elements but doesn't validate this assumption. This could lead to runtime exceptions if a smaller array is passed.

Add array length validation at the beginning of the constructor:

 	public VitalsAnthropometryModel(Object[] objArr) {
+		if (objArr == null || objArr.length < 19) {
+			throw new IllegalArgumentException("Input array must contain at least 19 elements");
+		}
 
 		if (objArr[0] != null)

62-96: 🛠️ Refactor suggestion

Add array bounds checking for robustness.

The constructor assumes the input array has at least 19 elements but doesn't verify this assumption. This could lead to ArrayIndexOutOfBoundsException.

Consider adding array length validation:

 public VitalsAnthropometryModel(Object[] objArr) {
+	if (objArr == null || objArr.length < 19) {
+		throw new IllegalArgumentException("Input array must have at least 19 elements");
+	}
 
 	if (objArr[0] != null)

93-94: 🛠️ Refactor suggestion

Add null checks for remaining fields.

These fields lack null checks, creating inconsistency with the defensive programming approach applied to other fields in this constructor.

Apply null checks consistently:

-		this.createdDate = (Timestamp) objArr[17];
-		this.createdBy = (String) objArr[18];
+		this.createdDate = objArr[17] != null ? (Timestamp) objArr[17] : null;
+		this.createdBy = objArr[18] != null ? (String) objArr[18] : null;

62-96: 🛠️ Refactor suggestion

Add array bounds validation.

The constructor assumes objArr has at least 19 elements but doesn't validate this, which could cause ArrayIndexOutOfBoundsException.

Add validation at the beginning of the constructor:

	public VitalsAnthropometryModel(Object[] objArr) {
+		if (objArr == null || objArr.length < 19) {
+			throw new IllegalArgumentException("Invalid input array");
+		}
♻️ Duplicate comments (1)
src/main/java/com/wipro/fhir/data/resource_model/AllergyIntoleranceDataModel.java (1)

63-76: Consistent null safety implementation - same recommendations apply.

The implementation follows the same pattern as other data models, which is good for consistency. The same potential improvements mentioned for AppointmentDataModel apply here:

  1. Add array bounds checking for the expected 12 elements
  2. Consider additional type validation for numeric conversions
  3. Validate that objArr itself is not null

The consistent approach across data models makes the codebase more maintainable.

🧹 Nitpick comments (8)
src/main/java/com/wipro/fhir/data/resource_model/AppointmentDataModel.java (1)

63-65: Consider wrapping numeric conversions in try-catch for better error handling.

While the Number casting approach is safer than direct primitive casting, it can still throw ClassCastException if the array element is not a numeric type.

-this.id = objArr[0] != null ? BigInteger.valueOf(((Number) objArr[0]).longValue()) : null;
+this.id = objArr[0] != null ? 
+    (objArr[0] instanceof Number ? BigInteger.valueOf(((Number) objArr[0]).longValue()) : null) : null;

Or use a helper method for safer conversion:

private BigInteger safeConvertToBigInteger(Object obj) {
    if (obj == null) return null;
    if (obj instanceof Number) {
        return BigInteger.valueOf(((Number) obj).longValue());
    }
    return null; // or throw exception based on requirements
}
src/main/java/com/wipro/fhir/data/resource_model/LabTestAndComponentModel.java (1)

80-81: BigDecimal casting requires the same safety considerations.

The BigDecimal casting on lines 80-81 has the same potential ClassCastException risk as the numeric conversions.

Consider type checking for BigDecimal fields as well:

-this.rangeMin = objArr[10] != null ? (BigDecimal) objArr[10] : null;
-this.rangeMax = objArr[11] != null ? (BigDecimal) objArr[11] : null;
+this.rangeMin = objArr[10] != null && objArr[10] instanceof BigDecimal ? (BigDecimal) objArr[10] : null;
+this.rangeMax = objArr[11] != null && objArr[11] instanceof BigDecimal ? (BigDecimal) objArr[11] : null;
src/main/java/com/wipro/fhir/data/resource_model/EncounterDataModel.java (1)

63-65: Ensure consistent error handling for both longValue() and intValue() conversions.

Lines 63-65 use intValue() while other models primarily use longValue(). Both have the same ClassCastException risk if the object is not a Number.

Consider creating a common utility method for safe numeric conversions:

private Integer safeConvertToInteger(Object obj) {
    if (obj == null) return null;
    if (obj instanceof Number) {
        return ((Number) obj).intValue();
    }
    return null; // or handle according to business requirements
}
src/main/java/com/wipro/fhir/data/resource_model/ConditionDiagnosisDataModel.java (1)

59-67: Excellent null safety implementation with room for additional defensive programming.

The null checks effectively prevent NullPointerException and the Number casting approach for BigInteger fields is safer than direct long casting. This handles various numeric types gracefully.

Consider adding array validation for even more robust defensive programming:

 public ConditionDiagnosisDataModel(Object[] objArr) {
+    if (objArr == null || objArr.length < 9) {
+        throw new IllegalArgumentException("Object array must not be null and must contain at least 9 elements");
+    }
     this.id = objArr[0] != null ? BigInteger.valueOf(((Number) objArr[0]).longValue()) : null;
     this.beneficiaryRegID = objArr[1] != null ? BigInteger.valueOf(((Number) objArr[1]).longValue()) : null;
     this.visitCode = objArr[2] != null ? BigInteger.valueOf(((Number) objArr[2]).longValue()) : null;
     this.providerServiceMapID = objArr[3] != null ? (Integer) objArr[3] : null;
     this.vanID = objArr[4] != null ? (Integer) objArr[4] : null;
     this.sctTerm = objArr[5] != null ? (String) objArr[5] : null;
     this.sctcode = objArr[6] != null ? (String) objArr[6] : null;
     this.createdDate = objArr[7] != null ? (Timestamp) objArr[7] : null;
     this.createdBy = objArr[8] != null ? (String) objArr[8] : null;
 }
src/main/java/com/wipro/fhir/data/resource_model/VitalsAnthropometryModel.java (1)

64-69: Consider using safer numeric casting approach.

The current approach casts directly to long, which could throw ClassCastException if the array element is a different numeric type. Other files in this PR use a safer approach.

Consider using the safer casting pattern used in other files:

-		if (objArr[0] != null)
-			this.beneficiaryRegID = BigInteger.valueOf((long) objArr[0]);
-		if (objArr[2] != null)
-			this.visitCode = BigInteger.valueOf((long) objArr[2]);
+		if (objArr[0] != null)
+			this.beneficiaryRegID = BigInteger.valueOf(((Number) objArr[0]).longValue());
+		if (objArr[2] != null)
+			this.visitCode = BigInteger.valueOf(((Number) objArr[2]).longValue());
src/main/java/com/wipro/fhir/data/resource_model/FamilyMemberHistoryDataModel.java (1)

59-70: Consider adding array bounds validation.

While the null checks are comprehensive, the constructor should also validate that the input array has the expected number of elements.

Add validation:

	public FamilyMemberHistoryDataModel(Object[] objArr) {
+		if (objArr == null || objArr.length < 10) {
+			throw new IllegalArgumentException("Invalid input array");
+		}
src/main/java/com/wipro/fhir/data/resource_model/MedicationRequestDataModel.java (1)

81-106: Add array bounds validation for robustness.

Consider validating the input array length to prevent ArrayIndexOutOfBoundsException.

Add validation:

	public MedicationRequestDataModel(Object[] objArr) {
+		if (objArr == null || objArr.length < 19) {
+			throw new IllegalArgumentException("Invalid input array");
+		}
src/main/java/com/wipro/fhir/data/resource_model/DiagnosticReportDataModel.java (1)

69-89: Consider array bounds validation.

The implementation is robust for null handling but should also validate array length to prevent potential ArrayIndexOutOfBoundsException.

Add validation:

	public DiagnosticReportDataModel(Object[] objArr) {
+		if (objArr == null || objArr.length < 18) {
+			throw new IllegalArgumentException("Invalid input array");
+		}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between daea650 and f90f001.

📒 Files selected for processing (10)
  • src/main/java/com/wipro/fhir/data/resource_model/AllergyIntoleranceDataModel.java (1 hunks)
  • src/main/java/com/wipro/fhir/data/resource_model/AppointmentDataModel.java (1 hunks)
  • src/main/java/com/wipro/fhir/data/resource_model/ConditionDiagnosisDataModel.java (1 hunks)
  • src/main/java/com/wipro/fhir/data/resource_model/DiagnosticReportDataModel.java (1 hunks)
  • src/main/java/com/wipro/fhir/data/resource_model/EncounterDataModel.java (1 hunks)
  • src/main/java/com/wipro/fhir/data/resource_model/FamilyMemberHistoryDataModel.java (1 hunks)
  • src/main/java/com/wipro/fhir/data/resource_model/LabTestAndComponentModel.java (1 hunks)
  • src/main/java/com/wipro/fhir/data/resource_model/MedicationRequestDataModel.java (1 hunks)
  • src/main/java/com/wipro/fhir/data/resource_model/VitalsAnthropometryModel.java (1 hunks)
  • src/main/java/com/wipro/fhir/data/users/User.java (2 hunks)
👮 Files not reviewed due to content moderation or server errors (4)
  • src/main/java/com/wipro/fhir/data/resource_model/VitalsAnthropometryModel.java
  • src/main/java/com/wipro/fhir/data/resource_model/FamilyMemberHistoryDataModel.java
  • src/main/java/com/wipro/fhir/data/resource_model/MedicationRequestDataModel.java
  • src/main/java/com/wipro/fhir/data/resource_model/DiagnosticReportDataModel.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
🔇 Additional comments (11)
src/main/java/com/wipro/fhir/data/users/User.java (2)

5-5: Add Jackson import for JSON deserialization
Importing JsonIgnoreProperties enables the annotation to ignore unexpected fields in incoming payloads.


18-18: Ignore unknown JSON properties on User
The @JsonIgnoreProperties(ignoreUnknown = true) annotation prevents failures when extra JSON fields are present, improving robustness.

src/main/java/com/wipro/fhir/data/resource_model/FamilyMemberHistoryDataModel.java (3)

60-69: Excellent implementation of comprehensive null checks.

The ternary operator approach provides consistent null handling across all fields, and the safer casting via ((Number) objArr[x]).longValue() improves type safety for BigInteger conversions.


60-69: Excellent consistent null checking implementation.

This constructor demonstrates good practices:

  • Consistent ternary operator approach for all fields
  • Safer numeric casting using Number.longValue() for BigInteger fields
  • Complete null checking coverage

60-69: Excellent implementation of null safety.

This constructor demonstrates best practices with consistent null checks for all fields and safer type casting using Number.longValue(). The ternary operator approach is clean and readable.

src/main/java/com/wipro/fhir/data/resource_model/MedicationRequestDataModel.java (3)

82-105: Well-implemented comprehensive null checking.

The consistent use of ternary operators for null checks and the safer ((Number) objArr[x]).longValue() casting approach significantly improves robustness and type safety.


82-105: Consistent and safe null checking implementation.

The constructor follows best practices with:

  • Consistent ternary operator pattern for all assignments
  • Safe numeric casting using Number.longValue()
  • Complete null checking coverage for all assigned fields

82-104: Excellent comprehensive null safety implementation.

The constructor properly handles all potential null values with consistent ternary operator patterns and uses safer Number.longValue() casting for BigInteger fields. This implementation aligns well with the defensive programming approach.

src/main/java/com/wipro/fhir/data/resource_model/DiagnosticReportDataModel.java (3)

70-87: Excellent comprehensive null checking implementation.

The consistent ternary operator approach and safer BigInteger casting via ((Number) objArr[x]).longValue() significantly improves code robustness and type safety.


70-88: Excellent implementation of null checking pattern.

The constructor demonstrates consistent best practices:

  • Uniform ternary operator pattern for all field assignments
  • Safe numeric casting using Number.longValue() for BigInteger fields
  • Complete null checking coverage
  • Appropriately leaves fields with default values unassigned

70-87: Excellent null safety implementation.

The constructor demonstrates proper defensive programming with consistent null checks and safer type casting. The ternary operator approach is clean and maintains good code readability.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 4, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
30.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@helenKaryamsetty helenKaryamsetty merged commit 2b01db1 into PSMRI:develop Jun 4, 2025
6 of 8 checks passed
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