Skip to main content

Introduction

OptiFlow provides comprehensive prescription management for optical stores. Create detailed eye prescriptions, link them to patients and workflow jobs, and automatically generate professional PDF documents.

Prescription Data Model

The Prescription model (app/Models/Prescription.php) stores complete optometric examination data.

Core Fields

  • Patient: Link to the customer contact receiving the prescription
  • Optometrist: Link to the optometrist who performed the examination
  • Workspace: Multi-tenant workspace association
  • Created Date: Automatic timestamp with human-readable formatting

Clinical Data

Prescriptions store comprehensive optometric data through relationships with mastertable items:
Why the patient visited (e.g., blurry vision, eye strain, routine checkup)
Patient’s current health conditions that may affect eye health
Family history of eye conditions (glaucoma, cataracts, etc.)

Visual Acuity Measurements

Prescriptions include detailed measurements for both eyes: Right Eye (OD - Oculus Dexter):
  • Sphere (SPH)
  • Cylinder (CYL)
  • Axis
  • Visual Acuity
  • Pupillary Distance
Left Eye (OS - Oculus Sinister):
  • Sphere (SPH)
  • Cylinder (CYL)
  • Axis
  • Visual Acuity
  • Pupillary Distance
All measurements follow standard optometric notation for consistency across the industry.

Creating Prescriptions

From the Interface

The PrescriptionController handles prescription creation:
1

Navigate to Prescriptions

Access the prescriptions section from the main navigation.
2

Click Create Prescription

Start a new prescription form.
3

Select Patient

Search for and select the patient (customer contact). You can pre-fill this with ?contact_id=123 query parameter.
4

Select Optometrist

Choose the optometrist who performed the examination. You can pre-fill this with ?optometrist_id=456.
5

Enter Clinical Data

Fill in consultation reasons, health status, family history, and recommendations using the mastertable selections.
6

Record Measurements

Enter sphere, cylinder, axis, and visual acuity for both eyes.
7

Save

Submit the prescription. It’s immediately available for viewing and PDF generation.

Pre-filling Forms

You can link directly to the prescription creation form with pre-selected values:
/prescriptions/create?contact_id=<patient-id>&optometrist_id=<optometrist-id>
This is useful when creating prescriptions from a patient’s profile or during workflow job processing.
The contact search uses the ContactSearch service with role filtering. Patients must have the “customer” role, and optometrists must have the “optometrist” role.

Managing Prescriptions

Listing Prescriptions

The prescriptions index uses the PrescriptionsTable for displaying data:
// app/Tables/PrescriptionsTable.php
// Provides sortable, filterable table of all prescriptions
Displayed Columns:
  • Patient name
  • Optometrist name
  • Creation date (with human-readable format)
  • Workspace
  • Actions (view, edit, download)

Viewing Prescription Details

The show view displays the complete prescription:
// Loads all relationships:
$prescription->load([
    'patient',
    'optometrist',
    'workspace',
    'motivos',
    'estadoActual',
    'historiaOcularFamiliar',
    'lentesRecomendados',
]);
Display Includes:
  • Patient and optometrist information
  • All clinical data and recommendations
  • Visual acuity measurements for both eyes
  • Company details (from CompanyDetail::getAll())
  • Creation timestamp with human-readable format

Editing Prescriptions

The edit form pre-populates all existing data:
// Transform prescription data for the form
$prescriptionData = $prescription->toArray();
$prescriptionData['motivos_consulta'] = $prescription->motivos->pluck('id')->all();
$prescriptionData['estado_salud_actual'] = $prescription->estadoActual->pluck('id')->all();
$prescriptionData['historia_ocular_familiar'] = $prescription->historiaOcularFamiliar->pluck('id')->all();
All mastertable relationships are transformed to ID arrays for easy form binding.
Editing a prescription creates a new version in some systems. Check your business requirements before allowing prescription edits.

Linking Prescriptions to Workflow Jobs

Prescriptions can be linked to workflow jobs via the prescription_id field on WorkflowJob:
// app/Models/WorkflowJob.php
public function prescription(): BelongsTo
{
    return $this->belongsTo(Prescription::class);
}

Workflow Integration

Workflows can require prescriptions:
// app/Models/Workflow.php
'prescription_requirement' => 'optional' | 'required'
Use Cases:
  • Required: Prescription eyewear orders must have a prescription
  • Optional: Contact lens orders may or may not need a new prescription
When a workflow requires a prescription, the job creation form will enforce this requirement before allowing the job to be saved.

PDF Generation

OptiFlow automatically generates professional PDF prescriptions using the DownloadPrescriptionController.

How It Works

