Doctors Who Code
Practical
Interoperability
FHIR  and  EMR  Integration
# your_first_fhir_call.py

import fhirclient
from fhirclient import client

settings = {
  'app_id': 'mfm_app',
  'api_base': EPIC_SANDBOX
}

smart = client.FHIRClient(
  settings=settings
)
The Problem
The Walled Garden Problem
EMRs hold the most clinically relevant data on the planet — yet most physician-developers cannot programmatically touch it.

This isn't a data problem.

It's an access problem.

🗄️

Data Silos

Lab results, imaging, notes — locked inside proprietary systems with no standard exit.

🔌

No Standard Interface

Every EMR vendor built their own API before FHIR. HL7 v2 messages are a relic of the fax era.

👩‍⚕️

Physician Exclusion

Clinicians who understand the data best have historically had zero access to extract or transform it.

FHIR Explained

What is FHIR — and Why Should You Care?

FHIR (Fast Healthcare Interoperability Resources) is HL7's RESTful API standard for exchanging healthcare data. It uses JSON/XML resources over HTTPS — the same stack you already know.
Resource
Patient
Demographics, identifiers, contact info
GET /fhir/R4/Patient
Resource
Observation
Vitals, labs, fetal measurements, CGM data
GET /fhir/R4/Observation
Resource
Condition
ICD-10-coded diagnoses and clinical findings
GET /fhir/R4/Condition
Resource
MedicationRequest
Prescriptions, dosing, clinical indications
GET /fhir/R4/MedicationRequest
The Opportunity
Why the Physician-Developer
Is FHIR's Most Important User
"The clinician who writes the guideline is also the one who can build the API wrapper that puts it to work at the bedside."
— DoctorsWhoCode.blog

Clinical Insight

You already know which data points matter. You don't need a product manager to explain the clinical context of a hemoglobin A1c.

Guideline Authority

SMFM, ACOG, ADA guidelines live in your head. FHIR lets you encode them as executable logic, not static PDFs.

Trust & Adoption

Physician-built tools have credibility with clinical colleagues that vendor tools never will.

Tutorial Step 0

Setting Up Your FHIR Sandbox Environment

01

Register on Epic's Open Portal

Visit open.epic.com and create a free developer account. No EHR contract or enterprise agreement required.

02

Create a Sandbox Application

Generate client credentials (Client ID + SMART launch URL). Select FHIR R4 as the API version — this is the current standard.

03

Install the Python FHIR Client

pip install fhirclient — The canonical Python wrapper over the FHIR REST API. Wraps OAuth 2.0 and resource serialization.

04

Point to the Sandbox Base URL

Epic sandbox base: fhir.epic.com/interconnect-amcurr-oauth/api/FHIR/R4. All API calls target this endpoint with your credentials.

Tutorial: First API Call
Demystifying FHIR:
Your First Patient
Record Pull
Pull a mock patient record from the Epic sandbox using 6 lines of Python.
# patient_pull.py
import fhirclient.models.patient as p
from fhirclient import client

settings = {
  'app_id': 'my_mfm_app',
  'api_base': 'https://fhir.epic.com/...'
}

smart = client.FHIRClient(settings=settings)

# Fetch a test patient by FHIR ID
patient = p.Patient.read('eD4W...', smart.server)

print(patient.name[0].given,
      patient.name[0].family)
JSON Response (excerpt)
{
  "resourceType": "Patient",
  "id": "eD4WJsigGxQHXMp...",
  "name": [{
    "family": "Johnson",
    "given": ["Maria"]
  }],
  "birthDate": "1991-04-17",
  "gender": "female",
  "identifier": [{
    "system": "urn:oid:1.2.840...",
    "value": "202031"
  }]
}
Authentication Layer

SMART on FHIR: The Authorization Standard

1App Launch
EHR opens your app via SMART launch URL with context parameters
2Auth Request
App redirects to EHR authorization server with scopes (patient/*.read)
3User Consent
Clinician approves access. EHR issues authorization code.
4Token Exchange
App exchanges code for access token + patient context ID
5FHIR API Call
App calls FHIR endpoints using Bearer token in Authorization header
Key scope: patient/*.read — grants read access to all FHIR resources for the in-context patient. Start here; narrow later.
Case Study
Escaping the Walled Garden: FGRManager as SMART App
FGRManager operationalizes SMFM Consult Series #52 — fetal growth restriction surveillance and delivery timing. As a SMART app, it would auto-populate EFW, AC, and umbilical artery Dopplers directly from the FHIR Observation resource.
Static HTML Tool SMART on FHIR App

FGRManager.html receives patient context on EHR launch via SMART protocol

Manual Data Entry Live FHIR Pull

Observation resources (EFW, AC percentile) populate fields automatically from the EMR

Isolated Algorithm Interoperable Standard

Delivery timing recommendations can be written back as FHIR CarePlan resources

Content Series

Practical Interoperability: The Series Roadmap

POST 01 Foundational
Demystifying FHIR: A Physician's Guide to Making Your First API Call
Coverage:
  • Setting up the Epic FHIR sandbox
  • OAuth 2.0 authentication in Python
  • Pulling Patient + Observation resources
  • Parsing JSON responses into clinical data structures
POST 02 Advanced
Escaping the Walled Garden: How to Build a Local SMART on FHIR App
Coverage:
  • SMART on FHIR launch protocol
  • Wrapping FGRManager as a SMART app
  • Auto-populating clinical data from EMR
  • Writing CarePlan resources back to EHR
Start Building
The EMR has an API.
You have Python.
What are you waiting for?
DoctorsWhoCode.blog