Skip to content

Navigation

The tree navigation module contains the object representations of the tree-navigation category FHIRPath functions.

Children

Bases: FHIRPathFunction

Representation of the FHIRPath children() function.

Source code in fhircraft/fhir/path/engine/navigation.py
class Children(FHIRPathFunction):
    """
    Representation of the FHIRPath [`children()`](https://hl7.org/fhirpath/N1/#children-collection) function.
    """

    def evaluate(
        self, collection: FHIRPathCollection, environment: dict, create: bool = False
    ) -> FHIRPathCollection:
        """
        Returns a collection with all immediate child nodes of all items in the input collection.

        Args:
            collection (FHIRPathCollection): The input collection.
            environment (dict): The environment context for the evaluation.
            create (bool): Whether to create new elements during evaluation if necessary.

        Returns:
            FHIRPathCollection: The output collection.
        """
        children_collection = []
        for item in collection:
            if isinstance(item.value, BaseModel):
                fields = item.value.__class__.model_fields
            elif isinstance(item.value, dict):
                fields = list(item.value.keys())
            else:
                fields = []
            for field in fields:
                children_collection.extend(
                    Element(field).evaluate([item], environment, create)
                )
        return children_collection

evaluate(collection, environment, create=False)

Returns a collection with all immediate child nodes of all items in the input collection.

Parameters:

Name Type Description Default
collection FHIRPathCollection

The input collection.

required
environment dict

The environment context for the evaluation.

required
create bool

Whether to create new elements during evaluation if necessary.

False

Returns:

Name Type Description
FHIRPathCollection FHIRPathCollection

The output collection.

Source code in fhircraft/fhir/path/engine/navigation.py
def evaluate(
    self, collection: FHIRPathCollection, environment: dict, create: bool = False
) -> FHIRPathCollection:
    """
    Returns a collection with all immediate child nodes of all items in the input collection.

    Args:
        collection (FHIRPathCollection): The input collection.
        environment (dict): The environment context for the evaluation.
        create (bool): Whether to create new elements during evaluation if necessary.

    Returns:
        FHIRPathCollection: The output collection.
    """
    children_collection = []
    for item in collection:
        if isinstance(item.value, BaseModel):
            fields = item.value.__class__.model_fields
        elif isinstance(item.value, dict):
            fields = list(item.value.keys())
        else:
            fields = []
        for field in fields:
            children_collection.extend(
                Element(field).evaluate([item], environment, create)
            )
    return children_collection

Descendants

Bases: FHIRPathFunction

Representation of the FHIRPath descendants() function.

Source code in fhircraft/fhir/path/engine/navigation.py
class Descendants(FHIRPathFunction):
    """
    Representation of the FHIRPath [`descendants()`](https://hl7.org/fhirpath/N1/#descendants-collection) function.
    """

    def evaluate(
        self, collection: FHIRPathCollection, environment: dict, create: bool = False
    ) -> FHIRPathCollection:
        """
        Returns a collection with all descendant nodes of all items in the input collection. The result does not include
        the nodes in the input collection themselves.

        Args:
            collection (FHIRPathCollection): The input collection.
            environment (dict): The environment context for the evaluation.
            create (bool): Whether to create new elements during evaluation if necessary.

        Returns:
            FHIRPathCollection: The output collection.

        Note:
            This function is a shorthand for `repeat(children())`.
        """
        return Repeat(Children()).evaluate(collection, environment, create)

evaluate(collection, environment, create=False)

Returns a collection with all descendant nodes of all items in the input collection. The result does not include the nodes in the input collection themselves.

Parameters:

Name Type Description Default
collection FHIRPathCollection

The input collection.

required
environment dict

The environment context for the evaluation.

required
create bool

Whether to create new elements during evaluation if necessary.

False

Returns:

Name Type Description
FHIRPathCollection FHIRPathCollection

The output collection.

Note

This function is a shorthand for repeat(children()).

Source code in fhircraft/fhir/path/engine/navigation.py
def evaluate(
    self, collection: FHIRPathCollection, environment: dict, create: bool = False
) -> FHIRPathCollection:
    """
    Returns a collection with all descendant nodes of all items in the input collection. The result does not include
    the nodes in the input collection themselves.

    Args:
        collection (FHIRPathCollection): The input collection.
        environment (dict): The environment context for the evaluation.
        create (bool): Whether to create new elements during evaluation if necessary.

    Returns:
        FHIRPathCollection: The output collection.

    Note:
        This function is a shorthand for `repeat(children())`.
    """
    return Repeat(Children()).evaluate(collection, environment, create)