source.getCount¶
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.getCount.
Signature: source.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, 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
// Given an HL7 source message containing multiple PID segments.
/* 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\r' +
'PID|1||654321^^^&1.2.3.4&ISO||Aimee^Smith||19850315|F|||456 Elm St^^Smalltown^CA^67890||(987)654-3210'
*/
// Retrieve the number of nodes that match the nodePath.
var patientCount = source.getCount('PID'); // expected: 2
json
// Example: Count the number of nodes that match a given path.
/* Sample JSON source:
{
"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 = source.getCount('observations/[]'); // 3
xml
// Example: Count the number of nodes that match a given path.
/* Sample XML source:
<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 = source.getCount('/root/observations/observation'); // 3