> ## Documentation Index
> Fetch the complete documentation index at: https://docs.adhdsimple.co.uk/llms.txt
> Use this file to discover all available pages before exploring further.

# Prescription Workflow

> Prescription management system architecture with service layer integration

## Architecture

```mermaid theme={null}
graph TB
    Patient[Patient Record] --> Create[Create Prescription]
    Create --> Service[PrescriptionService]
    Service --> Form[Prescription Form]
    Form --> Review[Clinical Review]
    Review --> Valid{Valid Prescription?}
    Valid -->|No| Edit[Edit Prescription]
    Valid -->|Yes| EdgeFunc[clinical-prescription-operations]
    EdgeFunc --> Save[Save to Database]
    Save --> Payment[Payment Processing]
    Payment --> Shipment[Create DHL Shipment]
    Shipment --> Pharmacy[Pharmacy Processing]
    Pharmacy --> Dispatch[Dispatch Medication]
    Dispatch --> Tracking[DHL Tracking]
    Tracking --> Delivery[Patient Delivery]
    
    Edit --> Service
    
    subgraph "28-Day Cycle"
        Delivery --> Monitor[Health Monitoring]
        Monitor --> Repeat[Repeat Prescription]
        Repeat --> Create
    end
```

## Components

### Prescription Form

* **Purpose**: Captures clinical prescription data
* **Technology**: React form with validation
* **Service Integration**: PrescriptionService
* **Key Functions**:
  * Medication selection with dosage
  * Patient health metrics input
  * Clinical pathway tracking

### Service Layer Operations

* **Purpose**: Business logic and data processing
* **Technology**: TypeScript services with Zod validation
* **Service Integration**: PrescriptionService
* **Key Functions**:
  * Prescription creation via PrescriptionService.create()
  * Order validation and compliance checking
  * Payment processing integration
  * Shipment creation coordination

### Edge Function Processing

* **Purpose**: Secure server-side operations
* **Technology**: clinical-prescription-operations Edge Function
* **Key Functions**:
  * Prescription record creation
  * Health metrics storage
  * Audit trail logging
  * Controlled drug compliance monitoring

### DHL Integration

* **Purpose**: Automated medication delivery
* **Technology**: DHL API via ShipmentService
* **Key Functions**:
  * Shipment creation with tracking
  * Van pickup scheduling
  * Delivery confirmation handling

## Clinical Pathways

### New Patient

Patient assessment → titration prescriptions → health monitoring → dosage adjustments.

### Stable Patient

Routine 28-day prescriptions → minimal monitoring → automatic renewals.

### Titration Patient

Frequent prescriptions → intensive monitoring → dosage optimization.

## Service Layer Integration

### Frontend to Service

* **PrescriptionService.create()** - Creates prescription orders
* **PrescriptionService.getById()** - Retrieves prescription details
* **PrescriptionService.update()** - Updates prescription status
* **PaymentService.processPayment()** - Handles payment processing
* **ShipmentService.createShipment()** - Creates DHL shipments

### Service to Edge Functions

* **clinical-prescription-operations** - Prescription CRUD operations
* **clinical-payment-operations** - Payment processing
* **clinical-shipment-operations** - Shipment management
* **prescription-notifications** - Patient notifications

<Note>
  **All prescriptions follow 28-day cycles for controlled drug compliance and are processed through the service layer architecture**
</Note>
