onconova.core.anonymization.base
AVERAGE_MONTH
module-attribute
¶
MAX_DATE_SHIFT
module-attribute
¶
REDACTED_STRING
module-attribute
¶
AnonymizationConfig
¶
AnonymizationMixin
¶
Mixin class for automatic anonymization of specified model fields after validation.
Attributes:
Name | Type | Description |
---|---|---|
anonymized |
bool
|
Flag indicating whether anonymization should be applied. |
__anonymization_fields__ |
Tuple[str, ...]
|
Class-level tuple listing the field names to anonymize. |
__anonymization_key__ |
Optional[str]
|
Optional key used in the anonymization process. |
__anonymization_functions__ |
Dict[str, Callable]
|
Optional mapping of field names to custom anonymization functions. |
Methods:
Name | Description |
---|---|
anonymize_data |
Pydantic model validator that anonymizes the configured fields if 'anonymized' is True. |
anonymize_value |
Instance method for anonymizing a single value, can be overridden by subclasses. |
__post_anonymization_hook__ |
Hook method for subclasses to implement post-anonymization actions. |
__anonymization_fields__
class-attribute
¶
__anonymization_functions__
class-attribute
¶
__anonymization_key__
class-attribute
¶
anonymized
class-attribute
instance-attribute
¶
__post_anonymization_hook__()
¶
Hook method for subclasses to implement additional actions after anonymization. Default implementation does nothing.
anonymize_data()
¶
Source code in onconova/core/anonymization/base.py
anonymize_age(age)
¶
Anonymize an age value by mapping it to its corresponding age bin.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Age
|
The age value to be anonymized. |
required |
Returns:
Name | Type | Description |
---|---|---|
AgeBin |
AgeBin
|
The anonymized age bin. |
Source code in onconova/core/anonymization/base.py
anonymize_by_redacting_string(original_value)
¶
anonymize_clinically_relevant_date(original_date, case_id)
¶
Anonymizes a date by shifting it by a random amount between -6 and 6 months.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Union[date, datetime, str]
|
The date to be anonymized. |
required |
|
str
|
The case ID used to generate the random timeshift. |
required |
Returns:
Type | Description |
---|---|
date | datetime
|
Union[date, datetime]: The anonymized date. |
Source code in onconova/core/anonymization/base.py
anonymize_personal_date(original_date)
¶
Anonymize a date by returning only the year.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Union[datetime, date, str]
|
The date to be anonymized. |
required |
Returns:
Name | Type | Description |
---|---|---|
date |
date
|
The year of the anonymized date with month and day set to 1. |
Source code in onconova/core/anonymization/base.py
anonymize_value(value, case_id)
¶
Anonymize a value by replacing it with a suitable placeholder.
This function anonymizes date/time fields by introducing a hash-based time-shift, anonymizes string fields by replacing by a placeholder, and anonymizes age fields by binning the age.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Any
|
The value to be anonymized. |
required |
|
str
|
The case ID to be used for hash-based anonymization. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The anonymized value. |