Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ data/
.dbt/
profiles.yml
.vscode/mcp.json
.cursor/mcp.json
.cursor/mcp.json.user.yml
4 changes: 4 additions & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ models:
+materialized: table
+docs:
node_color: '#EB6622'
vocabulary:
+schema: vocab
clinical:
+schema: cdm
staging:
synthea:
+materialized: view
Expand Down
8 changes: 8 additions & 0 deletions macros/generate_schema_name.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% macro generate_schema_name(custom_schema_name, node) -%}
{%- set default_schema = target.schema -%}
{%- if custom_schema_name is none -%}
{{ default_schema }}
{%- else -%}
{{ default_schema }}_{{ custom_schema_name | trim }}
{%- endif -%}
{%- endmacro %}
7 changes: 7 additions & 0 deletions macros/get_source.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{%- macro get_source(source_name, table_name) -%}
{%- if not var('seed_source', false) and table_name == 'source_to_concept_map_seed' -%}
{%- do return(ref('source_to_concept_map_seed')) -%}
{%- else -%}
{%- do return(source(source_name, table_name)) -%}
{%- endif -%}
{%- endmacro -%}
6 changes: 5 additions & 1 deletion macros/load_data_duckdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
{% set column_casts = [] %}
{% for column_name, column_type in columns.items() %}
{% if column_name in ['valid_start_date', 'valid_end_date'] %}
{% do column_casts.append("CAST(strptime(CAST(" ~ column_name ~ " AS VARCHAR), '%Y%m%d') AS DATE) AS " ~ column_name) %}
{% if parquet %}
{% do column_casts.append("CAST(" ~ column_name ~ " AS DATE) AS " ~ column_name) %}
{% else %}
{% do column_casts.append("CAST(strptime(CAST(" ~ column_name ~ " AS VARCHAR), '%Y%m%d') AS DATE) AS " ~ column_name) %}
{% endif %}
{% elif column_name|lower in ['start', 'stop', 'system', 'type', 'date'] %}
{% do column_casts.append("CAST(" ~ adapter.quote(column_name) ~ " AS " ~ api.Column.translate_type(column_type) ~ ") AS " ~ adapter.quote(column_name)) %}
{% else %}
Expand Down
14 changes: 14 additions & 0 deletions macros/macros.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ macros:
type: list[str]
description: A list of column names

- name: get_source
description: >
Wrapper macro around source() that returns a Relation object.
Routes source_to_concept_map_seed to ref() when seed_source is false,
since this table is not part of the Athena vocabulary download and
only exists in the seeds schema.
arguments:
- name: source_name
type: str
description: The source name as defined in the sources YAML.
- name: table_name
type: str
description: The table name within the source.

- name: string_truncate
description: This macro truncates a string to a specified length.
arguments:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% set column_names =
dbt_utils.get_filtered_columns_in_relation( source('vocabulary', 'source_to_concept_map_seed') )
{% set column_names =
dbt_utils.get_filtered_columns_in_relation( get_source('vocabulary', 'source_to_concept_map_seed') )
%}


WITH cte_stcm_lower AS (

SELECT
{{ lowercase_columns(column_names) }}
FROM {{ source('vocabulary','source_to_concept_map_seed') }}
FROM {{ get_source('vocabulary', 'source_to_concept_map_seed') }}
)

SELECT *
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
name = "dbt-synthea"
version = "0.1.0"
description = "dbt project for transforming Synthea synthetic patient data into OMOP CDM"
requires-python = ">=3.12,<3.14"
dependencies = [
"dbt-core>=1.9,<2",
"dbt-duckdb>=1.9,<2",
"duckdb",
]
852 changes: 852 additions & 0 deletions uv.lock

Large diffs are not rendered by default.