|
| 1 | +import time |
1 | 2 | from pydantic import ValidationError |
2 | 3 | from biasanalyzer.database import OMOPCDMDatabase, BiasDatabase |
3 | 4 | from biasanalyzer.cohort import CohortAction |
@@ -159,32 +160,41 @@ def display_concept_tree(self, concept_tree: dict, level: int = 0, show_in_text_ |
159 | 160 | return None |
160 | 161 |
|
161 | 162 |
|
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): |
163 | 165 | """ |
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 |
168 | 174 | """ |
| 175 | + |
169 | 176 | c_action = self._set_cohort_action() |
170 | 177 | 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) |
173 | 179 | 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) |
174 | 183 | print('cohort created successfully') |
175 | 184 | return created_cohort |
176 | 185 | else: |
177 | 186 | print('failed to create a valid cohort action object') |
178 | 187 | return None |
179 | 188 |
|
180 | 189 |
|
181 | | - |
182 | 190 | def compare_cohorts(self, cohort_id1, cohort_id2): |
183 | 191 | c_action = self._set_cohort_action() |
184 | 192 | if c_action: |
185 | 193 | return c_action.compare_cohorts(cohort_id1, cohort_id2) |
186 | 194 | else: |
187 | 195 | print('failed to create a valid cohort action object') |
| 196 | + return None |
| 197 | + |
188 | 198 |
|
189 | 199 | def cleanup(self): |
190 | 200 | self.bias_db.close() |
|
0 commit comments