Skip to content

Commit

Permalink
api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sprivite committed Nov 12, 2024
1 parent 42f6d89 commit 38b5c4a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
3 changes: 3 additions & 0 deletions docs/api/phenotypes/age_phenotype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# AgePhenotype

::: phenex.phenotypes.age_phenotype
3 changes: 3 additions & 0 deletions docs/api/phenotypes/logic_phenotype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# LogicPhenotype

::: phenex.phenotypes.logic_phenotype
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ nav:
- Phenotype: api/phenotypes/phenotype.md
- CodelistPhenotype: api/phenotypes/codelist_phenotype.md
- MeasurementPhenotype: api/phenotypes/measurement_phenotype.md
- AgePhenotype: api/phenotypes/age_phenotype.md
- LogicPhenotype: api/phenotypes/logic_phenotype.md
- Cohort: api/phenotypes/cohort.md
- License: LICENSE.md

Expand Down
31 changes: 6 additions & 25 deletions phenex/phenotypes/logic_phenotype.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ast
from typing import Dict, Union
from ibis.expr.types.relations import Table
from phenex.tables import PhenotypeTable, PHENOTYPE_TABLE_COLUMNS
Expand All @@ -23,10 +24,10 @@ def _execute(self, tables: Dict[str, Table]) -> PhenotypeTable:
PhenotypeTable: The resulting phenotype table containing the required columns.
"""
# Evaluate the boolean expression
boolean_result = self.evaluate_boolean(self.boolean_expression, tables)
boolean_result = self._evaluate_boolean(self.boolean_expression, tables)

# Evaluate the date expression
date_result = self.evaluate_date(self.date_expression, tables)
date_result = self._evaluate_date(self.date_expression, tables)

# Create a PhenotypeTable with the results
result_table = PhenotypeTable()
Expand All @@ -35,7 +36,7 @@ def _execute(self, tables: Dict[str, Table]) -> PhenotypeTable:

return result_table

def evaluate_boolean(self, boolean_expression, tables):
def _evaluate_boolean(self, boolean_expression, tables):
"""
Evaluates the boolean expression.
Expand All @@ -49,9 +50,9 @@ def evaluate_boolean(self, boolean_expression, tables):
# Implement the logic to evaluate the boolean expression
# Here we assume boolean_expression is a logical expression involving booleans
# For simplicity, we use eval to evaluate the expression
return eval(boolean_expression)
return ast.literal_eval(boolean_expression)

def evaluate_date(self, date_expression, tables):
def _evaluate_date(self, date_expression, tables):
"""
Evaluates the date expression.
Expand All @@ -65,23 +66,3 @@ def evaluate_date(self, date_expression, tables):
# Implement the logic to evaluate the date expression
# Here we just return the expression for simplicity
return date_expression


if False:
# Example usage
overt_bleed = True
cv_death = False
symptomatic_bleed = True

logic = LogicPhenotype(
boolean="overt_bleed or cv_death or symptomatic_bleed",
date="first|last|Phenotype",
value="greatest|least|Phenotype",
)

# Assuming tables is a dictionary of table names to Table objects
tables = {}

result = logic.execute(tables)
print(f"Boolean: {result['boolean']}")
print(f"Date: {result['date']}")

0 comments on commit 38b5c4a

Please sign in to comment.