Skip to main content
Version: 3.1

Medication return

Technical reference for medication returns in Care EMR. A medication return records medicines that come back from a patient to a pharmacy location. Care has no separate model for it: a return is a DeliveryOrder with a patient and no origin, and each returned item is a SupplyDelivery in that order.

This page covers only what is specific to returns. For every field of the two models, see Supply delivery.

Source:

Models​

ModelRole in a return
DeliveryOrderThe return. patient is set, origin is empty, destination is the location that takes the medicines back
SupplyDeliveryOne returned item: a product (lot) and a quantity
InvoiceThe refund invoice that Care creates when the return is completed. See Invoice

Both supply models extend EMRBaseModel.

A return does not point to the dispense that it reverses. care_fe can copy the product and the quantity of a dispense into a return item, but Care stores no link between them.

How a return is stored​

DeliveryOrder fields for a return​

FieldValue in a returnNotes
patientRequiredFK → Patient, PROTECT. Create only. Its presence makes the order a return
originEmptyCare refuses patient and origin together
supplierEmpty in care_feThe spec does not forbid it
destinationRequiredFK → FacilityLocation. Create only. The location that takes the medicines back
nameRequiredCharField(255)
noteOptionalTextField, nullable
statusRequireddraft or pending on create. See Status rules
patient_invoiceServer-setFK → Invoice, PROTECT. The refund invoice. Read as patient_invoice_id. An update cannot change it
extensionsOptionalAdditional fields, validated by ExtensionValidator

SupplyDelivery fields for a returned item​

FieldValue in a returnNotes
orderRequiredThe return's DeliveryOrder. Create only
supplied_itemRequiredFK → Product: the lot that comes back. Must be a product of the destination's facility
supplied_inventory_itemNot sentCare refuses it in the request. Care sets it to the stock row of the product at the destination, and creates that row with zero stock if it does not exist
supplied_item_quantityRequiredWhole number, at least 1. If supplied_item_pack_quantity and supplied_item_pack_size are both set, Care replaces it with their product
statusRequiredin_progress, completed, abandoned or entered_in_error. The client sets it, also on create
supplied_item_conditionOptionalnormal or damaged

Status rules​

DeliveryOrder.status uses SupplyDeliveryOrderStatusOptions: draft, pending, in_progress, completed, abandoned, entered_in_error.

ChangeRule for a return
CreateStatus must be draft or pending
Any change from abandoned or entered_in_errorRefused
From completedOnly to entered_in_error. The general rule also allows abandoned, but a return cannot be abandoned
To abandonedRefused: Cannot abandon a delivery order with medication return
To completedEvery item must be completed, abandoned or entered_in_error. Then Care creates the refund invoice
To entered_in_errorCare cancels the refund invoice and the items (see below)

A returned item cannot change status after it is completed, abandoned or entered_in_error. Care refuses a new item when the order is completed, abandoned or entered_in_error.

Stock​

  • An item adds stock at the destination only while its status is completed. Stock of a product at a location is the sum of completed deliveries into it, less outgoing deliveries and dispenses (sync_inventory_item).
  • Care recalculates the stock of the destination row after each create and update of an item.

Refund invoice (order to completed)​

generate_return_invoice() runs under a lock on the order and on the patient's account:

  1. If the order already has patient_invoice, Care keeps it and stops.
  2. Care takes the patient's default account at the destination's facility.
  3. Care creates an Invoice with is_refund = true, issue_date now, and a number from the facility's invoice number expression.
  4. For each completed item whose product has a charge item definition, Care applies that definition in reverse for the item's quantity. Each charge item gets status billed and the invoice as paid_invoice. Items whose product has no charge item definition get no charge.
  5. Care syncs the invoice totals, sets the invoice to issued, and links it to the order.
  6. Care queues a rebalance of the account.

The invoice takes created_by and updated_by from the order. Care checks no billing permission.

Entered in error (order to entered_in_error)​

cancel_return_invoice() runs under a lock on the order:

  1. If the order has a refund invoice, Care sets the invoice to cancelled. Its charge items become entered_in_error, with paid_invoice and paid_on cleared. Care queues a rebalance of the account.
  2. Care sets every item that is not already abandoned or entered_in_error to entered_in_error, and takes the completed quantities out of the destination's stock.
  3. If the destination does not have enough stock left, Care refuses the change: Inventory item does not have enough stock.

Resource specs (API schema)​

A return uses the delivery order and supply delivery specs. See Supply delivery for the full spec tables.

SpecUse in a return
SupplyDeliveryOrderWriteSpecCreate the return: name, status, note, destination, patient
BaseSupplyDeliveryOrderSpecUpdate the return: name, status, note and extensions only
SupplyDeliveryOrderReadSpec / SupplyDeliveryOrderRetrieveSpecRead the return. patient is a PatientListSpec object. patient_invoice_id is the refund invoice
SupplyDeliveryWriteSpecAdd an item: order, supplied_item, supplied_item_quantity, status
SupplyDeliveryUpdateSpecChange an item: status, supplied_item_condition, total_purchase_price

API integration notes​

  • Returns: /api/v1/facility/{facility_external_id}/order/delivery/. Items: /api/v1/supply_delivery/. Neither viewset has a delete.
  • To list returns, send patient_return=true and destination. Without patient_return=true, the list leaves returns out. A return list needs destination; origin alone is refused. Other filters: status (comma-separated), patient, created_date range, include_children. Ordering: created_date, modified_date.
  • To list the items of a return, send order={return_id} to /api/v1/supply_delivery/.
  • Read (return or item) needs can_read_medication_return in an organization of the destination's facility_organization_cache. Write (create, update, add or change items, status changes) needs can_write_medication_return there. The supply delivery permissions do not apply to returns.
  • Default roles with can_write_medication_return: Facility Admin. Default roles with can_read_medication_return: Facility Admin, Administrator, Staff, Doctor, Nurse, Volunteer, Pharmacist.