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, 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.

        Returns:
            FHIRPathCollection: The output collection.
        """
        collection = ensure_list(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], create))
        return children_collection

evaluate(collection, 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

Returns:

Name Type Description
FHIRPathCollection FHIRPathCollection

The output collection.

Source code in fhircraft/fhir/path/engine/navigation.py
def evaluate(
    self, collection: FHIRPathCollection, 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.

    Returns:
        FHIRPathCollection: The output collection.
    """
    collection = ensure_list(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], 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, 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.

        Returns:
            FHIRPathCollection: The output collection.

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

evaluate(collection, 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

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, 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.

    Returns:
        FHIRPathCollection: The output collection.

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