Skip to content

message.checkNodeExists

Use when: You want to read values from the modified message during mapping. If you need the original incoming message, use source.checkNodeExists.

Signature: message.checkNodeExists(nodePath, instance*, repetition*)

Returns: Boolean exists - true if node is found, false if node is not found

Check for the existence of one or more nodes that match the nodePath.

Note

This method doesn't check to see if the node is empty. If the node exists, this will return true whether there is data or not.

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.)
Integer instance* (optional) the instance to return: segment for HL7, ASTM, EDIFACT, or X12; row for CSV or fixed-length formats; or match for DICOM, JSON, or XML. Use 1 for the first instance. 1
Integer repetition* (optional) the field repeat instance for HL7 or ASTM to return. Use 1 for the first instance. 1

Examples

hl7

// Example: Check whether one or more nodes exist at a given path.

// assumes `message` is an HL7 message model object, like:
//    MSH|^~\&|SendingApp|SendingFac|ReceivingApp|ReceivingFac|202311071015||ADT^A01|1234|P|2.5
//    PID|1||123456^^^&1.2.3.4&ISO||Doe^John||19700101|M|||123 Main St^^Metropolis^NY^54321||(123)456-7890

// Check for existence of a node (any instance)
if (message.checkNodeExists("PID-3")) {
    // The patient identifier is present.
}

// Check for existence of a specific instance
if (message.checkNodeExists(
        "PID-13",  // node path
        1          // instance
    )) {
    // The first PID segment carries a phone number.
}

json

// Example: Check whether one or more nodes exist at a given path.

// Sample JSON message structure
message = qie.createJSONMessage(JSON.stringify(
    {
        "patient": {
            "name": "Jane Doe",
            "identifiers": [
                { "type": "MRN", "value": "12345" },
                { "type": "FIN", "value": "67890" }
            ]
        }
    }
));

if (message.checkNodeExists('/patient/name')) {
    // The patient name is present.
}

if (message.checkNodeExists('/patient/identifiers/value', 2)) {
    // A second identifier was supplied.
}

if (!message.checkNodeExists('/patient/phone')) {
    // No phone number was supplied.
}

xml

// Example: Check whether one or more nodes exist at a given path.

// Sample XML message structure
message = qie.createXMLMessage(
'<patient>' +
    '<name>Jane Doe</name>' +
    '<identifier type="MRN">12345</identifier>' +
    '<identifier type="FIN">67890</identifier>' +
'</patient>'
);

if (message.checkNodeExists('/patient/name')) {
    // The patient name is present.
}

if (message.checkNodeExists('/patient/identifier[2]')) {
    // A second identifier element was supplied.
}

if (!message.checkNodeExists('/patient/phone')) {
    // No phone number was supplied.
}