Skip to content

(fix) O3-5479: Implement safe patient display parsing with validation and fallbacks - #654

Merged
denniskigen merged 8 commits into
openmrs:mainfrom
omeriinnocent:openmrs-billing-app
Apr 1, 2026
Merged

(fix) O3-5479: Implement safe patient display parsing with validation and fallbacks#654
denniskigen merged 8 commits into
openmrs:mainfrom
omeriinnocent:openmrs-billing-app

Conversation

@omeriinnocent

@omeriinnocent omeriinnocent commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Requirements

  • This PR has a title that briefly describes the work done including a conventional commit type prefix and a Jira ticket number if applicable. See existing PR titles for inspiration.
  • My work is based on designs, which are linked or shown either in the Jira ticket or the description below.
  • My work includes tests or is validated by existing tests.

Summary

The mapBillProperties function splits patient.display on plain -, which breaks when the identifier or name contains hyphens. It also returns undefined when the display string is missing or has no separator, causing patient names to render as "undefined" in bills and invoices.

This PR extracts a parsePatientDisplay helper that:

  • Uses - (space-hyphen-space) as the delimiter, matching the format returned by the REST API
  • Takes everything after the first separator as the name, preserving names with additional hyphens
  • Returns empty strings instead of undefined when the display string is missing or has no separator
  • Trims whitespace from both identifier and name

Screenshots

Related Issue

https://openmrs.atlassian.net/browse/O3-5479

Other

@omeriinnocent

Copy link
Copy Markdown
Contributor Author

@ELVIS-KATO ,help review this

@ELVIS-KATO

Copy link
Copy Markdown
Contributor

Thanks @omeriinnocent for the fix. The changes address the ticket and the functionality looks good.
One small request: the additional comments added in the code are not necessary in this case. Since the code is already clear and self-explanatory, it would be better to remove them to keep the codebase clean and consistent.

So could you please remove those comments?

@omeriinnocent

Copy link
Copy Markdown
Contributor Author

Thanks @ELVIS-KATO ,

@omeriinnocent

Copy link
Copy Markdown
Contributor Author

hi @denniskigen ,can you have a look at this?

@ELVIS-KATO

Copy link
Copy Markdown
Contributor

LGTM @denniskigen @VeronicaMuthee

@denniskigen denniskigen changed the title fix(billing.resource.ts): implement safe patient display parsing with validation and fallbacks (fix) O3-5479: Implement safe patient display parsing with validation and fallbacks Mar 11, 2026
@NethmiRodrigo

Copy link
Copy Markdown
Contributor

Isn’t the hyphenated display the default way in OpenMRS and not likely to change? @dkayiwa @denniskigen

@EDSONZ-WASSWA

Copy link
Copy Markdown

Isn’t the hyphenated display the default way in OpenMRS and not likely to change? @dkayiwa @denniskigen

@NethmiRodrigo I think keeping them doesn't hurt because it's defensive against issues like corrupted data, and maybe future schema changes or third-party system integration

@denniskigen denniskigen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for looking into this, @omeriinnocent! Displaying undefined in the UI is definitely a bug worth fixing.

I checked the backend: BillResource exposes patient as Representation.REF, and the patient display comes from the REST module's patient resource getter, which formats it as IDENTIFIER - Given Family using - as the delimiter.

See inline comments for details. This would also benefit from a few unit tests for the parsing function — null input, standard format, hyphenated identifier, no hyphen, etc.

Comment thread src/billing.resource.ts
Comment thread src/billing.resource.ts
@omeriinnocent

Copy link
Copy Markdown
Contributor Author

thanks @ELVIS-KATO , @EDSONZ-WASSWA for the review feedback,

@omeriinnocent

Copy link
Copy Markdown
Contributor Author

Hi @denniskigen ,Thanks for the detailed feedback. I’ve addressed the comments and updated the implementation accordingly:
Refactored the safe patient display parsing to make it more robust. I added validation logic to ensure consistent data handling and introduced fallback mechanisms to gracefully handle unexpected or malformed input.
Test Updates:
Updated existing unit tests to align with the new logic and added additional test cases to cover edge scenarios, including validation and fallback behavior.

These changes aim to fully address the concerns you raised and improve overall reliability.
Please take another look when you have time — happy to make further adjustments if needed.

omeriinnocent and others added 2 commits April 1, 2026 22:21
The comment about backend sort order is still relevant context
for future maintainers.

@denniskigen denniskigen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks, @omeriinnocent!

@denniskigen
denniskigen merged commit a05c477 into openmrs:main Apr 1, 2026
7 checks passed
@omeriinnocent

Copy link
Copy Markdown
Contributor Author

wooh,thanks for your time @denniskigen

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.

5 participants