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

TRUNK-6171: Address inconsistency issues with ConditionService #4290

Merged
merged 5 commits into from
Mar 28, 2023

Conversation

mseaton
Copy link
Member

@mseaton mseaton commented Mar 28, 2023

Description of what I changed

This makes the following changes to conditions:

  • Fixes the ConditionService#saveCondition method to only void and recreate if a Condition has changed
  • Fixes the ConditionService#saveCondition method to not exclude updates to properties when a Condition is voided
  • Fixes the ConditionService#saveCondition method to not exclude updates to properties when a Condition is unvoided
  • Fixes the ConditionService#getAllConditions(Patient) method to exclude voided Conditions
  • Adds missing hashcode and equals methods to CodedOrFreeText
  • Add new method to Condition to compare whether it matches another Condition

Issue I worked on

see https://issues.openmrs.org/browse/TRUNK-6171

@coveralls
Copy link

coveralls commented Mar 28, 2023

Coverage Status

Coverage: 63.817% (+0.02%) from 63.799% when pulling 966d3b4 on TRUNK-6171 into cd0d8c5 on master.

Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

Thanks @mseaton! Lots of good stuff here! A couple of little niggles.

Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

A few questions, but generally looks good!

api/src/main/java/org/openmrs/Condition.java Show resolved Hide resolved

// If there is an existing condition, create a new condition from it and reset the existing instance state
Condition newCondition = Condition.newInstance(condition);
Context.refreshEntity(condition);
Copy link
Member

Choose a reason for hiding this comment

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

what does this do again? loads it in from the DB/cache again? (ie prior to any changes?)

Copy link
Member Author

@mseaton mseaton Mar 28, 2023

Choose a reason for hiding this comment

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

RTFM :)

/**
 * Used to re-read the state of the given instance from the underlying database.
 * @since 2.0
 * @param obj The object to refresh from the database in the session
 */

boolean conditionHasChanged = !newCondition.matches(condition);
boolean existingVoided = BooleanUtils.isTrue(condition.getVoided());
boolean newVoided = BooleanUtils.isTrue(newCondition.getVoided());
boolean unVoidOriginal = existingVoided && !newVoided;
Copy link
Member

Choose a reason for hiding this comment

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

we unvoid the original even if the new one differs from the old? wouldn't we just create a new condition in this case that we both want to unvoid and modify?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a good point. I had originally re-written that way, and it was failing, which is why I preserved the existing behavior. I'll have a look.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, per @mogoodrich comment and suggestion, I've removed the special "unvoid" handling, which I agree is unnecessary and wrong. Unvoiding shouldn't eliminate the audit trail of the previously voided data, it should just be treated like an edit, linking back to voided row. That is now working.

* Tests of methods within the Condition class
* @see Condition
*/
public class ConditionTest {
Copy link
Member Author

Choose a reason for hiding this comment

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

Unit test added here for the Condition matches method @mogoodrich

@mseaton
Copy link
Member Author

mseaton commented Mar 28, 2023

@ibacher and @mogoodrich - I think I've addressed all of your comments. Let me know how things are looking...

Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @mseaton

@sonarcloud
Copy link

sonarcloud bot commented Mar 28, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants