Skip to content

TRUNK-5748: Refactor code smells in openmrs-core#5937

Open
harshapilli369 wants to merge 9 commits intoopenmrs:masterfrom
harshapilli369:TRUNK-5748-refactor-code-smells
Open

TRUNK-5748: Refactor code smells in openmrs-core#5937
harshapilli369 wants to merge 9 commits intoopenmrs:masterfrom
harshapilli369:TRUNK-5748-refactor-code-smells

Conversation

@harshapilli369
Copy link

Description of what I changed

Refactored multiple code smells identified via SonarCloud in openmrs-core:

  • Renamed field 'allergies' to 'allergyList' in Allergies.java (S1700)
  • Fixed identical getId() implementations in Allergy and AllergyReaction (S4144)
  • Moved constants from Operator interface to new OperatorConstants class (S1214)
  • Extracted methods in Concept.java to reduce cognitive complexity (S3776)
  • Introduced CONCEPT_ID constant in HibernateConceptDAO.java (S1192)
  • Removed redundant null check before instanceof in CohortMembership.java (S4201)

Issue I worked on

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

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the
    code style of this project.

- Field name was duplicating the containing class name (SonarCloud S1700)
- Updated all internal references to use the new field name
…gyReaction

- getId() was duplicating the implementation of getAllergyId() (SonarCloud S4144)
- Updated getId() to delegate to specific getter instead of duplicating logic
- Applied Pull-up method refactoring technique
…ts class

- Interfaces should not solely consist of constants (SonarCloud S1214)
- Created OperatorConstants utility class to hold all operator constants
- Applied Move field and Extract class refactoring techniques
…itive complexity

- Extracted findShortestNameForLocale() method (SonarCloud S3776)
- Extracted findShortestNameForConcept() method
- Extracted resolveShortestName() method to decompose conditional
- Introduced explaining variables isSameLocale and isShorterThanCurrent
- Applied Extract Method, Decompose Conditional and Introduce Explaining Variable techniques
- String literal 'conceptId' was duplicated 15 times (SonarCloud S1192)
- Introduced private static final String CONCEPT_ID constant
- Replaced all 15 occurrences with the constant reference
- Applied Introduce Explaining Variable refactoring technique
…mbership.java

- instanceof already returns false for null values (SonarCloud S4201)
- Removed unnecessary null check to simplify conditional expression
- Applied Decompose Conditional refactoring technique
…ggingUtil

- Extracted FileLocationResolver interface (org.openmrs.logging)
- Created resolver implementations for each appender type in resolver/ package:
  RollingFileAppenderResolver, FileAppenderResolver, MemoryMappedFileAppenderResolver,
  RollingRandomAccessFileAppenderResolver, RandomAccessFileAppenderResolver,
  AbstractFileAppenderResolver
- Replaced if-else instanceof chain in getOpenmrsLogLocation() with resolver pattern
- Applied Replace Conditional with Polymorphism refactoring technique
harshapilli369 and others added 2 commits March 17, 2026 16:49
…d compatibility


- Restored all 21 constants in Operator interface marked as @deprecated
- Each constant now delegates to OperatorConstants for the actual value
- Prevents breaking changes for external modules using Operator.AND, 
  Operator.CONTAINS etc.
- Applied as suggested by reviewer @jwnasambu

Co-authored-by: jwnasambu <33891016+jwnasambu@users.noreply.github.com>
@sonarqubecloud
Copy link

@PranavAggarwal422
Copy link

Looks good overall. Just wondering if this might cause any issues in edge cases?

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.

3 participants