Skip to content

message.getLastNode

Use when: You want to read values from the modified message during mapping. If you need the original incoming message, use source.getLastNode.

Signature: message.getLastNode(nodePath)

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

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

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.)

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 last OBX-5 value
var lastObservation = message.getLastNode('OBX-5'); // "Negative"

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 last observation value
var lastObservation = message.getLastNode('/observations/value'); // Negative

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 last matching node
// In this case, the last <age> element
var lastAge = message.getLastNode("/people/person/age"); // 52