Skip to content

subject

oxytcmri.domain.entities.subject

This module contains the Subject class which represents a subject in the Oxy-TC trial, as well as the associated value objects.

Classes:

Name Description
SubjectType

Types of subjects in the study.

SubjectId

Value Object representing a subject identifier.

Subject

A subject participating in the study.

SubjectType

Bases: str, Enum

Types of subjects in the study.

A subject can be:

  • a healthy volunteer: passed an MRI to compare DTI values with patients
  • a test patient: sometimes centers needed to test an MRI on a patient
  • a patient: a patient in the trial

Methods:

Name Description
from_string

Convert a string to a SubjectType.

Attributes:

Name Type Description
HEALTHY_VOLUNTEER
PATIENT
TEST_PATIENT

HEALTHY_VOLUNTEER = 'Healthy Volunteer' class-attribute instance-attribute

PATIENT = 'Patient' class-attribute instance-attribute

TEST_PATIENT = 'Test Patient' class-attribute instance-attribute

from_string(value) classmethod

Convert a string to a SubjectType.

Parameters:

Name Type Description Default
value str

String to convert to a SubjectType. Must be "T", "V", or "P".

required

Returns:

Type Description
SubjectType

The corresponding SubjectType.

Raises:

Type Description
ValueError

If the string is not "H", "V", or "P"

Source code in oxytcmri/domain/entities/subject.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@classmethod
def from_string(cls, value: str) -> "SubjectType":
    """
    Convert a string to a SubjectType.

    Parameters
    ----------
    value: str
        String to convert to a SubjectType. Must be "T", "V", or "P".

    Returns
    -------
    SubjectType
        The corresponding SubjectType.

    Raises
    ------
    ValueError
        If the string is not "H", "V", or "P"
    """
    if value == "V":
        return cls.HEALTHY_VOLUNTEER
    if value == "P":
        return cls.PATIENT
    if value == "T":
        return cls.TEST_PATIENT

    raise ValueError(f"Invalid subject type: {value}. Expected 'V', 'P', or 'T'.")

SubjectId(id) dataclass

Value Object representing a subject identifier.

The ID follows the format "XX-YY-Z" where:

  • XX is the center number (01-99)
  • YY is the subject number within the center (01-99)
  • Z is the subject type (P, V, T)

Examples: "01-02-P", "10-03-V", "13-03-P"

Attributes:

Name Type Description
id str
center_id int

Get the center ID from the subject ID.

subject_number str

Get the subject number within the center.

subject_type SubjectType

Get the subject type.

id instance-attribute

center_id property

Get the center ID from the subject ID.

subject_number property

Get the subject number within the center.

subject_type property

Get the subject type.

Subject(id, subject_type, center_id) dataclass

A subject participating in the study.

Can be a healthy volunteer, a patient, or a test patient.

Methods:

Name Description
from_subject_id

Create a Subject from a subject ID.

from_string_id

Create a Subject from its string identifier.

Attributes:

Name Type Description
id SubjectId
subject_type SubjectType
center_id int

id instance-attribute

subject_type instance-attribute

center_id instance-attribute

from_subject_id(subject_id) classmethod

Create a Subject from a subject ID.

Parameters:

Name Type Description Default
subject_id SubjectId

The subject ID, in its value object type

required
Source code in oxytcmri/domain/entities/subject.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@classmethod
def from_subject_id(cls, subject_id: SubjectId) -> "Subject":
    """
    Create a Subject from a subject ID.

    Parameters
    ----------
    subject_id: SubjectId
        The subject ID, in its value object type
    """
    subject_type = subject_id.subject_type
    center_id = subject_id.center_id

    return cls(id=subject_id, subject_type=subject_type, center_id=center_id)

from_string_id(id_str) classmethod

Create a Subject from its string identifier.

Parameters:

Name Type Description Default
id_str str

String in the format "XX-YY-Z" where:

  • XX is the center number (01-99)
  • YY is the subject number within the center (01-99)
  • Z is the subject type (P, V, T)
required

Returns:

Type Description
Subject

The created Subject instance

Source code in oxytcmri/domain/entities/subject.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
@classmethod
def from_string_id(cls, id_str: str) -> Subject:
    """
    Create a Subject from its string identifier.

    Parameters
    ----------
    id_str : str
        String in the format "XX-YY-Z" where:

        - XX is the center number (01-99)
        - YY is the subject number within the center (01-99)
        - Z is the subject type (P, V, T)

    Returns
    -------
    Subject
        The created Subject instance
    """
    return Subject.from_subject_id(SubjectId(id_str))