tl;dr
We could add orders.sort_weight
(float) and carry this value forward when a new order is created from an existing one (i.e., when previous order
is set). Then the API could support reliable sorting of orders:
- Manual sorting by sort weight (default)
- Date created, descending
- Date created, ascending
- Alphabetic
When a new order was created from an existing one (e.g., revising an order), then it would naturally sort into the same position as the original.
-Burke
Burke’s pleonastic brain dump…
@darius, I think the order attributes idea was to support cycle number, which is commonly used in oncology to define a sequence of treatments over time (e.g., monthly treatments), not necessarily order sequencing (i.e., reproducing n orders with reliable sequencing – e.g., doctor orders A+B+C, later changes B to D, and we can reliably reproduce this as A+D+C). It’s possible the order attributes (i.e., an implementation-specific “sequence number” attribute) could meet this need, it’s worth considering if we can build this capability into the API.
I believe what @vsingh is describing is:
Scenario
- Doctor orders
A, B, and C
- The doctor later changes B
- This could be a revision (e.g., adjustment to instructions), changing
B
to B'
- This could be a replacement, replacing
B
with D
Requirements
- We can reliably display the original orders in the same sequence:
A
, B
, then C
- Currently this could be done using
date created
if timestamps are at least a second apart or using order number
if the algorithm being used is incremental and reliably sortable (e.g., contains an incrementing number). I don’t believe either of these are currently guaranteed by the API.
- The system can reliably reproduce the correct sequence even after orders are revised/replaced. If
B
was revised, then we can produce an order list as A
, B'
, then C
; if B
was replaced, we can produce an order list as A
, D
, then C
.
- Currently, you would need to take active orders and track any
previous order
back to original orders and, assuming the sorting mentioned above worked, use the date created
or order number
from the original orders to reliably reproduce the correct sequence.
NOTE: while the use case described by @vsingh is for drugs, this need for sequencing could be applied to any type of orders.
The simplest approach would be to add orders.order_weight
(float), allowing all orders to have an optional sort weight applied to reliably reproduce sequencing of orders. To support proper sequencing even after revisions/replacements, this assumes either the user will specify the position (weighting) when revising/replacing an order (which is probably not a reasonable expectation) or that the application (or the API) would need to trace any revision/replacements (via previous order
) to its original order to obtain its weighting. In essence, the “sort weight” for any order would come from the original order (first order in any chain of previous order
s). If the user creates a completely new order (without previous order
pointing to what it’s replacing), then the only way to control its position would be for them to manually position it (i.e., adjust its sort weight within active orders).
This could be simplified further If we add orders.sort_weight
(float) and ensure that the value is carried over whenever an order is created from an existing order (i.e., at the time that a previous order
link is being created). The API could then support three modes of sorting:
-
Natural sorting (default): orders listed in the order they were created.
-
Alphabetic sorting: orders listed alphabetically by name.
-
Manual sorting: order listed by sort weight (orders without a sort weight would be naturally sorted at the end)
I think that could work, but we would probably want to stop relying on uniqueness of date created
or the sortability of a potentially custom order number
and would end up making the API add default sort weight
values behind the scenes to support reliable natural sorting of orders (in the same sequence as they were created). So, in effect, the API would “manually” sort orders as they were created and any manual sorting would be manual adjustments to the values set by the API.
If we assume the number of orders may exceed the paging size, then sorting needs to be performed on the server side, so we end up with the API supporting the following sort modes:
- Manual sorting by sort weight (default)
- Date created, descending
- Date created, ascending
- Alphabetic