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

Cherry-Pick: Eliminate Warning Messages #1663

Closed
wants to merge 18 commits into from

Conversation

jorg3lopez
Copy link
Contributor

Description

Describe what changed in this PR at a high level.

Issue

Add a link to the issue here. Consider using
closing keywords
if the this PR isn't for a story (stories will be closed through different means).

Checklist

  • I have added tests to cover my changes
  • I have added logging where useful (with appropriate log level)
  • I have added JavaDocs where required
  • I have updated the documentation accordingly

Note: You may remove items that are not applicable

Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Bug
The test 'setPID3_4Value updates correctly when patient has a PID-3 identifier' might not be testing the functionality correctly as it does not verify the state before the update.

Code Smell
The test 'setPID3_4Value updates correctly when patient has a PID-3 identifier and the new value is null' might be overly complex and could be simplified or split into multiple tests for clarity.


when:
HapiHelper.setPID3_4Value(bundle, pid3_4)
HapiHelper.setPID3_4Value(bundle, pid3_4Value)

Choose a reason for hiding this comment

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

Consider adding assertions before the action in the test 'setPID3_4Value updates correctly when patient has a PID-3 identifier' to ensure that the state before the action is as expected. This will make the test more robust and clear. [important]

HapiHelper.setPID3_4Value(bundle, pid3_4Value)

when:
HapiHelper.setPID3_4Value(bundle, null)

Choose a reason for hiding this comment

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

In the test 'setPID3_4Value updates correctly when patient has a PID-3 identifier and the new value is null', consider verifying the initial state of pid3Identifier before setting it to null. This ensures that the test covers the changes thoroughly. [important]


when:
HapiHelper.setPID3_4Value(bundle, pid3_4)
HapiHelper.setPID3_4Value(bundle, pid3_4Value)

Choose a reason for hiding this comment

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

For the test 'setPID3_4Value does not modify bundle without PID-3 identifier', it would be beneficial to add more detailed assertions to check that no unintended modifications occur to the bundle. This can help catch subtle bugs. [medium]

Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Score
Possible issue
Add null-check for serviceRequest to prevent NullPointerException

Ensure that the method HapiHelper.getObr16ExtensionPractitioner(serviceRequest)
properly handles cases where serviceRequest might be null to avoid potential
NullPointerExceptions.

etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/CopyOrcOrderProviderToObrOrderProviderTest.groovy [123]

-def obr16Practitioner = HapiHelper.getObr16ExtensionPractitioner(serviceRequest)
+def obr16Practitioner = serviceRequest ? HapiHelper.getObr16ExtensionPractitioner(serviceRequest) : null
Suggestion importance[1-10]: 7

Why: Adding a null check before calling the method on serviceRequest is a good practice to prevent runtime exceptions. This suggestion is relevant and improves the robustness of the code.

7
Ensure methods handle null or empty bundle inputs safely

Verify that the HapiFhirHelper.getPID3_4Value(bundle) and
HapiFhirHelper.getPID3_5Value(bundle) methods include null checks or handle empty
bundles to prevent runtime errors.

etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/RemovePatientIdentifierTest.groovy [38-39]

-def actualPid3_4 = HapiFhirHelper.getPID3_4Value(bundle)
-def actualPid3_5 = HapiFhirHelper.getPID3_5Value(bundle)
+def actualPid3_4 = bundle ? HapiFhirHelper.getPID3_4Value(bundle) : null
+def actualPid3_5 = bundle ? HapiFhirHelper.getPID3_5Value(bundle) : null
Suggestion importance[1-10]: 7

Why: The suggestion to add null checks before using the bundle object in method calls is valid and enhances the code's safety against null pointer exceptions.

7
Add safety checks to handle potential null patient objects

Confirm that HapiHelper.getPIDPatient(bundle) method safely handles cases where
bundle might not contain a patient, to avoid potential errors when accessing
getNameFirstRep().

etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/RemovePatientNameTypeCodeTest.groovy [28]

-def patientName = HapiHelper.getPIDPatient(bundle).getNameFirstRep()
+def patient = HapiHelper.getPIDPatient(bundle)
+def patientName = patient ? patient.getNameFirstRep() : null
Suggestion importance[1-10]: 7

Why: The suggestion to add a null check for the patient object before accessing its methods is prudent and prevents potential runtime errors, improving the code's reliability.

7
Implement null checks and error handling for bundle in method calls

Ensure that the HapiHelper.getOrc12ExtensionPractitioner(bundle) method includes
error handling for cases where bundle might be null or does not contain expected
data, to prevent runtime exceptions.

etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/CopyOrcOrderProviderToObrOrderProviderTest.groovy [205]

-def practitioner = HapiHelper.getOrc12ExtensionPractitioner(bundle)
+def practitioner = bundle ? HapiHelper.getOrc12ExtensionPractitioner(bundle) : null
Suggestion importance[1-10]: 7

Why: Adding null checks for the bundle object before method invocations is a good defensive programming practice that prevents errors and enhances the code's robustness.

7

@jorg3lopez
Copy link
Contributor Author

closing this draft pr as we pushed the code in another branch.

@jorg3lopez jorg3lopez closed this Dec 27, 2024
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