Skip to content

Commit 8e843d8

Browse files
author
Sarah Morgan
authored
Merge branch 'main' into terminology_update
2 parents fbae962 + dbf6dc7 commit 8e843d8

24 files changed

Lines changed: 2752 additions & 88 deletions
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Generate and Deploy dbt Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- '**.yml'
9+
- '**.yaml'
10+
- '**.sql'
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
# Allow only one concurrent deployment
18+
concurrency:
19+
group: "pages"
20+
cancel-in-progress: false
21+
22+
env:
23+
PYTHON_VERSION: '3.9'
24+
25+
####### Secrets #######
26+
####### Snowflake
27+
DBT_TUVA_SNOWFLAKE_ACCOUNT: ${{ secrets.DBT_TUVA_SNOWFLAKE_ACCOUNT }}
28+
DBT_TUVA_CI_DATABASE: ${{ secrets.DBT_TUVA_CI_DATABASE }}
29+
DBT_SNOWFLAKE_CI_PASSWORD: ${{ secrets.DBT_SNOWFLAKE_CI_PASSWORD }}
30+
DBT_SNOWFLAKE_CI_ROLE: ${{ secrets.DBT_SNOWFLAKE_CI_ROLE }}
31+
DBT_SNOWFLAKE_CI_SCHEMA: ${{ secrets.DBT_SNOWFLAKE_CI_SCHEMA }}
32+
DBT_SNOWFLAKE_CI_USER: ${{ secrets.DBT_SNOWFLAKE_CI_USER }}
33+
DBT_SNOWFLAKE_CI_WAREHOUSE: ${{ secrets.DBT_SNOWFLAKE_CI_WAREHOUSE }}
34+
35+
jobs:
36+
generate-docs:
37+
runs-on: ubuntu-latest
38+
defaults:
39+
run:
40+
working-directory: ./integration_tests/docs_generate
41+
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v4
45+
46+
- name: Set up Python
47+
uses: actions/setup-python@v4
48+
with:
49+
python-version: ${{ env.PYTHON_VERSION }}
50+
51+
- name: Install dbt-core and Snowflake adapter
52+
run: |
53+
python -m pip install --upgrade pip
54+
pip install dbt-core==1.8.6 dbt-snowflake
55+
56+
# --- Setup dbt Profile ---
57+
- name: Create dbt profiles directory in working directory
58+
run: mkdir -p .dbt
59+
60+
- name: Create dbt profiles.yml for Snowflake (for docs context)
61+
run: |
62+
echo "default:
63+
outputs:
64+
dev:
65+
account: \"{{ env_var('DBT_TUVA_SNOWFLAKE_ACCOUNT') }}\"
66+
database: dev_ci_testing
67+
password: \"{{ env_var('DBT_SNOWFLAKE_CI_PASSWORD') }}\"
68+
role: \"{{ env_var('DBT_SNOWFLAKE_CI_ROLE') }}\"
69+
schema: \"{{ env_var('DBT_SNOWFLAKE_CI_SCHEMA') }}\"
70+
threads: 8
71+
type: snowflake
72+
user: \"{{ env_var('DBT_SNOWFLAKE_CI_USER') }}\"
73+
warehouse: \"{{ env_var('DBT_SNOWFLAKE_CI_WAREHOUSE') }}\"
74+
target: dev" > .dbt/profiles.yml
75+
76+
- name: Verify profiles.yml exists
77+
run: |
78+
echo "Current working directory: $(pwd)"
79+
echo "Contents of .dbt directory:"
80+
ls -la .dbt/
81+
echo "Contents of profiles.yml:"
82+
cat .dbt/profiles.yml
83+
84+
- name: dbt-deps
85+
run: dbt deps --profiles-dir .dbt
86+
87+
- name: dbt-debug
88+
run: dbt debug --profiles-dir .dbt
89+
90+
- name: dbt-build
91+
run: dbt build --profiles-dir .dbt
92+
93+
- name: dbt-docs-generate
94+
run: dbt docs generate --profiles-dir .dbt
95+
96+
- name: Verify target directory was created
97+
run: |
98+
echo "Contents of current directory:"
99+
ls -la
100+
echo "Contents of target directory:"
101+
ls -la target/
102+
103+
- name: Setup Pages
104+
uses: actions/configure-pages@v4
105+
106+
- name: Upload artifact
107+
uses: actions/upload-pages-artifact@v3
108+
with:
109+
path: './integration_tests/docs_generate/target'
110+
111+
deploy:
112+
needs: generate-docs
113+
runs-on: ubuntu-latest
114+
115+
environment:
116+
name: github-pages
117+
url: ${{ steps.deployment.outputs.page_url }}
118+
119+
steps:
120+
- name: Deploy to GitHub Pages
121+
id: deployment
122+
uses: actions/deploy-pages@v4

