CategoricalFilter
Bases: Filter
This class filters events in an EventTable based on specified categorical values.
Attributes:
Name | Type | Description |
---|---|---|
column_name |
str
|
The name of the column to filter by. |
allowed_values |
List[Union[str, int]]
|
The list of allowed values for the column. |
domain |
Optional[str]
|
The domain to which the filter applies. |
operator |
Optional[str]
|
The operator used for filtering. Options are "isin", "notin", "isnull", "notnull". Default is "isin". Be aware that "notin" removes null values! Thus "notin" can better be described 'has a value and and is not in' |
Methods:
Name | Description |
---|---|
filter |
PhenexTable) -> PhenexTable: Filters the given PhenexTable based on the specified column and allowed values. Parameters: table (PhenexTable): The table containing events to be filtered. Returns: PhenexTable: The filtered PhenexTable with events matching the allowed values. |
autojoin_filter |
PhenexTable, tables: dict = None) -> PhenexTable: Automatically joins the necessary tables and applies the filter. Use when the input table does not contain the column that defines the filter. For this to work, the tables must specify all required join keys. See DomainsDictionary for details. Parameters: table (PhenexTable): The table containing events to be filtered. tables (dict): A dictionary of tables for joining. Returns: PhenexTable: The filtered PhenexTable with events matching the allowed values. |
Examples:
# Example 1: Filter for SEX = 'Female'
sex_filter = CategoricalFilter(
column_name="SEX",
allowed_values=["Female"],
domain="PERSON"
)
# Example 2: Filter for inpatient (domain = encounter)
inpatient_filter = CategoricalFilter(
column_name="ENCOUNTER_TYPE",
allowed_values=["INPATIENT"],
domain="ENCOUNTER"
)
# Example 3: Filter for primary diagnosis position
primary_diagnosis_filter = CategoricalFilter(
column_name="DIAGNOSIS_POSITION",
allowed_values=[1],
domain="DIAGNOSIS"
)
# Example 4: Applying multiple filters in combination
inpatient_primary_position = inpatient_filter & primary_diagnosis_filter
# Example 5: Filter for not null status
primary_diagnosis_filter = CategoricalFilter(
column_name="DIAGNOSIS_STATUS",
operator="notnull",
domain="DIAGNOSIS"
)
# Example 6: Filter for diagnosis status. Notice that this will remove null rows! Only patients with a value in the diagnosis_status that is NOT history_of will remain.
primary_diagnosis_filter = CategoricalFilter(
column_name="DIAGNOSIS_STATUS",
operator="notin",
allowed_values=["HISTORY_OF"],
domain="DIAGNOSIS"
)
Source code in phenex/filters/categorical_filter.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
filter(table)
Filters the given table according to the rules of the Filter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
PhenexTable
|
The table to be filtered. |
required |
Returns:
Name | Type | Description |
---|---|---|
PhenexTable |
PhenexTable
|
The filtered table. The returned table has the exact same schema as the input table but has rows removed. |