Skip to content

Update data load templates - #42

Merged
Zhimin-arya merged 1 commit into
mainfrom
Zhimin-arya/update_data_load_template
Jul 21, 2026
Merged

Update data load templates#42
Zhimin-arya merged 1 commit into
mainfrom
Zhimin-arya/update_data_load_template

Conversation

@Zhimin-arya

Copy link
Copy Markdown
Contributor

Merge Checklist

Please review this list and check any items that require additions or modifications beyond your core changes. Reviewers can also use it to help confirm that nothing was missed.

Test if the flow runs successfully as an imported json file

  • Import the flow as a .json file and successfully run the flow

Test if the flow runs successfully as template

  • Switch DATAFLOW_TEMPLATE_BRANCH environment variable in docker-compose.yaml to the branch being reviewed and successfully run the flow

Inspect the nodes in the flow (either as a template or imported json file):

  • Each node has a short description that helps the user understand what the node does
  • Added documentation and type hints for embedded Python functions in flow templates (code in the Python node)
  • Result and error are removed in node data i.e. there should be no result or error visible for the nodes

[Currently not visible in UI]

  • Added a description for the flow template, including the OMOP CDM version and supported database(s)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates the OMOP CDM v5.3 and v5.4 data-load flow templates to align configuration with the template schema (databases/schemas) and correct encoding/truncation behavior.

Changes:

  • Fixes truncation gating by using truncate_tables_var (parsed boolean) rather than the raw truncate_tables string.
  • Corrects the default encoding value from utf+8 to utf-8.
  • Moves database_code, cdm_schema, and vocab_schema from variables into top-level databases / schemas sections.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
