Mirth Connect (NextGen) Tutorials & Channel Guide

Master interface engineering using Mirth Connect: setup TCP listeners, configure custom JavaScript transformers, map HL7 fields, and write to SQL databases.

1. Building an MLLP TCP Listener to File Writer Channel

Learn how to ingest incoming HL7 v2 messages over MLLP TCP sockets and output formatted XML/HL7 onto the local filesystem.

Beginner
  1. Source Connector: Set Connector Type to LLP Listener, set port to 6661, and set Data Type to HL7 v2.x.
  2. Destination Connector: Set Connector Type to File Writer, enter Directory path C:/HL7_Out/, and set File Name to ${message.messageId}.hl7.
  3. Deploy Channel: Save changes and click Deploy Channel inside the Mirth Administrator Console.
Sample Source Connector Settings
// Source Connector Settings:
Mode: Listener
Transport: MLLP / TCP
Local Port: 6661
Data Type: HL7 v2.x
Auto-ACK: Enabled (Generates MSH/MSA handshake automatically)

2. Extracting & Transforming HL7 PID Segments using JavaScript

Write custom E4X/JavaScript transformer steps to extract Patient Medical Record Numbers (MRN) and convert patient names to uppercase.

Intermediate
  1. Open your Channel Destination and navigate to the Transformers tab.
  2. Add a new Step, set the Type to JavaScript, and paste the transformation logic below.
  3. Use channelMap.put() to store variables for subsequent destinations or logging steps.
JavaScript Transformer Step
// Extract Patient Identifier (MRN) from PID.3.1
var patientMRN = msg['PID']['PID.3']['PID.3.1'].toString();

// Extract Patient Name and convert Family Name to Upper Case
var familyName = msg['PID']['PID.5']['PID.5.1'].toString().toUpperCase();
var givenName = msg['PID']['PID.5']['PID.5.2'].toString();

// Store in Channel Map for downstream Destination Connectors
channelMap.put('mrn', patientMRN);
channelMap.put('formattedName', familyName + ', ' + givenName);

// Modify original message field directly
msg['PID']['PID.5']['PID.5.1'] = familyName;

3. Writing HL7 Patient Data directly to SQL Database (Database Writer)

Configure a Database Writer destination to insert transformed patient demographics directly into MySQL/PostgreSQL tables.

Advanced
  1. Destination Connector: Set Connector Type to Database Writer.
  2. Driver: Select MySQL or PostgreSQL and enter Connection URL jdbc:mysql://localhost:3306/healthcare_db.
  3. SQL Statement: Write a parameterized INSERT query utilizing variables stored in your channelMap.
Parameterized SQL Query
INSERT INTO patient_admissions (
    mrn, 
    patient_name, 
    admission_date, 
    raw_message
) VALUES (
    '${mrn}', 
    '${formattedName}', 
    STR_TO_DATE('${msg['PV1']['PV1.44'].toString()}', '%Y%m%d%H%i%s'), 
    '${message.rawData}'
);