.github/workflows/outside_contributor_dbt_v1.8.6.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ env:
2828
DBT_REDSHIFT_CI_HOST: ${{ secrets.DBT_REDSHIFT_CI_HOST }}
2929
DBT_REDSHIFT_CI_USER: ${{ secrets.DBT_REDSHIFT_CI_USER }}
3030
DBT_REDSHIFT_CI_PASSWORD: ${{ secrets.DBT_REDSHIFT_CI_PASSWORD }}
31-
DBT_REDSHIFT_CI_PORT: ${{ secrets.DBT_REDSHIFT_CI_PORT }}
3231
####### Snowflake
3332
DBT_TUVA_SNOWFLAKE_ACCOUNT: ${{ secrets.DBT_TUVA_SNOWFLAKE_ACCOUNT }}
3433
DBT_TUVA_CI_DATABASE: ${{ secrets.DBT_TUVA_CI_DATABASE }}
@@ -686,15 +685,9 @@ jobs:
686685
run: dbt debug --profiles-dir ./profiles/redshift
687686
working-directory: ci_testing
688687

689-
# Changed to seed then compile to speed up processing time
690-
- name: dbt-seed
691-
run: |
692-
dbt seed --full-refresh --profiles-dir ./profiles/redshift --vars '{"use_synthetic_data": true,"clinical_enabled":true,"claims_enabled":true}'
693-
working-directory: ci_testing
694-
695-
- name: dbt-compile
688+
- name: dbt-build
696689
run: |
697-
dbt compile --profiles-dir ./profiles/redshift --vars '{"use_synthetic_data": true,"clinical_enabled":true,"claims_enabled":true,"fhir_preprocessing_enabled":true}'
690+
dbt build --full-refresh --profiles-dir ./profiles/redshift --vars '{"use_synthetic_data": true,"clinical_enabled":true,"claims_enabled":true}'
698691
working-directory: ci_testing
699692

700693
- name: Get the result
@@ -732,7 +725,7 @@ jobs:
732725
# Changed to compile to save processing time
733726
- name: dbt-compile
734727
run: |
735-
dbt build --full-refresh --profiles-dir ./profiles/redshift --vars '{"use_synthetic_data": true,"claims_enabled":true}'
728+
dbt compile --full-refresh --profiles-dir ./profiles/redshift --vars '{"use_synthetic_data": true,"claims_enabled":true}'
736729
working-directory: ci_testing
737730

738731
- name: Get the result

.github/workflows/tuva_internal_dbt_v1.8.6.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ env:
2929
DBT_REDSHIFT_CI_HOST: ${{ secrets.DBT_REDSHIFT_CI_HOST }}
3030
DBT_REDSHIFT_CI_USER: ${{ secrets.DBT_REDSHIFT_CI_USER }}
3131
DBT_REDSHIFT_CI_PASSWORD: ${{ secrets.DBT_REDSHIFT_CI_PASSWORD }}
32-
DBT_REDSHIFT_CI_PORT: ${{ secrets.DBT_REDSHIFT_CI_PORT }}
3332
####### Snowflake
3433
DBT_TUVA_SNOWFLAKE_ACCOUNT: ${{ secrets.DBT_TUVA_SNOWFLAKE_ACCOUNT }}
3534
DBT_TUVA_CI_DATABASE: ${{ secrets.DBT_TUVA_CI_DATABASE }}
@@ -270,15 +269,9 @@ jobs:
270269
run: dbt debug --profiles-dir ./profiles/redshift
271270
working-directory: ci_testing
272271

273-
# Breaking up dbt build into seed then compile to try and speed up processing
274-
- name: dbt-seed
275-
run: |
276-
dbt seed --full-refresh --profiles-dir ./profiles/redshift --vars '{"use_synthetic_data": true,"clinical_enabled":true,"claims_enabled":true}'
277-
working-directory: ci_testing
278-
279-
- name: dbt-compile
272+
- name: dbt-build
280273
run: |
281-
dbt compile --profiles-dir ./profiles/redshift --vars '{"use_synthetic_data": true,"clinical_enabled":true,"claims_enabled":true,"fhir_preprocessing_enabled":true}'
274+
dbt build --full-refresh --profiles-dir ./profiles/redshift --vars '{"use_synthetic_data": true,"clinical_enabled": true,"claims_enabled": true,"provider_attribution_enabled":true,"fhir_preprocessing_enabled":true}'
282275
working-directory: ci_testing
283276

284277
- name: Get the result

