message.removeFirstNode¶
Signature: message.removeFirstNode(nodePath)
Returns: void
Remove the first 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 first 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 first OBX segment
message.removeFirstNode('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|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
*/
json
// Example: Remove the first node that matches a given path.
// Sample JSON message structure
message = qie.createJSONMessage(JSON.stringify(
{
employees: [
{ name: "Thomas", role: "Engineer" },
{ name: "Sally", role: "Manager" }
]
}));
// Remove the first matching node
message.removeFirstNode("/employees/name");
/* result:
{
"employees": [
{
"role": "Engineer"
},
{
"name": "Sally",
"role": "Manager"
}
]
}
*/
xml
// Example: Remove the first 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 first observation node
message.removeFirstNode('observations/observation');
/* result:
<root>
<patient>
<id>123456</id>
<name>John Doe</name>
</patient>
<observations>
<observation>
<code>WBC</code>
<value>7.2</value>
</observation>
<observation>
<code>COVID</code>
<value>Negative</value>
</observation>
</observations>
</root>
*/