RelativeTimeRangeFilter
Bases: Filter
Filters events based on a time range relative to an anchor date.
Every time-relative operation in PhenEx requires an anchor date — the reference point from which "before" and "after" are measured. The anchor date is resolved as follows:
- If
anchor_phenotypeis provided, the EVENT_DATE of that phenotype is used as the anchor. The anchor phenotype must be executed before this filter runs (PhenEx handles this automatically when phenotypes are composed via the Cohort). - If
anchor_phenotypeis None (the default), theINDEX_DATEcolumn already present on the table is used. INDEX_DATE is set by the entry criterion of the cohort.
The when parameter controls the direction:
when='before': days prior to the anchor are positive, days after are negative.when='after': days after the anchor are positive, days before are negative.
This convention means that min_days and max_days are always expressed as positive numbers regardless of direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_days
|
Optional[Value]
|
Minimum number of days from the anchor date to include. Must use |
GreaterThanOrEqualTo(0)
|
max_days
|
Optional[Value]
|
Maximum number of days from the anchor date to include. Must use |
None
|
anchor_phenotype
|
Optional[Phenotype]
|
A phenotype whose EVENT_DATE is used as the anchor date. If None, the INDEX_DATE column on the input table is used. |
None
|
when
|
Optional[str]
|
Direction relative to the anchor. Either 'before' or 'after'. |
'before'
|
Examples:
Baseline period — one year before index date
Follow-up period — anytime after index date
Anchored to another phenotype — events within 90 days after AF diagnosis
from phenex.phenotypes import CodelistPhenotype
from phenex.codelists import Codelist
from phenex.filters import RelativeTimeRangeFilter
from phenex.filters.value import GreaterThanOrEqualTo, LessThanOrEqualTo
af = CodelistPhenotype(
name='af',
domain='CONDITION_OCCURRENCE',
codelist=Codelist([313217]),
return_date='first',
)
within_90d_of_af = RelativeTimeRangeFilter(
anchor_phenotype=af,
min_days=GreaterThanOrEqualTo(0),
max_days=LessThanOrEqualTo(90),
when='after',
)
Source code in phenex/filters/relative_time_range_filter.py
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 127 128 129 130 131 | |
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. |