Skip to content

FHIR Mapping Language Parser

FHIR Mapping Language parser and lexer utilities.

parser

FHIR Mapping Language Parser

Classes:

Name Description
FHIRMappingLanguageParser

An LALR-parser for the FHIR Mapping Language

Functions:

Name Description
parse

Parse a FHIR Mapping Language string into a StructureMap resource.

FHIRMappingLanguageParser

Path: fhircraft.fhir.mapper.parser.FHIRMappingLanguageParser

FHIRMappingLanguageParser(fhir_release: FHIRRelease, debug: bool = False, lexer_class: type | None = None)

Bases: FHIRPathParser

An LALR-parser for the FHIR Mapping Language

Methods:

Name Description
parse

Parse a FHIR Mapping Language string into a StructureMap resource.

is_valid

Check if the given FHIR Mapping Language string is valid.

p_mapper_structure_map

structureMap : m_structureMap_sections

p_mapper_structure_map_sections

m_structureMap_sections : m_structureMap_sections m_structureMap_section

p_mapper_structure_map_section_metadata

m_structureMap_section : m_metadata_entry

p_mapper_structure_map_section_map_id

m_structureMap_section : m_mapId

p_mapper_structure_map_section_conceptmap

m_structureMap_section : m_conceptmap

p_mapper_structure_map_section_structure

m_structureMap_section : m_structure

p_mapper_structure_map_section_imports

m_structureMap_section : m_imports

p_mapper_structure_map_section_const

m_structureMap_section : m_const

p_mapper_structure_map_section_group

m_structureMap_section : m_group

p_mapper_metadata_entry

m_metadata_entry : METADATA_DECLARATION m_identifier EQUAL m_metadata_value

p_mapper_metadata_value

m_metadata_value : m_literal

p_mapper_map_id

m_mapId : MAP m_url EQUAL m_identifier

p_conceptmap

m_conceptmap : CONCEPTMAP m_conceptmap_name '{' m_conceptmap_prefix_list m_conceptmap_mapping_list '}'

p_conceptmap_name

m_conceptmap_name : m_identifier

p_conceptmap_prefix_list

m_conceptmap_prefix_list : m_conceptmap_prefix_list m_conceptmap_prefix

p_conceptmap_prefix

m_conceptmap_prefix : PREFIX m_identifier EQUAL m_url

p_conceptmap_mapping_list

m_conceptmap_mapping_list : m_conceptmap_mapping_list m_conceptmap_mapping

p_conceptmap_mapping

m_conceptmap_mapping : m_identifier ':' m_conceptmap_code m_conceptmap_operator m_identifier ':' m_conceptmap_code

p_conceptmap_code

m_conceptmap_code : m_identifier

p_conceptmap_operator

m_conceptmap_operator : EQUAL

p_mapper_structure

m_structure : USES m_url m_structureAlias AS m_model_mode

p_mapper_structure_alias

m_structureAlias : ALIAS m_identifier

p_mapper_model_mode

m_model_mode : SOURCE

p_mapper_imports

m_imports : IMPORTS m_url

p_mapper_const

m_const : LET m_identifier EQUAL m_fhirpath ';'

p_mapper_extending_group

m_group : GROUP m_identifier m_parameters m_extends GROUPTYPE m_rules

p_mapper_group

m_group : GROUP m_identifier m_parameters GROUPTYPE m_rules

p_mapper_parameters

m_parameters : '(' m_parameter_list ')'

p_mapper_parameter_list

m_parameter_list : m_parameter ',' m_parameter

p_mapper_parameter

m_parameter : m_inputMode m_identifier m_type

p_mapper_type

m_type : ':' m_identifier

p_mapper_input_mode

m_inputMode : SOURCE

p_mapper_extends

m_extends : EXTENDS m_identifier

p_mapper_empty_rules

m_rules : '{' '}'

p_mapper_rules

m_rules : '{' m_rule_list '}'

p_mapper_rule_list_error

m_rule_list : m_rule

p_mapper_rule_list

m_rule_list : m_rule_delimited

p_mapper_rule_delimited

m_rule_delimited : m_rule ';'

p_mapper_rule_named

m_rule : m_rule m_rule_name

