EHR Integration Development: HL7, FHIR, and What Actually Works in Production
FHIR is the standard. That doesn't mean EHR integration is simple. Here's what your team needs to know before starting.
FHIR is the future of healthcare interoperability. Every major EHR vendor supports it. Every blog post about healthcare integration mentions it. What’s less discussed: FHIR is a standard for how data should be structured, not how it’s actually delivered from production systems. And you’ll still encounter HL7 v2 in clinics running 10-year-old infrastructure.
Before your team starts building EHR integration, understand what you’re actually integrating with, what will work, and where production reality diverges from the spec.
HL7 v2 vs FHIR R4: Why You’ll Need Both
HL7 v2
HL7 v2 is old. It’s been around since 1989. Despite this — or because of it — it’s the lingua franca of healthcare data. Most EHRs emit HL7 v2 messages for critical events: patient admission, discharge, lab results, billing updates.
An HL7 v2 message looks like this:
MSH|^~\&|SENDING_APP|SENDING_FAC|RECEIVING_APP|RECEIVING_FAC|20261119153000||ADT^A01|MSG00001|P|2.3
EVN||20261119153000|||^Physician Name|
PID|1||123456^^^MRN||DOE^JOHN||19700101|M|...
It’s a pipe-delimited format where each segment type (MSH for header, EVN for event, PID for patient) has a fixed structure. HL7 v2 is:
- Rigid — fields have exact positions; if data is in the wrong position, parsers fail
- Cryptic — the syntax is arcane and differs by message type (ADT for admission/discharge, ORU for lab results)
- Vendor-specific — every EHR implements v2 slightly differently
But it’s also mature, stable, and ubiquitous. If you’re integrating with Epic, Cerner, or any legacy system, you’re parsing HL7 v2.
FHIR R4
FHIR (Fast Healthcare Interoperability Resources) is what HIPAA and CMS want you to use. It’s JSON-based, RESTful, and versioned. A FHIR Patient resource looks like:
{
"resourceType": "Patient",
"id": "123456",
"name": [{ "given": ["John"], "family": "Doe" }],
"birthDate": "1970-01-01",
"gender": "male"
}
FHIR is:
- Flexible — optional fields, extensible; vendors add custom elements without breaking parsing
- Modern — JSON, standards-based, works with REST APIs and webhooks
- Standardized — CMS mandates FHIR for certain data exchanges (patient records via Blue Button, clinical summaries via C-CDA)
Here’s the problem: vendors support both. Epic supports HL7 v2 events (they’ve supported it for 20 years) and FHIR APIs (new). Cerner the same. Your integration needs to handle both, or you’ll hit walls when customers demand features the older protocol doesn’t support.
Vendor-Specific Quirks in Epic and Cerner
Both are market leaders. Both have documented FHIR and HL7 support. Neither implements the standard identically.
Epic
HL7 v2 events:
- Epic emits ORU (Observation Result) messages for lab results, but the OBR segment structure differs from the HL7 v2 spec in undocumented ways
- They use custom ZMI segments for extensions (Zxxx segments are vendor-defined); you need Epic’s Z-segment documentation to parse
- Admission events (ADT^A01) sometimes include nested segments that the standard parser chokes on
FHIR API:
- Epic’s FHIR Patient endpoint works, but nested references aren’t populated by default; you have to request them explicitly with the
_includeparameter - Epic uses a custom authorization model on top of OAuth (Argonaut profile); standard OAuth libraries often need tweaking
- Epic’s sandbox and production systems have different data, so integration testing doesn’t always translate
Cerner
HL7 v2 events:
- Cerner’s Lab Result messages (ORU) have a flatter structure than Epic’s; segments nest differently
- OBX (observation) segments sometimes repeat in ways the v2 spec allows but that catch naive parsers off guard
- Timing: Cerner sends the same event multiple times (soft duplicates); your system needs idempotent handling
FHIR API:
- Cerner’s FHIR endpoints require specific scopes;
launch/patientandpatient/Patient.readare common - Cerner sends FHIR messages as POST requests to your webhook URL (not REST polling); your system needs to listen for inbound webhooks
- Cardinality: a single Cerner Observation might map to multiple FHIR resources or vice versa
SMART on FHIR for Application Authorization
SMART (Substitutable Medical Applications and Reusable Technology) is the standard for how third-party healthcare apps request access to EHR data on behalf of a user.
The flow:
- User launches your app from within the EHR (Epic, Cerner, Athena, etc.)
- Your app redirects to the EHR’s OAuth authorization server
- User approves scope (e.g., “allow this app to read my patient list”)
- EHR returns an authorization code
- Your backend exchanges the code for an access token
- Your app uses the token to call FHIR APIs
Scopes matter. Common ones:
patient/Patient.read— read this patient’s demographic datapatient/Observation.read— read lab results and vitalspatient/MedicationRequest.read— read medicationslaunch— the EHR provides patient context automatically
Understanding scopes before you build saves refactoring. If your app needs allergy information, it needs patient/AllergyIntolerance.read. If the EHR doesn’t expose that scope, your integration stalls.
Real-Time vs Batch Data
Healthcare operates at two speeds.
Real-time (Events):
- Lab results completed → HL7 event emitted immediately → your system receives it via webhook or polling
- Patient admitted → ADT event sent → your system reacts instantly
Real-time is fast and accurate but requires both systems online and synchronized.
Batch (Nightly Exports):
- EHR exports all patient records at 2 AM → SFTP file appears in your system → your system processes it
- Incremental updates → EHR exports only changed records since last export
Batch is slower (hours of lag) but resilient; if your system is down at 2 AM, you catch up when you restart.
Production healthcare systems run both. They use real-time for critical alerts (critical lab values, patient admits) and batch for reconciliation and historical data.
If you’re building a new integration, support both: webhook listeners for events and a background job that polls or imports batch data as a safety net.
Testing Without Production PHI
You cannot and should not use real patient data for development. Doing so violates HIPAA and exposes you to liability.
What to do instead:
Use the EHR’s sandbox:
- Epic has sandboxes that mimic production infrastructure with fake patients
- Cerner provides test instances with synthetic data
- Most EHRs charge a fee for sandbox access (often $3k–$10k/year per vendor)
Generate synthetic data:
- Create test patients in the sandbox with realistic (but fake) data
- Write fixtures that emit HL7/FHIR messages in test environments
- Load test without touching production systems
Unit test parsing:
- Write tests that consume real HL7 v2 messages (from vendor documentation) without hitting a live EHR
- Validate that your parser handles all vendor quirks
Common Failure Modes in Production
Silent parsing failures: You receive a HL7 v2 message in a format your parser doesn’t expect. Instead of raising an exception, it quietly skips the malformed segment. Months later, your clinic discovers that allergies for 1000 patients weren’t synced. You never knew because parsing didn’t error.
Mitigation: log every parsing failure, monitor those logs, alert when unexpected formats appear.
Duplicate processing: An event reaches your system twice (network hiccup retried the message). Your system processes it twice, crediting the same lab result twice or duplicating a medication order.
Mitigation: use idempotent keys. Store a hash of the event; if you see it again, skip it.
Scope and authorization creep: You ship an integration requesting minimal scopes. A year later, a clinic needs a new feature requiring a scope your app doesn’t have. You’re locked out until they re-authorize and re-install the app.
Mitigation: request all scopes you think you’ll need upfront. It’s better to request and not use than to request again later.
Reference data loss:
A FHIR Medication Reference points to medication ID med-456, but your system doesn’t cache what med-456 is. When you query the reference later, it’s missing.
Mitigation: eagerly load and cache reference data; don’t rely on lazy-loading in production.
Webhook reliability: Your app crashes or updates at the same moment the EHR sends a critical alert webhook. The alert is lost because you weren’t listening.
Mitigation: use a message queue (SQS, RabbitMQ) between your webhook receiver and processor. Acknowledge receipt immediately; process asynchronously.
The Integration Order
- Pick one vendor to start — Epic or Cerner, not both. Get one working end-to-end first.
- Start with HL7 v2 — it’s older but more stable; you’ll debug fewer vendor quirks.
- Implement idempotent processing — build it in from day one.
- Test in sandbox — do not test in production.
- Add FHIR after v2 works — once you understand data flow, FHIR integration is incremental.
- Monitor for parse failures — this is your early warning system.
What Actually Works in Production
The teams that ship reliable EHR integrations do three things:
- They understand their vendor’s implementation, not just the spec
- They treat parsing failures as serious bugs, not edge cases
- They have people (maybe rotated) who understand both healthcare operations and integration code
That last one matters most. Developers who’ve never watched a clinic workflow often build integrations that technically work but clash with how clinics actually operate. Spend a day in a clinic. Watch how they use the EHR. That context prevents most integration failures.