dbt_project.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ seeds:
147147
terminology__ms_drg:
148148
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_terminology/0.14.15','ms_drg.csv',compression=true,null_marker=true) }}"
149149
terminology__ndc:
150-
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_terminology/0.14.15','ndc.csv',compression=true,null_marker=true) }}"
150+
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_terminology/0.14.16','ndc.csv',compression=true,null_marker=true) }}"
151151
terminology__nitos:
152152
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_terminology/0.14.15','nitos.csv',compression=true,null_marker=true) }}"
153153
terminology__other_provider_taxonomy:
@@ -165,9 +165,9 @@ seeds:
165165
terminology__revenue_center:
166166
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_terminology/0.14.16','revenue_center.csv',compression=true,null_marker=true) }}"
167167
terminology__rxnorm_to_atc:
168-
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_terminology/0.14.15','rxnorm_to_atc.csv',compression=true,null_marker=true) }}"
168+
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_terminology/0.14.16','rxnorm_to_atc.csv',compression=true,null_marker=true) }}"
169169
terminology__rxnorm_brand_generic:
170-
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_terminology/0.14.15','rxnorm_brand_generic.csv',compression=true,null_marker=true) }}"
170+
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_terminology/0.14.16','rxnorm_brand_generic.csv',compression=true,null_marker=true) }}"
171171
terminology__snomed_ct:
172172
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_terminology/0.14.15','snomed_ct.csv',compression=true,null_marker=true) }}"
173173
terminology__snomed_ct_transitive_closures:
@@ -238,7 +238,7 @@ seeds:
238238
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_value_sets/0.14.15','hcc_suspecting_icd_10_cm_mappings.csv',compression=true,null_marker=true) }}"
239239
pharmacy:
240240
pharmacy__rxnorm_generic_available:
241-
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_value_sets/0.14.15','rxnorm_generic_available.csv',compression=true,null_marker=true) }}"
241+
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_value_sets/0.14.16','rxnorm_generic_available.csv',compression=true,null_marker=true) }}"
242242
quality_measures:
243243
quality_measures__concepts:
244244
+post-hook: "{{ load_seed(var('custom_bucket_name','tuva-public-resources') ~ '/versioned_value_sets/0.14.15','quality_measures_concepts.csv',compression=true,null_marker=true) }}"

macros/metadata/tuva_invocations.sql

