LogicPhenotype
Bases: ComputationGraphPhenotype
LogicPhenotype is a composite phenotype that performs boolean operations using the boolean column of its component phenotypes and populations the boolean column of the resulting phenotype table. It should be used in any instance where multiple phenotypes are logically combined, for example, does a patient have diabetes AND hypertension, etc.
--> See the comparison table of CompositePhenotype classes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expression
|
ComputationGraph
|
The logical expression to be evaluated composed of phenotypes combined by python arithmetic operations. |
required |
return_date
|
Union[str, Phenotype]
|
The date to be returned for the phenotype. Can be "first", "last", or a Phenotype object. |
'first'
|
name
|
str
|
The name of the phenotype. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
table |
PhenotypeTable
|
The resulting phenotype table after filtering (None until execute is called) |
Source code in phenex/phenotypes/computation_graph_phenotypes.py
namespaced_table
property
A PhenotypeTable has generic column names 'person_id', 'boolean', 'event_date', and 'value'. The namespaced_table appends the phenotype name to all of these columns. This is useful when joining multiple phenotype tables together.
Returns:
Name | Type | Description |
---|---|---|
table |
Table
|
The namespaced table for the current phenotype. |
_coalesce_all_date_columns(table)
ComputationGraphPhenotypes have multiple possible date columns. To work with these date columns, which may be null, we perform a coalesce operation for each date column, which allows operations such as 'least' and 'greatest' to work correctly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
The Ibis table object (e.g., joined_table). |
required |
Returns:
Type | Description |
---|---|
Ibis expression representing the COALESCE of the columns. |
Source code in phenex/phenotypes/computation_graph_phenotypes.py
_execute(tables)
Executes the score phenotype processing logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tables
|
Dict[str, Table]
|
A dictionary where the keys are table names and the values are Table objects. |
required |
Returns:
Name | Type | Description |
---|---|---|
PhenotypeTable |
PhenotypeTable
|
The resulting phenotype table containing the required columns. |
Source code in phenex/phenotypes/computation_graph_phenotypes.py
_return_all_dates(table, date_columns)
If return date = all, we want to return all the dates on which phenotype criteria are fulfilled; this is a union of all the non-null dates in any leaf phenotype date columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
The Ibis table object (e.g., joined_table) that contains all leaf phenotypes stacked horizontally |
required | |
date_columns
|
List of base columns as ibis objects |
required |
Returns:
Type | Description |
---|---|
Ibis expression representing the UNION of all non null dates. |
Source code in phenex/phenotypes/computation_graph_phenotypes.py
execute(tables)
Executes the phenotype computation for the current object and its children. This method recursively iterates over the children of the current object and calls their execute method if their table attribute is None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tables
|
Dict[str, PhenexTable]
|
A dictionary mapping table names to PhenexTable objects. See phenex.mappers.DomainsDictionary.get_mapped_tables(). |
required |
Returns:
Name | Type | Description |
---|---|---|
table |
PhenotypeTable
|
The resulting phenotype table containing the required columns. The PhenotypeTable will contain the columns: PERSON_ID, EVENT_DATE, VALUE. DATE is determined by the return_date parameter. VALUE is different for each phenotype. For example, AgePhenotype will return the age in the VALUE column. A MeasurementPhenotype will return the observed value for the measurement. See the specific phenotype of interest to understand more. |