FHIRPath Mixin
FHIRPath mixin components
FHIRPathMixin
Path: fhircraft.fhir.path.mixin.FHIRPathMixin
Enhanced mixin class to incorporate a comprehensive FHIRPath interface to the child class.
This mixin provides convenient methods for working with FHIRPath expressions directly on FHIR resource instances, leveraging the enhanced FHIRPath interface.
Methods:
| Name | Description |
|---|---|
fhirpath_values |
Evaluates a FHIRPath expression and returns all matching values as a list. |
fhirpath_single |
Evaluates a FHIRPath expression and returns exactly one value. |
fhirpath_first |
Evaluates a FHIRPath expression and returns the first matching value. |
fhirpath_last |
Evaluates a FHIRPath expression and returns the last matching value. |
fhirpath_exists |
Checks if a FHIRPath expression matches any values. |
fhirpath_is_empty |
Checks if a FHIRPath expression matches no values. |
fhirpath_count |
Returns the number of values that match a FHIRPath expression. |
fhirpath_update_values |
Evaluates a FHIRPath expression and sets all matching locations to the given value. |
fhirpath_update_single |
Evaluates a FHIRPath expression and sets exactly one matching location to the given value. |
Attributes:
| Name | Type | Description |
|---|---|---|
fhirpath |
FhirPathParser
|
Initialized FHIRPath engine instance |
fhirpath_values
Evaluates a FHIRPath expression and returns all matching values as a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
FHIRPath expression to evaluate |
required |
Returns:
| Name | Type | Description |
|---|---|---|
List[Any]
|
List[Any]: A list of all values that match the FHIRPath expression. Returns an empty list if no matches are found. |
|
environment |
dict | None
|
Optional environment variables for evaluation |
Source code in fhircraft/fhir/path/mixin.py
fhirpath_single
Evaluates a FHIRPath expression and returns exactly one value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
FHIRPath expression to evaluate |
required |
default
|
Any
|
The default value to return if no matches are found |
None
|
environment
|
dict | None
|
Optional environment variables for evaluation |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The single matching value |
Raises:
| Type | Description |
|---|---|
FHIRPathRuntimeError
|
If more than one value is found |
Source code in fhircraft/fhir/path/mixin.py
fhirpath_first
Evaluates a FHIRPath expression and returns the first matching value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
FHIRPath expression to evaluate |
required |
default
|
Any
|
The default value to return if no matches are found |
None
|
environment
|
dict | None
|
Optional environment variables for evaluation |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The first matching value, or the default if no matches |
Source code in fhircraft/fhir/path/mixin.py
fhirpath_last
Evaluates a FHIRPath expression and returns the last matching value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
FHIRPath expression to evaluate |
required |
default
|
Any
|
The default value to return if no matches are found |
None
|
environment
|
dict | None
|
Optional environment variables for evaluation |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The last matching value, or the default if no matches |
Source code in fhircraft/fhir/path/mixin.py
fhirpath_exists
Checks if a FHIRPath expression matches any values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
FHIRPath expression to evaluate |
required |
environment
|
dict | None
|
Optional environment variables for evaluation |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if at least one value matches, False otherwise |
Source code in fhircraft/fhir/path/mixin.py
fhirpath_is_empty
Checks if a FHIRPath expression matches no values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
FHIRPath expression to evaluate |
required |
environment
|
dict | None
|
Optional environment variables for evaluation |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if no values match, False otherwise |
Source code in fhircraft/fhir/path/mixin.py
fhirpath_count
Returns the number of values that match a FHIRPath expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
FHIRPath expression to evaluate |
required |
environment
|
dict | None
|
Optional environment variables for evaluation |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of matching values |
Source code in fhircraft/fhir/path/mixin.py
fhirpath_update_values
Evaluates a FHIRPath expression and sets all matching locations to the given value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
FHIRPath expression to evaluate |
required |
value
|
Any
|
The value to set at all matching locations |
required |
environment
|
dict | None
|
Optional environment variables for evaluation |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no matching locations are found or if locations cannot be set |
Source code in fhircraft/fhir/path/mixin.py
fhirpath_update_single
Evaluates a FHIRPath expression and sets exactly one matching location to the given value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
FHIRPath expression to evaluate |
required |
value
|
Any
|
The value to set at the matching location |
required |
environment
|
dict | None
|
Optional environment variables for evaluation |
None
|
Raises:
| Type | Description |
|---|---|
FHIRPathError
|
If zero or more than one matching locations are found |
RuntimeError
|
If the location cannot be set |