p_mapping_rule

m_rule : m_rule_only_sources

p_mapper_rule_only_sources

m_rule_only_sources : m_rule_source_list m_dependent

p_identifier_list

m_identifier_list : m_identifier_list ',' m_identifier

p_mapper_rule_full

m_rule : m_rule_source_list RIGHT_ARROW m_rule_target_list m_dependent

p_mapper_rule_name

m_rule_name : m_identifier

p_mapper_rule_source_list

m_rule_source_list : m_rule_source_list ',' m_rule_source

p_mapper_rule_source

m_rule_source : m_rule_path m_source_modifiers

p_mapper_source_modifiers

m_source_modifiers : m_source_modifiers m_source_modifier

p_mapper_source_modifier

m_source_modifier : m_sourceType

p_mapper_rule_context

m_rule_path : m_identifier

p_mapper_rule_context_with_element

m_rule_path : m_identifier '.' m_identifier

p_mapper_rule_context_with_subelements

m_rule_path : m_rule_path '.' m_identifier

p_mapper_source_type

m_sourceType : ':' m_identifier

p_mapper_source_cardinality

m_sourceCardinality : INTEGER '.' '.' INTEGER

p_mapper_source_default

m_sourceDefault : DEFAULT '(' m_fhirpath ')'

p_mapper_source_list_mode

m_sourceListMode : FIRST

p_mapper_alias

m_alias : AS m_identifier

p_mapper_where_clause

m_whereClause : WHERE '(' m_fhirpath ')'

p_mapper_check_clause

m_checkClause : CHECK '(' m_fhirpath ')'

p_mapper_log

m_log : LOG '(' m_fhirpath ')'

p_mapper_rule_target_list

m_rule_target_list : m_rule_target_list ',' m_rule_target

p_mapper_rule_target_with_invocation

m_rule_target : m_invocation m_target_modifier_list

p_mapper_rule_target

m_rule_target : m_rule_path EQUAL m_transform m_target_modifier_list

p_mapper_target_modifier_list

m_target_modifier_list : m_target_modifier_list m_target_modifier

p_mapper_target_modifier

m_target_modifier : m_alias

p_mapper_target_list_mode

m_targetListMode : FIRST

p_mapper_transform

m_transform : m_transform_fhirpath

p_mapper_transform_rule_path

m_transform_rule_path : m_rule_path

p_mapper_transform_fhirpath

m_transform_fhirpath : '(' m_fhirpath ')'

p_mapper_transform_literal

m_transform_literal : m_literal

p_mapper_transform_invocation

m_transform_invocation : m_invocation

p_mapper_dependent_rules

m_dependent : THEN m_rules

p_mapper_dependent_invocation_list

m_dependent : THEN m_invocation_list

p_mapper_dependent_mixed

m_dependent : THEN m_invocation_list m_rules

p_mapper_invocation_list

m_invocation_list : m_invocation_list ',' m_invocation

p_mapper_invocation_with_parameters

m_invocation : m_identifier '(' m_param_list ')'

p_mapper_invocation

m_invocation : m_identifier '(' ')'

p_mapper_param_list

m_param_list : m_param_list ',' m_param

p_mapper_param

m_param : m_param_id

p_mapper_param_literal

m_param_literal : m_literal

p_mapper_param_id

m_param_id : m_identifier

p_mapper_fhir_path

m_fhirpath : expression

p_mapper_url

m_url : DELIMITEDIDENTIFIER

p_mapper_identifier

m_identifier : IDENTIFIER

p_fhirpath_identifier

identifier : IDENTIFIER

p_reserved_words_as_identifier

m_reserved_words : MAP

p_mapper_literal

m_literal : INTEGER

p_mapper_time

m_time : TIME

p_mapper_date

m_date : DATE

p_mapper_datetime

m_datetime : DATETIME

p_mapper_empty

m_empty :

Attributes:

Name Type Description
tokens

The list of token names used by the parser. This is required by PLY.

structure_map StructureMapUnion

The StructureMap resource being constructed during parsing.

tokens class-attribute instance-attribute

tokens = FHIRMappingLanguageLexer.tokens

The list of token names used by the parser. This is required by PLY.