flows/Load_OMOP_CDM_v54.json Aligns DB/schema configuration to databases/schemas, fixes encoding, and updates truncation logic (but drops one table from truncation list).
flows/Load_OMOP_CDM_v53.json Aligns DB/schema configuration to databases/schemas, fixes encoding, and updates truncation logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"name": "TruncateTables",
"description": "Truncate tables by setting boolean flag",
"python_code": "def exec(myinput) -> dict[str, str]:\n \"\"\"\n Execute database table truncation and schema mapping for CDM and vocabulary tables.\n \n This function creates a mapping of OMOP CDM (Common Data Model) and vocabulary tables\n to their respective database schemas, and optionally truncates these tables before\n returning the mapping.\n \n Args:\n myinput: Input parameter (currently unused, reserved for future functionality).\n \n Returns:\n dict[str, str]: A dictionary mapping table names to their schema names.\n Keys are table names (e.g., 'person', 'concept'), values are schema names.\n \n Raises:\n Exception: If any tables fail truncation and skip_if_error is False, or if\n truncation fails for any tables when skip_if_error is True (after attempting\n all tables).\n \n Note:\n - Requires global variables: cdm_schema, vocab_schema, database_code, truncate_tables, skip_truncate_if_error\n - truncate_tables flag controls whether tables are truncated (default: True)\n - skip_if_error flag controls error handling during truncation (default: False)\n \"\"\"\n\n # From shared variables\n cdm_schema_var: str = cdm_schema \n vocab_schema_var: str = vocab_schema\n database_code_var: str = database_code\n truncate_tables_var: bool = eval(truncate_tables) # If set to true, tables will be truncated\n skip_if_error: bool = eval(skip_truncate_if_error) # If set to true, tables that failed to be truncated will be ignored\n\n # List of OMOP CDM clinical data tables\n cdm_table_list: list[str] = [\n \"person\",\n \"observation_period\",\n \"visit_occurrence\",\n \"visit_detail\",\n \"condition_occurrence\",\n \"drug_exposure\",\n \"procedure_occurrence\",\n \"device_exposure\",\n \"measurement\",\n \"observation\",\n \"death\",\n \"note\",\n \"note_nlp\",\n \"specimen\",\n \"fact_relationship\",\n \"location\",\n \"care_site\",\n \"provider\",\n \"payer_plan_period\",\n \"cost\",\n \"drug_era\",\n \"dose_era\",\n \"condition_era\",\n \"episode\",\n \"episode_event\",\n \"metadata\",\n \"cdm_source\",\n \"attribute_definition\"\n ]\n\n # List of OMOP vocabulary tables\n vocab_table_list: list[str] = [\n \"concept\",\n \"vocabulary\",\n \"domain\",\n \"concept_class\",\n \"concept_relationship\",\n \"relationship\",\n \"concept_synonym\",\n \"concept_ancestor\",\n \"source_to_concept_map\",\n \"drug_strength\"\n ]\n\n # Mapping of table names to their respective schemas\n table_schema_map: dict[str, str] = {\n **{table: cdm_schema_var for table in cdm_table_list},\n **{table: vocab_schema_var for table in vocab_table_list},\n }\n\n if truncate_tables:\n truncate_success: dict[str, bool] = {}\n\n dbdao = DBDao(database_code=database_code_var)\n\n for table, schema in table_schema_map.items():\n try: \n dbdao.truncate_table(schema, table)\n except Exception as e:\n truncate_success[table] = False\n if skip_if_error:\n continue\n else:\n raise\n else:\n truncate_success[table] = True\n\n false_count = sum(1 for v in truncate_success.values() if v is False)\n if false_count > 0:\n false_keys = [k for k, v in truncate_success.items() if v is False]\n raise Exception(f\"Some tables failed truncation: {false_keys}\")\n\n return table_schema_map\n return table_schema_map"
"python_code": "def exec(myinput) -> dict[str, str]:\n \"\"\"\n Execute database table truncation and schema mapping for CDM and vocabulary tables.\n \n This function creates a mapping of OMOP CDM (Common Data Model) and vocabulary tables\n to their respective database schemas, and optionally truncates these tables before\n returning the mapping.\n \n Args:\n myinput: Input parameter (currently unused, reserved for future functionality).\n \n Returns:\n dict[str, str]: A dictionary mapping table names to their schema names.\n Keys are table names (e.g., 'person', 'concept'), values are schema names.\n \n Raises:\n Exception: If any tables fail truncation and skip_if_error is False, or if\n truncation fails for any tables when skip_if_error is True (after attempting\n all tables).\n \n Note:\n - Requires global variables: cdm_schema, vocab_schema, database_code, truncate_tables, skip_truncate_if_error\n - truncate_tables flag controls whether tables are truncated (default: True)\n - skip_if_error flag controls error handling during truncation (default: False)\n \"\"\"\n\n # From shared variables\n cdm_schema_var: str = cdm_schema \n vocab_schema_var: str = vocab_schema\n database_code_var: str = database_code\n truncate_tables_var: bool = eval(truncate_tables) # If set to true, tables will be truncated\n skip_if_error: bool = eval(skip_truncate_if_error) # If set to true, tables that failed to be truncated will be ignored\n\n # List of OMOP CDM clinical data tables\n cdm_table_list: list[str] = [\n \"person\",\n \"observation_period\",\n \"visit_occurrence\",\n \"visit_detail\",\n \"condition_occurrence\",\n \"drug_exposure\",\n \"procedure_occurrence\",\n \"device_exposure\",\n \"measurement\",\n \"observation\",\n \"death\",\n \"note\",\n \"note_nlp\",\n \"specimen\",\n \"fact_relationship\",\n \"location\",\n \"care_site\",\n \"provider\",\n \"payer_plan_period\",\n \"cost\",\n \"drug_era\",\n \"dose_era\",\n \"condition_era\",\n \"episode\",\n \"episode_event\",\n \"metadata\",\n \"cdm_source\"\n ]\n\n # List of OMOP vocabulary tables\n vocab_table_list: list[str] = [\n \"concept\",\n \"vocabulary\",\n \"domain\",\n \"concept_class\",\n \"concept_relationship\",\n \"relationship\",\n \"concept_synonym\",\n \"concept_ancestor\",\n \"source_to_concept_map\",\n \"drug_strength\"\n ]\n\n # Mapping of table names to their respective schemas\n table_schema_map: dict[str, str] = {\n **{table: cdm_schema_var for table in cdm_table_list},\n **{table: vocab_schema_var for table in vocab_table_list},\n }\n\n if truncate_tables_var:\n truncate_success: dict[str, bool] = {}\n\n dbdao = DBDao(database_code=database_code_var)\n\n for table, schema in table_schema_map.items():\n try: \n dbdao.truncate_table(schema, table)\n except Exception as e:\n truncate_success[table] = False\n if skip_if_error:\n continue\n else:\n raise\n else:\n truncate_success[table] = True\n\n false_count = sum(1 for v in truncate_success.values() if v is False)\n if false_count > 0:\n false_keys = [k for k, v in truncate_success.items() if v is False]\n raise Exception(f\"Some tables failed truncation: {false_keys}\")\n\n return table_schema_map\n return table_schema_map"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attribute_definition is not included in OMOP CDM 5.4.

@Zhimin-arya
Zhimin-arya merged commit 370800c into main Jul 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make data load templates an alternative to bash script in admin guide

3 participants