FHIRPath

  • Checkout this page from HL7 for the full specification
  • Please note that most of the comments on the parser classes are taken directly from HL7's FHIRPath specification with full credit given. I thought it would be helpful to have it as a comment while trying to use this package, so I've included it. If this is not allowed, please alert me, and I will immediately remove the comments.

Functionality

How To Use

  • To use this library, you can call one of two functions:
List r4WalkFhirPath(
  r4.Resource? resource,
  String pathExpression, [
  Map<String, dynamic>? passed,
]) =>
    walkFhirPath(resource?.toJson(), pathExpression, passed, FhirVersion.r4);

/// OR

List walkFhirPath(
  Map<String, dynamic>? resource,
  String pathExpression, [
  Map<String, dynamic>? passed,
  FhirVersion version = FhirVersion.r4,
]) {

This allows you to call the walkFhirPath function directly and pass it the FHIR version you are using, or you can call the function specifically for your version and it will pass that with it. This way the library can easily work with all versions of FHIR.

The resource is the main resource you're acting on (if you call walkFhirPath directly, you must pass it as a Map - call .toJson() on your resource). The pathExpression is the expression that will be evaluated and applied to the resource. If you need to pass in environmental variables, these are passed as the map. The passed Map's keys need to have a "%" in front of them, for instance:

{
    '%pi': 3.1415,
    '%birthday': '1776/07/04'
}

The passed resource WILL be added to this map as '%resource', so you don't need to add it, but be aware this it will be present, and if you try to pass in a different '%resource' it will be overwritten.

ToDo (functionality not supported yet)

  • Non-escape sequences
  • Quantities, toQuantity, convertsToQuantity, unary operators for Quantities
  • trace
  • Reflection
  • Correct takeParser
  • System.something (models - https://hl7.org/fhirpath/#models)
  • Confirm equivalence works properly
  • Correct some of the issues with "this is type"

Notes on Structure

  1. When executing a FHIRParser class, any result will be a List
  2. During the execution, this takes advantage of the FHIR datatypes
  3. However After execution (which acts recursively and traverses down the tree) there will be only values in the Lists, no more FHIR parsers

PetitParser

  • I personally found PetitParser more convenient to use than ANTLR for this library
  • However, the actual parsing is done separately from the tokenization (lexing), so if at some point someone wanted to change it to use ANTLR instead, they could swap out the lexer and the library should still function

Official FHIRPath grammar

Libraries

petit/lexer/arg_fxn_lexer
petit/parser/operation_parser/boolean_logic_parser
petit/parser/operation_parser/collections_parser
petit/parser/function_parser/combining_parser
petit/parser/operation_parser/comparison_parser
petit/parser/function_parser/conversions_parser
petit/utils/deep_comparison_lists
petit/lexer/deprecated_lexer
petit/parser/function_parser/deprecated_parser
petit/quantity/duration_code
petit/parser/operation_parser/equality_parser
petit/utils/exceptions
petit/parser/function_parser/existence_parser
petit/lexer/extension_lexer
petit/parser/function_parser/extension_parser
petit/utils/fhir_datatypes
fhir_path
petit/lexer/fhir_path_lexer
petit/parser/fhir_path_parsers/fhir_path_parser
petit/quantity/fhir_path_quantity
petit/parser/function_parser/filtering_projection_parser
petit/parser/function_parser/function_parser
petit/lexer/lexer_lists
petit/lexer/lexers
petit/lexer/literal_lexer
petit/parser/literal_parser
petit/parser/function_parser/math_parser
petit/parser/operation_parser/math_parser
petit/lexer/no_arg_fxn_lexer
petit/parser/operation_parser/operation_parser
petit/lexer/operator_lexer
petit/parser/parser
petit/petit_fhir_path
petit/utils/polymorphic_prefixes
petit/lexer/precedence
petit/quantity/quantity
petit/lexer/quantity_lexer
petit/quantity/ratios
petit/utils/singleton_evaluation
petit/lexer/special_lexer
petit/parser/special_parser
petit/parser/function_parser/string_manipulation_parser
petit/quantity/string_unit_to_property
petit/parser/function_parser/subsetting_parser
petit/parser/function_parser/tree_navigation_parser
petit/parser/operation_parser/types_parser
petit/quantity/ucum_prefixes
petit/quantity/ucum_units
petit/quantity/unit_code
petit/parser/function_parser/utility_parser
petit/utils/utils
petit/parser/fhir_path_parsers/value_parser
petit/utils/versions
petit/walk_fhir_path