structure_map instance-attribute

structure_map: StructureMapUnion

The StructureMap resource being constructed during parsing.

parse

parse(input_string: str) -> StructureMapUnion

Parse a FHIR Mapping Language string into a StructureMap resource.

Parameters:

Name Type Description Default
input_string str

The FHIR Mapping Language string to parse.

required

Returns:

Name Type Description
StructureMapUnion StructureMapUnion

The parsed StructureMap resource.

is_valid

is_valid(input_string: str) -> bool

Check if the given FHIR Mapping Language string is valid.

Parameters:

Name Type Description Default
input_string str

The FHIR Mapping Language string to validate.

required

Returns:

Name Type Description
bool bool

True if the string is valid, False otherwise.

p_mapper_structure_map

p_mapper_structure_map(p)

structureMap : m_structureMap_sections

p_mapper_structure_map_sections

p_mapper_structure_map_sections(p)
m_structureMap_sections m_structureMap_section

| m_empty

p_mapper_structure_map_section_metadata

p_mapper_structure_map_section_metadata(p)

m_structureMap_section : m_metadata_entry

p_mapper_structure_map_section_map_id

p_mapper_structure_map_section_map_id(p)

m_structureMap_section : m_mapId

p_mapper_structure_map_section_conceptmap

p_mapper_structure_map_section_conceptmap(p)

m_structureMap_section : m_conceptmap

p_mapper_structure_map_section_structure

p_mapper_structure_map_section_structure(p)

m_structureMap_section : m_structure

p_mapper_structure_map_section_imports

p_mapper_structure_map_section_imports(p)

m_structureMap_section : m_imports

p_mapper_structure_map_section_const

p_mapper_structure_map_section_const(p)

m_structureMap_section : m_const

p_mapper_structure_map_section_group

p_mapper_structure_map_section_group(p)

m_structureMap_section : m_group

p_mapper_metadata_entry

p_mapper_metadata_entry(p)

m_metadata_entry : METADATA_DECLARATION m_identifier EQUAL m_metadata_value

p_mapper_metadata_value

p_mapper_metadata_value(p)

p_mapper_map_id

p_mapper_map_id(p)
MAP m_url EQUAL m_identifier

| MAP m_url EQUAL STRING

p_conceptmap

p_conceptmap(p)

m_conceptmap : CONCEPTMAP m_conceptmap_name '{' m_conceptmap_prefix_list m_conceptmap_mapping_list '}'

p_conceptmap_name

p_conceptmap_name(p)
m_identifier

| STRING

p_conceptmap_prefix_list

p_conceptmap_prefix_list(p)
m_conceptmap_prefix_list m_conceptmap_prefix

| m_conceptmap_prefix | m_empty

p_conceptmap_prefix

p_conceptmap_prefix(p)

m_conceptmap_prefix : PREFIX m_identifier EQUAL m_url

p_conceptmap_mapping_list

p_conceptmap_mapping_list(p)
m_conceptmap_mapping_list m_conceptmap_mapping

| m_conceptmap_mapping | m_empty

p_conceptmap_mapping

p_conceptmap_mapping(p)

m_conceptmap_mapping : m_identifier ':' m_conceptmap_code m_conceptmap_operator m_identifier ':' m_conceptmap_code

p_conceptmap_code

p_conceptmap_code(p)
m_identifier

| STRING

p_conceptmap_operator

p_conceptmap_operator(p)
EQUAL

| NOT_EQUAL | DOUBLE_EQUAL | GREATER_EQUAL_THAN | LESS_EQUAL_THAN

p_mapper_structure

p_mapper_structure(p)
USES m_url m_structureAlias AS m_model_mode

| USES m_url AS m_model_mode

p_mapper_structure_alias

p_mapper_structure_alias(p)

m_structureAlias : ALIAS m_identifier

p_mapper_model_mode

p_mapper_model_mode(p)
SOURCE

| QUERIED | TARGET | PRODUCED

p_mapper_imports

p_mapper_imports(p)

m_imports : IMPORTS m_url

p_mapper_const

p_mapper_const(p)

m_const : LET m_identifier EQUAL m_fhirpath ';'

p_mapper_extending_group

