FHIR Mapping Language
FHIR Mapping Language parser and transformation utilities.
ArbitraryModel
Path: fhircraft.fhir.mapper.engine.core.ArbitraryModel
Bases: BaseModel
A dynamic Pydantic model that accepts arbitrary fields.
This is used for arbitrary target structures in mappings where no specific structure definition is provided. Unlike plain dicts, this model is compatible with the FHIRPath engine's update mechanisms, allowing complex nested path creation and array operations.
FHIRMappingEngine
Path: fhircraft.fhir.mapper.engine.core.FHIRMappingEngine
FHIRMappingEngine(repository: CompositeStructureDefinitionRepository | None = None, factory: ResourceFactory | None = None)
FHIRMappingEngine is responsible for executing FHIR StructureMap-based transformations between FHIR resources.
This engine validates, processes, and applies mapping rules defined in a StructureMap to transform source FHIR resources into target resources, supporting complex mapping logic, rule dependencies, and FHIRPath-based expressions.
Attributes:
| Name | Type | Description |
|---|---|---|
repository |
CompositeStructureDefinitionRepository
|
Repository for FHIR StructureDefinitions. |
factory |
ResourceFactory
|
Factory for constructing FHIR resource models. |
transformer |
MappingTransformer
|
Executes FHIRPath-based transforms. |
Methods:
| Name | Description |
|---|---|
execute |
Executes a FHIR StructureMap transformation using the provided sources and optional targets. |
process_group |
Processes a StructureMap group by validating input parameters, constructing a local mapping scope, |
process_rule |
Processes a single StructureMap rule within the given mapping scope. |
process_source |
Processes a StructureMapGroupRuleSource object within a given MappingScope and returns the variable name |
process_target |
Processes a StructureMapGroupRuleTarget within the given mapping scope. |
validate_structure_map |
Validates the structure and content of a given StructureMap instance. |
Source code in fhircraft/fhir/mapper/engine/core.py
execute
execute(structure_map: StructureMap, sources: tuple[BaseModel | dict], targets: tuple[BaseModel | dict] | None = None, group: str | None = None) -> tuple[BaseModel, ...]
Executes a FHIR StructureMap transformation using the provided sources and optional targets.
This method resolves structure definitions, validates input data, sets up the mapping scope, binds source and target instances to group parameters, and processes the entrypoint group to produce the mapped target instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure_map
|
StructureMap
|
The StructureMap resource defining the transformation rules. |
required |
sources
|
tuple[BaseModel | dict]
|
Source data to be mapped, as a tuple of Pydantic models or dictionaries. |
required |
targets
|
tuple[BaseModel | dict] | None
|
Optional target instances to populate. If not provided, new instances are created as needed. |
None
|
group
|
str | None
|
The name of the entrypoint group to execute. If not specified, the first group is used. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[BaseModel, ...]
|
tuple[BaseModel, ...]: A tuple of resulting target instances after the transformation. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If StructureMap imports are present (not supported). |
ValueError
|
If a constant in the StructureMap is missing a name or conflicts with a model name. |
RuntimeError
|
If the number of provided sources or targets does not match the group parameters, or if required targets are missing. |
TypeError
|
If provided sources or targets do not match the expected types for the group parameters. |
Source code in fhircraft/fhir/mapper/engine/core.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
process_group
process_group(group: StructureMapGroup, parameters: list[FHIRPath] | tuple[FHIRPath], scope: MappingScope)
Processes a StructureMap group by validating input parameters, constructing a local mapping scope, and executing the group's rules in the correct order, handling special list modes ('first' and 'last').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
StructureMapGroup
|
The group definition containing mapping rules and input definitions. |
required |
parameters
|
list[FHIRPath] | tuple[FHIRPath]
|
The input parameters to be mapped, corresponding to the group's input definitions. |
required |
scope
|
MappingScope
|
The parent mapping scope to use as the basis for the group's local scope. |
required |
Raises:
| Type | Description |
|---|---|
MappingError
|
If the number of provided parameters does not match the group's input definitions. |
RuntimeError
|
If more than one rule with 'first' or 'last' target list mode is found in the group. |
NotImplementedError
|
If a target list mode other than 'first' or 'last' is encountered. |
Source code in fhircraft/fhir/mapper/engine/core.py
process_rule
process_rule(rule: StructureMapGroupRule, scope: MappingScope) -> MappingScope
Processes a single StructureMap rule within the given mapping scope.
This method handles the evaluation and execution of a StructureMapGroupRule, including: - Cycle detection to prevent infinite recursion. - Source processing to determine iteration counts and validate type, condition, and check constraints. - Iterative processing for each source instance, including: - Creating an iteration-specific mapping scope. - Setting indexed FHIRPath variables for the current iteration. - Processing target mappings, dependent rules/groups, and nested rules. - Merging results from each iteration back into the main scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
StructureMapGroupRule
|
The rule to process. |
required |
scope
|
MappingScope
|
The current mapping scope. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MappingScope |
MappingScope
|
The updated mapping scope after processing the rule. |
Raises:
| Type | Description |
|---|---|
RuleProcessingError
|
If any rule constraints (such as cardinality, type, or checks) are violated, or if required variables or dependent groups are not found. |
Source code in fhircraft/fhir/mapper/engine/core.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
process_source
process_source(source: StructureMapGroupRuleSource, scope: MappingScope) -> str
Processes a StructureMapGroupRuleSource object within a given MappingScope and returns the variable name associated with the resolved FHIRPath expression.
This method resolves the FHIRPath context from the source, applies any specified element path, and modifies the path according to the listMode option (e.g., first, last, not_first, not_last, only_one). The resulting FHIRPath expression is stored in the scope under a variable name, which is either provided by the source or generated uniquely.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
StructureMapGroupRuleSource
|
The source mapping definition containing context, element, listMode, and variable. |
required |
scope
|
MappingScope
|
The current mapping scope used to resolve FHIRPath and store variables. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The variable name under which the resolved FHIRPath expression is stored in the scope. |
Source code in fhircraft/fhir/mapper/engine/core.py
process_target
process_target(target: StructureMapGroupRuleTarget, scope: MappingScope) -> Any
Processes a StructureMapGroupRuleTarget within the given mapping scope.
This method resolves the FHIRPath context for the target, applies any specified element path, determines the appropriate insertion index, and stores the resulting FHIRPath in the scope as a variable. If a transform is specified on the target, it executes the transform with the provided parameters and updates the target structure with the transformed value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
StructureMapGroupRuleTarget
|
The mapping target to process, containing context, element, variable, transform, and parameters. |
required |
scope
|
MappingScope
|
The current mapping scope, used for resolving FHIRPath contexts and managing variables. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result of processing the target, typically the updated FHIRPath or transformed value. |
Raises:
| Type | Description |
|---|---|
RuleProcessingError
|
If the target context is not specified. |
Source code in fhircraft/fhir/mapper/engine/core.py
validate_structure_map
validate_structure_map(structure_map: StructureMap) -> List[str]
Validates the structure and content of a given StructureMap instance.
This method checks for the presence of required groups and structure declarations, ensures that both source and target structures are defined, and verifies that each group contains rules. It also delegates rule-specific validation to the _validate_rule method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure_map
|
StructureMap
|
The StructureMap object to validate. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of validation issue messages. The list is empty if no issues are found. |
Source code in fhircraft/fhir/mapper/engine/core.py
StructureMapModelMode
Path: fhircraft.fhir.mapper.engine.core.StructureMapModelMode
StructureMapTargetListMode
Path: fhircraft.fhir.mapper.engine.core.StructureMapTargetListMode
MappingError
Path: fhircraft.fhir.mapper.engine.exceptions.MappingError
Bases: Exception
Base exception for mapping engine errors.
RuleProcessingError
Path: fhircraft.fhir.mapper.engine.exceptions.RuleProcessingError
Bases: MappingError
Raised when rule processing fails.
ValidationError
Path: fhircraft.fhir.mapper.engine.exceptions.ValidationError
Bases: MappingError
Raised when input data validation fails.
MappingScope
Path: fhircraft.fhir.mapper.engine.scope.MappingScope
dataclass
MappingScope(name: str, types: Dict[str, type[BaseModel]] = dict(), source_instances: Dict[str, BaseModel] = dict(), target_instances: Dict[str, BaseModel] = dict(), concept_maps: Dict[str, ConceptMap] = dict(), groups: OrderedDict[str, StructureMapGroup] = OrderedDict(), variables: Dict[str, FHIRPath] = dict(), default_groups: Dict[str, StructureMapGroup] = dict(), processing_rules: Set[str] = set(), parent: Optional[MappingScope] = None)
A scope defines the visibility and accessibility of identifiers (variables, types, etc.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the scope |
required |
types
|
Dict[str, type[BaseModel]]
|
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) |
<class 'dict'>
|
source_instances
|
Dict[str, BaseModel]
|
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) |
<class 'dict'>
|
target_instances
|
Dict[str, BaseModel]
|
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) |
<class 'dict'>
|
concept_maps
|
Dict[str, ConceptMap]
|
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) |
<class 'dict'>
|
groups
|
OrderedDict[str, StructureMapGroup]
|
Dictionary that remembers insertion order |
<class 'collections.OrderedDict'>
|
variables
|
Dict[str, FHIRPath]
|
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) |
<class 'dict'>
|
default_groups
|
Dict[str, StructureMapGroup]
|
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) |
<class 'dict'>
|
processing_rules
|
Set[str]
|
Build an unordered collection of unique elements. |
<dynamic>
|
parent
|
ForwardRef | None
|
Parent mapping scope |
None
|
Methods:
| Name | Description |
|---|---|
define_variable |
Defines a new variable in the current scope. |
get_instances |
Returns a dictionary containing all instances from the current scope, including those inherited from the parent scope (if any), as well as target and source instances. |
get_concept_map |
Retrieve a ConceptMap by its identifier from the current scope or any parent scopes. |
get_target_instance |
Retrieve a target instance by its identifier from the current scope or any parent scopes. |
get_source_instance |
Retrieve a source instance by its identifier from the current scope or any parent scopes. |
get_type |
Retrieve the type associated with the given identifier from the current scope or its parent scopes. |
resolve_symbol |
Resolves a symbol (variable, type, or group) by its identifier from the current scope or any parent scopes. |
has_symbol |
Checks if a symbol with the given identifier exists in the current scope. |
has_local_symbol |
Checks if a symbol with the given identifier exists in the current scope only. |
resolve_fhirpath |
Resolve a symbol as a FHIRPath expression. |
get_all_visible_symbols |
Retrieves all visible symbols in the current scope, including those inherited from parent scopes. |
get_scope_path |
Returns the hierarchical path of scope names from the root to the current scope as a list of strings. |
get_scope_depth |
Returns the depth of the current scope within the scope hierarchy. |
create_child_scope |
Creates and returns a new child MappingScope with the specified name, setting the current scope as its parent. |
is_processing_rule |
Check if a given rule name is present in the list of processing rules. |
start_processing_rule |
Marks the beginning of processing for a specific rule by adding its name to the set of currently processing rules. |
finish_processing_rule |
Marks the specified rule as finished by removing it from the set of currently processing rules. |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the scope |
types |
Dict[str, type[BaseModel]]
|
Registry of available FHIR types by identifier |
source_instances |
Dict[str, BaseModel]
|
The source instances being mapped |
target_instances |
Dict[str, BaseModel]
|
The target instances being mapped |
concept_maps |
Dict[str, ConceptMap]
|
Registry of available concept maps for value transformations |
groups |
OrderedDict[str, StructureMapGroup]
|
The groups defined on this scope |
variables |
Dict[str, FHIRPath]
|
Registry of variables mapped to resolved FHIRPath expressions |
default_groups |
Dict[str, StructureMapGroup]
|
Registry of default mapping groups by type signature |
processing_rules |
Set[str]
|
Set of currently processing rules |
parent |
Optional[MappingScope]
|
Parent mapping scope |
types
class-attribute
instance-attribute
Registry of available FHIR types by identifier
source_instances
class-attribute
instance-attribute
The source instances being mapped
target_instances
class-attribute
instance-attribute
The target instances being mapped
concept_maps
class-attribute
instance-attribute
concept_maps: Dict[str, ConceptMap] = field(default_factory=dict)
Registry of available concept maps for value transformations
groups
class-attribute
instance-attribute
groups: OrderedDict[str, StructureMapGroup] = field(default_factory=OrderedDict)
The groups defined on this scope
variables
class-attribute
instance-attribute
Registry of variables mapped to resolved FHIRPath expressions
default_groups
class-attribute
instance-attribute
default_groups: Dict[str, StructureMapGroup] = field(default_factory=dict)
Registry of default mapping groups by type signature
processing_rules
class-attribute
instance-attribute
Set of currently processing rules
parent
class-attribute
instance-attribute
parent: Optional[MappingScope] = None
Parent mapping scope
define_variable
Defines a new variable in the current scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The name of the variable to define. |
required |
value
|
FHIRPath
|
The FHIRPath instance to assign to the variable. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided value is not an instance of FHIRPath. |
Source code in fhircraft/fhir/mapper/engine/scope.py
get_instances
Returns a dictionary containing all instances from the current scope, including those inherited from the parent scope (if any), as well as target and source instances.
Returns:
| Type | Description |
|---|---|
Dict[str, BaseModel]
|
Dict[str, BaseModel]: A dictionary mapping instance names to their corresponding BaseModel objects, aggregated from the parent scope, target instances, and source instances. |
Source code in fhircraft/fhir/mapper/engine/scope.py
get_concept_map
get_concept_map(identifier: str) -> ConceptMap
Retrieve a ConceptMap by its identifier from the current scope or any parent scopes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The unique identifier of the ConceptMap to retrieve. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ConceptMap |
ConceptMap
|
The ConceptMap instance associated with the given identifier. |
Raises:
| Type | Description |
|---|---|
MappingError
|
If the ConceptMap with the specified identifier is not found in the current or any parent scopes. |
Source code in fhircraft/fhir/mapper/engine/scope.py
get_target_instance
Retrieve a target instance by its identifier from the current scope or any parent scopes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The unique identifier of the target instance to retrieve. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BaseModel |
BaseModel
|
The target instance associated with the given identifier. |
Raises:
| Type | Description |
|---|---|
MappingError
|
If the target instance is not found in the current or any parent scopes. |
Source code in fhircraft/fhir/mapper/engine/scope.py
get_source_instance
Retrieve a source instance by its identifier from the current scope or any parent scopes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The unique identifier of the source instance to retrieve. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BaseModel |
BaseModel
|
The source instance associated with the given identifier. |
Raises:
| Type | Description |
|---|---|
MappingError
|
If the source instance is not found in the current or any parent scopes. |
Source code in fhircraft/fhir/mapper/engine/scope.py
get_type
Retrieve the type associated with the given identifier from the current scope or its parent scopes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The identifier for which to retrieve the associated type. |
required |
Returns:
| Type | Description |
|---|---|
type[BaseModel]
|
type[BaseModel]: The type associated with the identifier. |
Raises:
| Type | Description |
|---|---|
MappingError
|
If the identifier is not found in the current or any parent scope. |
Source code in fhircraft/fhir/mapper/engine/scope.py
resolve_symbol
Resolves a symbol (variable, type, or group) by its identifier from the current scope or any parent scopes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The name of the symbol to resolve. |
required |
Returns:
| Type | Description |
|---|---|
Union[FHIRPath, type[BaseModel], StructureMapGroup]
|
Union[FHIRPath, type[BaseModel], StructureMapGroup]: The resolved symbol, which can be a variable, a type, or a group. |
Raises:
| Type | Description |
|---|---|
MappingError
|
If the symbol cannot be found in the current or any parent scopes. |
Source code in fhircraft/fhir/mapper/engine/scope.py
has_symbol
Checks if a symbol with the given identifier exists in the current scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The name of the symbol to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the symbol exists, False otherwise. |
Source code in fhircraft/fhir/mapper/engine/scope.py
has_local_symbol
Checks if a symbol with the given identifier exists in the current scope only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The name of the symbol to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the symbol exists, False otherwise. |
Source code in fhircraft/fhir/mapper/engine/scope.py
resolve_fhirpath
Resolve a symbol as a FHIRPath expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The symbol identifier to resolve |
required |
Returns: The resolved FHIRPath expression Raises: MappingError: If the symbol is not found or is not a FHIRPath
Source code in fhircraft/fhir/mapper/engine/scope.py
get_all_visible_symbols
Retrieves all visible symbols in the current scope, including those inherited from parent scopes.
This method aggregates symbols from the parent scope (if present) and then overrides them with symbols defined in the current scope. The symbols include variables, types, and groups.
Returns:
| Type | Description |
|---|---|
Dict[str, Union[FHIRPath, type[BaseModel], StructureMapGroup]]
|
Dict[str, Union[FHIRPath, type[BaseModel], StructureMapGroup]]: A dictionary mapping symbol names to their corresponding objects, representing all symbols visible in the current scope. |
Source code in fhircraft/fhir/mapper/engine/scope.py
get_scope_path
Returns the hierarchical path of scope names from the root to the current scope as a list of strings.
If the current scope has a parent, the method recursively retrieves the parent's scope path and appends the current scope's name. If there is no parent, returns a list containing only the current scope's name.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: The list of scope names representing the path from the root to the current scope. |
Source code in fhircraft/fhir/mapper/engine/scope.py
get_scope_depth
get_scope_depth() -> int
Returns the depth of the current scope within the scope hierarchy.
Traverses up the parent scopes recursively, incrementing the depth count for each parent until the root scope is reached.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The depth of the current scope, where the root scope has a depth of 0. |
Source code in fhircraft/fhir/mapper/engine/scope.py
create_child_scope
create_child_scope(name: str) -> MappingScope
Creates and returns a new child MappingScope with the specified name, setting the current scope as its parent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the child scope to be created. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MappingScope |
MappingScope
|
A new instance of MappingScope with the given name and the current scope as its parent. |
Source code in fhircraft/fhir/mapper/engine/scope.py
is_processing_rule
Check if a given rule name is present in the list of processing rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_name
|
str
|
The name of the rule to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the rule is in the processing rules, False otherwise. |
Source code in fhircraft/fhir/mapper/engine/scope.py
start_processing_rule
start_processing_rule(rule_name: str) -> None
Marks the beginning of processing for a specific rule by adding its name to the set of currently processing rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_name
|
str
|
The name of the rule to start processing. |
required |
Source code in fhircraft/fhir/mapper/engine/scope.py
finish_processing_rule
finish_processing_rule(rule_name: str) -> None
Marks the specified rule as finished by removing it from the set of currently processing rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_name
|
str
|
The name of the rule to mark as finished. |
required |
Source code in fhircraft/fhir/mapper/engine/scope.py
MappingTransformer
Path: fhircraft.fhir.mapper.engine.transformer.MappingTransformer
MappingTransformer is responsible for executing various FHIR Mapping Language transforms within a mapping scope. It provides implementations for a set of standard transforms (such as copy, create, truncate, cast, append, reference, uuid, translate, evaluate, etc.) used in FHIR StructureMap-based data transformations.
Attributes:
| Name | Type | Description |
|---|---|---|
_transforms |
dict
|
A mapping of transform names to their corresponding handler methods. |
Raises:
| Type | Description |
|---|---|
MappingError
|
If an invalid or unsupported transform is requested. |
NotImplementedError
|
If a requested transform or feature is not implemented. |
RuleProcessingError
|
For invalid parameters or processing errors in transforms. |
Methods:
| Name | Description |
|---|---|
execute |
Executes a registered FHIR Mapping Language transform by name. |
Source code in fhircraft/fhir/mapper/engine/transformer.py
execute
execute(name: str, scope: MappingScope, parameters: List[StructureMapGroupRuleTargetParameter]) -> Any
Executes a registered FHIR Mapping Language transform by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the transform to execute. |
required |
scope
|
MappingScope
|
The current execution scope or context for the transform. |
required |
parameters
|
List[StructureMapGroupRuleTargetParameter]
|
Parameters to be passed to the transform function. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
result |
Any
|
The result of the executed transform function. |
Raises:
| Type | Description |
|---|---|
MappingError
|
If the specified transform name is not registered. |
NotImplementedError
|
If the transform is registered but not implemented. |
Source code in fhircraft/fhir/mapper/engine/transformer.py
TransformParameter
Path: fhircraft.fhir.mapper.engine.transformer.TransformParameter
dataclass
Represents a parameter used in a transformation process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the parameter. |
required |
type
|
str
|
The data type of the parameter. |
required |
is_optional
|
bool
|
Indicates whether the parameter is optional. Defaults to False. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the parameter. |
type |
str
|
The data type of the parameter. |
is_optional |
bool
|
Indicates whether the parameter is optional. Defaults to False. |
validate_transform_parameters
validate_transform_parameters(*signatures: list[TransformParameter]) -> Callable
A decorator to validate the parameters passed to a transformation function against one or more expected signatures.
Each signature is a list of TransformParameter objects that define the expected parameter names, types, and whether they are optional.
The decorator checks if the provided parameters match any of the given signatures in terms of count and type.
If a match is found, the decorated function is called with the validated and unpacked parameters.
If no signature matches, a RuleProcessingError is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*signatures
|
list[TransformParameter]
|
One or more lists of |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
A decorator that wraps the target function with parameter validation logic. |
Raises:
| Type | Description |
|---|---|
RuleProcessingError
|
If the provided parameters do not match any of the given signatures. |