Skip to content

message.removeAllNodes

Signature: message.removeAllNodes(nodePath)

Returns: void

Remove all nodes that match 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 all nodes that match 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 all OBX segments
message.removeAllNodes('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
*/

json

// Example: Remove all nodes that match a given path.

// Sample JSON message structure
message = qie.createJSONMessage(JSON.stringify(
{
    people: [
        { name: "Thomas", children: [{ name: "Alice" }, { name: "Bob" }] },
        { name: "Sally",   children: [{ name: "Chris" }, { name: "David" }] }
    ]
}));

// Remove all matching nodes
message.removeAllNodes("/people/children"); // {"people":[{"name":"Thomas"},{"name":"Sally"}]}

xml

// Example: Remove all nodes that match 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 all observation nodes
message.removeAllNodes('observations/observation');
/* result:
<root>
   <patient>
      <id>123456</id>
      <name>John Doe</name>
   </patient>
   <observations>
   </observations>
</root>
*/