Update data load templates - #42
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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 rawtruncate_tablesstring. - Corrects the default
encodingvalue fromutf+8toutf-8. - Moves
database_code,cdm_schema, andvocab_schemafromvariablesinto top-leveldatabases/schemassections.
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" |
Contributor
Author
There was a problem hiding this comment.
attribute_definition is not included in OMOP CDM 5.4.
csafreen
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Test if the flow runs successfully as template
DATAFLOW_TEMPLATE_BRANCHenvironment variable in docker-compose.yaml to the branch being reviewed and successfully run the flowInspect the nodes in the flow (either as a template or imported json file):
[Currently not visible in UI]