1
1
import pytest
2
2
3
- from execution_engine .omop .cohort import PopulationInterventionPair
3
+ from execution_engine .omop .cohort import PopulationInterventionPairExpr
4
4
from execution_engine .omop .cohort .recommendation import Recommendation
5
5
from execution_engine .omop .concepts import Concept
6
6
from execution_engine .omop .criterion .visit_occurrence import ActivePatients
7
+ from execution_engine .util import logic
7
8
from tests .mocks .criterion import MockCriterion
8
9
9
10
10
11
class TestRecommendation :
11
12
12
13
def test_serialization (self ):
13
14
# Register the mock criterion class
14
- from execution_engine .omop .criterion import factory
15
-
16
- factory .register_criterion_class ("MockCriterion" , MockCriterion )
17
15
18
16
original = Recommendation (
19
- pi_pairs = [] ,
17
+ expr = logic . BooleanFunction () ,
20
18
base_criterion = MockCriterion ("c" ),
21
19
name = "foo" ,
22
20
title = "bar" ,
@@ -47,7 +45,7 @@ def test_serialization_with_active_patients(self, concept):
47
45
# specifically because there used to be a problem with the
48
46
# serialization of that combination.
49
47
original = Recommendation (
50
- pi_pairs = [] ,
48
+ expr = logic . BooleanFunction () ,
51
49
base_criterion = ActivePatients (),
52
50
name = "foo" ,
53
51
title = "bar" ,
@@ -60,11 +58,12 @@ def test_serialization_with_active_patients(self, concept):
60
58
deserialized = Recommendation .from_json (json )
61
59
assert original == deserialized
62
60
63
- def test_database_serialization (self , concept ):
61
+ def test_database_serialization (
62
+ self ,
63
+ concept ,
64
+ db_session , # use_db_session fixture for a proper database clean up after this test
65
+ ):
64
66
from execution_engine .execution_engine import ExecutionEngine
65
- from execution_engine .omop .criterion .factory import register_criterion_class
66
-
67
- register_criterion_class ("MockCriterion" , MockCriterion )
68
67
69
68
e = ExecutionEngine (verbose = False )
70
69
@@ -74,18 +73,18 @@ def test_database_serialization(self, concept):
74
73
population_criterion = MockCriterion ("p" )
75
74
intervention_criterion = MockCriterion ("i)" )
76
75
77
- pi_pair = PopulationInterventionPair (
76
+ pi_pair = PopulationInterventionPairExpr (
77
+ population_expr = population_criterion ,
78
+ intervention_expr = intervention_criterion ,
78
79
name = "foo" ,
79
80
url = "foo" ,
80
81
base_criterion = base_criterion ,
81
- population = population_criterion ,
82
- intervention = intervention_criterion ,
83
82
)
84
83
85
84
pi_pairs = [pi_pair ]
86
85
87
86
recommendation = Recommendation (
88
- pi_pairs = pi_pairs ,
87
+ expr = pi_pair ,
89
88
base_criterion = ActivePatients (),
90
89
name = "foo" ,
91
90
title = "bar" ,
@@ -105,33 +104,33 @@ def test_database_serialization(self, concept):
105
104
with pytest .raises (ValueError , match = r"Database ID has not been set yet!" ):
106
105
assert pi_pair .id is None
107
106
108
- for criterion in pi_pair .flatten ():
109
- with pytest .raises (
110
- ValueError , match = r"Database ID has not been set yet!"
111
- ):
112
- assert criterion .id is None
107
+ for criterion in recommendation .atoms ():
108
+ with pytest .raises (ValueError , match = r"Database ID has not been set yet!" ):
109
+ assert criterion .id is None
113
110
114
111
e .register_recommendation (recommendation )
115
112
116
113
assert recommendation .id is not None
117
114
assert recommendation .base_criterion .id is not None
115
+
118
116
for pi_pair in recommendation .population_intervention_pairs ():
119
117
assert pi_pair .id is not None
120
- for criterion in pi_pair .flatten ():
121
- assert criterion .id is not None
118
+
119
+ for criterion in recommendation .atoms ():
120
+ assert criterion .id is not None
122
121
123
122
rec_loaded = e .load_recommendation_from_database (url )
124
123
125
124
assert recommendation == rec_loaded
126
125
assert rec_loaded .id == recommendation .id
127
- assert len (rec_loaded ._pi_pairs ) == len ( pi_pairs )
126
+ assert len (list ( rec_loaded .population_intervention_pairs ())) == 1
128
127
129
- for pi_pair_loaded , pi_pair in zip (rec_loaded ._pi_pairs , pi_pairs ):
128
+ for pi_pair_loaded , pi_pair in zip (
129
+ list (rec_loaded .population_intervention_pairs ()), pi_pairs
130
+ ):
130
131
assert pi_pair_loaded .id == pi_pair .id
131
132
132
- assert len (pi_pair_loaded .flatten ()) == len (pi_pair .flatten ())
133
-
134
- for criterion_loaded , criterion in zip (
135
- pi_pair_loaded .flatten (), pi_pair .flatten ()
136
- ):
137
- assert criterion .id == criterion_loaded .id
133
+ for criterion_loaded , criterion in zip (
134
+ rec_loaded .atoms (), recommendation .atoms ()
135
+ ):
136
+ assert criterion .id == criterion_loaded .id
0 commit comments