p_mapper_extending_group(p)
GROUP m_identifier m_parameters m_extends GROUPTYPE m_rules

| GROUP m_identifier m_parameters m_extends m_rules

p_mapper_group

p_mapper_group(p)
GROUP m_identifier m_parameters GROUPTYPE m_rules

| GROUP m_identifier m_parameters m_rules

p_mapper_parameters

p_mapper_parameters(p)
'(' m_parameter_list ')'

| '(' m_parameter ')'

p_mapper_parameter_list

p_mapper_parameter_list(p)
m_parameter ',' m_parameter

| m_parameter_list ',' m_parameter

p_mapper_parameter

p_mapper_parameter(p)
m_inputMode m_identifier m_type

| m_inputMode m_identifier

p_mapper_type

p_mapper_type(p)

m_type : ':' m_identifier

p_mapper_input_mode

p_mapper_input_mode(p)
SOURCE

| TARGET

p_mapper_extends

p_mapper_extends(p)

m_extends : EXTENDS m_identifier

p_mapper_empty_rules

p_mapper_empty_rules(p)

m_rules : '{' '}'

p_mapper_rules

p_mapper_rules(p)

m_rules : '{' m_rule_list '}'

p_mapper_rule_list_error

p_mapper_rule_list_error(p)
m_rule

| m_rule_list m_rule

p_mapper_rule_list

p_mapper_rule_list(p)
m_rule_delimited

| m_rule_list m_rule_delimited | m_empty

p_mapper_rule_delimited

p_mapper_rule_delimited(p)

m_rule_delimited : m_rule ';'

p_mapper_rule_named

p_mapper_rule_named(p)

m_rule : m_rule m_rule_name

p_mapping_rule

p_mapping_rule(p)
m_rule_only_sources

| m_rule

p_mapper_rule_only_sources

p_mapper_rule_only_sources(p)
m_rule_source_list m_dependent

| m_rule_source_list

p_identifier_list

p_identifier_list(p)
m_identifier_list ',' m_identifier

| m_identifier

p_mapper_rule_full

p_mapper_rule_full(p)
m_rule_source_list RIGHT_ARROW m_rule_target_list m_dependent

| m_rule_source_list RIGHT_ARROW m_rule_target_list ':' m_identifier_list | m_rule_source_list RIGHT_ARROW m_rule_target_list

p_mapper_rule_name

p_mapper_rule_name(p)
m_identifier

| STRING

p_mapper_rule_source_list

p_mapper_rule_source_list(p)
m_rule_source_list ',' m_rule_source

| m_rule_source

p_mapper_rule_source

p_mapper_rule_source(p)

m_rule_source : m_rule_path m_source_modifiers

p_mapper_source_modifiers

p_mapper_source_modifiers(p)
m_source_modifiers m_source_modifier

| m_source_modifier | m_empty

p_mapper_source_modifier

p_mapper_source_modifier(p)
m_sourceType

| m_sourceCardinality | m_sourceDefault | m_sourceListMode | m_alias | m_whereClause | m_checkClause | m_log

p_mapper_rule_context

p_mapper_rule_context(p)

m_rule_path : m_identifier

p_mapper_rule_context_with_element

p_mapper_rule_context_with_element(p)

m_rule_path : m_identifier '.' m_identifier

p_mapper_rule_context_with_subelements

p_mapper_rule_context_with_subelements(p)

m_rule_path : m_rule_path '.' m_identifier

p_mapper_source_type

p_mapper_source_type(p)

m_sourceType : ':' m_identifier

p_mapper_source_cardinality

p_mapper_source_cardinality(p)
INTEGER '.' '.' INTEGER

| INTEGER '.' '.' '*'

p_mapper_source_default

p_mapper_source_default(p)

m_sourceDefault : DEFAULT '(' m_fhirpath ')'

p_mapper_source_list_mode

p_mapper_source_list_mode(p)
FIRST

| NOT_FIRST | LAST | NOT_LAST | ONLY_ONE

p_mapper_alias

p_mapper_alias(p)

m_alias : AS m_identifier

p_mapper_where_clause

p_mapper_where_clause(p)

m_whereClause : WHERE '(' m_fhirpath ')'

