Sending to the Right Pharmacy Is Harder Than You Think
When I first started building prescribing workflows, I assumed pharmacy routing would be the easy part. The provider picks a pharmacy, we send the script there. Done. It took about two weeks of integration work to understand why that assumption was wrong.
Routing a prescription to the correct pharmacy requires resolving identifiers most engineers have never encountered, handling a capability matrix that changes without notice, and building fallbacks for when the happy path fails. This is what I've learned.
The identifier problem
Pharmacies have multiple identifiers, and the ones patients know are not the ones you need. A patient says "CVS on Main Street." That's not a database key. What you actually need is an NCPDP ID — a seven-digit identifier assigned to every pharmacy by the National Council for Prescription Drug Programs. This is the ID that e-prescribing networks use to route messages.
The first mistake I made was building a pharmacy search that stored names and addresses. We used those to display options to providers and then tried to look up the NCPDP ID at order time. The lookup was slow and occasionally returned multiple matches for the same physical location. When a chain pharmacy had two entries — one for retail, one for specialty — providers picked the wrong one and the script went nowhere.
Store the NCPDP ID when the patient or provider selects a pharmacy. Display the name. Route with the ID. Never try to resolve the ID at order time from a name or address.
Mail order vs. retail: different pipes, different data
Telehealth companies often want to route to mail-order pharmacies because they serve patients in all fifty states. This seems like a simpler model — one or two pharmacy partners instead of thousands of retail locations. It is simpler until you look at how the data requirements differ.
Retail pharmacies receive prescriptions via the Surescripts network using NCPDP SCRIPT transactions. Mail-order pharmacies often have their own portals, proprietary APIs, or custom EDI feeds on top of that. Some want day-supply fields populated differently. Some want DEA numbers validated against their own registry. A few still prefer fax for certain drug classes even when they technically support e-prescribing.
We spent two weeks integrating with one mail-order partner only to discover they expected a custom field in a non-standard namespace. Their documentation didn't mention it. We found out when orders started failing silently — the script left our system with a success response and never appeared in their queue.
If you're integrating with mail-order partners directly, budget time for test order validation, not just API connectivity. A 200 response from their ingest endpoint does not mean the order was accepted.
Not every pharmacy can receive e-prescriptions
This one surprised me. The Surescripts network covers the overwhelming majority of retail pharmacies in the United States, but coverage is not universal. Small independent pharmacies in rural areas sometimes fall outside it. Compounding pharmacies frequently do. Veterinary pharmacies almost always do.
Your prescribing vendor can usually check whether a given NCPDP ID is capable of receiving electronic prescriptions before you try to send. Use that check. Build it into your pharmacy selection flow, not as an afterthought at order submission time. When a provider selects a pharmacy that can't receive e-scripts, tell them before they finish writing the order — not after they hit submit.
For pharmacies outside the network, fax fallback is still common. Some e-prescribing vendors handle this transparently. Others require you to handle the routing decision yourself. Know which you're working with before you build the selection UI.
The same pharmacy, three different IDs
Here's something nobody warned me about: a single physical pharmacy location can have multiple NCPDP IDs. A large retail chain pharmacy might have one ID for its retail counter and a separate ID for its on-site specialty pharmacy. A hospital outpatient pharmacy can have additional IDs for different departments.
This matters when you're pre-populating a "preferred pharmacy" for a patient. If a patient filled a specialty medication at a chain pharmacy using the specialty NCPDP ID and you save that for future use, their next regular prescription might get routed to the specialty counter and either rejected or delayed.
We ended up showing providers the pharmacy type alongside the name in our search results — "CVS Pharmacy (Retail)" vs "CVS Specialty (Specialty)." It added a couple of hours of UI work and eliminated a recurring category of misdirected orders.
What to do when routing fails
Even with all of this in place, orders fail to route. Pharmacy systems go offline. The network has transient errors. An NCPDP ID that worked yesterday stops accepting messages today because the pharmacy closed or changed systems.
Your vendor will typically return a routing error that tells you the destination couldn't be reached. What they won't tell you is what to do next. That's your problem to solve.
We built a simple fallback: if routing fails, we surface a "redirect to a different pharmacy" action in our care coordinator dashboard. The original order stays in a pending state. When the coordinator selects a new destination, we re-route. This avoided the worst outcome, which was providers rewriting orders from scratch and creating duplicate prescriptions.
What I'd do on day one
- Store NCPDP IDs, not names or addresses. Resolve the ID when the patient or provider makes their pharmacy selection, then carry it through the entire order lifecycle.
- Check e-prescribing capability before the order is written. Your vendor almost certainly exposes a lookup for this. Use it in your pharmacy search results, not at submission time.
- Show pharmacy type in search results. Retail, specialty, mail-order, compounding — make this visible so providers don't route to the wrong counter.
- Test with real mail-order partners end to end. API connectivity is not the same as successful order ingestion. Submit test orders and confirm they appear in the destination queue.
- Build a routing failure workflow before launch. It will happen. Having a care coordinator action ready is cheaper than building it reactively after a patient calls asking where their medication is.
Pharmacy routing is one of those problems that looks solved at the API level and reveals its complexity when you're handling real patients. Getting it right early saves a lot of support tickets and a lot of awkward calls to patients explaining why their prescription is at the wrong counter across town.