Skip to content

message.getCount

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

Signature: message.getCount(nodePath)

Returns: Integer count - the number of nodes that match the nodePath

Get the number of nodes that match 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, Text, X12, XML.

Parameters

Type Name Description Default
String nodePath the node path (XPath, HPath, Column ID, etc.)

Examples

hl7

// Example: Count the number of nodes that match 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
//    PID|1||654321^^^&1.2.3.4&ISO||Aimee^Smith||19850315|F|||456 Elm St^^Smalltown^CA^67890||(987)654-3210

// Count matching nodes
var patientCount = message.getCount("PID"); // 2

json

// Example: Count the number of nodes that match a given path.

// Sample JSON message structure
message = qie.createJSONMessage(
   '{' +
   '"patient": {' +
   '"id": "123456",' +
   '"name": "John Doe"' +
   '},' +
   '"observations": [' +
   '{ "code": "GLU", "value": 105 },' +
   '{ "code": "WBC", "value": 7.2 },' +
   '{ "code": "COVID", "value": "Negative" }' +
   ']' +
   '}'
);

// Count number of observations
var observationCount = message.getCount('observations/[]'); // 3

xml

// Example: Count the number of 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>`
);

// Count number of observation nodes
var observationCount = message.getCount('/root/observations/observation'); // 3