The “Order” type in OpenMRS has a property called “orderNumber”.
This was added (over a decade ago!) in (see Jira )
The use case was for Order Number to be something auto-generated by OpenMRS and never set by another means. Implementers are able to configure their own “order number generator” bean to configure how the order numbers are assigned, but order numbers are never able to be arbitrarily set… in fact, the property does not have a setter, and, even if you set the property via reflection, the saveOrder API method overwrites it with a number assigned by OpenMRS.
Although I remember and understand this reasoning at the time, I feel like this is a bit restrictive, especially in a world where we want to be able to move patient records around either between OpenMRS instances or between OpenMRS and other systems, and I feel that OpenMRS business logic should not be restrictive to the level of preventing that.
My particular use case is that were are working on merging OpenMRS instances and are building a lightweight tool that exports patients via the REST Web Services module into json records and then loads those records into an existing system. Basically, I’d like to be able to specify an order number in REST web services post and have that order number be set.
The simplest way to allow this would be to:
- add a setter to Core for orderNumber
- change the save logic in OrderService so that if there is an order number on the incoming order number, don’t overwrite it with a number generated by the order number
- change REST web services so that orderNumber is “creatable”
This is likely a little too permissive, so I’d suggest:
- create a global property like “allow setting order number”, defaults to false
- add a setter to Core for orderNumber, but add some sort of validator/interceptor so that this fails if the GP created above is set to false
- change the save logic in OrderService so that if there is an order number on the incoming order number AND the GP is set to true, don’t overwrite it with a number generated by the order number
- change REST web services so that orderNumber is “creatable” (ie, basically defer to Core to handle whether this is allowed or not)
Thoughts? You can see previous discussions on this ticket here: Jira
Ideally I’d like to avoid going through the hoops of creating an extra endpoint for this, and I think it’s reasonable to expect OpenMRS to be able to operate in a mode where data exported from OpenMRS via REST can be imported with little manipulation.
(As an aside, yes, our importer/exporter tool will need to do some manipulation of the order numbers to avoid having duplicate order numbers when we merge systems).
Thanks and take care,
Mark