user_management.domain.specifications.user package

Submodules

user_management.domain.specifications.user.date_of_birth module

user_management.domain.specifications.user.email module

user_management.domain.specifications.user.name module

user_management.domain.specifications.user.phone module

Module contents

Public API for User-related business rule specifications.

This module provides composable, reusable specification objects that encapsulate domain validation rules for the User entity. These specifications are used to enforce business invariants during user creation, profile updates, and system audits.

Each specification implements the is_satisfied_by(value) -> bool interface, enabling clean, testable, and readable validation logic within the domain layer.

Specifications support: - Fail-fast validation - Reusability across use cases - Composability (e.g., AND/OR rules) - Clear separation of concerns

They are central to enforcing data integrity, security, and compliance (e.g., HIPAA/GDPR).

Import specifications directly using:

from src.user_management.domain.specifications.user import (
    ValidEmailSpecification,
    ValidNameSpecification,
    ValidPhoneE164Specification,
    ValidDateOfBirthSpecification,
    ValidUserRoleSpecification,
    ValidUserStatusSpecification,
    ValidCreatedAtSpecification,
    ValidUpdatedAtSpecification
)
class user_management.domain.specifications.user.ValidCreatedAtSpecification[source]

Bases: Specification

Specification to validate that created_at is a valid timestamp for user creation.

Enforces temporal integrity by rejecting invalid or impossible timestamps. Used during User aggregate construction to ensure domain invariants are preserved.

is_satisfied_by(created_at) bool[source]

Checks if the provided value is a valid created_at timestamp.

Parameters:

created_at – The value to validate. Expected to be a timezone-aware UTC datetime.

Returns:

True if the timestamp is valid; False otherwise.

Return type:

bool

class user_management.domain.specifications.user.ValidDateOfBirthSpecification[source]

Bases: Specification

Specification to validate that a date of birth is realistic and properly formatted.

Enforces domain invariants for user age during creation and updates. Used within the User aggregate to prevent invalid or impossible dates.

is_satisfied_by(dob) bool[source]

Checks if the provided value is a valid date of birth.

Parameters:

dob – The value to validate. Expected to be a datetime.date object.

Returns:

True if the date is valid; False otherwise.

Return type:

bool

class user_management.domain.specifications.user.ValidEmailSpecification[source]

Bases: Specification

Specification to validate that an email address conforms to structural rules.

Ensures only properly formatted emails are accepted in the domain layer. Used within the User aggregate to enforce fail-fast validation and prevent invalid identities.

is_satisfied_by(email) bool[source]

Checks if the provided value is a valid email address.

Parameters:

email – The value to validate. Must be a string to pass.

Returns:

True if the email is valid; False otherwise.

Return type:

bool

class user_management.domain.specifications.user.ValidNameSpecification[source]

Bases: Specification

Specification to validate that a first or last name conforms to allowed format rules.

Enforces clean, readable names within the User aggregate. Used during creation and updates to maintain data integrity in healthcare workflows.

is_satisfied_by(name) bool[source]

Checks if the provided value is a valid name.

Parameters:

name – The value to validate. Expected to be a string.

Returns:

True if the name is valid; False otherwise.

Return type:

bool

class user_management.domain.specifications.user.ValidPhoneE164Specification[source]

Bases: Specification

Specification to validate that a phone number conforms to the E.164 international standard.

Enforces consistent formatting across user profiles and supports integration with third-party telephony providers. Used within the User aggregate for fail-fast validation.

is_satisfied_by(phone) bool[source]

Checks if the provided value is a valid E.164 phone number or None.

Parameters:

phone – The value to validate. Expected to be a string or None.

Returns:

True if the phone is None or correctly formatted; False otherwise.

Return type:

bool

class user_management.domain.specifications.user.ValidUUIDSpecification[source]

Bases: Specification

Specification to validate that a UUID is a properly typed identity object.

Enforces strict type checking to ensure only valid UUID instances are accepted during User aggregate creation. Prevents common errors like passing strings or None as identifiers in critical healthcare workflows.

is_satisfied_by(uuid) bool[source]

Checks if the provided value is a valid UUID instance.

Parameters:

uuid – The value to validate. Expected to be a uuid.UUID object.

Returns:

True if the value is a valid UUID; False otherwise.

Return type:

bool

class user_management.domain.specifications.user.ValidUpdatedAtSpecification[source]

Bases: Specification

Specification to validate that updated_at is a valid timestamp for user record updates.

Enforces temporal correctness by rejecting invalid or impossible timestamps. Used during User aggregate construction to ensure domain invariants are preserved.

is_satisfied_by(updated_at) bool[source]

Checks if the provided value is a valid updated_at timestamp.

Parameters:

updated_at – The value to validate. Expected to be a timezone-aware UTC datetime.

Returns:

True if the timestamp is valid; False otherwise.

Return type:

bool

class user_management.domain.specifications.user.ValidUserRoleSpecification[source]

Bases: Specification

Specification to validate that a user role is a valid enum member.

Enforces domain integrity by rejecting strings, None, or invalid types during User creation or role updates. Ensures only approved roles are assigned.

is_satisfied_by(user_role) bool[source]

Checks if the provided value is a valid UserRole enum member.

Parameters:

user_role – The value to validate. Expected to be a UserRole instance.

Returns:

True if the role is a valid enum member; False otherwise.

Return type:

bool

class user_management.domain.specifications.user.ValidUserStatusSpecification[source]

Bases: Specification

Specification to validate that a user status is a valid enum member.

Enforces domain integrity by rejecting strings, None, or invalid types during User creation or status updates. Ensures only approved states are assigned.

is_satisfied_by(user_status) bool[source]

Checks if the provided value is a valid UserStatus enum member.

Parameters:

user_status – The value to validate. Expected to be a UserStatus instance.

Returns:

True if the status is a valid enum member; False otherwise.

Return type:

bool