Skip to content
Guides

X12 claims from an SFTP folder

Pick up X12 837 files from an SFTP folder, post each claim as JSON to a claims system, and write a 999 back for the sender.

On this page
X12 claims from an SFTP folder. Build a workflow that picks up X12 837 claim files from an SFTP folder: an x12 trigger reading the folder and writing a 999 per functional group, and a destination that maps each claim to JSON and posts it to a claims endpoint. Test it with a synthetic run input, deploy it, and watch a synthetic claims file for TESTPATIENT get picked up, acknowledged and parsed in Messages.

This guide builds a workflow that picks up X12 837 claim files from an SFTP folder, posts each claim to a claims system as JSON, and writes a 999 acknowledgment back to the folder the sender reads. The engine polls the folder itself, so the sender only drops files.

Here is the flow.

sequenceDiagram
    participant Sender as Clearinghouse (test)
    participant SFTP as SFTP server
    participant Engine as MedHook engine
    participant Claims as Claims system

    Sender->>SFTP: Upload claims.x12 to /inbound/837
    Engine->>SFTP: List the folder, read claims.x12
    Engine->>Engine: Check the envelope, record one run per transaction set
    Engine->>SFTP: Write claims.x12.999 to /outbound/acks
    Engine->>SFTP: Move claims.x12 to /inbound/837/done
    Engine->>Claims: POST the claim as JSON
    Claims-->>Engine: 2xx

Before you start

  • A running engine and a signed-in user with the operator role. See the Quick start.
  • An SFTP server the engine can reach, with an account that can read /inbound/837 and write to /inbound/837/done, /inbound/837/error and /outbound/acks.
  • An HTTPS endpoint for the claims, for example https://claims.example.test/intake.

Steps

1. Create the two adapter profiles

Open Adapters and choose New connection once for each.

  1. Pick SFTP, name it Clearinghouse SFTP, and fill in the host, the account and the server's pinned host key in hostKeyFingerprints, as in SFTP file to FHIR. The pickup refuses a server whose key is not pinned.
  2. Pick Generic REST, name it Claims API, and set baseUrl to https://claims.example.test/intake.

For each, choose Test connection to check that the engine can reach it, then Save connection. Settings that aren't in the short form are under More settings.

2. Create the workflow

Open Workflows and choose New workflow. On Start, pick Batch file and Blank workflow, then Continue. On Source, pick SFTP pickup and the Connection Clearinghouse SFTP, then Continue. Leave Sample empty and choose Continue. On Draft, enter the name 837 claims intake and choose Open in builder. You change the trigger to X12 in the next step. See Start a workflow.

3. Point the source at the folder

Select Source and set Trigger type to x12 · EDI transactions. Then set:

FieldValue
Transaction sets (empty: all)837
Arrives bysftp · the engine picks files up from a folder
SFTP profileClearinghouse SFTP
Folder/inbound/837
File names*.x12
File names area glob (*, ?, [abc])
Check every (seconds, min 10)60
After a file is recordedmove · to the processed folder
Processed folder/inbound/837/done
Error folder/inbound/837/error
999 / TA1 folder/outbound/acks
Acknowledgments999 per functional group

Each pickup lists the folder, oldest file first, and skips a file that changed in the last 5 seconds, because it may still be being written. The engine remembers every file it has run, so a file it ran but cannot move yet does not run again. Pickup is at least once: a crash in the short window just after a file's runs are recorded can run that file a second time (see Triggers: duplicates and crashes).

4. Know what each run gets

The engine checks the envelope, then records one run for each transaction set (ST to SE) the trigger takes. A file with three claims' transaction sets is three runs. Each run's input has:

FieldWhat it holds
transactionSet837
controlNumberST02, the transaction set control number
interchangeControlNumberISA13
groupControlNumberGS06
parsedDatathe set, parsed: segments, segmentsById and the first occurrence of each segment by id, such as parsedData.CLM
rawDatathe set as X12 text, in its own envelope

parsedData is what an x12-parse step returns, so a destination can map from it directly. A resend of a set with the same sender, receiver, ISA13, GS06 and ST02 does not run again.

5. Add the destination

Choose + Add destination and set Destination name to Claims API. Under Output, choose + Add output step and set Output to Data map → JSON. Then add these rows with Add row, each with JSON path as the source kind, or by typing a Target path next to each field once a sample is loaded (step 6):

SourceTarget path
$.parsedData.CLM[1]claimId
$.parsedData.CLM[2]totalCharge
$.parsedData.NM1[3]subscriber.family
$.parsedData.NM1[9]subscriber.memberId
$.controlNumbertransactionControlNumber

