Skip to content

source.checkNodeExists

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

Signature: source.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 (0=header row) 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

// Given an HL7 source message with PID fields.
/* source:
'MSH|^~\\&|SendingApp|SendingFac|ReceivingApp|ReceivingFac|202311071015||ADT^A01|1234|P|2.5\r' +
'PID|1||123456^^^&1.2.3.4&ISO||Doe^John||19700101|M|||123 Main St^^Metropolis^NY^54321||(123)456-7890'
*/

// Check if the patient ID (PID-3) exists in the message.
if (source.checkNodeExists('PID-3')) {
    // The patient identifier is present.
}

// Check if the patient phone number (PID-13) exists as the first instance (1-based).
if (source.checkNodeExists(
        'PID-13',    // nodePath
        1            // instance (1-based)
    )) {
    // The first PID segment carries a phone number.
}

json

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

/* Sample JSON source structure
{
    "patient": {
        "name": "Jane Doe",
        "identifiers": [
            { "type": "MRN", "value": "12345" },
            { "type": "FIN", "value": "67890" }
        ]
    }
}
*/

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

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

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

xml

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

/* Sample XML source
<patient>
    <name>Jane Doe</name>
    <identifier type="MRN">12345</identifier>
    <identifier type="FIN">67890</identifier>
</patient>
*/
if (source.checkNodeExists('/patient/name')) {
    // The patient name is present.
}

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

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