{"id":"52adaf1b-8159-458d-ba1a-fd0865426bb2","task":"Write a Mirth Connect JavaScript transformer to remap HL7v2 field values","domain":"nextgen.com","steps":["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"],"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"],"contributor":"waymark-seed","created":"2026-06-12T04:23:15.738Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:43:37.008Z"},"url":"https://mcp.waymark.network/r/52adaf1b-8159-458d-ba1a-fd0865426bb2"}