Skip to content

message.addChildAfter

Signature: message.addChildAfter(nodePath, childNode, value*)

Returns: void

Add the specified childNode after the first node that matches nodePath.

Note

This method only applies to the following formatted messages: HL7, ASTM, EDIFACT, X12, XML.

Parameters

Type Name Description Default
String nodePath the node path (XPath, HPath, Column ID, etc.)
String childNode the name of the child node to add
String value* (optional) the value of the child node to add null

Examples

hl7

// assumes `message` is an HL7 message model object, like:
//    MSH|^~\&|||||||ORU^R01|12345
//    PID|||10001||Doe^John

message.addChildAfter('PID', 'OBR', 'OBR|1|||88304^PATHOLOGY');
message.addChildAfter('OBR' , 'OBX', 'OBX|2|TX|TEST2||Second observation');
message.addChildAfter('OBR' , 'OBX', 'OBX|1|TX|TEST1||First observation');

/* resulting message:
MSH|^~&|||||||ORU^R01|12345
PID|||10001||Doe^John
OBR|1|||88304^PATHOLOGY
OBX|1|TX|TEST1||First observation
OBX|2|TX|TEST2||Second observation
*/

xml

// Given an XML message like:
message = qie.createXMLMessage(
`
<people>
    <person>
        <name>Nate</name>
        <age>30</age>
    </person>
    <person>
        <name>John</name>
        <age>41</age>
    </person>
</people>
`
);

// Add a child node immediately AFTER the node matched by nodePath
message.addChildAfter(
    "/people/person[name='John']/age", // nodePath to insert after
    "favorite_dessert",                // childNode
    "ice cream"                        // value
);

// Resulting XML:
// <people>
//     <person>
//         <name>Nate</name>
//         <age>30</age>
//     </person>
//     <person>
//         <name>John</name>
//         <age>41</age>
//         <favorite_dessert>ice cream</favorite_dessert>
//     </person>
// </people>