diff --git a/acmc/omop.py b/acmc/omop.py index 2a0bfd1ff0ee7284ff1b8e81387a7d7c4785be93..7075994944e0ee886f2a5a09d0eb765a07792f7e 100644 --- a/acmc/omop.py +++ b/acmc/omop.py @@ -186,7 +186,7 @@ def concept_set_exist(cursor, concept_set_name): cursor.execute(query, (concept_set_name,)) # 1 if exists, 0 otherwise - return cursor.fetchone()[0] 1 + return cursor.fetchone()[0] == 1 def export(map_path, export_path, version, omop_metadata): logger.debug(f"exporting with metadata {omop_metadata} at version {version}") @@ -271,6 +271,20 @@ def export(map_path, export_path, version, omop_metadata): df_out["concept_set_id"] = concept_set_id df_out.to_sql("CONCEPT_SET_ITEM", conn, if_exists='append', index=False) + # Output all tables to CSV + # Get the list of all tables + cur.execute("SELECT name FROM sqlite_master WHERE type='table';") + tables = cur.fetchall() # List of tables + + # Export each table to a separate CSV file + for table in tables: + table_name = table[0] # Extract table name + df = pd.read_sql_query(f"SELECT * FROM {table_name}", conn) + output_file = f"{table_name}.csv" + output_path = export_path / output_file + df.to_csv(output_path, index=False) # Save as CSV + logger.info(f"Exported {table_name} to {table_name}.csv") + conn.close() logger.debug(f"Created export db successfully")