Skip to content

FHIRPath Mixin

FHIRPath mixin components

mixin

Classes:

Name Description
FHIRPathMixin

Enhanced mixin class to incorporate a comprehensive FHIRPath interface to the child class.

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.

fhirpath_values

fhirpath_values(expression: str, environment: dict | None = None) -> List[Any]

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

fhirpath_single

fhirpath_single(expression: str, default: Any = None, environment: dict | None = None) -> Any

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

fhirpath_first

fhirpath_first(expression: str, default: Any = None, environment: dict | None = None) -> Any

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

fhirpath_last

fhirpath_last(expression: str, default: Any = None, environment: dict | None = None) -> Any

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

fhirpath_exists

fhirpath_exists(expression: str, environment: dict | None = None) -> bool

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

fhirpath_is_empty

fhirpath_is_empty(expression: str, environment: dict | None = None) -> bool

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

fhirpath_count

fhirpath_count(expression: str, environment: dict | None = None) -> int

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

fhirpath_update_values

fhirpath_update_values(expression: str, value: Any, environment: dict | None = None) -> None

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

fhirpath_update_single

fhirpath_update_single(expression: str, value: Any, environment: dict | None = None) -> None

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
FHIRPathException

If zero or more than one matching locations are found

RuntimeError

If the location cannot be set