OpenVPMS uses a technique called optimistic locking to ensure that multiple users editing the same object don't overwrite each other's changes. If two users edit the same object, the first user to save wins, and the second user's changes are rolled back.
Whilst this prevents data corruption, it means that the second user to save loses their changes.
This project will introduce edit locks so that when a user edits an object, they acquire a lock. If another tries to edit the same object, a message will be displayed and editing will be prevented.
Initially, only support for invoice edit locks will be provided, but this may be extended to other objects in future.
Locks
Locks are acquired when editing an object. A lock contains:
- the object being edited
- the user
- the time the lock was acquired
When editing completes, the lock is released.
If a lock has been acquired for an object, and another user tries to edit the same object, an error message will be displayed e.g.
This invoice is being currently being edited by J Smith.
Invoice Editing
Invoices are the primary cause of save conflicts, so these will be the first candidates for edit locks. It also means that deadlock detection won't be required.
Invoice locks need to be acquired when performing:
- Customer Charges (new, edit, delete, finalisation)
- Check-In
- Consult
- Check-Out
- Estimates - Invoice
- Customer Orders - Invoice
- Prescriptions - Dispense
Invoices also update many other objects. These must not be edited while their associated invoice is edited. This includes:
- medications
- prescriptions
- investigations
- documents
- reminders
- visits
Lock Expiry
Locks will automatically expire if a user logs out or their session is terminated.
Lock Removal
A new administration workspace will be provided to:
- query current locks
- remove individual locks
Exclusions
This project will not support:
- automatically releasing locks if a user is away from their terminal
- preventing invoices or related objects being updated by background tasks e.g.:
- Reporting - Debtors - End Period
- Reporting - Reminders - Send All
These could cause a user's changes to be rolled back, so should be run when editing is not being performed.