Skip to content

Add nickname-aware patient name search#6170

Open
JasonWang-0401 wants to merge 1 commit into
openmrs:masterfrom
JasonWang-0401:nickname-aware-patient-search
Open

Add nickname-aware patient name search#6170
JasonWang-0401 wants to merge 1 commit into
openmrs:masterfrom
JasonWang-0401:nickname-aware-patient-search

Conversation

@JasonWang-0401
Copy link
Copy Markdown

Description

Adds an opt-in nickname/alias layer to patient name search so that searching a common English given-name nickname matches a patient registered under the formal name and vice versa — e.g. Bob finds a patient stored as Robert. Soundex cannot connect these, because a nickname is a social alias, not a phonetic one (Soundex("Bob")=B100 vs Soundex("Robert")=R163).

The change mirrors the existing Soundex analyzer pattern instead of adding a subsystem — one new analyzer, one new indexed field per relevant name, one runtime toggle, no schema change, no new service or DAO:

  • nicknames.txt — curated Solr-format synonym dictionary (given/middle names).
  • SearchAnalysis — new NICKNAME_ANALYZER constant.
  • LuceneConfig — registers nicknameAnalyzer (Whitespace + Classic + LowerCase + ASCIIFolding + SynonymGraphFilter over nicknames.txt + FlattenGraphFilter).
  • PersonName — two index-time @FullTextFields, givenNameNickname and middleNameNickname, queried with the plain EXACT analyzer (expansion happens only at index time).
  • OpenmrsConstants — new default-off boolean GlobalProperty patientSearch.matchMode.nickname, seeded as a core global property with BooleanDatatype.
  • PersonQuery.getPersonNameQuery — adds the nickname fields to the query only when the toggle is enabled, composing with the existing match modes.

Default-off and additive, so existing deployments are unaffected until an administrator enables it and rebuilds the search index.

Testing

Adds two PatientDAOTest cases covering the enabled and disabled paths:

  • getPatients_shouldMatchNicknameWhenNicknameSearchIsEnabledBob matches a patient registered as Robert.
  • getPatients_shouldNotMatchNicknameWhenNicknameSearchIsDisabled — with the toggle off (default), Bob does not match Robert (regression guard).
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 — BUILD SUCCESS

🤖 Generated with Claude Code

Adds an opt-in nickname/alias layer to patient name search so that searching a
common English given-name nickname matches a patient registered under the formal
name and vice versa (e.g. "Bob" finds "Robert"). Soundex cannot connect these
because a nickname is a social alias, not a phonetic variant.

The change mirrors the existing analyzer pattern instead of adding a subsystem:

- nicknames.txt: curated Solr-format synonym dictionary (given/middle names).
- SearchAnalysis.NICKNAME_ANALYZER: new analyzer name constant.
- LuceneConfig: registers nicknameAnalyzer (Whitespace + Classic + LowerCase +
  ASCIIFolding + SynonymGraphFilter over nicknames.txt + FlattenGraphFilter).
- PersonName: two new index-time @FullTextField fields, givenNameNickname and
  middleNameNickname, queried with the plain EXACT analyzer.
- OpenmrsConstants: new default-off boolean GlobalProperty
  patientSearch.matchMode.nickname, seeded as a core global property.
- PersonQuery.getPersonNameQuery: adds the nickname fields to the query only
  when the toggle is enabled, composing with the existing match modes.

Default-off and additive, so existing deployments are unaffected until an
administrator enables it and rebuilds the search index. Adds two PatientDAOTest
cases covering the enabled and disabled paths.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

@jwnasambu jwnasambu left a comment

Choose a reason for hiding this comment

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

@JasonWang-0401 Thanks for the PR! Could you please link the jira issue this PR addresses? This helps with traceability and project tracking.

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