Add Parameter to Include Discontinued Orders in API Endpoint

Description

The current API endpoint for retrieving orders does not return discontinued orders. This behavior is due to the endpoint calling an API method (getActiveOrders) that is designed to exclude discontinued orders. For backward compatibility and to address use cases that require including discontinued orders, a new parameter includeDiscontinuedOrders should be added to the endpoint. The endpoint should then call the appropriate API method (getOrdersIncludingDiscontinued) introduced in platform 2.2.

Steps to Reproduce:

  1. Call the existing orders endpoint.

  2. Observe that orders with a DISCONTINUE action are not included in the response .i.e. the DISCONTINUE order does not appear to be discontinuing the order properly. Instead of seeing an order with a DISCONTINUE action, we consistently get an order with the action of NEW.Upon investigation, it was found that a new row with the action DISCONTINUE and a corresponding date_stopped is created in the database. However, the endpoint fetches only the original row with the action NEW, leaving out the discontinued row.

Proposed Solution:

  1. Add a new parameter includeDiscontinuedOrders to the orders endpoint.

  2. Modify the endpoint logic to call getOrdersIncludingDiscontinued when includeDiscontinuedOrders is set to true.

  3. Ensure that both active and discontinued orders are returned in the response when the parameter is used.

  4. Investigate and fix the issue where the DISCONTINUE order is not being processed correctly by the endpoint, ensuring the discontinuation action and corresponding date are included in the response.

Environment:

  • OpenMRS Platform 2.2 and above

  • Affected version: openmrs 3.0[The entire discussion is on this PR ]

Activity

Juliet Wamalwa August 27, 2024 at 6:13 PM

am so sorry for the late response I was in the middle of a bug fix. Kindly am happy to work on it and present tomorrow during the coffee break.

Daniel Kayiwa August 26, 2024 at 9:49 PM

can you change the url by doing two things:

  1. Remove the &status=ACTIVE parameter

  2. Change the orderType parameter to orderTypes

And hence end up with something like this below:

`/openmrs/ws/rest/v1/order?patient=025b4433-efa2-4eab-9473-748a1cf34222&careSetting=6f0c9a92-6f24-11e3-af88-005056821db0&orderTypes=131168f4-15f5-102d-96e4-000c29c2a5d7&v=custom:(uuid,dosingType,orderNumber,accessionNumber,patient:ref,action,careSetting:ref,previousOrder:ref,dateActivated,scheduledDate,dateStopped,autoExpireDate,orderType:ref,encounter:ref,orderer:(uuid,display,person:(display)),orderReason,orderReasonNonCoded,orderType,urgency,instructions,commentToFulfiller,drug:(uuid,display,strength,dosageForm:(display,uuid),concept),dose,doseUnits:ref,frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)`

Juliet Wamalwa July 30, 2024 at 12:44 PM

Kindly this is the ticket I have created in relation to the DISCONTINUE order.

Fixed

Details

Assignee

Reporter

Priority

Created July 30, 2024 at 12:38 PM
Updated December 2, 2024 at 11:11 AM
Resolved December 2, 2024 at 11:11 AM