Skip to content

Commit 6d3bdc6

Browse files
committed
feat: implement relativeTime extension
1 parent eeea021 commit 6d3bdc6

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

converter/parser/util.py renamed to execution_engine/converter/parser/util.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from execution_engine.omop.criterion.abstract import Criterion
55
from execution_engine.omop.criterion.procedure_occurrence import ProcedureOccurrence
6+
from execution_engine.omop.vocabulary import OMOP_SURGICAL_PROCEDURE
67
from execution_engine.util import logic
78
from execution_engine.util.temporal_logic_util import Presence
89

@@ -20,8 +21,6 @@ def _wrap_criteria_with_factory(
2021
:raises ValueError: If an unexpected element type is encountered.
2122
"""
2223

23-
from digipod.concepts import OMOP_SURGICAL_PROCEDURE
24-
2524
new_expr: logic.Expr
2625

2726
if isinstance(expr, Criterion):
@@ -31,8 +30,16 @@ def _wrap_criteria_with_factory(
3130
# Create a new combination of the same type with the same operator
3231
args = []
3332

33+
interval_criterion = (
34+
expr.interval_criterion if hasattr(expr, "interval_criterion") else None
35+
)
36+
3437
# Loop through all elements
3538
for element in expr.args:
39+
40+
if element == interval_criterion:
41+
# interval_criterion must not be wrapped!
42+
args.append(element)
3643
if isinstance(element, logic.Expr):
3744
# Recursively wrap nested combinations
3845
args.append(_wrap_criteria_with_factory(element, factory))

execution_engine/omop/cohort/graph_builder.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ def filter_symbols(cls, node: logic.Expr, filter_: logic.Expr) -> logic.Expr:
3737
if isinstance(node, logic.Symbol):
3838
return logic.LeftDependentToggle(left=filter_, right=node)
3939
elif isinstance(node, logic.Expr):
40-
converted_args = [cls.filter_symbols(a, filter_) for a in node.args]
40+
if hasattr(node, "interval_criterion") and node.interval_criterion:
41+
# we must not wrap the interval_criterion
42+
interval_criterion = node.interval_criterion
43+
converted_args = [
44+
cls.filter_symbols(a, filter_)
45+
for a in node.args
46+
if not a == interval_criterion
47+
] + [interval_criterion]
48+
else:
49+
converted_args = [cls.filter_symbols(a, filter_) for a in node.args]
4150

4251
if any(a is not b for a, b in zip(node.args, converted_args)):
4352
node.update_args(*converted_args)
@@ -64,6 +73,9 @@ def filter_intervention_criteria_by_population(cls, expr: logic.Expr) -> logic.E
6473
def traverse(
6574
expr: logic.Expr,
6675
) -> None:
76+
if expr is None:
77+
pass
78+
6779
if isinstance(expr, PopulationInterventionPairExpr):
6880
p, i = expr.left, expr.right
6981

execution_engine/omop/vocabulary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
OMOP_INTENSIVE_CARE = 32037
88
OMOP_INPATIENT_VISIT = 9201
99
OMOP_OUTPATIENT_VISIT = 9202
10+
OMOP_SURGICAL_PROCEDURE = 4301351 # OMOP surgical procedure
1011

1112

1213
class VocabularyNotFoundError(Exception):

execution_engine/util/logic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,12 @@ def dict(self, include_id: bool = False) -> dict:
622622
data = super().dict(include_id=include_id)
623623

624624
if self.interval_criterion:
625+
626+
if len(self.args) <= 1:
627+
raise ValueError(
628+
"More than one argument required if interval_criterion is set"
629+
)
630+
625631
args, pop = self.args[:-1], self.args[-1]
626632

627633
if pop != self.interval_criterion:

tests/execution_engine/omop/criterion/combination/test_temporal_combination.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from execution_engine.omop.criterion.noop import NoopCriterion
1414
from execution_engine.omop.criterion.procedure_occurrence import ProcedureOccurrence
1515
from execution_engine.omop.db.omop import tables
16+
from execution_engine.omop.vocabulary import OMOP_SURGICAL_PROCEDURE
1617
from execution_engine.task.process import get_processing_module
1718
from execution_engine.util import logic, temporal_logic_util
1819
from execution_engine.util.enum import TimeIntervalType
@@ -43,8 +44,6 @@
4344

4445
process = get_processing_module()
4546

46-
OMOP_SURGICAL_PROCEDURE = 4301351 # OMOP surgical procedure
47-
4847

4948
def intervals_to_df(result, by=None):
5049
df = intervals_to_df_orig(result, by, process.normalize_interval)

0 commit comments

Comments
 (0)