message.setAllNodes¶
Signature: message.setAllNodes(nodePath, value)
Returns: void
Find all nodes that match nodePath and set each nodes value.
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.) | |
| String | value | the new value for each matching node |
Examples¶
hl7
// Example: Set the value of 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
// Set all OBX-5 values
message.setAllNodes('OBX-5', 'REDACTED');
/* 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||REDACTED|mg/dL|70-110|N|||F
OBX|2|NM|WBC^White Blood Cell Count^L||REDACTED|10*3/uL|4.0-11.0|N|||F
OBX|3|ST|COVID^COVID Result^L||REDACTED|||N|||F
*/
json
// Example: Set the value of all nodes that match a given path.
// Sample JSON message structure
message = qie.createJSONMessage(JSON.stringify(
{
employees: [
{ name: "Thomas", role: "Engineer" },
{ name: "Sally", role: "Manager" }
]
}));
// Update all matching nodes
message.setAllNodes("/employees/name", "John");
// Verify all matches were updated
var firstName = message.getNode("/employees/name[1]"); // "John"
var secondName = message.getNode("/employees/name[2]"); // "John"
xml
// Example: Set the value of 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>`
);
// Set all observation values
message.setAllNodes('observations/observation/value', 'REDACTED');
/* result:
<root>
<patient>
<id>123456</id>
<name>John Doe</name>
</patient>
<observations>
<observation>
<code>GLU</code>
<value>REDACTED</value>
</observation>
<observation>
<code>WBC</code>
<value>REDACTED</value>
</observation>
<observation>
<code>COVID</code>
<value>REDACTED</value>
</observation>
</observations>
</root>
*/