Skip to content

Conversation

@praneeth622
Copy link
Contributor

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. 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. (See also: Styleguide)
  • My work includes tests or is validated by existing tests.

Summary

This PR fixes a critical crash that occurs when a user without an associated Provider record attempts to access the Orders workspace. Previously, the application would crash with a TypeError: Cannot read properties of null (reading 'uuid') error because the code attempted to access session.currentProvider.uuid without checking if currentProvider exists.

Changes made:

  • Added null-safe checks for currentProvider throughout the order basket component
  • Implemented a clear, user-friendly error notification when no provider is associated with the current user
  • Disabled order submission when currentProvider is null to prevent data integrity issues
  • Added comprehensive unit tests covering both null and non-null provider scenarios

Why this matters:

  • Users can now see a clear error message instead of experiencing a crash: "Current user is not a provider. A provider account is required to place orders. Please contact your system administrator."
  • The workspace remains functional for viewing, but appropriately blocks order creation
  • Prevents potential null pointer exceptions in production

Screenshots

Before (Crash):
image
image

After (Graceful Error):
The workspace opens successfully and displays an inline error notification explaining that the current user is not a provider and cannot place orders.
image

Related Issue

https://issues.openmrs.org/browse/O3-4648

Other

Testing:

  • All linting checks passed
  • Created new test file order-basket.component.test.tsx with 6 test cases:
    • ✅ Component renders without crashing when currentProvider is null
    • ✅ Error notification is displayed when currentProvider is null
    • ✅ Submit button is disabled when currentProvider is null
    • ✅ Component renders normally when currentProvider exists
    • ✅ No crash when accessing currentProvider.uuid in useEffect (provider exists)
    • ✅ No crash when accessing currentProvider.uuid in useEffect (provider is null)

Note: This PR improves upon the previously declined PR #2763 by:

  • Not blocking the workspace from opening entirely
  • Providing clearer user guidance
  • Using Testing Library best practices
  • Minimal, focused changes only to affected files

- Add null checks for currentProvider to prevent TypeError
- Show clear error message when user is not a provider
- Disable order submission when no provider exists
- Add comprehensive unit tests for null provider scenario

Fixes O3-4648
Copilot AI review requested due to automatic review settings January 10, 2026 21:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical crash that occurs when a user without an associated Provider record attempts to access the Orders workspace. Previously, the application would crash with a TypeError: Cannot read properties of null error when attempting to access currentProvider.uuid. The fix adds null-safety checks and provides graceful error handling with clear user feedback.

Changes:

  • Added null-safe initialization for currentProvider with conditional logic
  • Added null check in useEffect to prevent accessing currentProvider.uuid when null
  • Implemented user-friendly error notification displayed when currentProvider is null
  • Disabled order submission button when currentProvider is null to maintain data integrity
  • Added comprehensive unit tests covering both null and non-null provider scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/esm-patient-orders-app/src/order-basket/order-basket.component.tsx Modified currentProvider initialization to handle null values, added conditional rendering for error notification, updated button disable logic, and added null check in useEffect
packages/esm-patient-orders-app/src/order-basket/order-basket.component.test.tsx Added comprehensive test suite with 6 test cases covering null and non-null provider scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@NethmiRodrigo
Copy link
Collaborator

@praneeth622 please look into the failing workflows

@denniskigen
Copy link
Member

@praneeth622 I don't see the inline notification you proposed in the screenshot. Mind posting an updated one?

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