functionDefinition
Defines a named function with typed parameters and an optional return type. Functions may be fluent (usable via dot notation), external (implemented by the host environment), or defined by a CQL expression body.
Examples
Simple function with parameter and return type
define function "Age At"(asOf DateTime) returns Integer: AgeInYearsAt(asOf)
Fluent function callable via dot notation
define fluent function "ToInterval"(period FHIR.Period) returns Interval<DateTime>: Interval[period."start".value, period."end".value]
External function (implemented by host)
define function "LogMessage"(msg String) returns String: external
Public multi-parameter function
define public function "CalculateBMI"(weight Decimal, height Decimal) returns Decimal: weight / (height * height)
EBNF
functionDefinition
: 'define' accessModifier? fluentModifier? 'function' identifierOrFunctionIdentifier
'(' (operandDefinition (',' operandDefinition)*)? ')'
('returns' typeSpecifier)?
':' (functionBody | 'external')
;