Skip to content

message.removeLastNode

Signature: message.removeLastNode(nodePath)

Returns: void

Remove 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, X12, XML.

Parameters

Type Name Description Default
String nodePath the node path (XPath, HPath, Column ID, etc.)

Examples

hl7

// Example: Remove the last node that matches a given path.

// 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

// Remove the last OBX segment
message.removeLastNode('OBX');
/* result:
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
*/

json

// Example: Remove the last node that matches a given path.

// Sample JSON message structure
message = qie.createJSONMessage(JSON.stringify(
{
    employees: [
        { name: "Thomas", role: "Engineer" },
        { name: "Sally",  role: "Manager" },
        { name: "Thomas", role: "Technician" }
    ]
}));

// Remove the last matching node
message.removeLastNode("/employees/name");
/* result:
{
    "employees": [
        {
            "name": "Thomas",
            "role": "Engineer"
        },
        {
            "name": "Sally",
            "role": "Manager"
        },
        {
            "role": "Technician"
        }
    ]
}
*/

xml

// Example: Remove the last node that matches a given path.

// Sample XML message structure
message = qie.createXMLMessage(
   `<root>
      <patient>
         <id>123456</id>
         <name>John Doe</name>
      </patient>
      <observations>
         <observation>
            <code>GLU</code>
            <value>105</value>
         </observation>
         <observation>
            <code>WBC</code>
            <value>7.2</value>
         </observation>
         <observation>
            <code>COVID</code>
            <value>Negative</value>
         </observation>
      </observations>
   </root>`
);

// Remove the last observation node
message.removeLastNode('observations/observation');
/* result:
<root>
   <patient>
      <id>123456</id>
      <name>John Doe</name>
   </patient>
   <observations>
      <observation>
         <code>GLU</code>
         <value>105</value>
      </observation>
      <observation>
         <code>WBC</code>
         <value>7.2</value>
      </observation>
   </observations>
</root>
*/