p_mapper_check_clause

p_mapper_check_clause(p)

m_checkClause : CHECK '(' m_fhirpath ')'

p_mapper_log

p_mapper_log(p)

m_log : LOG '(' m_fhirpath ')'

p_mapper_rule_target_list

p_mapper_rule_target_list(p)
m_rule_target_list ',' m_rule_target

| m_rule_target

p_mapper_rule_target_with_invocation

p_mapper_rule_target_with_invocation(p)

m_rule_target : m_invocation m_target_modifier_list

p_mapper_rule_target

p_mapper_rule_target(p)
m_rule_path EQUAL m_transform m_target_modifier_list

| m_rule_path m_target_modifier_list

p_mapper_target_modifier_list

p_mapper_target_modifier_list(p)
m_target_modifier_list m_target_modifier

| m_target_modifier | m_empty

p_mapper_target_modifier

p_mapper_target_modifier(p)

m_target_modifier : m_alias | m_targetListMode

p_mapper_target_list_mode

p_mapper_target_list_mode(p)
FIRST

| SHARE | LAST | SINGLE

p_mapper_transform

p_mapper_transform(p)
m_transform_fhirpath

| m_transform_invocation | m_transform_rule_path | m_transform_literal

p_mapper_transform_rule_path

p_mapper_transform_rule_path(p)

m_transform_rule_path : m_rule_path

p_mapper_transform_fhirpath

p_mapper_transform_fhirpath(p)

m_transform_fhirpath : '(' m_fhirpath ')'

p_mapper_transform_literal

p_mapper_transform_literal(p)

m_transform_literal : m_literal

p_mapper_transform_invocation

p_mapper_transform_invocation(p)

m_transform_invocation : m_invocation

p_mapper_dependent_rules

p_mapper_dependent_rules(p)

m_dependent : THEN m_rules

p_mapper_dependent_invocation_list

p_mapper_dependent_invocation_list(p)

m_dependent : THEN m_invocation_list

p_mapper_dependent_mixed

p_mapper_dependent_mixed(p)

m_dependent : THEN m_invocation_list m_rules

p_mapper_invocation_list

p_mapper_invocation_list(p)
m_invocation_list ',' m_invocation

| m_invocation

p_mapper_invocation_with_parameters

p_mapper_invocation_with_parameters(p)

m_invocation : m_identifier '(' m_param_list ')'

p_mapper_invocation

p_mapper_invocation(p)

m_invocation : m_identifier '(' ')'

p_mapper_param_list

p_mapper_param_list(p)
m_param_list ',' m_param

| m_param

p_mapper_param

p_mapper_param(p)
m_param_id

| m_param_literal

p_mapper_param_literal

p_mapper_param_literal(p)

m_param_literal : m_literal

p_mapper_param_id

p_mapper_param_id(p)

m_param_id : m_identifier

p_mapper_fhir_path

p_mapper_fhir_path(p)

m_fhirpath : expression

p_mapper_url

p_mapper_url(p)
DELIMITEDIDENTIFIER

| STRING

p_mapper_identifier

p_mapper_identifier(p)
IDENTIFIER

| DELIMITEDIDENTIFIER | ROOT_NODE | m_reserved_words

p_fhirpath_identifier

p_fhirpath_identifier(p)
IDENTIFIER

| DELIMITEDIDENTIFIER | ROOT_NODE | m_reserved_words

p_reserved_words_as_identifier

p_reserved_words_as_identifier(p)
MAP

| USES | AS | SOURCE | TARGET | PRODUCED | QUERIED | GROUP | EXTENDS | THEN | CONCEPTMAP | PREFIX | IMPORTS | LET | DEFAULT | FIRST | LAST | SHARE | SINGLE

p_mapper_literal

p_mapper_literal(p)
INTEGER

| ROOT_NODE | STRING | BOOLEAN | DECIMAL | m_date | m_time | m_datetime

p_mapper_time

p_mapper_time(p)

m_time : TIME

p_mapper_date

p_mapper_date(p)

m_date : DATE

p_mapper_datetime

p_mapper_datetime(p)

m_datetime : DATETIME

p_mapper_empty

p_mapper_empty(p)

