walkFhirPath function
Start here! This is where the fun begins. This is a bit confusing, so we'll explain the arguments that can be passed.
The FHIRPath specification defines the following inputs:
context
context Is the original node that was passed to the evaluation engine before starting evaluation.
Should always be passed in through the context
parameter.
resource
resource the resource that contains the original node that is in %context
May be passed in either through an entry in the environment
map,
named "%resource", or through the dedicated parameter.
A non-null dedicated parameter takes precedence.
rootResource
rootResource the container resource for the resource identified by %resource
May be passed in either through an entry in the environment
map,
named "%rootResource", or through the dedicated parameter.
A non-null dedicated parameter takes precedence.
environment variables / resources
environment
- arbitrary named environment variables.
These should be passed in as a map, where each key has the format
"%variable-name".
{
"%pi": 3.1415927,
"%myname": "Grey"
}
*** Lazy-loading ***
Instead of a static value, the environment
may map keys to functions
which return the actual value. These functions will only be evaluated when
the variable is accessed. This lazy evaluation may boost performance, for
instance when iif is used to determine which of two expensive objects is to
be used.
The lazy-loading mechanism is currently only supported through the
environment
map, not for explicitly passed-in parameters.
Implementation
List<dynamic> walkFhirPath({
required Map<String, dynamic>? context,
required String pathExpression,
Map<String, dynamic>? resource,
Map<String, dynamic>? rootResource,
Map<String, dynamic>? environment,
FhirVersion version = FhirVersion.r4,
}) {
final ast = parseFhirPath(pathExpression);
return executeFhirPath(
context: context,
parsedFhirPath: ast,
pathExpression: pathExpression,
resource: resource,
rootResource: rootResource,
environment: environment,
version: version,
);
}