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

GET/api/v1/sales/products/List OTC products (catalog)
POST/api/v1/sales/products/Create OTC product
GET/api/v1/sales/products/{id}/Get product details
POST/api/v1/sales/transactions/Create sales transaction
GET/api/v1/sales/transactions/List transactions
GET/api/v1/sales/transactions/{id}/Get transaction details
POST/api/v1/sales/transactions/{id}/complete/Complete transaction (payment & finalize)
GET/api/v1/sales/transactions/{id}/receipt/Get receipt (JSON/PDF)
POST/api/v1/sales/consultations/Create customer consultation
POST/api/v1/sales/follow-ups/Schedule follow-up & notify
GET/api/v1/sales/loyalty-programs/List loyalty programs
POST/api/v1/sales/loyalty-accounts/Create loyalty account
GET/api/v1/sales/analytics/Sales analytics & forecasting
GET/api/v1/sales/ai-recommendations/AI product recommendations
GET/api/v1/inventory/medications/Medication catalog
GET/api/v1/inventory/pharmacies/Pharmacy locations
GET/api/v1/inventory/stock/Inventory items & quantities
POST/api/v1/inventory/movements/Record stock movements
GET/api/v1/inventory/alerts/Stock alerts & notifications
POST/api/v1/dispensing/dispenses/Create dispense record
GET/api/v1/dispensing/queue/Prescription dispensing queue
POST/api/v1/dispensing/refills/Request prescription refill
GET/api/v1/procurement/suppliers/List suppliers
POST/api/v1/procurement/suppliers/Create supplier
GET/api/v1/procurement/supplier-medications/Supplier medication catalog
POST/api/v1/procurement/purchase-orders/Create purchase order
GET/api/v1/procurement/purchase-orders/List purchase orders
POST/api/v1/procurement/grn/Create goods received note
GET/api/v1/drug-safety/interactions/Drug interaction checks
GET/api/v1/drug-safety/allergies/Drug allergy database
GET/api/v1/drug-safety/recalls/Drug recall alerts
GET/api/v1/drug-safety/controlled-substances/Controlled substances
POST/api/v1/drug-safety/controlled-register/Record controlled substance transaction
GET/api/v1/drug-safety/alerts/Safety alerts
GET/api/v1/cold-chain/storage-units/Cold storage units
GET/api/v1/cold-chain/readings/Temperature readings
GET/api/v1/cold-chain/excursions/Temperature excursions
GET/api/v1/cold-chain/products/Cold chain products
POST/api/v1/cold-chain/transports/Record cold chain transport
GET/api/v1/compounding/formulas/Compound formulas
GET/api/v1/compounding/ingredients/Formula ingredients
POST/api/v1/compounding/preparations/Record compound preparation
POST/api/v1/returns/customer/Create customer return
POST/api/v1/returns/supplier/Create supplier return
POST/api/v1/returns/destruction/Record drug destruction
POST/api/v1/quality/incidents/Report quality incident
GET/api/v1/quality/capas/Corrective/Preventive Actions
GET/api/v1/quality/audits/Quality audits

Pharmacy 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.

  1. Product Search: GET /api/v1/sales/products/ with search parameters
  2. AI Recommendations: GET /api/v1/sales/ai-recommendations/ for personalized suggestions
  3. Create Transaction: POST /api/v1/sales/transactions/ with items array
  4. Customer Consultation: POST /api/v1/sales/consultations/ if needed
  5. Process Payment: POST /api/v1/sales/transactions/{id}/complete/
  6. Generate Receipt: GET /api/v1/sales/transactions/{id}/receipt/?format=pdf
  7. Schedule Follow-up: POST /api/v1/sales/follow-ups/ if required
  8. 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.

  1. Check Queue: GET /api/v1/dispensing/queue/ for pending prescriptions
  2. Verify Patient: Check patient details via Patients API
  3. Drug Interactions: GET /api/v1/drug-safety/interactions/ for all medications
  4. Allergy Check: GET /api/v1/drug-safety/allergies/ for patient allergies
  5. Controlled Substances: Check /api/v1/drug-safety/controlled-substances/ if applicable
  6. Inventory Check: GET /api/v1/inventory/stock/ for medication availability
  7. Create Dispense: POST /api/v1/dispensing/dispenses/ with prescription details
  8. Record Controlled Transaction: POST /api/v1/drug-safety/controlled-register/ if controlled
  9. Update Inventory: POST /api/v1/inventory/movements/ for stock reduction
  10. Send Notification: Use Notifications API for pickup ready alerts

Inventory Management Workflow

Maintain optimal stock levels with automated procurement, stock alerts, and movement tracking.

  1. Monitor Stock Levels: GET /api/v1/inventory/stock/ regularly
  2. Check Alerts: GET /api/v1/inventory/alerts/ for low stock notifications
  3. Find Suppliers: GET /api/v1/procurement/suppliers/ for available vendors
  4. Check Supplier Catalog: GET /api/v1/procurement/supplier-medications/
  5. Create Purchase Order: POST /api/v1/procurement/purchase-orders/
  6. Receive Goods: POST /api/v1/procurement/grn/ when delivery arrives
  7. Record Stock Movement: POST /api/v1/inventory/movements/ for receipts
  8. 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.

  1. Customer Return: POST /api/v1/returns/customer/ with return details
  2. Inspect Returned Items: Check condition and expiry
  3. Supplier Return: POST /api/v1/returns/supplier/ if needed
  4. Drug Destruction: POST /api/v1/returns/destruction/ for expired/unusable drugs
  5. Report Incident: POST /api/v1/quality/incidents/ for quality issues
  6. Create CAPA: Use /api/v1/quality/capas/ for corrective actions
  7. Schedule Audit: Use /api/v1/quality/audits/ for compliance checks

