Turn faxed referrals into Epic referrals without re-keying: pick up faxes from RightFax, Kno2 or eFax, extract with IDP and send low-confidence fields to a person, validate and normalize, match an existing Epic patient before creating anyone, then deliver over HL7 v2 (REF^I12, ADT^A28/A04, MDM^T02) via MLLP to Epic Bridges or an interface engine, or over FHIR R4 (Patient, DocumentReference) with SMART Backend Services. ACKs and MRNs are logged, and failures go to an exception queue.
Tags: healthcare, provider, epic, hl7v2, fhir, referral-management, intelligent-document-processing, patient-matching, smart-on-fhir, system-api, process-api
Fax Referral Intake to Epic: HL7 v2 or FHIR
Deliverable: A Mule application that picks up faxed referrals from the fax server, extracts them with IDP, checks Epic for an existing patient, and delivers the referral to Epic as HL7 v2 (REF^I12, with ADT and MDM options) over MLLP or as FHIR R4 resources. Every send is confirmed by an ACK or HTTP status, the Epic MRN is logged, and failures go to an exception queue.
Objective: Faxed referrals still reach most Epic organizations through RightFax, Kno2 or eFax, and staff re-key every one. That is slow, introduces typos in names, DOBs and phones, and creates duplicate patients when no one searches first. Working looks like this: the fax is read automatically, only low-confidence fields reach a person, the patient is matched before anyone is created, and the referral lands in the Epic referral work queue with the fax attached.
What's Getting Built
- Fax Intake Listener (Process API, source) — polls the email inbox, SFTP drop or watched folder the fax server writes to, and starts one intake per document ·
POLL sftp:/inbound/fax, POLL imap:referrals@, POLL file:/fax/drop
- Referral Intake (Process API) — runs extract, confidence gate, validate and normalize, patient match, map and send, confirm ·
POST /referrals, GET /referrals/{referralId}, POST /referrals/{referralId}/review
- IDP Referral Extraction (target) — reuses the library's referral prompt suite and returns JSON with a confidence score per field ·
RUN idp-prompt-referral-packet-page-classification, RUN idp-prompt-patient-demographics-extraction, RUN idp-prompt-prescriber-information-extraction, RUN idp-prompt-insurance-card-extraction
- Epic HL7 v2 System API (System API) — builds REF^I12, ADT^A28/A04 and MDM^T02, sends them over MLLP, and parses the ACK ·
POST /hl7/referral, POST /hl7/patient, POST /hl7/document
- Epic FHIR R4 System API (System API, from the MuleSoft Accelerator for Healthcare) — patient search and match, patient create, document attach, optional ServiceRequest ·
POST /Patient/$match, GET /Patient?family&given&birthdate&telecom, POST /Patient, POST /DocumentReference, POST /ServiceRequest
- Referral Exception Queue (target) — Anypoint MQ queue with a dead-letter queue, holding low-confidence, invalid, ambiguous-match and rejected referrals for a person to handle ·
PUBLISH referral.exceptions, PUBLISH referral.review
Out of scope: scheduling, benefits verification and prior authorization, which continue inside Epic. To orchestrate those too, see provider-referral-management-orchestration.
Prerequisites
- Anypoint Platform with a CloudHub 2.0 Private Space or Runtime Fabric. Patient data shouldn't run on shared CloudHub workers.
- MuleSoft IDP licensed, with the referral prompt suite deployed. Reuse the library prompts instead of writing new ones.
- MuleSoft Accelerator for Healthcare from Exchange, for the HL7 v2 connector, FHIR R4 API specs and the Epic FHIR R4 System API.
- HL7 path: a named Epic Bridges analyst, or the owner of your interface engine. Confirm which inbound interfaces you license: inbound referral (REF), inbound ADT, and inbound documents (MDM). Then agree the MLLP host, port, VPN or private link, MSH-3/4/5/6 values, and the ACK mode (original or enhanced).
- FHIR path: an app registered on fhir.epic.com as a Backend System using SMART Backend Services, which is an OAuth 2.0 client credentials flow with a signed JWT. Ask for this early because access takes longer than the build:
- Registration creates a non-production client ID and a production one that does nothing until you enable it.
- Your organization signs the open.epic API Subscription Agreement, runs a vendor security review, and downloads the client ID into your environment. There is no self-serve route to production.
- Register an RS384 public key or JWKS URL per environment, and every interaction used (Patient read, search, create; DocumentReference create). Writes beyond the standard read set are enabled per organization.
- Prove the FHIR path in your non-production Epic before production code.
- A signed BAA covering the fax server, IDP and Anypoint, and including documents stored while IDP processes them.
- Decide whether Mule may create patients at all, or only queue the referral for a person to register. Many Epic organizations restrict inbound patient creation because Epic normally originates registrations.
Choose your path
- HL7 v2 over MLLP (recommended for production) — Every Epic interface team supports inbound HL7, REF^I12 carries patient, insurance, referring provider and reason in one message, and no write API approval is needed.
- FHIR R4 (demo and roadmap) — For the demo, or once you're granted Patient.Create and DocumentReference.Create. ServiceRequest support varies; confirm it for your environment.
Both paths share steps 1–4; only the System API in step 5 changes, so you can start on HL7 and add FHIR later without rebuilding.
Architecture
1. Receive the fax
- Listen wherever the fax server already writes: SFTP (preferred), a mailbox, or a watched folder. Don't ask the fax team to reroute for the pilot.
- Use the document's SHA-256 as the idempotency key; fax servers retry and mailboxes re-deliver.
- Move each file to a processing folder on pickup and to an archive only after Epic confirms, so a crash leaves it retryable.
- Carry the fax metadata (sending number, received time, page count) through for provider matching and troubleshooting.
2. Extract with IDP and gate on confidence
- If the fax may hold more than one patient, run
idp-prompt-multi-patient-packet-segmentation first, then idp-prompt-referral-packet-page-classification, then the extractors for demographics, prescriber (referring provider) and insurance card.
- Threshold per field, not per document: start at 0.90 for name, DOB, sex and member ID and 0.80 for address and reason, tuned on historical faxes.
- A field below threshold sends the referral to IDP human review (
referral.review); nothing reaches Epic until a person confirms it.
- Record each field's prompt, confidence and corrector as the audit trail.
3. Validate and normalize
- Required fields: patient name, DOB, sex, phone, address, payer, referring provider, reason for referral. A missing required field goes to the exception queue with the field name, not a generic error.
- Normalize dates to
YYYYMMDD for HL7 and YYYY-MM-DD for FHIR, phones to E.164 (and HL7 XTN), names to family and given with suffixes split out, sex to the HL7 table 0001 and FHIR AdministrativeGender codes, and states to USPS two-letter codes.
- Look up the referring provider's NPI in NPPES when the fax gives only a name and practice.
- Reject impossible values (future DOB, short phone) here; an Epic AE is harder to work than a validation error.
4. Check for an existing patient
- FHIR: call
Patient/$match with name, DOB, sex, phone and address, and accept only a single result with Epic's "certain" or "probable" grade at or above the agreed score. If $match isn't enabled, fall back to GET /Patient on family, given, birthdate and phone.
- Epic rejects searches that are too vague, so always send name, DOB and at least one more identifier. A rejected search is an exception, not "no match", or the flow will create a duplicate patient.
- Follow the Bundle's
next link exactly as returned rather than building your own, and don't rely on _count to cap the result size.
- HL7: most organizations let Epic's own patient matching handle it on the inbound interface, using the PID segment. Confirm the matching rules with the Bridges team. If you have an inbound query interface (QBP^Q22), use it before sending.
- One match: attach the referral to that patient and carry the MRN in PID-3. No match: create a new patient only if your policy allows it, otherwise send the referral for a person to register. More than one match: always go to the exception queue. Never pick one.
- Log the match decision and score, never demographics.
5. Map and send
HL7 v2 path
- REF^I12 (patient referral) is the default. Map MSH, RF1 (referral status, priority, type, reason, external referral ID), PRD (referring provider with NPI in PRD-7, and referred-to provider), PID, PV1, IN1 (payer, plan, member ID), DG1 (diagnosis if the fax has one) and NTE (reason for referral as free text).
- ADT^A28 or A04 if you only want a patient record created and will handle the referral in Epic.
- MDM^T02 to attach the original fax as a document: TXA for the document type and status, and an OBX with the PDF Base64-encoded as ED. Send it after the referral ACKs so the document files to the right patient.
- Send over MLLP one message at a time per connection, waiting for each ACK. Build the DataWeave mappings on the accelerator's HL7 v2 types.
FHIR R4 path
- Read the token endpoint from your
/.well-known/smart-configuration; it differs per environment.
- Sign an RS384 JWT (
iss/sub = client ID, aud = token endpoint, unique jti, exp ≤ 5 minutes) and post it with grant_type=client_credentials and the jwt-bearer assertion type.
- Request exact
system/ scopes such as system/Patient.rs, system/Patient.c, system/DocumentReference.c.
- Tokens last about an hour; refresh a few minutes early rather than waiting for a 401.
POST /Patient if there is no match and creation is allowed, with USCDI elements: name, birthDate, gender, telecom, address and identifiers.
POST /DocumentReference with the fax PDF linked to the Patient, using the type, category and author your Epic team requires (enabled per organization).
- Map optional US Core fields defensively; production often leaves them empty.
POST /ServiceRequest for the referral only where your Epic team has confirmed it's supported. Otherwise the DocumentReference and the work queue carry the referral.
6. Confirm and hand off
- HL7: read MSA-1. AA (accepted) is success. AE (error) and AR (rejected) go to the exception queue with MSA-3 and the ERR segment. No ACK within the agreed timeout counts as a failure, but resend with the same MSH-10 control ID so Epic can recognize a duplicate.
- FHIR: 201 with a
Location header is success. Read the new Patient ID and the MRN identifier. 4xx goes to exceptions without retrying, while 429 and 5xx are retried with backoff and then sent to exceptions.
- Log the Epic MRN, control ID or resource ID, and final status against the referral ID.
- The referral lands in the Epic referral work queue, where scheduling and insurance verification carry on.
7. Exceptions
- One exception queue, with a reason code:
LOW_CONFIDENCE, MISSING_REQUIRED, INVALID_VALUE, AMBIGUOUS_MATCH, CREATE_NOT_ALLOWED, EPIC_REJECTED, EPIC_TIMEOUT.
- Each exception carries the referral ID, reason, stage and a link to the fax in the secured store, with no patient data in the message.
- A corrected referral re-enters at the failed stage with the same idempotency key, so a fix never duplicates anything.
- Repeated failures move to the dead-letter queue and alert.
8. Security and compliance
- HIPAA, with a BAA covering the fax server, IDP and Anypoint, and the USCDI data elements on the FHIR path.
- TLS 1.2 or higher on every HTTP hop. MLLP runs over a site-to-site VPN or private link, with TLS on MLLP if the interface engine supports it.
- Run in a CloudHub 2.0 Private Space or on Runtime Fabric. Keep the JWT private key and MLLP credentials in a secrets manager, never in properties files.
- No patient data in logs. Log the referral ID, stage, status, MRN as a token, and timings only. Mask PID, IN1 and Patient bodies in any error handler.
- Audit every step: fax received, fields extracted, corrections, match decision, message sent, response.
- For more HIPAA controls and API policies, see the MuleSoft Accelerator for Healthcare on Exchange.
Sample payload — normalized referral before mapping
{
"referralId": "FXR-2026-10-08-000231",
"source": { "channel": "SFTP", "sha256": "9f2c…e41a", "pages": 4 },
"patient": { "family": "Nguyen", "given": ["Ava"], "birthDate": "1984-03-17", "sex": "female", "phone": "+14055550142",
"address": { "line1": "1200 N Walker Ave", "city": "Oklahoma City", "state": "OK", "postalCode": "73103" } },
"coverage": { "payer": "BlueCross BlueShield of Oklahoma", "memberId": "ZXP448812093" },
"referringProvider": { "name": "Sarah Kim, MD", "npi": "1234567893" },
"referral": { "reason": "Persistent atrial fibrillation", "specialty": "Cardiology" },
"match": { "result": "SINGLE", "mrn": "E1234567" },
"delivery": [ { "type": "REF^I12", "ack": "AA" }, { "type": "MDM^T02", "ack": "AA" } ],
"status": "DELIVERED"
}
Deterministic checks
POST /referrals returns 202 with a referralId, and the same fax (same SHA-256) submitted twice returns the original referralId and sends nothing to Epic a second time.
- No referral reaches step 5 with any field below its confidence threshold that hasn't been reviewed by a person.
- A referral missing any required field goes to the exception queue with
MISSING_REQUIRED and the field name, and never reaches Epic.
- More than one patient match always results in
AMBIGUOUS_MATCH. The flow never selects a patient on its own.
- Every REF^I12 the mapping produces validates against the HL7 v2 schema used by your interface, with the referring provider's NPI in PRD-7.
- MDM^T02 for a referral is sent only after the REF^I12 or ADT for that referral has been acknowledged with AA.
- An AE or AR ACK, a timeout, or a FHIR 4xx always ends in the exception queue, and a retried HL7 send reuses the original MSH-10.
- Every JWT is RS384 with a unique
jti and exp within 5 minutes of iat.
- A rejected Patient search never leads to
POST /Patient.
- Application logs from the full test run contain no names, DOBs, phones, addresses or member IDs.
- The MUnit suite covering mapping, confidence gating, match branching and ACK handling passes with at least 80% coverage.
Testing and validation
- Fax a real referral PDF end to end on the HL7 path to a test interface engine. Confirm the parsed REF^I12 and MDM^T02, an AA ACK for each, and the MRN logged.
- Run the same fax on the FHIR path against Epic's Interconnect FHIR APIs in your non-production environment. Confirm the Patient and DocumentReference are created, then confirm a
Patient search on name, DOB and phone finds the new patient.
- Fax a second referral for the now-existing patient. Confirm it attaches with no second patient created — the case a naive build gets wrong.
- Fax a referral matching a near-duplicate (same name and DOB, different phone). Confirm
AMBIGUOUS_MATCH.
- Force one field below threshold; confirm the referral waits in review and nothing is sent.
- Have the interface engine return AE and AR and drop the connection before the ACK. Confirm each case lands in exceptions and that the retry reuses the MSH-10.
- Make a read call against the Epic R4 sandbox (
https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4/) with the non-production client ID and an Epic test patient to prove SMART Backend Services. Don't promise a live write there: the sandbox is mainly for reads, and Patient.Create isn't confirmed.
Phased rollout
Phase 1 — Connect
- Demo stack: a real faxed PDF through IDP, the DataWeave mappings to REF^I12 and FHIR Patient, an interface engine for the HL7 path, Epic's Interconnect FHIR APIs for the FHIR path if needed, and a read call to the Epic sandbox to show SMART Backend Services.
- Confirm the licensed inbound interfaces with the Bridges team, open the VPN, and exchange an ADT^A28 test message with your non-production Epic environment.
Phase 2 — Map and validate
- Map REF^I12 and MDM^T02 to your interface spec and run a few hundred historical faxes through non-production Epic.
- Tune thresholds and matching with the referral team, and settle automatic creation versus queuing for a person.
Phase 3 — Production
- Go live on the HL7 path for one referring clinic or specialty, then widen.
- Add FHIR writes once you're approved for Patient.Create and DocumentReference.Create.
- Hand the exception queue, threshold tuning and interface monitoring to operations.
Success metrics
- Median time from fax received to Epic work queue, against today's manual entry.
- Share of faxes delivered untouched, rising as thresholds are tuned.
- Duplicate patients from referrals, near zero.
- AE/AR rate, exceptions by reason code, latency and throughput.
Troubleshooting
- Duplicate patients appear in Epic — Likely cause: match skipped or inbound matching not configured. Fix: match before every create and review PID matching rules with the Bridges team.
- Every REF^I12 comes back AR — Likely cause: inbound referral isn't licensed, or MSH-5/6 are wrong. Fix: confirm with the Bridges team; fall back to ADT^A28 plus MDM^T02.
- The fax doesn't file to the patient — Likely cause: MDM^T02 sent before the patient existed. Fix: send MDM only after an AA.
- FHIR returns 403 "The access token provided is valid, but is not authorized for this service" — Likely cause: a scope or registration gap, or a write API not enabled in your environment. Fix: register the exact interaction (search is separate from read), request the matching
system/ scope, and confirm write approval with your Epic team.
invalid_client at the token endpoint — Likely cause: the wrong client ID for the environment, the client not yet downloaded there, or a JWT with a late exp or reused jti. Fix: check which client ID each environment expects and confirm the download.
- Sandbox OAuth errors right after a registration change — Likely cause: Epic's sandbox can take a day or two to apply changes. Fix: wait, and register well ahead of a demo.
- A search that works in one Epic environment fails in another — Likely cause: every Epic site is configured differently. Fix: test the match query in each non-production environment and keep search parameters per environment in configuration.
- The same fax produces two referrals — Likely cause: idempotency keyed on file name. Fix: key on the document's SHA-256.
- Referral sits with no ACK — Likely cause: MLLP framing mismatch or a dropped VPN. Fix: confirm block characters with the interface team and alert on ACK timeouts.