Skip to content

Sample ID

sample_id

Sample ID Value Object

Represents a unique identifier for a biological sample.

Classes

SampleId dataclass

SampleId(value: str)

Value Object for sample identifier.

Parameters:

Name Type Description Default
value str

Sample identifier name (cannot be empty)

required

Raises:

Type Description
ValueError

If value is empty or contains only spaces

Notes

This object is immutable ensuring identifier consistency throughout the application lifecycle.

Functions
__post_init__
__post_init__()

Validates the identifier after initialization.

Raises:

Type Description
ValueError

If value is empty or None.

Source code in src/domain/value_objects/sample_id.py
def __post_init__(self):
    """
    Validates the identifier after initialization.

    Raises
    ------
    ValueError
        If value is empty or None.
    """
    if not self.value or not self.value.strip():
        raise ValueError("Sample ID cannot be empty")
__str__
__str__() -> str

Returns string representation of Sample ID.

Returns:

Type Description
str

The identifier value.

Source code in src/domain/value_objects/sample_id.py
def __str__(self) -> str:
    """
    Returns string representation of Sample ID.

    Returns
    -------
    str
        The identifier value.
    """
    return self.value
__repr__
__repr__() -> str

Returns debug representation of Sample ID.

Returns:

Type Description
str

Representation in format "SampleId('value')".

Source code in src/domain/value_objects/sample_id.py
def __repr__(self) -> str:
    """
    Returns debug representation of Sample ID.

    Returns
    -------
    str
        Representation in format "SampleId('value')".
    """
    return f"SampleId('{self.value}')"
__hash__
__hash__() -> int

Allows using SampleId as dictionary key.

Returns:

Type Description
int

Hash of the value.

Source code in src/domain/value_objects/sample_id.py
def __hash__(self) -> int:
    """
    Allows using SampleId as dictionary key.

    Returns
    -------
    int
        Hash of the value.
    """
    return hash(self.value)