Architecting Rx-Gated E-commerce with EMR Integration: Best Path for Authorize-Only Payments and Clinical Approval Workflow
Source: Dev.to
Overview
How would you architect an e‑commerce build for a longevity clinic given the following requirements?
- Some SKUs require a prescription (including injectables), others are OTC, plus memberships and subscription packages.
- The critical requirement is medical review prior to final payment capture for Rx‑required SKUs.
High‑level Flow
- Customer places an order.
- If the cart contains any Rx‑required SKU, the payment is authorized only (no capture).
- A medical‑risk assessment (rules‑based binary decision model) runs using clinic‑supplied thresholds and patient context.
Outcomes
| Result | Action |
|---|---|
| Approved | Capture payment and fulfill the order. |
| More action required | Hold the authorization, trigger a telehealth consult scheduling within 7 days, then a clinician manually approves or denies. After the decision, capture the payment or void/refund. |
Architecture Pathways
1. Custom or Headless Commerce with Middleware Orchestration
- Build a headless storefront (e.g., React, Next.js) that talks to a middleware orchestration service.
- The middleware implements an order state machine, integrates a rules engine for medical‑risk assessment, and handles EMR synchronization.
- Payment provider is called with an authorize‑only request; capture is performed only after clinical approval.
2. WooCommerce (Self‑Hosted) with Custom Plugins
- Use WooCommerce as the base e‑commerce platform.
- Develop custom plugins to:
- Detect Rx‑required SKUs in the cart.
- Perform an authorize‑only transaction.
- Call out to a rules engine and the clinic’s EMR for medical review.
- Manage the hold, capture, or void workflow based on the clinician’s decision.
3. Split Model: Non‑Rx Storefront + Rx Enrollment Portal
- Separate the public storefront (OTC, memberships, subscriptions) from an Rx enrollment portal.
- The portal handles eligibility checks, telehealth scheduling, and clinical approval before any payment is taken.
- Reduces policy risk on the commerce platform because the payment for Rx items is only processed after clinical clearance.
4. Alternative Architecture (Not Yet Considered)
- Serverless Event‑Driven Architecture:
- Use a serverless function (e.g., AWS Lambda) triggered on order creation to start the authorization flow.
- Store order state in a durable store (DynamoDB, Firestore).
- Publish events to a message bus (SNS, Pub/Sub) that invoke the rules engine and EMR integration.
- A separate workflow (Step Functions, Cloud Workflows) handles telehealth scheduling, clinician review, and final capture/void actions.
Recommendation Question
Which architecture is most robust for authorize‑only then capture after clinical approval, especially with telehealth escalation and manual overrides?