Compounding Workflow

Prepare custom compounded medications with formula management and quality control.

  1. Select Formula: GET /api/v1/compounding/formulas/ for approved formulas
  2. Check Ingredients: GET /api/v1/compounding/ingredients/ for formula components
  3. Verify Stock: GET /api/v1/inventory/stock/ for ingredient availability
  4. Record Preparation: POST /api/v1/compounding/preparations/
  5. Quality Testing: Document testing results
  6. Label & Dispense: Follow dispensing workflow for delivery

Products (OTC catalog)

Manage OTC products sold at pharmacies.

GET/api/v1/sales/products/
POST/api/v1/sales/products/
GET/api/v1/sales/products/{product_id}/

Attributes

iduuid

Product ID

namestring

Product name

skustring

Stock keeping unit (optional)

categorystring

Product category

retail_pricedecimal

Retail price (local currency)

stock_quantityinteger

Standalone stock quantity (if not tied to Inventory model)

inventory_itemuuid

Linked InventoryItem id (optional)

is_activeboolean

Whether product is active and sellable

RESPONSE200
{
  "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
}
Create product (request)
bash
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.

POST/api/v1/sales/transactions/
POST/api/v1/sales/transactions/{transaction_id}/complete/
GET/api/v1/sales/transactions/{transaction_id}/receipt/
POST/api/v1/sales/transactions/{transaction_id}/cancel/

Create Transaction: Request Body

pharmacy_iduuidrequired

Facility / pharmacy ID

cashierstringrequired

Cashier identifier

itemsarrayrequired

List of items: [{product_id, quantity}]

payment_methodstringrequired

'cash' or external method (mobile_money, card)

customer_namestringoptional

Customer name

customer_phonestringoptional

Customer phone number

discount_amountdecimaloptional

Discount applied to transaction

notesstringoptional

Free text notes

Request: create transaction (curl)
bash
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"}'
Request: create transaction (fetch)
javascript
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);
RESPONSE201
{
  "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.

Download PDF receipt
bash
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.

POST/api/v1/sales/consultations/
POST/api/v1/sales/follow-ups/
POST/api/v1/sales/follow-ups/{id}/complete/
Request: schedule follow up
bash
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"}'
RESPONSE200
{
  "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.

GET/api/v1/inventory/stock/
POST/api/v1/inventory/movements/
GET/api/v1/inventory/pharmacies/
GET/api/v1/inventory/alerts/
Record stock movement (request)
bash
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"}'
RESPONSE200
{
  "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.

POST/api/v1/dispensing/dispenses/
GET/api/v1/dispensing/queue/
POST/api/v1/dispensing/refills/
Create a dispense
bash
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.

POST/api/v1/procurement/purchase-orders/
POST/api/v1/procurement/grn/Create GRN (Goods Received Note)
Create purchase order
bash
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"}'
RESPONSE201
{
  "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.

GET/api/v1/inventory/stock/
POST/api/v1/inventory/movements/
GET/api/v1/inventory/alerts/
GET/api/v1/inventory/pharmacies/
Check stock levels
bash
curl "https://api.mediloop.co/api/v1/inventory/stock/?pharmacy=fac-123" \
  -H "Authorization: Bearer <TOKEN>"
Record stock movement
bash
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.

GET/api/v1/compounding/formulas/
POST/api/v1/compounding/preparations/
Record compound preparation
bash
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.

POST/api/v1/returns/customer/
POST/api/v1/returns/supplier/
Create customer return
bash
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.

GET/api/v1/drug-safety/interactions/
GET/api/v1/drug-safety/recalls/
Check interaction
bash
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.

POST/api/v1/cold-chain/readings/
GET/api/v1/cold-chain/storage-units/

Quality Management (QMS)

Incident reporting, CAPA, and audits to support regulatory compliance.

POST/api/v1/quality/incidents/
POST/api/v1/quality/capas/
POST/api/v1/quality/audits/
Report incident
bash
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.

GET/api/v1/sales/analytics/summary/
GET/api/v1/sales/analytics/basket/
GET/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.

POST/api/v1/charges/Create a billing charge (via billing-service)
POST/api/v1/payments/Process a payment for a charge
POST/api/v1/notifications/send/Send a notification (WhatsApp)
Create charge (example)
bash
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"}'
RESPONSE201
{
  "id": "charge-abc-123",
  "status": "created",
  "total_amount": 1180,
  "currency": "UGX"
}
Send notification (example)
bash
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:

StatusWhenSuggested handling
400 / 422Validation errors (bad payload, missing fields)Show field-level errors to user and prevent submission.
404Resource not found (product, transaction, invoice)Refresh resources, show 'not found' and offer recovery (create / search).
401 / 403Authentication / authorization failuresPrompt re-login or request elevated permissions.
502 / 503Upstream 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=pdf endpoint 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.