Pharmacy API
The Pharmacy API provides everything necessary to build a full-featured pharmacy application on top of the MediLoop backend. It covers OTC product catalog, point-of-sale (transactions, receipts, payments), dispensing queues, inventory and stock movements, procurement (suppliers, purchase orders), returns, cold chain monitoring, drug safety (interactions/recalls), compounding, and a Quality Management System (QMS).
Authentication: All endpoints require a valid JWT service or user token. See the Authentication page for Keycloak / JWT details and example tokens.
Top-level endpoints
/api/v1/sales/products/List OTC products (catalog)/api/v1/sales/products/Create OTC product/api/v1/sales/products/{id}/Get product details/api/v1/sales/transactions/Create sales transaction/api/v1/sales/transactions/List transactions/api/v1/sales/transactions/{id}/Get transaction details/api/v1/sales/transactions/{id}/complete/Complete transaction (payment & finalize)/api/v1/sales/transactions/{id}/receipt/Get receipt (JSON/PDF)/api/v1/sales/consultations/Create customer consultation/api/v1/sales/follow-ups/Schedule follow-up & notify/api/v1/sales/loyalty-programs/List loyalty programs/api/v1/sales/loyalty-accounts/Create loyalty account/api/v1/sales/analytics/Sales analytics & forecasting/api/v1/sales/ai-recommendations/AI product recommendations/api/v1/inventory/medications/Medication catalog/api/v1/inventory/pharmacies/Pharmacy locations/api/v1/inventory/stock/Inventory items & quantities/api/v1/inventory/movements/Record stock movements/api/v1/inventory/alerts/Stock alerts & notifications/api/v1/dispensing/dispenses/Create dispense record/api/v1/dispensing/queue/Prescription dispensing queue/api/v1/dispensing/refills/Request prescription refill/api/v1/procurement/suppliers/List suppliers/api/v1/procurement/suppliers/Create supplier/api/v1/procurement/supplier-medications/Supplier medication catalog/api/v1/procurement/purchase-orders/Create purchase order/api/v1/procurement/purchase-orders/List purchase orders/api/v1/procurement/grn/Create goods received note/api/v1/drug-safety/interactions/Drug interaction checks/api/v1/drug-safety/allergies/Drug allergy database/api/v1/drug-safety/recalls/Drug recall alerts/api/v1/drug-safety/controlled-substances/Controlled substances/api/v1/drug-safety/controlled-register/Record controlled substance transaction/api/v1/drug-safety/alerts/Safety alerts/api/v1/cold-chain/storage-units/Cold storage units/api/v1/cold-chain/readings/Temperature readings/api/v1/cold-chain/excursions/Temperature excursions/api/v1/cold-chain/products/Cold chain products/api/v1/cold-chain/transports/Record cold chain transport/api/v1/compounding/formulas/Compound formulas/api/v1/compounding/ingredients/Formula ingredients/api/v1/compounding/preparations/Record compound preparation/api/v1/returns/customer/Create customer return/api/v1/returns/supplier/Create supplier return/api/v1/returns/destruction/Record drug destruction/api/v1/quality/incidents/Report quality incident/api/v1/quality/capas/Corrective/Preventive Actions/api/v1/quality/audits/Quality auditsPharmacy Workflows
Complete workflows for building a fully functional pharmacy application, including OTC sales, prescription dispensing, inventory management, and compliance.
OTC Sales Workflow
Handle over-the-counter product sales with customer consultations, loyalty programs, and follow-ups.
- Product Search: GET /api/v1/sales/products/ with search parameters
- AI Recommendations: GET /api/v1/sales/ai-recommendations/ for personalized suggestions
- Create Transaction: POST /api/v1/sales/transactions/ with items array
- Customer Consultation: POST /api/v1/sales/consultations/ if needed
- Process Payment: POST /api/v1/sales/transactions/{id}/complete/
- Generate Receipt: GET /api/v1/sales/transactions/{id}/receipt/?format=pdf
- Schedule Follow-up: POST /api/v1/sales/follow-ups/ if required
- Loyalty Points: Update customer loyalty account via /api/v1/sales/loyalty-accounts/
Prescription Dispensing Workflow
Process prescription orders from queue, check interactions, dispense medications, and handle controlled substances.
- Check Queue: GET /api/v1/dispensing/queue/ for pending prescriptions
- Verify Patient: Check patient details via Patients API
- Drug Interactions: GET /api/v1/drug-safety/interactions/ for all medications
- Allergy Check: GET /api/v1/drug-safety/allergies/ for patient allergies
- Controlled Substances: Check /api/v1/drug-safety/controlled-substances/ if applicable
- Inventory Check: GET /api/v1/inventory/stock/ for medication availability
- Create Dispense: POST /api/v1/dispensing/dispenses/ with prescription details
- Record Controlled Transaction: POST /api/v1/drug-safety/controlled-register/ if controlled
- Update Inventory: POST /api/v1/inventory/movements/ for stock reduction
- Send Notification: Use Notifications API for pickup ready alerts
Inventory Management Workflow
Maintain optimal stock levels with automated procurement, stock alerts, and movement tracking.
- Monitor Stock Levels: GET /api/v1/inventory/stock/ regularly
- Check Alerts: GET /api/v1/inventory/alerts/ for low stock notifications
- Find Suppliers: GET /api/v1/procurement/suppliers/ for available vendors
- Check Supplier Catalog: GET /api/v1/procurement/supplier-medications/
- Create Purchase Order: POST /api/v1/procurement/purchase-orders/
- Receive Goods: POST /api/v1/procurement/grn/ when delivery arrives
- Record Stock Movement: POST /api/v1/inventory/movements/ for receipts
- Cold Chain Check: GET /api/v1/cold-chain/readings/ for temperature-sensitive items
Returns & Quality Management
Handle customer returns, supplier returns, drug destruction, and maintain quality standards.
- Customer Return: POST /api/v1/returns/customer/ with return details
- Inspect Returned Items: Check condition and expiry
- Supplier Return: POST /api/v1/returns/supplier/ if needed
- Drug Destruction: POST /api/v1/returns/destruction/ for expired/unusable drugs
- Report Incident: POST /api/v1/quality/incidents/ for quality issues
- Create CAPA: Use /api/v1/quality/capas/ for corrective actions
- Schedule Audit: Use /api/v1/quality/audits/ for compliance checks
Compounding Workflow
Prepare custom compounded medications with formula management and quality control.
- Select Formula: GET /api/v1/compounding/formulas/ for approved formulas
- Check Ingredients: GET /api/v1/compounding/ingredients/ for formula components
- Verify Stock: GET /api/v1/inventory/stock/ for ingredient availability
- Record Preparation: POST /api/v1/compounding/preparations/
- Quality Testing: Document testing results
- Label & Dispense: Follow dispensing workflow for delivery
Products (OTC catalog)
Manage OTC products sold at pharmacies.
/api/v1/sales/products//api/v1/sales/products//api/v1/sales/products/{product_id}/Attributes
iduuidProduct ID
namestringProduct name
skustringStock keeping unit (optional)
categorystringProduct category
retail_pricedecimalRetail price (local currency)
stock_quantityintegerStandalone stock quantity (if not tied to Inventory model)
inventory_itemuuidLinked InventoryItem id (optional)
is_activebooleanWhether product is active and sellable
{
"id": "prod-abc-123",
"name": "Paracetamol 500mg",
"sku": "PARA-500",
"category": "analgesic",
"retail_price": 500,
"stock_quantity": 120,
"inventory_item": "inv-111-222",
"is_active": true
}curl -X POST https://api.mediloop.co/api/v1/sales/products/ -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" -d '{"name":"Paracetamol 500mg","sku":"PARA-500","category":"analgesic","retail_price":500.00,"stock_quantity":120}'Sales Transactions (Point-of-Sale)
Create and manage POS transactions, process payments, and generate receipts.
/api/v1/sales/transactions//api/v1/sales/transactions/{transaction_id}/complete//api/v1/sales/transactions/{transaction_id}/receipt//api/v1/sales/transactions/{transaction_id}/cancel/Create Transaction: Request Body
pharmacy_iduuidrequiredFacility / pharmacy ID
cashierstringrequiredCashier identifier
itemsarrayrequiredList of items: [{product_id, quantity}]
payment_methodstringrequired'cash' or external method (mobile_money, card)
customer_namestringoptionalCustomer name
customer_phonestringoptionalCustomer phone number
discount_amountdecimaloptionalDiscount applied to transaction
notesstringoptionalFree text notes
curl -X POST https://api.mediloop.co/api/v1/sales/transactions/ \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"pharmacy_id":"fac-123","cashier":"alice","items":[{"product_id":"prod-abc-123","quantity":2}],"payment_method":"cash","customer_name":"John Doe","customer_phone":"+256700000000"}'fetch('https://api.mediloop.co/api/v1/sales/transactions/', {
method: 'POST',
headers: {
'Authorization': 'Bearer <TOKEN>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
pharmacy_id: 'fac-123',
cashier: 'alice',
items: [{ product_id: 'prod-abc-123', quantity: 2 }],
payment_method: 'cash'
})
}).then(r => r.json()).then(console.log).catch(console.error);{
"id": "txn-111-222",
"transaction_number": "TXN-0001",
"pharmacy": "fac-123",
"cashier": "alice",
"subtotal": 1000,
"tax_amount": 180,
"discount_amount": 0,
"total_amount": 1180,
"payment_method": "cash",
"payment_status": "completed",
"status": "completed"
}Receipt endpoint
You can fetch transaction receipt as JSON or PDF: ?format=pdf. Add &email=foo@example.com to email the receipt.
curl "https://api.mediloop.co/api/v1/sales/transactions/txn-111-222/receipt/?format=pdf" -H "Authorization: Bearer <TOKEN>"Consultations & Follow-ups
Create pharmacist consultations linked to transactions and schedule follow-ups with notifications.
/api/v1/sales/consultations//api/v1/sales/follow-ups//api/v1/sales/follow-ups/{id}/complete/curl -X POST https://api.mediloop.co/api/v1/sales/follow-ups/ \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"consultation":"consult-111","scheduled_at":"2025-12-21T09:00:00Z","scheduled_by":"pharm1","notes":"Check improvement"}'{
"id": "followup-111",
"consultation": "consult-111",
"scheduled_at": "2025-12-21T09:00:00Z",
"scheduled_by": "pharm1",
"reminder_sent": true,
"completed": false
}Inventory
Inventory endpoints manage stock, movements, alerts, and pharmacy locations.
/api/v1/inventory/stock//api/v1/inventory/movements//api/v1/inventory/pharmacies//api/v1/inventory/alerts/curl -X POST https://api.mediloop.co/api/v1/inventory/movements/ \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"inventory_item":"inv-111","movement_type":"receipt","quantity":100,"notes":"Received PO PO-123"}'{
"id": "movement-111",
"inventory_item": "inv-111",
"movement_type": "receipt",
"quantity": 100,
"quantity_before": 20,
"quantity_after": 120,
"reference_type": "purchase_order",
"reference_id": "PO-123"
}Dispensing
Prescription fulfillment: manage queues, refills and dispenses.
/api/v1/dispensing/dispenses//api/v1/dispensing/queue//api/v1/dispensing/refills/curl -X POST https://api.mediloop.co/api/v1/dispensing/dispenses/ \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"prescription_id":"presc-111","pharmacy_id":"fac-123","pharmacist":"pharm1","items":[{"medication_code":"med-abc","quantity":1}]}'Procurement
Suppliers, purchase orders and goods-received notes.
/api/v1/procurement/purchase-orders//api/v1/procurement/grn/Create GRN (Goods Received Note)curl -X POST https://api.mediloop.co/api/v1/procurement/purchase-orders/ \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"supplier":"sup-111","items":[{"medication_code":"med-abc","quantity":100,"unit_price":450}],"expected_delivery":"2025-12-28"}'{
"id": "po-111",
"supplier": "sup-111",
"status": "created",
"items": [
{
"medication_code": "med-abc",
"quantity": 100,
"unit_price": 450
}
]
}Inventory Management
Track stock levels, record movements, and manage pharmacy locations.
/api/v1/inventory/stock//api/v1/inventory/movements//api/v1/inventory/alerts//api/v1/inventory/pharmacies/curl "https://api.mediloop.co/api/v1/inventory/stock/?pharmacy=fac-123" \
-H "Authorization: Bearer <TOKEN>"curl -X POST https://api.mediloop.co/api/v1/inventory/movements/ \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"pharmacy_id":"fac-123","medication_code":"med-abc","movement_type":"sale","quantity":-1,"reference_type":"transaction","reference_id":"txn-111"}'Compounding
Manage compound formulas, ingredients, and preparation records.
/api/v1/compounding/formulas//api/v1/compounding/preparations/curl -X POST https://api.mediloop.co/api/v1/compounding/preparations/ \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"formula_id":"form-111","batch_size":10,"prepared_by":"pharm1","ingredients_used":[{"ingredient_id":"ing-abc","quantity":5}]}'Returns
Customer and supplier return flows with destruction records.
/api/v1/returns/customer//api/v1/returns/supplier/curl -X POST https://api.mediloop.co/api/v1/returns/customer/ \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"transaction_id":"txn-111","items":[{"product_id":"prod-abc-123","quantity":1}],"reason":"expired"}'Drug Safety
Drug interaction checks, recalls and alerts to keep dispensing safe.
/api/v1/drug-safety/interactions//api/v1/drug-safety/recalls/curl "https://api.mediloop.co/api/v1/drug-safety/interactions/?items=med-abc,med-def" \
-H "Authorization: Bearer <TOKEN>"Cold Chain
Temperature readings, storage units and excursion alerts for temperature-sensitive products.
/api/v1/cold-chain/readings//api/v1/cold-chain/storage-units/Quality Management (QMS)
Incident reporting, CAPA, and audits to support regulatory compliance.
/api/v1/quality/incidents//api/v1/quality/capas//api/v1/quality/audits/curl -X POST https://api.mediloop.co/api/v1/quality/incidents/ \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"reported_by":"staff-1","summary":"Temperature excursion","details":"Cold room was 12°C for 2 hours","severity":"high","attachments":[]}'Analytics & Forecasting
Sales summary, top products, basket analysis, and persisted forecasts.
/api/v1/sales/analytics/summary//api/v1/sales/analytics/basket//api/v1/sales/analytics/forecast/Billing & Notifications
The pharmacy service integrates with a separate Billing service for creating charges and payments, and with a Notification (WhatsApp) service for sending messages and reminders.
/api/v1/charges/Create a billing charge (via billing-service)/api/v1/payments/Process a payment for a charge/api/v1/notifications/send/Send a notification (WhatsApp)curl -X POST https://billing.mediloop.co/api/v1/charges/ \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"patient_uhid":"UG123","service_code":"otc_sales","service_description":"OTC sale TXN-123","quantity":1,"reference_type":"SalesTransaction","reference_id":"txn-111","pharmacy_id":"fac-123"}'{
"id": "charge-abc-123",
"status": "created",
"total_amount": 1180,
"currency": "UGX"
}curl -X POST https://notifications.mediloop.co/api/v1/notifications/send/ -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" -d '{"recipient":"+256700000000","template":"dispense_ready","parameters":{"medication_name":"Paracetamol"}}'Errors & Integration notes
You can download a small Postman starter collection for Pharmacy endpoints from docs/postman/MediLoop_Pharmacy.postman_collection.json. This collection includes sample requests for Products and Transactions to help you start building a frontend quickly.
Common error patterns for pharmacy endpoints:
| Status | When | Suggested handling |
|---|---|---|
| 400 / 422 | Validation errors (bad payload, missing fields) | Show field-level errors to user and prevent submission. |
| 404 | Resource not found (product, transaction, invoice) | Refresh resources, show 'not found' and offer recovery (create / search). |
| 401 / 403 | Authentication / authorization failures | Prompt re-login or request elevated permissions. |
| 502 / 503 | Upstream service unavailable (billing / notifications) | Retry with backoff; show transient error message and log for investigation. |
- All endpoints expect a valid JWT Authorization header:
Authorization: Bearer <token>. - For POS flows, ensure transaction create → (billing charge) → payment → complete sequence is followed to keep records consistent.
- Use the
/api/v1/sales/transactions/{transaction_id}/receipt/?format=pdfendpoint to generate receipt PDFs for printing or email. - Notification and billing integrations are synchronous in the API paths — handle 502/503 and retry according to network best practices.
- Consider using the analytics endpoints to pre-populate recommended merchandising and purchase order suggestions.