Open the channel's source or destination transformer in Mirth Connect Administrator and select the JavaScript transformer type; the transformer receives the inbound message as the 'msg' variable pre-parsed into Mirth's E4X XML representation of the HL7v2 message
Access segment fields using E4X dot notation: for example, msg['PID']['PID.5']['PID.5.1'].toString() retrieves the patient family name from PID-5.1; use array indexing for repeated segments such as msg['OBX'][0] for the first OBX segment
Implement a lookup or mapping table within the transformer using a JavaScript object literal to convert local codes to standard codes, for example mapping local order codes to LOINC codes in OBR-4; store frequently changed mappings in Mirth's code templates for reuse across channels
Use the channelMap and globalMap objects to pass values between source transformer and destination transformers; set values with channelMap.put('key', value) and retrieve them with channelMap.get('key') in downstream transformers
Modify field values by direct assignment: msg['OBX']['OBX.3']['OBX.3.1'] = 'new_value'; Mirth serializes the modified E4X structure back to an HL7v2 string when the transformer completes
Use logger.info() and logger.error() for diagnostic logging during development; log entries appear in the Mirth server log and can be filtered by channel and log level to aid debugging
Known gotchas
Mirth's E4X XML uses a specific segment/field/component path format — mistakes in the dot-notation path silently return an empty string rather than throwing an error, making it easy to write transformers that appear to work but produce empty fields
When a segment may appear zero or multiple times (e.g., OBX), always check for existence before accessing — accessing msg['OBX'][5] when only 4 OBX segments exist returns undefined and subsequent operations will throw a JavaScript error that halts the transformer
JavaScript in Mirth transformers runs in a Rhino (Java-based) JavaScript engine — modern ES6+ syntax such as arrow functions, template literals, and let/const may not be supported depending on the Mirth version; use ES5 syntax for compatibility
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp