user_management.domain.exceptions package

Submodules

user_management.domain.exceptions.base module

Base domain exceptions for the NextGenHealth system. All other domain-specific errors inherit from these.

exception user_management.domain.exceptions.base.DomainError[source]

Bases: Exception

Base exception class for all business rule violations in the domain.

This is not raised directly, but serves as the parent for all domain exceptions. Helps with broad exception handling at higher layers.

user_management.domain.exceptions.credentials module

Exceptions related to user credentials (password, authentication).

exception user_management.domain.exceptions.credentials.InvalidCredentialsError[source]

Bases: DomainError

Base exception for credential-related validation failures.

Examples

  • Weak password

  • Password reuse

  • Failed verification attempts

exception user_management.domain.exceptions.credentials.InvalidPasswordError[source]

Bases: InvalidCredentialsError

Raised when a password does not meet security requirements.

Rules:
  • At least 8 characters

  • Not commonly used (e.g., ‘123456’)

  • Not empty or whitespace-only

user_management.domain.exceptions.user module

Exceptions related to User entity validation and business rules.

Each exception represents a specific violation of domain invariants, enabling precise error handling and meaningful feedback during user management operations.

exception user_management.domain.exceptions.user.InvalidCreatedAtError[source]

Bases: InvalidUserError

Raised when created_at timestamp is invalid.

A valid created_at must:
  • Be a timezone-aware datetime object

  • Use UTC timezone

  • Not be in the future

  • Not be unrealistically old

Critical for audit trails and compliance (e.g., HIPAA/GDPR).

exception user_management.domain.exceptions.user.InvalidDateOfBirthError[source]

Bases: InvalidUserError

Raised when date of birth is in the future or unrealistically far in the past.

Business rule: date of birth must be:
  • A valid date object

  • Not in the future

  • Not before 1900 (or configurable minimum)

Example violations: born in 2050 or 1800.

exception user_management.domain.exceptions.user.InvalidEmailError[source]

Bases: InvalidUserError

Raised when an email does not conform to RFC-like formatting rules.

Valid emails must:
  • Be a non-empty string

  • Contain exactly one ‘@’

  • Have valid local-part and domain structure

Example invalid values: ‘invalid-email’, ‘user@’, @domain.com

exception user_management.domain.exceptions.user.InvalidNameError[source]

Bases: InvalidUserError

Raised when first_name or last_name contains invalid characters.

Names must:
  • Be non-empty strings

  • Contain only alphabetic characters (A-Z, a-z) and single spaces

  • Not include numbers, symbols, accents, or consecutive spaces

Ensures consistency and compliance in personal data representation.

exception user_management.domain.exceptions.user.InvalidPhoneNumberError[source]

Bases: InvalidUserError

Raised when phone number is provided but not in E.164 format.

Valid format: ‘+’ followed by 1–15 digits (e.g., ‘+1234567890’).

Example invalid values:
  • ‘123-456-7890’ (formatted)

  • ‘1234567890’ (missing +)

  • ‘+12’ (too short)

Aligns with international telephony standards for global systems.

exception user_management.domain.exceptions.user.InvalidUUIDError[source]

Bases: InvalidUserError

Raised when the provided UUID is not a valid UUID instance.

This includes:
  • None

  • Empty string

  • Malformed string (e.g., ‘not-a-uuid’)

  • Wrong type (e.g., int, dict, list)

The User entity requires a valid UUID object for identity integrity and auditability.

exception user_management.domain.exceptions.user.InvalidUpdatedAtError[source]

Bases: InvalidUserError

Raised when updated_at timestamp is invalid.

A valid updated_at must:
  • Be a timezone-aware datetime object

  • Use UTC timezone

  • Not be in the future

  • Not be earlier than created_at

Enforces chronological consistency in user record history.

exception user_management.domain.exceptions.user.InvalidUserError[source]

Bases: DomainError

Base exception raised when a User violates identity or business rules.

Serves as the parent class for all user-related validation errors. Helps enable broad exception handling at higher layers while preserving specificity.

Examples

  • Invalid UUID format

  • Malformed email address

  • Name containing invalid characters

  • Date of birth in the future

exception user_management.domain.exceptions.user.InvalidUserRoleError[source]

Bases: InvalidUserError

Raised when the assigned role is not a valid UserRole enum member.

The system only accepts predefined roles like PATIENT, DOCTOR, NURSE, ADMINISTRATOR.

Prevents unauthorized access levels due to invalid or malformed roles.

exception user_management.domain.exceptions.user.InvalidUserStatusError[source]

Bases: InvalidUserError

Raised when the user status is not a valid UserStatus enum member.

Only ACTIVE, INACTIVE, and LOCKED are allowed.

Ensures account lifecycle state is always consistent and auditable.

Module contents

Public API for domain exceptions. Allows clean imports across the project.

exception user_management.domain.exceptions.DomainError[source]

Bases: Exception

Base exception class for all business rule violations in the domain.

This is not raised directly, but serves as the parent for all domain exceptions. Helps with broad exception handling at higher layers.

exception user_management.domain.exceptions.InvalidCreatedAtError[source]

Bases: InvalidUserError

Raised when created_at timestamp is invalid.

A valid created_at must:
  • Be a timezone-aware datetime object

  • Use UTC timezone

  • Not be in the future

  • Not be unrealistically old

Critical for audit trails and compliance (e.g., HIPAA/GDPR).

exception user_management.domain.exceptions.InvalidCredentialsError[source]

Bases: DomainError

Base exception for credential-related validation failures.

Examples

  • Weak password

  • Password reuse

  • Failed verification attempts

exception user_management.domain.exceptions.InvalidDateOfBirthError[source]

Bases: InvalidUserError

Raised when date of birth is in the future or unrealistically far in the past.

Business rule: date of birth must be:
  • A valid date object

  • Not in the future

  • Not before 1900 (or configurable minimum)

Example violations: born in 2050 or 1800.

exception user_management.domain.exceptions.InvalidEmailError[source]

Bases: InvalidUserError

Raised when an email does not conform to RFC-like formatting rules.

Valid emails must:
  • Be a non-empty string

  • Contain exactly one ‘@’

  • Have valid local-part and domain structure

Example invalid values: ‘invalid-email’, ‘user@’, @domain.com

exception user_management.domain.exceptions.InvalidNameError[source]

Bases: InvalidUserError

Raised when first_name or last_name contains invalid characters.

Names must:
  • Be non-empty strings

  • Contain only alphabetic characters (A-Z, a-z) and single spaces

  • Not include numbers, symbols, accents, or consecutive spaces

Ensures consistency and compliance in personal data representation.

exception user_management.domain.exceptions.InvalidPasswordError[source]

Bases: InvalidCredentialsError

Raised when a password does not meet security requirements.

Rules:
  • At least 8 characters

  • Not commonly used (e.g., ‘123456’)

  • Not empty or whitespace-only

exception user_management.domain.exceptions.InvalidPatientProfileCreatedAtError[source]

Bases: InvalidPatientProfileError

exception user_management.domain.exceptions.InvalidPatientProfileEmergencyContactNameError[source]

Bases: InvalidPatientProfileError

exception user_management.domain.exceptions.InvalidPatientProfileEmergencyContactPhoneError[source]

Bases: InvalidPatientProfileError

exception user_management.domain.exceptions.InvalidPatientProfileInsuranceInfoError[source]

Bases: InvalidPatientProfileError

exception user_management.domain.exceptions.InvalidPatientProfileMedicalHistorySummaryError[source]

Bases: InvalidPatientProfileError

exception user_management.domain.exceptions.InvalidPatientProfilePreferredLanguageError[source]

Bases: InvalidPatientProfileError

exception user_management.domain.exceptions.InvalidPatientProfileUpdatedAtError[source]

Bases: InvalidPatientProfileError

exception user_management.domain.exceptions.InvalidPatientProfileUserUUIDError[source]

Bases: InvalidPatientProfileError

exception user_management.domain.exceptions.InvalidPhoneNumberError[source]

Bases: InvalidUserError

Raised when phone number is provided but not in E.164 format.

Valid format: ‘+’ followed by 1–15 digits (e.g., ‘+1234567890’).

Example invalid values:
  • ‘123-456-7890’ (formatted)

  • ‘1234567890’ (missing +)

  • ‘+12’ (too short)

Aligns with international telephony standards for global systems.

exception user_management.domain.exceptions.InvalidUUIDError[source]

Bases: InvalidUserError

Raised when the provided UUID is not a valid UUID instance.

This includes:
  • None

  • Empty string

  • Malformed string (e.g., ‘not-a-uuid’)

  • Wrong type (e.g., int, dict, list)

The User entity requires a valid UUID object for identity integrity and auditability.

exception user_management.domain.exceptions.InvalidUpdatedAtError[source]

Bases: InvalidUserError

Raised when updated_at timestamp is invalid.

A valid updated_at must:
  • Be a timezone-aware datetime object

  • Use UTC timezone

  • Not be in the future

  • Not be earlier than created_at

Enforces chronological consistency in user record history.

exception user_management.domain.exceptions.InvalidUserError[source]

Bases: DomainError

Base exception raised when a User violates identity or business rules.

Serves as the parent class for all user-related validation errors. Helps enable broad exception handling at higher layers while preserving specificity.

Examples

  • Invalid UUID format

  • Malformed email address

  • Name containing invalid characters

  • Date of birth in the future

exception user_management.domain.exceptions.InvalidUserRoleError[source]

Bases: InvalidUserError

Raised when the assigned role is not a valid UserRole enum member.

The system only accepts predefined roles like PATIENT, DOCTOR, NURSE, ADMINISTRATOR.

Prevents unauthorized access levels due to invalid or malformed roles.

exception user_management.domain.exceptions.InvalidUserStatusError[source]

Bases: InvalidUserError

Raised when the user status is not a valid UserStatus enum member.

Only ACTIVE, INACTIVE, and LOCKED are allowed.

Ensures account lifecycle state is always consistent and auditable.