File Destination

Write processed messages to files on the local filesystem.

Overview

The File destination writes each processed message to a file on the local filesystem. It supports configurable output directories and dynamic filename patterns using message metadata variables. This is useful for archiving processed messages, generating output files for batch processing systems, or writing data to shared network volumes.

Configuration

Define a File destination in your root intu.yaml under the destinations key:

yaml
# intu.yaml
destinations:
  outbound-files:
    type: file
    file:
      scheme: local
      directory: /data/outbound/processed
      filename_pattern: "${channelId}_${timestamp}_${messageId}.json"

Properties

scheme string optional
Storage scheme. Currently only local is supported. Defaults to local.
directory string required
Absolute or relative path to the output directory. The directory is created automatically if it does not exist. Supports environment variable interpolation.
filename_pattern string optional
Template for generating output filenames. The following variables are available: ${messageId}, ${timestamp}, ${channelId}, ${date}, ${time}. Defaults to ${messageId}.dat.
mode string optional
Write mode. overwrite replaces existing files; append appends to an existing file. Defaults to overwrite.
file_permissions string optional
Unix file permissions for created files, in octal notation (e.g. "0644"). Defaults to "0644".

Filename Pattern Variables

Variable Description Example
${messageId} Unique message identifier a1b2c3d4-e5f6-7890
${timestamp} ISO 8601 timestamp (file-safe) 20260305T143022Z
${channelId} ID of the processing channel adt-processor
${date} Current date in YYYYMMDD format 20260305
${time} Current time in HHmmss format 143022

Full Example

Receive HL7v2 ORU messages via MLLP, transform them to a structured JSON lab report, and write each report to an output directory.

Root Configuration

yaml
# intu.yaml
destinations:
  lab-report-archive:
    type: file
    file:
      scheme: local
      directory: /data/outbound/lab-reports
      filename_pattern: "lab_${date}_${messageId}.json"
      file_permissions: "0640"

Channel Configuration

yaml
# channels/lab-reports/channel.yaml
name: lab-reports
description: Archive processed lab results as JSON files

source:
  type: tcp
  tcp:
    port: 6663
    mode: mllp

destinations:
  - lab-report-archive

Destination Transformer

typescript
// channels/lab-reports/transformer.ts
import { Message, Context } from "@intu/sdk";

interface LabResult {
  orderId: string;
  patientId: string;
  collectionDate: string;
  results: Array<{
    code: string;
    display: string;
    value: string;
    units: string;
    referenceRange: string;
    abnormalFlag: string;
  }>;
}

export default function transform(msg: Message, ctx: Context): Message {
  const hl7 = msg.body;
  const pid = hl7.segments?.find((s: any) => s.name === "PID");
  const obr = hl7.segments?.find((s: any) => s.name === "OBR");
  const obxSegments = hl7.segments?.filter((s: any) => s.name === "OBX") ?? [];

  const report: LabResult = {
    orderId: obr?.fields[2]?.components[0] ?? "",
    patientId: pid?.fields[3]?.components[0] ?? "",
    collectionDate: obr?.fields[7]?.components[0] ?? "",
    results: obxSegments.map((obx: any) => ({
      code: obx.fields[3]?.components[0] ?? "",
      display: obx.fields[3]?.components[1] ?? "",
      value: obx.fields[5]?.components[0] ?? "",
      units: obx.fields[6]?.components[0] ?? "",
      referenceRange: obx.fields[7]?.components[0] ?? "",
      abnormalFlag: obx.fields[8]?.components[0] ?? "",
    })),
  };

  return {
    ...msg,
    body: JSON.stringify(report, null, 2),
  };
}
Note The output directory is created automatically on first write if it does not exist. Ensure the intu process has write permissions to the parent directory.