Skip to content

source.getNode

Use when: You want to read values from the original incoming message before any mapping changes. If you need the modified message during mapping, use message.getNode.

All other message types

Signature: source.getNode(nodePath, instance*, repetition*)

Returns: String nodeValue - the value of the first node that matches the nodePath

Get the value of the first node that matches the nodePath.

Note

When the optional instance value is specified, the nodePath for HL7, ASTM, EDIFACT, or X12 should not include an instance identifier.

Note

This method only applies to the following formatted messages: HL7, ASTM, CSV, DICOM, EDIFACT, Old Fxd Width, Fxd Length, ISO 8583, JSON, Text, X12, XML.

Parameters

Type Name Description Default
String nodePath the node path (XPath, HPath, Column ID, etc.)
Integer instance* (optional) the instance to return: segment for HL7, ASTM, EDIFACT, or X12; row for CSV (0=header row) or fixed-length formats; or match for DICOM, JSON, or XML. Use 1 for the first instance. 1
Integer repetition* (optional) the field repeat instance for HL7 or ASTM to return. Use 1 for the first instance. 1

Examples

hl7

/* Given an HL7 source:
MSH|^~\\&|LAB|HOSPITAL|EHR|HOSPITAL|20260317103000||ORU^R01|MSG00001|P|2.5
PID|1||123456^^^HOSPITAL^MR||Doe^John||19800101|M
OBR|1||ORDER123|88304^Lab Panel^L
OBX|1|NM|GLU^Glucose^L||105|mg/dL|70-110|N|||F
OBX|2|NM|WBC^White Blood Cell Count^L||7.2|10*3/uL|4.0-11.0|N|||F
OBX|3|ST|COVID^COVID Result^L||Negative|||N|||F
*/

// Get the first OBX-5 value
var firstObservationNode = source.getNode('OBX-5'); // 105

// Get the second OBX-5 value
var secondObservationNode = source.getNode(
   'OBX-5', // nodePath
   2        // instance
);          // 7.2

json

/* Given a JSON source:
{
    "patient": {
        "id": "123456",
        "name": "John Doe"
    },
    "observations": [
        { "code": "GLU", "value": 105 },
        { "code": "WBC", "value": 7.2 },
        { "code": "COVID", "value": "Negative" }
    ]
}
*/

// Get the first observation value
var firstObservationNode = source.getNode('/observations/value'); // 105

// Get the second observation value
var secondObservationNode = source.getNode(
   '/observations/value', // nodePath
   2                      // instance
);                        // 7.2

xml

// Given an XML source containing multiple <person> elements with <age> values.
/* source:
'<?xml version="1.0" encoding="UTF-8"?>' +
'<people>' +
'   <person>' +
'      <name>Nate</name>' +
'      <age>30</age>' +
'   </person>' +
'   <person>' +
'      <name>John</name>' +
'      <age>41</age>' +
'   </person>' +
'   <person>' +
'      <name>Jane</name>' +
'      <age>52</age>' +
'   </person>' +
'</people>'
*/

// Retrieve the value of the first node that matches the nodePath.
var firstAge = source.getNode('/people/person/age'); // expected: "30"

// Retrieve the value of the 2nd matching node (instance is 1-based).
var secondAge = source.getNode(
    '/people/person/age', // nodePath
    2                     // instance (1-based)
);                        // expected: "41"

Binary message types

Signature: source.getNode(nodePath)

Returns: String nodeValue - the source message as a string

Get the entire source message as a string, decoded with the message type's encoding.

Note

'/' is the only valid node path; all others throw an exception.

Note

Use this to hold a PDF, image, or other non-text payload in the channel or message cache, which store strings only, and rebuild the exact bytes later. This works only with a single-byte encoding such as ISO-8859-1; a plain text payload simply comes back as readable text.

Note

This returns the same result as source.toString().

Parameters

Type Name Description Default
String nodePath the node path; must be '/'

Example

// Example 1: Hold the received PDF, image, or other non-text payload in a cache and rebuild the exact bytes later.

// A byte-for-byte string requires a single-byte character set, e.g. ISO-8859-1, which is the default encoding for a Binary message.
var originalBytesAsString = source.getNode('/');

// The channel and message caches store strings only, so the payload has to travel as one.
messageCache.setValue('originalBytesAsString', originalBytesAsString);

// ...in a later node...
var cachedBytesAsString = messageCache.getValue('originalBytesAsString');
message.setBytes(new java.lang.String(cachedBytesAsString).getBytes('ISO-8859-1')); // the original received bytes, unchanged

// Example 2: Read a plain text byte array in a Binary channel.

// When the bytes really are text, the decoded string is human-readable
var textPayload = source.getNode('/'); // e.g. "Some plain text here."

if (StringUtils.isBlank(textPayload)) {
    qie.warn('The received payload is empty or only whitespace.');
}