Skip to main content
Version: 3.1

Supply Request

Technical reference for the SupplyRequest model in Care EMR. A SupplyRequest is one requested item: a quantity of one catalog entry (ProductKnowledge), not a stocked batch, on one request order.

Each requested item belongs to a RequestOrder, which is a purchase order or a stock request. The order has its own reference: Request Order.

Source:

The Django model is the storage layer. status and supplied_item_condition are plain CharFields there. The allowed values, the validation and the read and write schemas are in the Pydantic resource specs.

Models​

ModelPurpose
SupplyRequestOne requested item: a quantity of one catalog entry on a request order
RequestOrderThe purchase order or stock request that groups the requested items. Same model file; documented in Request Order

SupplyRequest fields​

FieldTypeNotes
statusCharField(255)Spec-bound to SupplyRequestStatusOptions. Required on create and on update
quantityDecimalField, max_digits=20, decimal_places=6, nullableThe write specs take a whole number of at least 1 (decimal_places=0, ge=1). The read spec returns an int
supplied_item_conditionCharField(255)Model only. No spec reads or writes it, so the API never reaches it
itemFK → ProductKnowledge, CASCADEThe catalog entry, not a stocked batch. Required on create, given as a UUID. Not in the update spec, so it cannot change. Care does not check it against the order's facility
orderFK → RequestOrder, nullable, CASCADERequired on create and on update, given as a UUID. The update resolves it again, so an update can move the item to another order

SupplyRequestStatusOptions values​

Defined in spec.py and bound to SupplyRequest.status. The labels are the ones Care's frontend shows.

ValueLabelNotes
draftDraft
activeActiveCare's frontend creates every new item with this status
suspendedSuspended
cancelledCancelledSet on every item when its order moves to abandoned. A cancelled item can still move back to draft or active
processedProcessed
completedCompletedFinal for status changes
entered_in_errorEntered in ErrorSet on every item when its order moves to entered_in_error. Final for status changes

No delivery sets a requested item to completed or processed. The order cascade is the only writer of item status outside a direct edit.

RelationNotes
order → RequestOrderThe order that holds the item. See Request Order
item → ProductKnowledgeThe catalog entry. See Product Knowledge
SupplyDelivery.supply_request → SupplyRequestA delivered item can point at one requested item. This is the only link between deliveries and request orders. See Supply Delivery

Resource specs (API schema)​

Spec classUsed forFields and behaviour
BaseSupplyRequestSpecShared baseid (optional), status: SupplyRequestStatusOptions, quantity: Decimal (max_digits=20, decimal_places=0, ge=1). __exclude__ = ["item"]
SupplyRequestWriteSpecCreateBase fields plus item: UUID4 and order: UUID4. Resolves item to a ProductKnowledge and order to a RequestOrder with get_object_or_404
SupplyRequestUpdateSpecUpdate (pydantic_update_model)Base fields plus order: UUID4, resolved again. It has no item
SupplyRequestReadSpecReadBase fields, with quantity as an int, item as a nested ProductKnowledgeReadSpec object and order as a nested SupplyRequestOrderReadSpec object

Validation​

  • status and quantity are required. quantity is a whole number of at least 1.
  • Create requires item and order. Update requires order and takes no item.
  • supplied_item_condition is not in any spec.

Status rules​

SupplyRequestViewSet runs these rules on create and on update.

  • An item cannot be added to an order that is abandoned or entered_in_error ("Request order is abandoned or entered in error") or completed ("Request order is completed"). Orders in draft, pending and in_progress accept new items.
  • The item's own status rule compares the item's old status with the order status values. Only an item in entered_in_error or completed cannot change status. The messages are "Request order is abandoned or entered in error" and "Request order is completed".
  • abandoned is not an item status. So a cancelled item, for example one cancelled when its order was abandoned, can move back to draft or active.
  • An update never checks the order's status. Items of a completed, abandoned or entered_in_error order can still be edited: quantity, and status within the rule above.
  • When its order moves to abandoned or entered_in_error, every item of the order changes status. See Request Order.

API integration notes​

Endpoints​

SupplyRequestViewSet serves requested items at /api/v1/supply_request/, outside the facility URL.

ActionRequestNotes
createPOST /api/v1/supply_request/SupplyRequestWriteSpec. Care's frontend sends one create per item, with status active
listGET /api/v1/supply_request/Needs at least one of order, origin, destination. Care's frontend lists an order's items with ?order={id}
retrieveGET /api/v1/supply_request/{id}/
updatePUT or PATCH /api/v1/supply_request/{id}/SupplyRequestUpdateSpec. Both methods run the same update
upsertPOST /api/v1/supply_request/upsert/At most MAX_DATAPOINTS_PER_UPSERT items (default 100). Items with an id go through the normal update. If one item fails, nothing is saved
request orders of a delivery orderGET /api/v1/supply_request/request_orders/?delivery_order={id}Up to 100 request orders that the delivery order's items point at. See Request Order

The API has no delete for requested items.

Filters​

ParameterBehaviour
order, origin, destination, include_childrenScope parameters. A list needs at least one of order, origin, destination, else "No filters provided"
statusOne or more statuses
itemThe catalog entry (item__external_id)
supplierThe supplier of the order (order__supplier__external_id)

Authorization​

PermissionSlugDefault roles
"Can Create Supply Request on Facility"can_write_supply_requestFacility Admin, Staff, Doctor, Nurse
"Can Read Supply Request"can_read_supply_requestFacility Admin, Administrator, Staff, Doctor, Nurse, Volunteer, Pharmacist

The permission must be held in one of the location's organizations, as described in Request Order.

ActionCare checksRefusal
create, update"Can Create Supply Request on Facility" at the order's origin or at its destination. So for a stock request the supplying location can also add or edit items"Cannot write supply requests"
retrieve, list"Can Read Supply Request" at the order's origin or at its destination"Cannot read supply requests"
  • Care's frontend item picker lists the facility's catalog entries. That list needs "Can Read Product Knowledge" in any organization of the facility.
  • The role lists are defaults. The Admin role of the permission files is left out: role sync leaves it with the responsibility-organization context only.

Errors​

MessageCause
"Request order is abandoned or entered in error"Create on an abandoned or entered_in_error order, or a status change of an item in entered_in_error
"Request order is completed"Create on a completed order, or a status change of a completed item
"Cannot write supply requests"No write permission at the order's origin or destination
"Cannot read supply requests"No read permission at the order's origin or destination
"No filters provided"A list without order, origin or destination
"No datapoints provided", "Too many datapoints provided"An upsert with no items, or with more than MAX_DATAPOINTS_PER_UPSERT items