Skip to content
Recipes

Lab results from a Windows share

Pick up HL7v2 result files from an SMB share, the way a Mirth File Reader does, convert each one to FHIR R4 and POST it to a FHIR server, with processed and error folders.

On this page

Many labs and instruments drop each result as an .hl7 file on a Windows file share, and a Mirth File Reader picks them up. This recipe does the same job in MedHook: it picks up each new file, converts the HL7v2 message to a FHIR R4 transaction Bundle, POSTs it to a FHIR server, and moves the file to a processed folder.

Source and destination

The engine polls the share itself. Each file becomes one run, and each run sends one transaction Bundle to the FHIR server.

flowchart LR
    A[SMB share] -->|result.hl7| B[File pickup trigger]
    B -->|file text in content| C[HL7v2 to FHIR]
    C -->|transaction Bundle| D[FHIR R4 server]
  • Source: one HL7v2 message per file, such as an ORU^R01 result, in a folder on an SMB share.
  • Destination: any FHIR R4 server a FHIR REST profile can reach.
  • Result: for an ORU^R01, a Patient, a ServiceRequest per order and an Observation per OBX, in one transaction. The file moves to the processed folder once its run is recorded.

What it uses

The SMB profile names the share. Paths in the trigger are folders inside that share:

json
{
  "name": "Lab results share",
  "adapterType": "smb",
  "config": {
    "host": "files.example.test",
    "share": "lab",
    "domain": "EXAMPLE",
    "username": "svc-medhook",
    "password": "synthetic-secret"
  }
}

The trigger picks up *.hl7 once a minute, skips files a sender is still writing, and moves each file when its run is recorded:

json
{
  "type": "file",
  "adapterProfileId": "lab-results-share",
  "remotePath": "/results",
  "pollInterval": 60000,
  "filenamePattern": "*.hl7",
  "afterProcessing": "move",
  "processedPath": "/results-done",
  "errorPath": "/results-error",
  "minFileAgeMs": 10000,
  "ignoreDot": true,
  "encoding": "utf8"
}

Each run's input is { "triggerType": "file", "triggerId": "...", "file": { "name", "path", "size", "modifiedAt" }, "content": "MSH|..." }. The HL7v2 to FHIR transform reads the message from content directly, as a Mirth File Reader feeds its transformer. Keep filenamePattern to your HL7 files: a file that does not start with MSH is not read as HL7. The conversion step's config sets the sender's time zone and turns on conditional creates, so a resent file does not duplicate the Patient:

json
{
  "timezone": "America/Chicago",
  "missingTimezone": "fail",
  "conditionalCreate": true
}

The send step uses the create action with an empty config. A transaction Bundle goes to the base URL as one POST, so the urn:uuid: references between its resources resolve.

A test file needs only synthetic data:

text
MSH|^~\&|LAB|EXAMPLE-LAB|MEDHOOK|EXAMPLE|20261020083000-0500||ORU^R01|LAB0001|P|2.5.1
PID|1||TP-0001^^^EXAMPLE^MR||TESTPATIENT^ALEX||19800412|F
ORC|RE|ORD1001
OBR|1|ORD1001||2345-7^Glucose^LN|||20261020080000-0500
OBX|1|NM|2345-7^Glucose^LN||98|mg/dL|70-99|N|||F

Line endings can be \r, \n or Windows \r\n. If the lab writes files in Windows-1252 or ISO-8859-1, set encoding to windows-1252 or latin1.

Other file servers

The same workflow works on every transport the file pickup reads. Only the profile changes, and with it what remotePath is relative to:

Mirth File Reader schemeProfileremotePath is
SMBSMBa folder in the profile's share
FTP or FTPSFTP / FTPSa folder on the server
WebDAVWebDAVa folder below the profile's baseUrl
S3Amazon S3a key prefix below the profile's prefix
FILELocal Filea folder below the profile's baseDir, on a mounted volume
SFTPSFTPa folder on the server

Status

Available on this release.

Know the limits before you go live:

  • One file is one message. A file that holds several messages, such as an FHS/BHS batch, is not split into one run per message. Have the sender write one message per file.
  • errorPath takes a file larger than maxFileBytes (10 MB by default), which is never read. A file whose run fails, for example because it is not HL7 or the FHIR server rejects the Bundle, still moves to processedPath: the failed execution stays in the history, and you can replay it once the workflow or the destination is fixed. See Replay.
  • MedHook's SMB client speaks SMB 2.0 and 2.1 without SMB 3 encryption, so file content crosses the network unencrypted. Keep the share on a private network or a VPN. For PHI, your operator can mount the share on the engine instead and you use a Local File profile. A private host also needs SSRF_ALLOWLIST.
  • Pickup is at least once. A crash in one short window can run a file twice, which is why the conversion uses conditional creates. See Duplicates and crashes.

Reference