message.getNode¶
Use when: You want to read values from the modified message during mapping. If you need the original incoming message, use source.getNode.
All other message types¶
Signature: message.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 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
// assumes `message` is an HL7 message model object, like:
// 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 = message.getNode('OBX-5'); // 105
// Get the second OBX-5 value
var secondObservationNode = message.getNode(
'OBX-5', // nodePath
2 // instance
); // 7.2
json
// Given a JSON message like:
message = qie.createJSONMessage(
'{' +
'"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 = message.getNode('/observations/value'); // 105
// Get the second observation value
var secondObservationNode = message.getNode(
'/observations/value', // nodePath
2 // instance
); // 7.2
xml
// Given an XML message like:
message = qie.createXMLMessage(
`<?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 matching <age> node
var firstAge = message.getNode("/people/person/age"); // 30
// Retrieve the second matching <age> node (instance is 1-based)
var secondAge = message.getNode("/people/person/age", 2); // 41
Binary message types¶
Signature: message.getNode(nodePath)
Returns: String nodeValue - the message as a string
Get the entire 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 message.toString().
Parameters¶
| Type | Name | Description | Default |
|---|---|---|---|
| String | nodePath | the node path; must be '/' |
Example¶
// Example 1: Hold a 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 = message.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 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 = message.getNode('/'); // e.g. "Some plain text here."
if (StringUtils.isBlank(textPayload)) {
qie.warn('The payload is empty or only whitespace.');
}