A segment array holds the segment id first, so CLM[1] is CLM01, the claim id. On the totalCharge row, open the cog, choose Type under + Add op, leave it on number and choose Apply, so the amount is sent as a number.

Under Send, set Adapter profile to Claims API · generic-rest and choose post under Action. Leave Endpoint and Body empty, so the step POSTs the mapped JSON to the base URL.

6. Test with a sample

A dry run takes the run input as JSON. Choose Load sample, then Paste a sample (or Replace, if the workflow already has one), paste this synthetic input and choose Save sample:

json
{
  "transactionSet": "837",
  "controlNumber": "0001",
  "interchangeControlNumber": "000000101",
  "parsedData": {
    "BHT": ["BHT", "0019", "00", "BATCH0001", "20261020", "0930", "CH"],
    "NM1": [
      "NM1",
      "IL",
      "1",
      "TESTPATIENT",
      "SYNTHETIC",
      "",
      "",
      "",
      "MI",
      "MEMBER0001"
    ],
    "CLM": ["CLM", "CLAIM0001", "125.00", "", "", "11:B:1", "Y", "A", "Y", "Y"]
  }
}

Choose Run test. Claims API shows WOULD SEND, and Would send reads:

json
{
  "claimId": "CLAIM0001",
  "totalCharge": 125,
  "subscriber": { "family": "TESTPATIENT", "memberId": "MEMBER0001" },
  "transactionControlNumber": "0001"
}

7. Save and deploy

Choose Save. To deploy, in Workflows, turn on the workflow's switch and choose Go to Deploy, then choose Deploy v1 to all messages on the Versions tab (see Save and deploy). Deploy needs a passing test newer than the last save, passing saved test cases (if the workflow has any) and an approval. Once deployed, the engine starts picking up files from the folder.

Test it

Save this synthetic interchange as claims.x12. The first line must stay exactly as it is: the ISA segment is fixed-width.

text
ISA*00*          *00*          *ZZ*CLEARINGHOUSE  *ZZ*MEDHOOK        *261020*0930*^*00501*000000101*0*T*:~
GS*HC*CLEARINGHOUSE*MEDHOOK*20261020*0930*1*X*005010X222A1~
ST*837*0001*005010X222A1~
BHT*0019*00*BATCH0001*20261020*0930*CH~
NM1*IL*1*TESTPATIENT*SYNTHETIC****MI*MEMBER0001~
CLM*CLAIM0001*125.00***11:B:1*Y*A*Y*Y~
SE*5*0001~
GE*1*1~
IEA*1*000000101~

Upload it:

bash
printf 'put claims.x12 /inbound/837/claims.x12\n' | sftp -b - testuser@sftp.example.test

Within a minute:

  • /outbound/acks/claims.x12.999 holds a 999 addressed back to CLEARINGHOUSE, with AK9*A*1*1*1: one group, one set received, one accepted.
  • claims.x12 is in /inbound/837/done.
  • Messages shows one run of 837 claims intake with type 837, control ID 0001 and ACK AA, and the claims system received the JSON from step 6. Select the run: its Parsed tab lists the interchange segment by segment, from ISA through the CLM claim to IEA.

Upload the same file again under another name. It runs nothing, because that set was already accepted.

🎉 Claim files dropped on the SFTP server now reach the claims system as JSON, and the sender gets a 999 for each one. To build X12 instead, see x12-generate in Transforms.

Troubleshooting

  • No file is picked up. Check that the workflow is deployed, that the file name matches File names, and that the file has not changed in the last 5 seconds. A file whose transaction sets no trigger takes runs nothing and stays in the folder.
  • Nothing is picked up and the log says SFTP host key not trusted. Pin the server's key on the SFTP profile, as in SFTP file to FHIR.
  • The 999 says AK9*R, and the file is in the error folder. Every set was rejected by the syntax checks, so nothing ran. The 999 says which segment counts or control numbers are wrong. The sender fixes the file and sends it again with new control numbers.
  • The file is not X12. It has no ISA header. It moves to the Error folder and runs nothing.
  • The file ran but stays in the folder. The processed folder already has a file with that name, and SFTP rename does not overwrite. Rename or remove the old file there. The file does not run again in the meantime.
  • The claims system gets every claim as one run. A run is one transaction set. If the sender puts several claims in one ST to SE set, add a loop over the CLM segments in parsedData.segmentsById.CLM.

Reference