// app/Http/Controllers/DownloadPrescriptionController.php
public function __invoke(Prescription $prescription): Response
{
    $prescription->load([
        'motivos',
        'estadoActual',
        'historiaOcularFamiliar',
        'lentesRecomendados',
        'gotasRecomendadas',
        'monturasRecomendadas',
        'workspace',
        'patient',
        'optometrist',
    ]);

    $pdf = Pdf::loadView('prescriptions.pdf', [
        'prescription' => $prescription,
        'company' => CompanyDetail::getAll(),
    ])->setPaper('a4', 'portrait');

    $filename = "receta-{$prescription->patient->name}-{$prescription->id}.pdf";

    return $pdf->stream($filename);
}

PDF Contents

The generated PDF includes:
  • Company logo and details
  • Patient information (name, contact details)
  • Optometrist information
  • Examination date
  • Visual acuity measurements (right and left eye)
  • Clinical data (consultation reasons, health status, family history)
  • Recommendations (lenses, frames, eye drops)
  • Professional formatting and layout

Downloading PDFs

Users can download prescription PDFs from:
  • The prescription detail page
  • The prescriptions table (action menu)
  • Direct link: /prescriptions/{id}/download
PDFs are generated on-demand using DomPDF. The DOMPDF_ENABLE_REMOTE constant is set to false for security.

Prescription Reports

OptiFlow includes built-in prescription reports:

Prescriptions Summary Report

// app/Reports/PrescriptionsSummaryReport.php
// Provides overview of prescriptions over time
Metrics:
  • Total prescriptions created
  • Prescriptions by optometrist
  • Prescriptions by time period
  • Most common recommendations

Prescriptions by Doctor Report

// app/Reports/PrescriptionsByDoctorReport.php
// Breaks down prescription volume by optometrist
Insights:
  • Which optometrists are most active
  • Average prescriptions per doctor
  • Trends over time
Use these reports for performance tracking, resource planning, and understanding your optometry service utilization.

Mastertable Integration

Prescriptions use mastertables for standardized clinical data.

Available Mastertables

  • motivos_consulta - Consultation reasons
  • estado_salud_actual - Current health status
  • historia_ocular_familiar - Family eye history
  • tipos_de_lentes - Lens types
  • tipos_de_montura - Frame types
  • tipos_de_gotas - Eye drop types

Many-to-Many Relationships

Prescriptions use pivot tables to link multiple items:
public function lentesRecomendados(): BelongsToMany
{
    return $this->belongsToMany(
        MastertableItem::class,
        'prescription_item',
        'prescription_id',
        'mastertable_item_id'
    )
    ->wherePivot('mastertable_alias', 'tipos_de_lentes')
    ->withPivot('mastertable_alias');
}
This allows prescriptions to have multiple recommendations (e.g., both progressive and anti-reflective lenses).
Mastertables are customizable. Optical stores can add their own consultation reasons, lens types, and recommendations specific to their practice.

Permissions

Prescription access is controlled by permissions:
  • PrescriptionsView - View prescriptions
  • PrescriptionsCreate - Create new prescriptions
  • PrescriptionsEdit - Modify existing prescriptions
// Example permission check in controller
abort_unless($user->can(Permission::PrescriptionsCreate), 403);
Ensure that only qualified optometrists have permission to create and edit prescriptions. Prescriptions are medical documents and should be treated with appropriate access controls.

Best Practices

Always double-check patient details before creating a prescription. Incorrect patient linking can cause serious issues.
Fill in all visual acuity fields. Incomplete prescriptions may not be usable by labs or dispensing staff.
After creating a prescription, generate and review the PDF to ensure all data appears correctly.
Standardize your mastertable items across all optometrists for consistent reporting and data analysis.
Prescription data is critical. Ensure your workspace includes prescriptions in regular database backups.

Integration with Automations

Prescriptions can trigger automations when linked to workflow jobs: Example Automation: When a job with a prescription enters the “Ready for Pickup” stage, automatically send the prescription PDF to the customer via WhatsApp.
// In automation context:
$context = new AutomationContext(
    job: $workflowJob,
    // ...
);

// Prescription is accessible via:
$workflowJob->prescription
Combine prescriptions with automations to automatically notify customers when their prescription eyewear is ready and include the prescription PDF for their records.

Common Use Cases

Eye Exam to Order

Create prescription during eye exam, then immediately create a workflow job for eyewear order.

Prescription History

View patient’s complete prescription history to track vision changes over time.

Insurance Claims

Generate prescription PDFs for insurance claim submissions.

Lab Orders

Include prescription details when sending orders to external lens labs.

Prescription Lifecycle

1

Examination

Optometrist performs eye examination and determines prescription values.
2

Creation

Prescription is created in OptiFlow with all measurements and recommendations.
3

Review

Optometrist reviews the prescription and generates PDF for patient.
4

Order Creation

If patient wants eyewear, create a workflow job and link the prescription.
5

Fulfillment

Workflow job progresses through stages. Prescription data is available at each stage.
6

Delivery

Customer receives eyewear along with printed prescription for their records.

Workflows Overview

Learn how prescriptions integrate with workflows

Building Automations

Automate prescription delivery and notifications

Build docs developers (and LLMs) love