Back to Blog

The Rx Order Pipeline: From Manual Faxes to a Trackable System

· 4 min read
Share:
The Rx Order Pipeline: From Manual Faxes to a Trackable System

Part of the Technical Breakdown series on my 4-year engagement with Prestige Men's Health.

Prescription orders are where the clinic's workflow meets a genuinely old-school piece of healthcare infrastructure: most pharmacies still expect orders by fax. The pipeline I built, starting mid-2023, takes an order from creation through PDF generation to the correct pharmacy's fax line — and later, where the pharmacy supports it, through electronic prescription (ePrescription) instead. 76+ commits over about a year and a half, concentrated in two build phases: the initial pipeline in 2023, and a full Filament-based admin rebuild in late 2024.

The initial build: order, generate, fax

The first version covered the basics — create/edit a prescription order, generate the right PDF format, route it to the correct pharmacy's fax number. Even "generate the right PDF" had real edge cases: different pharmacies expect different formats, and a pharmacy-specific quantity-formatting bug ("fix westlake pdf quantity") was exactly the kind of thing you only find once a specific pharmacy's fax machine (or the human reading it) flags that the numbers look wrong.

Problem: PDF previews showing stale or empty data

Two related bugs from the same root cause: the PDF preview endpoint could get cached by the browser and show a previous order's data instead of the current one, and in some cases the preview rendered before the order's line items had fully loaded, producing a technically-valid but empty PDF.

// BEFORE (conceptual)
public function preview(PrescriptionOrder $order)
{
    return response()->view('prescriptions.pdf', ['order' => $order]);
    // No cache-busting — the browser (or an intermediate proxy) can serve
    // a stale previous response for the same URL pattern.
}
// AFTER (conceptual)
public function preview(PrescriptionOrder $order)
{
    $order->loadMissing('lineItems', 'pharmacy', 'client'); // guarantee fully hydrated before render

    return response()
        ->view('prescriptions.pdf', ['order' => $order])
        ->header('Cache-Control', 'no-store, no-cache, must-revalidate')
        ->header('ETag', $order->updated_at->timestamp); // force revalidation on any order change
}

A PDF with missing data isn't a visible error — it's a fax that looks fine until someone at the pharmacy notices a blank dosage field. That's a worse failure mode than a loud error, which is why both the caching and the eager-loading fix mattered together, not just one or the other.

The 2024 rebuild: from a basic CRUD flow to a Filament-managed pipeline

By late 2024, prescription orders got a full admin rebuild on Filament — PrescriptionOrderResource, PrescriptionClientOrderResource, a dedicated pharmacy-manager view, order replication (so a recurring prescription doesn't need to be rebuilt from scratch each cycle), and ePrescription actions wired directly into the admin list view for pharmacies that support electronic routing instead of fax.

// AFTER — app/Filament/Resources/PrescriptionOrderResource.php (conceptual)
class PrescriptionOrderResource extends Resource
{
    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('client.full_name'),
                TextColumn::make('pharmacy.name'),
                TextColumn::make('status')->badge(),
            ])
            ->actions([
                Action::make('replicate')
                    ->icon('heroicon-o-document-duplicate')
                    ->action(fn (PrescriptionOrder $record) => $record->replicate()->save()),
                Action::make('sendEPrescription')
                    ->visible(fn (PrescriptionOrder $record) => $record->pharmacy->supports_eprescribe)
                    ->action(fn (PrescriptionOrder $record) => app(SendEPrescription::class)->handle($record)),
                Action::make('faxOrder')
                    ->visible(fn (PrescriptionOrder $record) => ! $record->pharmacy->supports_eprescribe)
                    ->action(fn (PrescriptionOrder $record) => app(FaxPrescriptionOrder::class)->handle($record)),
            ]);
    }
}

The order-replicate action is a small feature with an outsized impact on day-to-day staff workload — most prescription orders at a clinic like this are recurring, and rebuilding the same order from a blank form every refill cycle is exactly the kind of repetitive task worth eliminating with one button.

The autonomous AI layer, here too

A real Copilot coding-agent PR from the early-2026 batch — copilot/improve-pdf-generation-speed — specifically targeted PDF generation performance on this pipeline, part of the same wave of ~65 autonomous PRs that touched SMS and the Tebra sync. The pattern holds across every subsystem in this series: by 2026, performance and reliability work that used to be a manual profiling session was something an autonomous agent could pick up, fix, and submit as a reviewable PR on its own.


This is one of four deep-dives off the main technical breakdown post — the others cover the SMS communication platform, the Kareo/Tebra EHR sync, and the patient portal.

Share:

Comments

No comments yet — be the first to share your thoughts.

Leave a comment

Your comment will be reviewed before it appears publicly.

Never published — only used if we need to reach you.

More from the blog