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:
- Model:
care/emr/models/supply_request.py - Spec:
care/emr/resources/inventory/supply_request/spec.py - Viewset:
care/emr/api/viewsets/inventory/supply_request.py
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
| Model | Purpose |
|---|---|
SupplyRequest | One requested item: a quantity of one catalog entry on a request order |
RequestOrder | The purchase order or stock request that groups the requested items. Same model file; documented in Request Order |
SupplyRequest fields
| Field | Type | Notes |
|---|---|---|
status | CharField(255) | Spec-bound to SupplyRequestStatusOptions. Required on create and on update |
quantity | DecimalField, max_digits=20, decimal_places=6, nullable | The write specs take a whole number of at least 1 (decimal_places=0, ge=1). The read spec returns an int |
supplied_item_condition | CharField(255) | Model only. No spec reads or writes it, so the API never reaches it |
item | FK → ProductKnowledge, CASCADE | The 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 |
order | FK → RequestOrder, nullable, CASCADE | Required 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.
| Value | Label | Notes |
|---|---|---|
draft | Draft | |
active | Active | Care's frontend creates every new item with this status |
suspended | Suspended | |
cancelled | Cancelled | Set on every item when its order moves to abandoned. A cancelled item can still move back to draft or active |
processed | Processed | |
completed | Completed | Final for status changes |
entered_in_error | Entered in Error | Set 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.
Related models
| Relation | Notes |
|---|---|
order → RequestOrder | The order that holds the item. See Request Order |
item → ProductKnowledge | The catalog entry. See Product Knowledge |
SupplyDelivery.supply_request → SupplyRequest | A 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 class | Used for | Fields and behaviour |
|---|---|---|
BaseSupplyRequestSpec | Shared base | id (optional), status: SupplyRequestStatusOptions, quantity: Decimal (max_digits=20, decimal_places=0, ge=1). __exclude__ = ["item"] |
SupplyRequestWriteSpec | Create | Base fields plus item: UUID4 and order: UUID4. Resolves item to a ProductKnowledge and order to a RequestOrder with get_object_or_404 |
SupplyRequestUpdateSpec | Update (pydantic_update_model) | Base fields plus order: UUID4, resolved again. It has no item |
SupplyRequestReadSpec | Read | Base fields, with quantity as an int, item as a nested ProductKnowledgeReadSpec object and order as a nested SupplyRequestOrderReadSpec object |
Validation
statusandquantityare required.quantityis a whole number of at least 1.- Create requires
itemandorder. Update requiresorderand takes noitem. supplied_item_conditionis 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
abandonedorentered_in_error("Request order is abandoned or entered in error") orcompleted("Request order is completed"). Orders indraft,pendingandin_progressaccept 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_errororcompletedcannot change status. The messages are "Request order is abandoned or entered in error" and "Request order is completed". abandonedis not an item status. So acancelleditem, for example one cancelled when its order was abandoned, can move back todraftoractive.- An update never checks the order's status. Items of a
completed,abandonedorentered_in_errororder can still be edited:quantity, andstatuswithin the rule above. - When its order moves to
abandonedorentered_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.
| Action | Request | Notes |
|---|---|---|
| create | POST /api/v1/supply_request/ | SupplyRequestWriteSpec. Care's frontend sends one create per item, with status active |
| list | GET /api/v1/supply_request/ | Needs at least one of order, origin, destination. Care's frontend lists an order's items with ?order={id} |
| retrieve | GET /api/v1/supply_request/{id}/ | |
| update | PUT or PATCH /api/v1/supply_request/{id}/ | SupplyRequestUpdateSpec. Both methods run the same update |
| upsert | POST /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 order | GET /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
| Parameter | Behaviour |
|---|---|
order, origin, destination, include_children | Scope parameters. A list needs at least one of order, origin, destination, else "No filters provided" |
status | One or more statuses |
item | The catalog entry (item__external_id) |
supplier | The supplier of the order (order__supplier__external_id) |
Authorization
| Permission | Slug | Default roles |
|---|---|---|
| "Can Create Supply Request on Facility" | can_write_supply_request | Facility Admin, Staff, Doctor, Nurse |
| "Can Read Supply Request" | can_read_supply_request | Facility Admin, Administrator, Staff, Doctor, Nurse, Volunteer, Pharmacist |
The permission must be held in one of the location's organizations, as described in Request Order.
| Action | Care checks | Refusal |
|---|---|---|
| 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
| Message | Cause |
|---|---|
| "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 |
Related
- Concept: Purchase Order
- Concept: Stock Request
- Reference: Request Order
- Reference: Product Knowledge
- Reference: Supply Delivery
- Reference: Inventory Item
- Reference: Location
- Reference: EMR base model
- Source: supply_request.py on GitHub
- Spec: supply_request/spec.py on GitHub
- Viewset: supply_request.py viewset on GitHub