Lines changed: 54 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,59 @@
1-
{% macro create_tuva_invocations_table() %}
2-
3-
{%- set schema_name = var('tuva_schema_prefix') ~ '_metadata' if var('tuva_schema_prefix',None) != None else 'metadata' -%}
4-
5-
{% do adapter.create_schema(api.Relation.create(database=target.database, schema=schema_name)) %}
6-
7-
{%- set table_name = 'tuva_invocations' -%}
8-
{%- set target_type = target.type -%}
1+
{% macro create_tuva_invocations_table(schema_name) %}
2+
{# Creates a tuva invocations table. Returns true if the table is created or exists. Returns false if a non-supported platform is used. #}
3+
{% do adapter.create_schema(api.Relation.create(database=target.database, schema=schema_name)) %}
4+
5+
{%- set table_name = 'tuva_invocations' -%}
6+
{%- set target_type = target.type -%}
97

10-
{%- if target_type in ['redshift','postgres','duckdb'] -%}
11-
{%- set sql -%}
12-
CREATE TABLE IF NOT EXISTS {{ schema_name }}.{{ table_name }}
13-
(
14-
invocation_id {{ dbt.type_string() }},
15-
project_name {{ dbt.type_string() }},
16-
tuva_package_version {{ dbt.type_string() }},
17-
run_started_at {{ dbt.type_timestamp() }}
18-
)
19-
{%- endset -%}
20-
{% do run_query(sql) %}
21-
{{ return(true) }}
22-
{%- elif target_type in ['snowflake','databricks','bigquery'] -%}
23-
{%- set sql -%}
24-
CREATE OR REPLACE TABLE {{ schema_name }}.{{ table_name }}
25-
(
26-
invocation_id {{ dbt.type_string() }},
27-
project_name {{ dbt.type_string() }},
28-
tuva_package_version {{ dbt.type_string() }},
29-
run_started_at {{ dbt.type_timestamp() }}
30-
)
31-
{%- endset -%}
32-
{% do run_query(sql) %}
33-
{{ return(true) }}
34-
{%- if target_type in ['fabric'] -%}
35-
{%- set sql -%}
36-
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{{ table_name }}' AND TABLE_SCHEMA = '{{ schema_name }}')
37-
CREATE TABLE {{ schema_name }}.{{ table_name }}
38-
(
39-
invocation_id {{ dbt.type_string() }},
40-
project_name {{ dbt.type_string() }},
41-
tuva_package_version {{ dbt.type_string() }},
42-
run_started_at {{ dbt.type_timestamp() }}
43-
)
44-
{%- endset -%}
45-
{% do run_query(sql) %}
46-
{{ return(true) }}
8+
{%- if target_type in ['redshift','postgres','duckdb'] -%}
9+
{%- set sql -%}
10+
CREATE TABLE IF NOT EXISTS {{ schema_name }}.{{ table_name }}
11+
(
12+
invocation_id {{ dbt.type_string() }},
13+
project_name {{ dbt.type_string() }},
14+
tuva_package_version {{ dbt.type_string() }},
15+
run_started_at {{ dbt.type_timestamp() }}
16+
)
17+
{%- endset -%}
18+
{% do run_query(sql) %}
19+
{{ return(true) }}
20+
{%- elif target_type in ['snowflake','databricks','bigquery'] -%}
21+
{%- set sql -%}
22+
CREATE OR REPLACE TABLE {{ schema_name }}.{{ table_name }}
23+
(
24+
invocation_id {{ dbt.type_string() }},
25+
project_name {{ dbt.type_string() }},
26+
tuva_package_version {{ dbt.type_string() }},
27+
run_started_at {{ dbt.type_timestamp() }}
28+
)
29+
{%- endset -%}
30+
{% do run_query(sql) %}
31+
{{ return(true) }}
32+
{%- elif target_type in ['fabric'] -%}
33+
{%- set sql -%}
34+
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{{ table_name }}' AND TABLE_SCHEMA = '{{ schema_name }}')
35+
CREATE TABLE {{ schema_name }}.{{ table_name }}
36+
(
37+
invocation_id {{ dbt.type_string() }},
38+
project_name {{ dbt.type_string() }},
39+
tuva_package_version {{ dbt.type_string() }},
40+
run_started_at {{ dbt.type_timestamp() }}
41+
)
42+
{%- endset -%}
43+
{% do run_query(sql) %}
44+
{{ return(true) }}
45+
{%- else -%}
46+
{{ return(false) }}
4747
{%- endif -%}
48-
{%- else -%}
49-
{{ return(false) }}
50-
{%- endif -%}
5148

5249
{% endmacro %}
5350

5451

5552
{% macro log_invocation_start() %}
56-
{# Get the schema name using the same logic as in create_tuva_invocations_table #}
57-
{%- set schema_name = var('tuva_schema_prefix') ~ '_metadata' if var('tuva_schema_prefix',None) != None else 'metadata' -%}
58-
53+
{# Records the invocation start with the tuva project package version. #}
54+
{%- set schema_name = generate_schema_name(custom_schema_name='metadata') %}
5955
{# Capture the boolean result from create_tuva_invocations_table #}
60-
{%- set table_created = the_tuva_project.create_tuva_invocations_table() -%}
56+
{%- set table_created = the_tuva_project.create_tuva_invocations_table(schema_name) -%}
6157

6258
{# Only run DML if table_created is true. It will be false if a non-supported database is used. #}
6359
{%- if table_created -%}
@@ -81,22 +77,18 @@
8177

8278
{% do run_query(query) %}
8379

84-
{%- do the_tuva_project.drop_old_tuva_invocations() -%}
80+
{%- do the_tuva_project.drop_old_tuva_invocations(schema_name) -%}
81+
8582
{%- endif -%}
8683

8784
{% endmacro %}
8885

8986

90-
{% macro drop_old_tuva_invocations() %}
91-
{%- set schema_name = var('tuva_schema_prefix') ~ '_metadata' if var('tuva_schema_prefix',None) != None else 'metadata' -%}
92-
{%- set retention_days = var('tuva_metadata_retention_days', 30) -%}
93-
{%- set retention_days = retention_days | int -%}
94-
95-
{# Delete records older than the retention period #}
96-
{% do log("Deleting Tuva invocations older than " ~ retention_days ~ " days", info=True) %}
87+
{% macro drop_old_tuva_invocations(schema_name) %}
88+
{# Deletes tuva invocation records older than the retention period. #}
89+
{%- set retention_days = var('tuva_metadata_retention_days', 30) | int -%}
9790

98-
{# Use the dateadd function to calculate the cutoff date #}
99-
{% set dateadd = adapter.dispatch('dateadd', 'datetime') %}
91+
{% set dateadd = adapter.dispatch('dateadd', 'datetime') %}
10092
{% set query %}
10193
delete from {{ schema_name }}.tuva_invocations
10294
where run_started_at < cast({{ dateadd('day', -1 * retention_days, current_timestamp()) }} as {{ dbt.type_timestamp() }})

0 commit comments

Comments
 (0)