diff --git a/lib/database.py b/lib/database.py index 06015db399e6c1e1b944ba1d41907baef6c8bf27..9c2792b35d38845eedb89d434e5de246a98937df 100644 --- a/lib/database.py +++ b/lib/database.py @@ -1600,7 +1600,7 @@ class Database(object): data_provider_class = Database._get_data_provider_class(sphn_base_iri=sphn_base_iri) is_legacy = Database._is_legacy_schema(sphn_base_iri=sphn_base_iri) ddl_statements = {} - supporting_tables_with_dpi = self.get_tables_with_dpi(project_name=project_name) + supporting_tables_with_dpi = Database._get_tables_with_dpi(project_name=project_name) # Get JSON schema bucket = Buckets.CONNECTOR.value json_schema_name = f'{project_name}/RML/{project_name}_json_schema.json' @@ -3840,8 +3840,8 @@ ORDER BY concept, attribute, count_distinct_values else: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"No download bundle found for project '{project}'") - - def get_tables_with_dpi(self, project_name: str) -> list: + @staticmethod + def _get_tables_with_dpi(project_name: str) -> list: """Gets supporting concepts with property sphn:hasDataProvider Args: @@ -3851,13 +3851,14 @@ ORDER BY concept, attribute, count_distinct_values list: table names """ table_names = [] - self.create_connection() + database = Database(project=project_name) + database.create_connection() query = "SELECT table_name FROM supporting_concepts WHERE data_provider_id=%s AND project_name=%s" - self.cursor.execute(query, (self.config.data_provider_id, project_name)) - records = self.cursor.fetchall() + database.cursor.execute(query, (database.config.data_provider_id, project_name)) + records = database.cursor.fetchall() for table_name in records: table_names.append("supporting__" + table_name[0]) - self.close_connection() + database.close_connection() return table_names def get_sphn_base_iri(self, project: str) -> str: diff --git a/lib/database_extractor.py b/lib/database_extractor.py index 44d9a5b5967f1989b8e1fb5d35cd6e0f1c196cef..57b2cd44cb25a76f6387c6fa66fa1ba537fc8a33 100644 --- a/lib/database_extractor.py +++ b/lib/database_extractor.py @@ -154,7 +154,7 @@ class DatabaseExtractor(Database): patients_to_process = database_extractor.get_patients_to_process(data_provider_class=data_provider_class) chunks = database_extractor.chunks(patient_ids=patients_to_process) tables_definition, supporting_tables_definition = database_extractor.generate_tables_definition(data_provider_class=data_provider_class) - supporting_tables_with_dpi = database_extractor.get_tables_with_dpi(project_name=project_name) + supporting_tables_with_dpi = Database._get_tables_with_dpi(project_name=project_name) with ProcessPoolExecutor(max_workers=database_extractor.config.machine_cpus) as executor: futures = [] for _, chunk in enumerate(chunks):