Skip to content

Conversation

@RajPrakash681
Copy link
Contributor

@RajPrakash681 RajPrakash681 commented Nov 3, 2025

O3-5174: Prevent duplicate billable services in billing form

Problem

The system was allowing users to add the same billable service multiple times, creating duplicate line items without warning. This resulted in confusing bills with entries like "Antenatal care & Antenatal care & Orthopedic Service", making it unclear whether the user intended to add duplicates or increase quantities.

Solution

Implemented a duplicate detection mechanism in the billing form that:

  • Detects when a user attempts to add a service that already exists in the bill
  • Displays a user-friendly warning notification with the service name
  • Provides clear action options: "Yes, increase quantity" or "Cancel"
  • Increases the quantity of the existing item if the user confirms
  • Prevents creating duplicate line items

Changes Made

Files Modified:

  1. src/billing-form/billing-form.component.tsx

    • Added duplicateWarning state to track duplicate service attempts
    • Modified selectBillableItem() to detect existing services before adding
    • Added handleIncreaseQuantity() to increment quantity when user confirms
    • Added handleDismissWarning() to close the warning without action
    • Added warning notification UI with action buttons
  2. translations/en.json

    • Added translation keys:
      • duplicateServiceWarning: "Duplicate service detected"
      • duplicateServiceMessage: "{{itemName}} is already in this bill. Would you like to increase the quantity?"
      • increaseQuantity: "Yes, increase quantity"
      • cancel: "Cancel"

Testing

  • Verified duplicate detection works for all billable services
  • Tested "Yes, increase quantity" functionality - quantity increments correctly
  • Tested "Cancel" button - warning dismisses without changes
  • Confirmed no duplicate line items are created
  • Verified existing functionality (manual quantity updates) still works

📸 Screenshots

Quantity increased after clicking "Yes, increase quantity":
Screenshot 2025-11-03 201301
Screenshot 2025-11-03 201321

Related Issue

Fixes #O3-5174

Impact

  • Improves user experience by providing clear feedback
  • Prevents billing errors from accidental duplicate entries
  • Maintains data integrity by ensuring one line item per service
  • Gives users control over their intent (increase quantity vs. cancel)

@RajPrakash681
Copy link
Contributor Author

@VeronicaMuthee please have a look!

@VeronicaMuthee
Copy link

@RajPrakash681 thanks for your PR. Requesting @NethmiRodrigo & @denniskigen to review.

@denniskigen
Copy link
Member

denniskigen commented Nov 4, 2025

@RajPrakash681 this fix should happen in the backend module.

@RajPrakash681
Copy link
Contributor Author

@RajPrakash681 this fix should happen in the backend module.

@denniskigen Thank you for the feedback!
I have two questions:

  1. Should I implement this in the backend first (in openmrs-module-billing) and then update this PR to handle the backend response?

  2. Or would you prefer both implementations - backend for data integrity + frontend for immediate UX feedback (preventing unnecessary API calls)?

I'm happy to implement the backend validation. Please let me know the preferred approach!

@denniskigen
Copy link
Member

I've updated the ticket accordingly, @RajPrakash681. There is a frontend component:

The frontend billing form prevents users from adding the same billable service multiple times as separate line items, even when different payment methods or prices are involved. The duplicate detection logic only checks the billableService.uuid, ignoring payment method differences. This prevents legitimate use cases like billing the same service with part cash and part insurance.

The frontend checks for duplicates using only billableService.uuid. If the same service is selected again, it merges by incrementing quantity, even when the payment method or price differs.

which should be fixed, but I'd lean towards starting with the backend fix (the primary issue) before solving the secondary issue on the frontend.

@VeronicaMuthee
Copy link

VeronicaMuthee commented Nov 4, 2025

@denniskigen denniskigen marked this pull request as draft December 2, 2025 13:17
@denniskigen
Copy link
Member

Set to draft pending discussions on a separate form such as Talk.

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