Skip to content

Commit 4694e52

Browse files
authored
Merge pull request #14 from VACLab/cohort_creation_background_enhancement
Cohort creation background enhancement
2 parents 9847534 + 04aaa1a commit 4694e52

File tree

4 files changed

+70
-42
lines changed

4 files changed

+70
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ config.yaml
33
__pycache__/
44
dist/
55
.coverage
6+
.ipynb_checkpoints/

biasanalyzer/api.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from pydantic import ValidationError
23
from biasanalyzer.database import OMOPCDMDatabase, BiasDatabase
34
from biasanalyzer.cohort import CohortAction
@@ -159,32 +160,41 @@ def display_concept_tree(self, concept_tree: dict, level: int = 0, show_in_text_
159160
return None
160161

161162

162-
def create_cohort(self, cohort_name, cohort_desc, query_or_yaml_file, created_by):
163+
def create_cohort(self, cohort_name: str, cohort_desc: str, query_or_yaml_file: str, created_by: str,
164+
delay: float=0):
163165
"""
164-
cohort_name: name of the cohort
165-
cohort_desc: description of the cohort
166-
query_or_yaml_file: a SQL query or YAML cohort creation file
167-
created_by: name of the user that created the cohort
166+
API method that allows to create a cohort
167+
:param cohort_name: name of the cohort
168+
:param cohort_desc: description of the cohort
169+
:param query_or_yaml_file: a SQL query or YAML cohort creation file
170+
:param created_by: name of the user that created the cohort
171+
:param delay: the number of seconds to sleep/delay for simulating long-running task for async testing,
172+
default is 0, meaning no delay
173+
:return: CohortData object if cohort is created successfully; otherwise, None
168174
"""
175+
169176
c_action = self._set_cohort_action()
170177
if c_action:
171-
created_cohort = c_action.create_cohort(cohort_name, cohort_desc, query_or_yaml_file,
172-
created_by)
178+
created_cohort = c_action.create_cohort(cohort_name, cohort_desc, query_or_yaml_file, created_by)
173179
if created_cohort is not None:
180+
if delay > 0:
181+
print(f"[DEBUG] Simulating long-running task with {delay} seconds delay...")
182+
time.sleep(delay)
174183
print('cohort created successfully')
175184
return created_cohort
176185
else:
177186
print('failed to create a valid cohort action object')
178187
return None
179188

180189

181-
182190
def compare_cohorts(self, cohort_id1, cohort_id2):
183191
c_action = self._set_cohort_action()
184192
if c_action:
185193
return c_action.compare_cohorts(cohort_id1, cohort_id2)
186194
else:
187195
print('failed to create a valid cohort action object')
196+
return None
197+
188198

189199
def cleanup(self):
190200
self.bias_db.close()

biasanalyzer/cohort.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ def create_cohort(self, cohort_name: str, description: str, query_or_yaml_file:
7979
Create a new cohort by executing a query on OMOP CDM database
8080
and storing the result in BiasDatabase. The query can be passed in directly
8181
or built from a yaml file using a corresponding SQL query template
82+
:param cohort_name: the name of the cohort
83+
:param description: the description of the cohort
84+
:param query_or_yaml_file: the SQL query string or yaml file name for creating a cohort
85+
:param created_by: created_by string indicating who created the cohort, it could be 'system',
86+
or a username, or whatever metadata to record who created the cohort
87+
:return: CohortData object if cohort is created successfully; otherwise, return None
8288
"""
8389
stages = [
8490
"Built query",

0 commit comments

Comments
 (0)