m_empty :

IteratorToTokenStream

Path: fhircraft.fhir.mapper.parser.IteratorToTokenStream

IteratorToTokenStream(iterator)

A simple wrapper around an iterator to provide a token stream interface.

Methods:

Name Description
token

Return the next token from the iterator, or None if the iterator is exhausted.

token

token()

Return the next token from the iterator, or None if the iterator is exhausted.

parse

parse(input_string: str, fhir_release: FHIRRelease) -> StructureMapUnion

Parse a FHIR Mapping Language string into a StructureMap resource.

Parameters:

Name Type Description Default
input_string str

The FHIR Mapping Language string to parse.

required
fhir_release FHIRRelease

The FHIR release version to use for parsing.

required

Returns:

Name Type Description
StructureMapUnion StructureMapUnion

The parsed StructureMap resource.

lexer

Classes:

Name Description
FHIRMappingLanguageLexer

A Lexical analyzer for FHIR Mapping Language.

FHIRMappingLanguageLexer

Path: fhircraft.fhir.mapper.lexer.FHIRMappingLanguageLexer

FHIRMappingLanguageLexer(debug=False)

Bases: FHIRPathLexer

A Lexical analyzer for FHIR Mapping Language.

Methods:

Name Description
tokenize

Maps a string to an iterator over tokens. In other words: [char] -> [token]

t_ignore_WHITESPACE

[\s]

t_METADATA_DECLARATION

\/\/\/

t_ignore_DOCUMENTATION

\/{2}(.*)

t_RIGHT_ARROW

->

t_DATETIME

@\d{4}(?:-\d{2}(?:-\d{2})?)?T(?:\d{2}(?::\d{2}(?::\d{2}(?:.\d{3}(?:[+|-]\d{2}(?::\d{2})?)?)?)?)?)?

t_DATE

@\d{4}(?:-\d{2}(?:-\d{2})?)?

t_BOOLEAN

true|false

t_TIME

\@T\d{2}(?::\d{2}(?::\d{2}(?:.\d{3}(?:[+|-]\d{2}(?::\d{2})?)?)?)?)?

t_NUMBER

-?\d+(.\d+)?

t_STRING

(\'([\']*)?\')|(\"([\"]*)?\")

t_GROUPTYPE

<>|<>

t_DOUBLE_EQUAL

==

t_DELIMITEDIDENTIFIER

`[a-zA-Z][a-zA-Z0-9-][^`]*`

t_error_invalid_function

"

tokenize

tokenize(string)

Maps a string to an iterator over tokens. In other words: [char] -> [token]

t_ignore_WHITESPACE

t_ignore_WHITESPACE(t)

[\s]

t_METADATA_DECLARATION

t_METADATA_DECLARATION(t)

\/\/\/

t_ignore_DOCUMENTATION

t_ignore_DOCUMENTATION(t)

\/{2}(.*)

t_RIGHT_ARROW

t_RIGHT_ARROW(t)

->

t_DATETIME

t_DATETIME(t)

@\d{4}(?:-\d{2}(?:-\d{2})?)?T(?:\d{2}(?::\d{2}(?::\d{2}(?:.\d{3}(?:[+|-]\d{2}(?::\d{2})?)?)?)?)?)?

t_DATE

t_DATE(t)

@\d{4}(?:-\d{2}(?:-\d{2})?)?

t_BOOLEAN

t_BOOLEAN(t)

true|false

t_TIME

t_TIME(t)

\@T\d{2}(?::\d{2}(?::\d{2}(?:.\d{3}(?:[+|-]\d{2}(?::\d{2})?)?)?)?)?

t_NUMBER

t_NUMBER(t)

-?\d+(.\d+)?

t_STRING

t_STRING(t)

(\'([\']*)?\')|(\"([\"]*)?\")

t_GROUPTYPE

t_GROUPTYPE(t)

<>|<>

t_DOUBLE_EQUAL

t_DOUBLE_EQUAL(t)

==

t_DELIMITEDIDENTIFIER

t_DELIMITEDIDENTIFIER(t)

`[a-zA-Z][a-zA-Z0-9-][^`]*`

t_error_invalid_function

t_error_invalid_function(t)

"