You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚠ This document applies to the Handlebars engine. Follow this link for the documentation of Liquid engine.
Helper Functions
The open-source release includes a set of helper functions to assist with template creation. The current list of available helper functions is below. If these do not meet your needs, you can also write your own helper functions. Some of the helper functions are used by both the HL7 v2 to FHIR and C-CDA to FHIR implementation, while others are specific to data type.
HL7 v2 Specific Helper Functions
Helper Function
Description
Syntax
getFieldRepeats
Returns repeat list for a field
getFieldRepeatsfieldData
getFirstSegments
Returns first instance of the segments
getFirstSegmentsmessage segment1 segment2 …
getSegmentLists
Extract HL7 v2 segments
getSegmentListsmessage segment1 segment2 …
getRelatedSegmentList
Given a segment name and index, return the collection of related named segments
Returns part of string between start and end positions (end not included)
strSlicestring start end
split
Splits the string based on regex. e.g. (split "a,b,c" ",")
splitstring regex
concat
Returns the concatenation of provided strings
concataString bString cString …
replace
Replaces text in a string using a regular expression
replacestring searchRegex replaceStr
match
Returns an array containing matches with a regular expression
matchstring regex
contains
Returns true if a string includes another string
containsaStringbString
toString
Converts to string
toStringobject
toJsonString
Converts to JSON string
toJsonStringobject
toLower
Converts string to lower case
toLowerstring
toUpper
Converts string to upper case
toUpperstring
base64Encode
Returns base64 encoded string
base64Encodestring
base64Decode
Returns base64 decoded string
base64Decodestring
escapeSpecialChars
Returns string with special chars escaped
escapeSpecialCharsstring
unescapeSpecialChars
Returns string after removing escaping of special char
unescapeSpecialCharsstring
sha1Hash
Returns sha1 hash (in hex) of given string
sha1Hashstring
gzip
Returns compressed string
gzipstringinEncodingoutEncoding
gunzip
Returns decompressed string
gunzipstringinEncodingoutEncoding
Collection Helper Functions
Helper Function
Description
Syntax
elementAt
Returns array element at position index
elementAtarray index
length
Returns array length
lengtharray
slice
Returns part of array between start and end positions (end not included)
slicearray start end
toArray
Returns an array created (if needed) from given object
toArrayobject
Mathematical Helper Functions
Helper Function
Description
Syntax
isNaN
Checks if the object is not a number using JavaScript isNaN
isNaNobject
abs
Returns the absolute value of a number
absa
ceil
Returns the next largest whole number or integer
ceila
floor
Returns the largest integer less than or equal to a given number
floora
max
Returns the largest of zero or more numbers
maxa b …
min
Returns the lowest-valued number passed into it, or NaN if any parameter isn't a number and can't be converted into one
mina b …
pow
Returns the base to the exponent power, that is, base^exponent
powx y
random
Returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range — which you can then scale to your desired range
random
round
Returns the value of a number rounded to the nearest integer
rounda
sign
Returns either a positive or negative +/- 1, indicating the sign of a number passed into the argument. If the number passed into is 0, it will return a +/- 0. Note that if the number is positive, an explicit (+) will not be returned
signa
trunc
Returns the integer part of a number by removing any fractional digits
trunca
add
Add two numbers: + number1 number 2
adda b
subtract
Subtract second number from the first: - number 1 number 2
subtracta b
multiply
Multiply two numbers: * number1 number2
multiplya b
divide
Divide first number by the second number: / number1 number2
dividea b
DateTime Helper Functions
Helper Function
Description
Syntax
addHyphensDate
Adds hyphens to a date without hyphens
addHyphensDatedate
now
Provides current UTC time in YYYYMMDDHHmmssSSS format
now
formatAsDateTime
Converts an YYYYMMDDHHmmssSSS string, e.g. 20040629175400000 to dateTime format, e.g. 2004-06-29T17:54:00.000z
formatAsDateTimedateTimeString
Miscellaneous Helper Functions
Helper Function
Description
Syntax
assert
Fails with message if predicate is false
assertpredicate message
evaluate
Returns template result object
evaluatetemplatePath inObj
generateUUID
Generates a GUID based on a URL. Sometimes it will also be invoked with a message object argument. It may generate different ids if the source file is read from different platforms, because although semantics are the same, the source files may contain different newline characters.
Here comes an example, the result of generateUUID '<ClinicalDocument>\n <section>...' and the result of generateUUID '<ClinicalDocument>\r\n <section>...' are not equal
generateUUIDurl
generateUUIDV2
Generates a consistent GUID based on a URL. Sometimes it will also be invoked with a message object argument. If the input contains any platform related newline characters, such as \n or \r, the generated GUID will also be consistent by removing these characters.
Here comes an example, the result of generateUUIDV2 '<ClinicalDocument>\n <section>...' and the result of generateUUIDV2 '<ClinicalDocument>\r\n <section>...' are exactly equal