LogicPhenotype Tutorial¶
The LogicPhenotype allows us to combine phenotypes with logical operations AND, OR and NOT
There are obvious use cases for this in RWD :
- We want to combine information from multiple domains, for example "procedures" and "diagnoses". An example is : Which patients have a diagnosis for heart transplant OR a procedure for heart transplant?
- We want to calculate complicated logical definitions : It is common to generate algorithms to correctly classify patients has having a condition. This means we want patients to fulfill some lab value criteria, diagnosis criteria and so on. We can create arbitraily complex definitions using Complex Phenotype
Combining information from multiple domains¶
We often want to ask 'which patients have a diagnosis of condition_x OR a procedure treating condition_x'. Diagnoses and procedures are often found in separate domains, the condition_occurrence and procedure_occurence table
LogicPhenotype allows us to combine information from multiple domains
Step 1 : Create component phenotypes¶
ht_procedure_codes = Codelist("heart_transplant")
ht_diagnosis_codes = Codelist("heart_transplant")
ht_procedures = CodelistPhenotype(
name_phenotype="ht_procedures",
codelist=ht_procedure_codes,
domain="procedure_occurrence",
time_range_filter=ONEYEAR_PREINDEX,
)
ht_diagnoses = CodelistPhenotype(
name_phenotype="ht_diagnoses",
codelist= ht_diagnosis_codes,
domain="condition_occurrence",
time_range_filter=ONEYEAR_PREINDEX,
)
Step 2 : Create LogicPhenotype¶
We are now ready to create our LogicPhenotype using our component phenotypes. Here we can use the logical operations and, or (&,|).
Here we will show two logic phenotypes, one using OR and one using AND.
# use logical OR
ht_or = LogicPhenotype(
name_phenotype="ht_procedure_OR_diagnosis",
logic = ht_procedures | ht_diagnoses
)
# use logical AND
ht_and = LogicPhenotype(
name_phenotype="ht_procedure_AND_diagnosis",
logic = ht_procedures & ht_diagnoses
)
Complicated logical phenotypes¶
We can add arbitraily complex logic to our operations. Lets add two more component phenotypes, death and an 'end of coverage' phenotype. We will use these to create a censoring event phenotype, which is ht
# create two new component phenotypes
death = DeathPhenotype()
late_date_active = ContinuousCoveragePhenotype(return_date="last")
# create a logic phenotype combining all components
censoring_event = LogicPhenotype(
name_phenotype="any_censoring",
logic= ht_or | death | late_date_active,
return_date="first",
)