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. |
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
Source code in phenex/filters/categorical_filter.py
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. |