FHIR R4 US Core System API over athenaOne REST — Patient, Organization (departments), and Encounter resources with OAuth token caching, athenaOne-to-FHIR DataWeave transforms, and auto-pagination for patient search.
AthenaHealth Patient FHIR System API
Objective: Deploy the Athena Health FHIR R4 US Core Patient System API (hls-athenahealth-patient-fhir-sapi) — a Mule 4 System API that exposes FHIR R4 resources to Process and Experience APIs while calling athenaOne proprietary REST (and a department-scoped FHIR DSTU2 Encounter endpoint) on the back end. Consumers speak application/fhir+json or application/fhir+xml; the implementation handles OAuth, practice scoping, DataWeave mapping, and athenaOne pagination. This is the athenahealth EHR unlock — not a Health Cloud sync. Pair it under Patient 360: EHR to Salesforce Health Cloud when the source EHR is athenahealth.
What's Getting Built
- Athena Health FHIR R4 US Core Patient API (System API) — FHIR R4 US Core facade over athenaOne REST with practice scoping and DataWeave mapping ·
GET /{ehr-version}/{practiceId}/Patients, GET /{ehr-version}/{practiceId}/Patients/{id}, POST /{ehr-version}/{practiceId}/Patients, GET /{ehr-version}/{practiceId}/Organization, GET /{ehr-version}/{practiceId}/Encounter, POST /$sync
- OAuth token cache (Object Store) — private Object Store caching the athenaOne client_credentials token to avoid per-request token calls ·
ee:cache GET token, ee:cache PUT token (10-minute TTL), STORE max 1 entry
- athenaOne REST (target) — athenaOne proprietary REST and department-scoped FHIR DSTU2 back end the System API calls ·
POST /oauth2/v1/token, GET /v1/{practiceId}/patients, GET /v1/{practiceId}/patients/{patientid}, POST /v1/{practiceId}/patients, GET /v1/{practiceId}/departments, GET /v1/{practiceId}/{departmentid}/fhir/dstu2/Encounter
- Patient matching and $sync orchestration (Process API) — consumes FHIR from the System API and upserts into Health Cloud ·
POST /$sync, POST /patients/match
- Portal and mobile channel (Experience API) — portal/mobile facing layer that passes source=portal for MM/dd/yyyy DOB formatting ·
GET /patients?source=portal, GET /patients/{id}
Prerequisites
- Anypoint Platform org with Mule 4.4+ runtime (reference project targets 4.4.0), APIkit, and secure-configuration-property-module.
- athenahealth developer portal sandbox application — register and create credentials. Preview host:
api.preview.platform.athenahealth.com.
- OAuth 2.0 client ID and secret with scope
athena/service/Athenanet.MDP.*; token endpoint uses HTTP Basic authentication with those credentials on POST /oauth2/v1/token.
- Sandbox practice ID configured in
env-{env}.yaml under athena-health.common.constants.practiceid.
- Production MDP marketplace approval and per-practice athenaNet enablement before switching to
api.platform.athenahealth.com.
Architecture
Reference implementation
The supplied Mule application hls-athenahealth-patient-fhir-sapi (v1.0.0-SNAPSHOT) includes:
| Module |
Purpose |
athena-health-fhir-r4-system-api.xml |
APIkit router, console on /console/*, listener on /api/* (port 8082) |
token-implementation.xml |
client_credentials token fetch; 10-minute Object Store cache |
patient-implementation.xml |
Patient search, read, create; FHIR R4 US Core mapping |
organization-implementation.xml |
Department list → FHIR Organization Bundle |
encounters-implementation.xml |
Encounter search via department-scoped FHIR DSTU2 path |
sync-implementation.xml |
Stub — POST /$sync logs "TBD" |
global.xml |
Secure properties (env-{env}.yaml), separate HTTP configs for API and token |
errorHandler.xml |
Propagates upstream HTTP status and error payload |
RAML title: Athena Health FHIR R4 US Core Patient API (athena-health-fhir-r4-system-api.raml, version v1).
1. Published API contract
Base path pattern: /{ehr-version}/{practiceId}/… plus a top-level sync operation.
| FHIR resource (System API) |
HTTP |
Implementation status |
athenaOne back-end |
| Patients search |
GET |
Implemented — auto-follows next links until exhausted |
GET /v1/{practiceId}/patients |
| Patients read |
GET /{id} |
Implemented |
GET /v1/{practiceId}/patients/{patientid} |
| Patients create |
POST |
Implemented — FHIR → form-urlencoded |
POST /v1/{practiceId}/patients |
| Patients update/delete |
PUT, DELETE |
Stub (APIkit logger only) |
Not wired |
| Organization search |
GET |
Implemented (maps departments) |
GET /v1/{practiceId}/departments |
| Organization write/delete |
POST, PUT, DELETE |
Stub |
Not wired |
| Encounter search |
GET |
Implemented |
GET /v1/{practiceId}/{departmentid}/fhir/dstu2/Encounter |
| Encounter write/delete |
POST, PUT, DELETE |
Stub |
Not wired |
| AllergyIntolerance |
GET, POST, PUT, DELETE |
RAML only — no APIkit flows in reference project |
Extend to athenaOne allergy endpoints |
| $sync |
POST |
Stub — accepts sourceSystem, patientId, hcPatientId, resourcesToSync |
Intended for Health Cloud bulk sync |
Media types: application/fhir+json and application/fhir+xml.
Patient search supports the full athenaOne query surface documented in searchParams.yaml (100+ parameters including firstname, lastname, dob, departmentid, limit, offset). When source=portal and DOB is present, the implementation reformats DOB to MM/dd/yyyy before calling athenaOne.
2. Exchange FHIR RAML libraries (bundled)
Import or reuse these Exchange assets (versions pinned in the reference exchange.json):
Exchange assets
Import these from the MuleSoft Accelerator for Healthcare use-case page on Anypoint Exchange:
| Asset |
Includes |
| FHIR R4 Commons Library |
Shared FHIR datatypes and traits (v3.0.1) |
| FHIR R4 Resource Types Library |
Generic FHIR resource/search RAML traits (v1.0.4) |
| FHIR R4 US Core Patient Library |
US Core Patient resource and Bundle types (v1.0.1) |
| FHIR R4 Organization Library |
Organization resource types (v1.0.1) |
| FHIR R4 Encounter Library |
Encounter resource types (v1.0.0) |
| FHIR R4 AllergyIntolerance Library |
AllergyIntolerance types for future implementation (v1.0.0) |
3. OAuth and connectivity
- Token flow (
token-generation): POST /oauth2/v1/token with grant_type=client_credentials and scope=athena/service/Athenanet.MDP.*, body application/x-www-form-urlencoded.
- Basic auth on the token HTTP config uses
secure::athena-health.endpoints.token.username and .password (encrypt with secure-properties module; reference uses Blowfish).
- Caching:
ee:cache + private Object Store, 10-minute TTL, max 1 entry — avoids per-request token calls.
- API calls: Bearer token on
AthenaHealth-Instance-HTTP_configuration; base path /v1/; correlation ID forwarded on every request.
- Configure hosts in
env-local.yaml (preview) vs production YAML; never commit plaintext secrets.
4. Data transformation highlights
Patient GET by ID: Maps athenaOne patient JSON → FHIR R4 Patient (name, telecom, gender, birthDate, address, managingOrganization reference).
Patient search: Aggregates all pages when athenaOne returns a next URL; builds a FHIR searchset Bundle with slim Patient entries (id, gender, birthDate, address).
Patient POST: Maps FHIR Patient → form fields (departmentid from managingOrganization.reference, firstname, lastname, dob as MM/dd/yyyy, mobilephone).
Organization GET: Maps departments[] → FHIR Organization searchset Bundle (department phone, address, name).
Encounter GET: Calls DSTU2 Encounter API; maps entries to FHIR R4 Encounter searchset; encounter class codes resolved via commonCodes.yaml (AMB, EMER, IMP, etc.).
5. API-led layering
- System API (this asset): FHIR façade, token management, athenaOne HTTP, pagination, DataWeave transforms.
- Process API (downstream): Patient matching,
$sync orchestration, Health Cloud upsert — consumes FHIR from this API only.
- Experience API (downstream): Portal or mobile channels; pass
source=portal on patient search when DOB formatting is required.
- Publish RAML to Exchange; front with API Manager Client ID enforcement and HIPAA audit policies.
6. Gaps to close before production
- Implement AllergyIntolerance flows (RAML and examples exist; no Mule flows yet).
- Replace stub PUT/DELETE/POST handlers for Organization and Encounter with real athenaOne mappings.
- Build POST /$sync to pull
resourcesToSync (Patient, Encounter, AllergyIntolerance, Condition, Observation, etc.) for Health Cloud.
- Add practice allow-list validation — reference passes
{practiceId} from URI directly to athenaOne.
- Replace generic error handler with FHIR OperationOutcome responses where consumers expect FHIR errors.
- Remove or redact default
encryption.key from global.xml; use environment-specific keys and Secrets Manager in production.
- Upgrade Mule runtime and connector versions from 2022 baseline after regression testing.
7. Error handling and operations
- Global error handler propagates athenaOne HTTP status and response body to the caller.
- APIkit returns structured JSON for 400, 404, 405, 406, 415, and 501.
- Log correlation IDs on all outbound athenaOne requests (
sendCorrelationId=ALWAYS).
- Monitor token cache hit rate and athenaOne 429 responses; serialize patient search pagination loops.
8. Security and compliance
- Encrypt PHI in transit and at rest.
- Audit-log every access to and modification of patient data.
- Enforce minimum-necessary access for integration operators and support users.
For additional HIPAA controls, API policies, and reference security patterns, see the MuleSoft Accelerator for Healthcare on Anypoint Exchange.
Sample payload — POST /$sync request body (reference RAML)
{
"sourceSystem": "epic",
"patientId": "FHIR_ID",
"hcPatientId": "906F0000000BQGnIAO",
"resourcesToSync": ["Patient"]
}
Testing and validation
- Deploy to local with
env=local; hit GET /api/{ehr-version}/{practiceId}/Patients?firstname=…&lastname=…&dob=… and confirm a FHIR searchset Bundle returns.
- Call GET
/api/{ehr-version}/{practiceId}/Patients/{patientid} and validate US Core Patient fields against athenaOne sandbox source.
- POST a FHIR Patient with managingOrganization reference; confirm athenaOne returns
patientid and form-urlencoded outbound body.
- GET
/api/{ehr-version}/{practiceId}/Organization and confirm departments appear as Organization entries.
- GET
/api/{ehr-version}/{practiceId}/Encounter?departmentid=… with required search params; confirm Encounter Bundle and class code mapping from commonCodes.yaml.
- Verify token cache: two rapid calls should produce one token POST to
/oauth2/v1/token within the 10-minute window.
Phased rollout
Phase 1 — Connect
- Import
hls-athenahealth-patient-fhir-sapi into Anypoint Studio; encrypt sandbox credentials in env-local.yaml.
- Deploy to CloudHub or RTF; expose
/api/* through API Manager with HTTPS.
- Validate token generation against
api.preview.platform.athenahealth.com.
Phase 2 — Map and test
- Exercise implemented Patient, Organization, and Encounter GET/POST paths; document any practice-specific query params.
- Implement AllergyIntolerance and remaining stub operations needed by your Process API.
- Complete Testing and validation including pagination, portal DOB path, and error propagation.
Phase 3 — Production
- Pass MDP certification; switch hosts to
api.platform.athenahealth.com per environment YAML.
- Enable per-practice rollout only after athenaNet app enablement; add allow-list enforcement.
Success metrics
- Implemented FHIR operations return valid US Core payloads passable by FHIR validators for Patient and Organization.
- Patient search with
next pagination completes without manual offset management for panels up to athenaOne totalcount.
- Token cache hit rate ≥ 95% under steady Process API load.
- Zero plaintext OAuth secrets in deployed configuration artifacts.
Configuration checklist
Before first sandbox deploy, complete the shared Healthcare integration configuration checklist — secure property keys, TLS, OAuth, and credential naming conventions are documented once for all Exchange use cases.
10. Implementation starting point
Unpack hls-athenahealth-patient-fhir-sapi and import as a Mule 4 Maven project (com.muleoft.consulting:hls-athenahealth-patient-fhir-sapi:1.0.0-SNAPSHOT).
Set global property env (default local) and populate src/main/resources/env-local.yaml with preview host, token URI, practice ID, and encrypted credentials.
Run locally on port 8082; open APIkit console at /console/ to exercise FHIR endpoints.
Extend stub flows (AllergyIntolerance, $sync, PUT/DELETE) following the patterns in patient-implementation.xml and organization-implementation.xml.
Publish the RAML asset Athena Health FHIR System API to Exchange for downstream Process API teams.
Troubleshooting
- 401 from athenaOne on patient GET — Likely cause: expired or uncached token, or Basic auth misconfigured on token connector. Fix: Clear Object Store cache, verify encrypted username/password decrypt correctly, and test token POST in isolation.
- Patient search returns empty Bundle but athenaOne has matches — Likely cause: DOB format mismatch — portal path expects MM/dd/yyyy conversion. Fix: Pass
source=portal only when DOB length ≥ 10, or send DOB already in athenaOne format for non-portal searches.
- Encounter GET fails or returns no entries — Likely cause: missing
departmentid query param or wrong DSTU2 path template. Fix: Confirm athena-health.endpoints.api.uris.encounter.base-uri includes {departmentid} placeholder and URI param is set from query string.
- POST /$sync returns success but does nothing — Likely cause: reference implementation is a stub (
sync-implementation-Main-flow logs TBD). Fix: Implement sync orchestration calling Patient and Encounter implementations per resourcesToSync before relying on this endpoint.
Deliverable: A deployable Athena Health FHIR R4 US Core Patient System API that wraps athenaOne REST with OAuth caching, FHIR-native request/response contracts, implemented Patient/Organization/Encounter reads and Patient create — plus a clear extension path for AllergyIntolerance, $sync, and remaining write operations.