diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml new file mode 100644 index 000000000..d4bee6459 --- /dev/null +++ b/.github/workflows/unit_tests.yml @@ -0,0 +1,110 @@ +name: Unit Tests + +on: + pull_request: + branches: + - main + paths: + - 'models/**' + - 'macros/**' + - 'integration_tests/**' + +permissions: + contents: read + pull-requests: read + +jobs: + unit_tests: + name: Run Unit Tests (DuckDB) + runs-on: ubuntu-latest + env: + PYTHON_VERSION: "3.10" + DBT_PROJECT_DIR: "./integration_tests" + DBT_PROFILES_DIR: "./integration_tests/profiles/duckdb" + DBT_MOTHERDUCK_CI_PATH: ${{ secrets.DBT_MOTHERDUCK_CI_PATH }} + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install dbt-duckdb + run: pip install dbt-core dbt-duckdb + + - name: Install dbt dependencies + run: dbt deps --project-dir ${{ env.DBT_PROJECT_DIR }} --profiles-dir ${{ env.DBT_PROFILES_DIR }} + + - name: Load seeds + run: | + dbt seed \ + --project-dir ${{ env.DBT_PROJECT_DIR }} \ + --profiles-dir ${{ env.DBT_PROFILES_DIR }} + + - name: Build model schemas + run: | + dbt run --empty \ + --project-dir ${{ env.DBT_PROJECT_DIR }} \ + --profiles-dir ${{ env.DBT_PROFILES_DIR }} \ + || echo "Note: some models may fail with --empty (e.g. pivot macros). This is expected." + + - name: Run unit tests + run: | + dbt test \ + --select test_type:unit \ + --project-dir ${{ env.DBT_PROJECT_DIR }} \ + --profiles-dir ${{ env.DBT_PROFILES_DIR }} + + check_test_coverage: + name: Check Unit Test Coverage + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check new models have unit tests + run: | + # Get list of new model SQL files in this PR + NEW_MODELS=$(git diff --name-only --diff-filter=A origin/main...HEAD -- 'models/**/*.sql' | grep -v '__sources\|__docs' || true) + + if [ -z "$NEW_MODELS" ]; then + echo "No new model files found. Skipping coverage check." + exit 0 + fi + + echo "New model files in this PR:" + echo "$NEW_MODELS" + echo "" + + MISSING_TESTS="" + for model_file in $NEW_MODELS; do + model_dir=$(dirname "$model_file") + + # Check for unit test files in the model directory or parent + has_tests=false + if ls "$model_dir"/*unit_tests*.yml 2>/dev/null | grep -q .; then + has_tests=true + fi + parent_dir=$(dirname "$model_dir") + if ls "$parent_dir"/*unit_tests*.yml 2>/dev/null | grep -q .; then + has_tests=true + fi + + if [ "$has_tests" = false ]; then + MISSING_TESTS="$MISSING_TESTS\n - $model_file" + fi + done + + if [ -n "$MISSING_TESTS" ]; then + echo "" + echo "::warning::The following new models are in directories without unit test files:$MISSING_TESTS" + echo "" + echo "Consider adding unit tests in a *_unit_tests.yml file in the model directory." + else + echo "All new model directories have unit test files." + fi diff --git a/.gitignore b/.gitignore index a87a23670..969080803 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ dbt_modules/ dbt_packages/ package-lock.yml +# Local DuckDB databases +*.duckdb +*.duckdb.wal + # Logs logs/ diff --git a/integration_tests/dbt_project.yml b/integration_tests/dbt_project.yml index ec5c21c60..8d097a399 100644 --- a/integration_tests/dbt_project.yml +++ b/integration_tests/dbt_project.yml @@ -11,6 +11,7 @@ vars: # prefix: 'x_' # Prefix to identify passthrough columns (default: 'x_') # strip: false # Whether to strip prefix in final output (default: false) + tuva_unit_tests_enabled: true error_empty_seeds: true ## Use this variable to run the project with synthetic data loaded as seeds # otherwise set to false and set the input vars below diff --git a/integration_tests/profiles/duckdb/profiles.yml b/integration_tests/profiles/duckdb/profiles.yml index 7bfe92b24..8ac281e66 100644 --- a/integration_tests/profiles/duckdb/profiles.yml +++ b/integration_tests/profiles/duckdb/profiles.yml @@ -1,6 +1,10 @@ default: target: ci outputs: + dev: + type: duckdb + path: dev.duckdb + threads: 4 ci: type: duckdb path: "{{ env_var('DBT_MOTHERDUCK_CI_PATH') }}" diff --git a/models/claims_preprocessing/claims_preprocessing_unit_tests.yml b/models/claims_preprocessing/claims_preprocessing_unit_tests.yml new file mode 100644 index 000000000..0525be87c --- /dev/null +++ b/models/claims_preprocessing/claims_preprocessing_unit_tests.yml @@ -0,0 +1,380 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # CLAIMS ENROLLMENT MODELS + # ========================================================================= + + # ------------------------------------------------------------------------- + # claims_enrollment__member_months + # ------------------------------------------------------------------------- + + - name: test_member_months_generates_months_within_enrollment + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__member_months + description: > + Generates one member_month row for each calendar month that overlaps + with the enrollment period. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', enrollment_start_date: '2023-01-15', enrollment_end_date: '2023-03-10', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-01-01', year: 2023, month: 1} + - {full_date: '2023-01-15', year: 2023, month: 1} + - {full_date: '2023-01-31', year: 2023, month: 1} + - {full_date: '2023-02-01', year: 2023, month: 2} + - {full_date: '2023-02-28', year: 2023, month: 2} + - {full_date: '2023-03-01', year: 2023, month: 3} + - {full_date: '2023-03-10', year: 2023, month: 3} + - {full_date: '2023-03-31', year: 2023, month: 3} + - {full_date: '2023-04-01', year: 2023, month: 4} + - {full_date: '2023-04-30', year: 2023, month: 4} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202302', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202303', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + + - name: test_member_months_excludes_non_overlapping_months + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__member_months + description: > + Enrollment spanning only part of January should not generate a + February member month. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-01-31', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-01-01', year: 2023, month: 1} + - {full_date: '2023-01-31', year: 2023, month: 1} + - {full_date: '2023-02-01', year: 2023, month: 2} + - {full_date: '2023-02-28', year: 2023, month: 2} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + + - name: test_member_months_deduplicates_duplicate_eligibility_rows + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__member_months + description: > + Duplicate eligibility rows should not fan out member months because the + output grain is distinct on person, member, month, payer, plan, and data_source. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-03-31', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-03-31', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-01-01', year: 2023, month: 1} + - {full_date: '2023-01-31', year: 2023, month: 1} + - {full_date: '2023-02-01', year: 2023, month: 2} + - {full_date: '2023-02-28', year: 2023, month: 2} + - {full_date: '2023-03-01', year: 2023, month: 3} + - {full_date: '2023-03-31', year: 2023, month: 3} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202302', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202303', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + + - name: test_member_months_single_day_enrollment + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__member_months + description: > + A single-day enrollment (start == end) should still generate one + member month row for the calendar month containing that date. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', enrollment_start_date: '2023-06-15', enrollment_end_date: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-06-01', year: 2023, month: 6} + - {full_date: '2023-06-15', year: 2023, month: 6} + - {full_date: '2023-06-30', year: 2023, month: 6} + - {full_date: '2023-07-01', year: 2023, month: 7} + - {full_date: '2023-07-31', year: 2023, month: 7} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202306', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + + - name: test_member_months_overlapping_spans_same_person + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__member_months + description: > + Two overlapping enrollment spans for the same person/plan should + produce deduplicated member months, not double-counted rows. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-03-31', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', enrollment_start_date: '2023-02-15', enrollment_end_date: '2023-04-30', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-01-01', year: 2023, month: 1} + - {full_date: '2023-01-31', year: 2023, month: 1} + - {full_date: '2023-02-01', year: 2023, month: 2} + - {full_date: '2023-02-15', year: 2023, month: 2} + - {full_date: '2023-02-28', year: 2023, month: 2} + - {full_date: '2023-03-01', year: 2023, month: 3} + - {full_date: '2023-03-31', year: 2023, month: 3} + - {full_date: '2023-04-01', year: 2023, month: 4} + - {full_date: '2023-04-30', year: 2023, month: 4} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202302', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202303', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202304', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + + - name: test_member_months_gap_between_enrollment_spans + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__member_months + description: > + An enrollment gap (Jan-Feb, then Apr-May) should produce member months + only for the enrolled months, skipping March entirely. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-02-28', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', enrollment_start_date: '2023-04-01', enrollment_end_date: '2023-05-31', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-01-01', year: 2023, month: 1} + - {full_date: '2023-01-31', year: 2023, month: 1} + - {full_date: '2023-02-01', year: 2023, month: 2} + - {full_date: '2023-02-28', year: 2023, month: 2} + - {full_date: '2023-03-01', year: 2023, month: 3} + - {full_date: '2023-03-31', year: 2023, month: 3} + - {full_date: '2023-04-01', year: 2023, month: 4} + - {full_date: '2023-04-30', year: 2023, month: 4} + - {full_date: '2023-05-01', year: 2023, month: 5} + - {full_date: '2023-05-31', year: 2023, month: 5} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202302', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202304', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202305', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + + - name: test_member_months_different_payers_separate_rows + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__member_months + description: > + The same person enrolled with two different payers in the same month + should produce separate member month rows per payer. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-01-31', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', member_id: 'M1', payer: 'MCD', plan: 'PlanB', data_source: 'src1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-01-31', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-01-01', year: 2023, month: 1} + - {full_date: '2023-01-31', year: 2023, month: 1} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCD', plan: 'PlanB', data_source: 'src1'} + + - name: test_member_months_cross_year_enrollment + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__member_months + description: > + Enrollment spanning December to January of the next year generates + member months in both years with correct year_month codes. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', enrollment_start_date: '2023-12-01', enrollment_end_date: '2024-01-31', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-12-01', year: 2023, month: 12} + - {full_date: '2023-12-31', year: 2023, month: 12} + - {full_date: '2024-01-01', year: 2024, month: 1} + - {full_date: '2024-01-31', year: 2024, month: 1} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202312', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', year_month: '202401', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + + # ------------------------------------------------------------------------- + # claims_enrollment__flag_claims_with_enrollment + # ------------------------------------------------------------------------- + + - name: test_flag_claims_matching_enrollment + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__flag_claims_with_enrollment + description: > + Claims that match an enrollment member month via person_id, member_id, + payer, plan, data_source, and year_month are returned. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', claim_line_start_date: '2023-01-15', claim_start_date: null, admission_date: null} + - {claim_id: 'C2', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', claim_line_start_date: '2023-04-15', claim_start_date: null, admission_date: null} + - input: ref('claims_enrollment__member_months') + rows: + - {member_month_key: 'mmk1', person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', member_month_key: 'mmk1', inferred_claim_start_year_month: '202301', inferred_claim_start_column_used: 'claim_line_start_date', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_flag_claims_uses_fallback_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__flag_claims_with_enrollment + description: > + When claim_line_start_date is null, falls back to claim_start_date, + then admission_date. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', claim_line_start_date: null, claim_start_date: '2023-02-10', admission_date: null} + - {claim_id: 'C2', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', claim_line_start_date: null, claim_start_date: null, admission_date: '2023-03-05'} + - input: ref('claims_enrollment__member_months') + rows: + - {member_month_key: 'mmk2', person_id: 'P1', member_id: 'M1', year_month: '202302', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {member_month_key: 'mmk3', person_id: 'P1', member_id: 'M1', year_month: '202303', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', member_month_key: 'mmk2', inferred_claim_start_year_month: '202302', inferred_claim_start_column_used: 'claim_start_date', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', member_month_key: 'mmk3', inferred_claim_start_year_month: '202303', inferred_claim_start_column_used: 'admission_date', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_flag_claims_multiple_lines_same_claim + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__flag_claims_with_enrollment + description: > + Multiple claim lines for the same claim_id should each independently + match enrollment and produce separate output rows. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', claim_line_start_date: '2023-01-10', claim_start_date: null, admission_date: null} + - {claim_id: 'C1', claim_line_number: 2, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', claim_line_start_date: '2023-01-10', claim_start_date: null, admission_date: null} + - input: ref('claims_enrollment__member_months') + rows: + - {member_month_key: 'mmk1', person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', member_month_key: 'mmk1', inferred_claim_start_year_month: '202301', inferred_claim_start_column_used: 'claim_line_start_date', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C1', claim_line_number: 2, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', member_month_key: 'mmk1', inferred_claim_start_year_month: '202301', inferred_claim_start_column_used: 'claim_line_start_date', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # claims_enrollment__flag_rx_claims_with_enrollment + # ------------------------------------------------------------------------- + + - name: test_flag_rx_claims_matching_enrollment + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__flag_rx_claims_with_enrollment + description: > + Pharmacy claims that match an enrollment member month via + person_id, member_id, payer, plan, data_source, and paid_year_month + are returned. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__pharmacy_claim') + rows: + - {claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', paid_date: '2023-01-20'} + - {claim_id: 'RX2', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', paid_date: '2023-05-20'} + - input: ref('claims_enrollment__member_months') + rows: + - {member_month_key: 'mmk1', person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', member_month_key: 'mmk1', paid_year_month: '202301', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_flag_rx_claims_excludes_unenrolled_months + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__flag_rx_claims_with_enrollment + description: > + Pharmacy claims paid in months without enrollment should be excluded + from the result set entirely. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__pharmacy_claim') + rows: + - {claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', paid_date: '2023-06-15'} + - input: ref('claims_enrollment__member_months') + rows: + - {member_month_key: 'mmk1', person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: [] + + - name: test_flag_rx_claims_multiple_lines_same_claim + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: claims_enrollment__flag_rx_claims_with_enrollment + description: > + Multiple claim lines for the same pharmacy claim should each + independently match enrollment. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__pharmacy_claim') + rows: + - {claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', paid_date: '2023-01-10'} + - {claim_id: 'RX1', claim_line_number: 2, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', paid_date: '2023-01-10'} + - input: ref('claims_enrollment__member_months') + rows: + - {member_month_key: 'mmk1', person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', member_month_key: 'mmk1', paid_year_month: '202301', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'RX1', claim_line_number: 2, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', member_month_key: 'mmk1', paid_year_month: '202301', tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/claims_preprocessing/encounters/encounter_gap_unit_tests.yml b/models/claims_preprocessing/encounters/encounter_gap_unit_tests.yml new file mode 100644 index 000000000..7b239718a --- /dev/null +++ b/models/claims_preprocessing/encounters/encounter_gap_unit_tests.yml @@ -0,0 +1,1924 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGING MODELS + # ========================================================================= + + # ------------------------------------------------------------------------- + # encounters__stg_medical_claim + # ------------------------------------------------------------------------- + + - name: test_gap_stg_medical_claim_joins_service_category + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__stg_medical_claim + description: > + Joins medical claims to service category grouper and patient_data_source_id, + producing enriched claim lines with service category and patient identifiers. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, claim_type: 'professional', admission_date: null, discharge_date: null, claim_start_date: '2023-01-01', claim_end_date: '2023-01-01', claim_line_start_date: '2023-01-01', claim_line_end_date: '2023-01-01', bill_type_code: null, hcpcs_code: '99213', hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null, drg_code_type: null, drg_code: null, admit_source_code: null, admit_type_code: null, place_of_service_code: '11', revenue_center_code: null, diagnosis_code_type: 'icd-10-cm', diagnosis_code_1: 'J06.9', billing_npi: 'NPI1', rendering_npi: 'NPI2', facility_npi: 'NPI3', discharge_disposition_code: null, paid_amount: 100.00, charge_amount: 150.00, allowed_amount: 120.00, data_source: 'src1'} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'C1', claim_line_number: 1, duplicate_row_number: 1, service_category_1: 'office-based', service_category_2: 'office-based visit', service_category_3: 'office-based visit', data_source: 'src1'} + - input: ref('encounters__patient_data_source_id') + rows: + - {person_id: 'P1', data_source: 'src1', patient_data_source_id: 1} + - input: ref('ccsr__dxccsr_v2023_1_cleaned_map') + rows: [] + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__nitos') + rows: [] + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + - input: ref('terminology__revenue_center') + rows: [] + - input: ref('terminology__place_of_service') + rows: [] + - input: ref('terminology__bill_type') + rows: [] + - input: ref('terminology__ccs_services_procedures') + rows: [] + expect: + rows: + - {person_id: 'P1', patient_data_source_id: 1, claim_id: 'C1', claim_line_number: 1, claim_type: 'professional', service_category_1: 'office-based', service_category_2: 'office-based visit', service_category_3: 'office-based visit', paid_amount: 100.00, data_source: 'src1'} + + - name: test_gap_stg_medical_claim_ignores_lower_priority_service_category_rows + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__stg_medical_claim + description: > + The join to service_category__service_category_grouper should only keep + duplicate_row_number = 1 so a single claim line does not fan out. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, claim_type: 'professional', admission_date: null, discharge_date: null, claim_start_date: '2023-01-01', claim_end_date: '2023-01-01', claim_line_start_date: '2023-01-01', claim_line_end_date: '2023-01-01', bill_type_code: null, hcpcs_code: '99213', drg_code_type: null, drg_code: null, admit_source_code: null, admit_type_code: null, place_of_service_code: '11', revenue_center_code: null, diagnosis_code_type: 'icd-10-cm', diagnosis_code_1: 'J06.9', billing_npi: 'NPI1', rendering_npi: 'NPI2', facility_npi: 'NPI3', discharge_disposition_code: null, paid_amount: 100.00, charge_amount: 150.00, allowed_amount: 120.00, data_source: 'src1'} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', duplicate_row_number: 1, service_category_1: 'office-based', service_category_2: 'office-based visit', service_category_3: 'office-based visit'} + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', duplicate_row_number: 2, service_category_1: 'outpatient', service_category_2: 'emergency department', service_category_3: 'emergency department'} + - input: ref('encounters__patient_data_source_id') + rows: + - {person_id: 'P1', data_source: 'src1', patient_data_source_id: 1} + - input: ref('ccsr__dxccsr_v2023_1_cleaned_map') + rows: [] + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__nitos') + rows: [] + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + - input: ref('terminology__revenue_center') + rows: [] + - input: ref('terminology__place_of_service') + rows: [] + - input: ref('terminology__bill_type') + rows: [] + - input: ref('terminology__ccs_services_procedures') + rows: [] + expect: + rows: + - {person_id: 'P1', patient_data_source_id: 1, claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', service_category_1: 'office-based', service_category_2: 'office-based visit', service_category_3: 'office-based visit', paid_amount: 100.00, data_source: 'src1'} + + # ========================================================================= + # INTERMEDIATE MODELS - Prof Claims (inpatient types) + # ========================================================================= + + # ------------------------------------------------------------------------- + # acute_inpatient__prof_claims + # ------------------------------------------------------------------------- + + - name: test_gap_acute_inpatient_prof_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: acute_inpatient__prof_claims + description: > + Matches professional claims to acute inpatient encounters by date overlap, + assigning claim_attribution_number to prevent duplicate attribution. + given: + - input: ref('acute_inpatient__generate_encounter_id') + rows: + - {encounter_id: 1, patient_data_source_id: 1, encounter_claim_number: 1} + - input: ref('acute_inpatient__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-05'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-02', data_source: 'src1'} + - input: ref('encounters__prof_and_lower_priority') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-05', claim_id: 'PROF1', claim_line_number: 1, claim_attribution_number: 1} + + # ------------------------------------------------------------------------- + # inpatient_hospice__prof_claims + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_hospice_prof_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_hospice__prof_claims + description: > + Matches professional claims to inpatient hospice encounters by date overlap. + given: + - input: ref('inpatient_hospice__generate_encounter_id') + rows: + - {encounter_id: 1, patient_data_source_id: 1, encounter_claim_number: 1} + - input: ref('inpatient_hospice__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-02-01', encounter_end_date: '2023-02-10'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-02-03', data_source: 'src1'} + - input: ref('encounters__prof_and_lower_priority') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-02-01', encounter_end_date: '2023-02-10', claim_id: 'PROF1', claim_line_number: 1, claim_attribution_number: 1} + + # ------------------------------------------------------------------------- + # inpatient_psych__prof_claims + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_psych_prof_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_psych__prof_claims + description: > + Matches professional claims to inpatient psych encounters by date overlap. + given: + - input: ref('inpatient_psych__generate_encounter_id') + rows: + - {encounter_id: 1, patient_data_source_id: 1, encounter_claim_number: 1} + - input: ref('inpatient_psych__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-03-01', encounter_end_date: '2023-03-14'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-03-05', data_source: 'src1'} + - input: ref('encounters__prof_and_lower_priority') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-03-01', encounter_end_date: '2023-03-14', claim_id: 'PROF1', claim_line_number: 1, claim_attribution_number: 1} + + # ------------------------------------------------------------------------- + # inpatient_rehab__prof_claims + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_rehab_prof_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_rehab__prof_claims + description: > + Matches professional claims to inpatient rehab encounters by date overlap. + given: + - input: ref('inpatient_rehab__generate_encounter_id') + rows: + - {encounter_id: 1, patient_data_source_id: 1, encounter_claim_number: 1} + - input: ref('inpatient_rehab__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-04-01', encounter_end_date: '2023-04-20'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-04-10', data_source: 'src1'} + - input: ref('encounters__prof_and_lower_priority') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-04-01', encounter_end_date: '2023-04-20', claim_id: 'PROF1', claim_line_number: 1, claim_attribution_number: 1} + + # ------------------------------------------------------------------------- + # inpatient_long_term__prof_claims + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_long_term_prof_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_long_term__prof_claims + description: > + Matches professional claims to inpatient long term encounters by date overlap. + given: + - input: ref('inpatient_long_term__generate_encounter_id') + rows: + - {encounter_id: 1, patient_data_source_id: 1, encounter_claim_number: 1} + - input: ref('inpatient_long_term__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-05-01', encounter_end_date: '2023-05-30'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-05-15', data_source: 'src1'} + - input: ref('encounters__prof_and_lower_priority') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-05-01', encounter_end_date: '2023-05-30', claim_id: 'PROF1', claim_line_number: 1, claim_attribution_number: 1} + + # ------------------------------------------------------------------------- + # inpatient_snf__prof_claims + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_snf_prof_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_snf__prof_claims + description: > + Matches professional claims to inpatient SNF encounters by date overlap. + given: + - input: ref('inpatient_snf__generate_encounter_id') + rows: + - {encounter_id: 1, patient_data_source_id: 1, encounter_claim_number: 1} + - input: ref('inpatient_snf__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-21'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-06-10', data_source: 'src1'} + - input: ref('encounters__prof_and_lower_priority') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-21', claim_id: 'PROF1', claim_line_number: 1, claim_attribution_number: 1} + + # ------------------------------------------------------------------------- + # inpatient_substance_use__prof_claims + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_substance_use_prof_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_substance_use__prof_claims + description: > + Matches professional claims to inpatient substance use encounters by date overlap. + given: + - input: ref('inpatient_substance_use__generate_encounter_id') + rows: + - {encounter_id: 1, patient_data_source_id: 1, encounter_claim_number: 1} + - input: ref('inpatient_substance_use__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-07-01', encounter_end_date: '2023-07-14'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-07-05', data_source: 'src1'} + - input: ref('encounters__prof_and_lower_priority') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-07-01', encounter_end_date: '2023-07-14', claim_id: 'PROF1', claim_line_number: 1, claim_attribution_number: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Emergency Department + # ========================================================================= + + # ------------------------------------------------------------------------- + # emergency_department__generate_encounter_id_pre_sort + # ------------------------------------------------------------------------- + + - name: test_gap_ed_generate_encounter_id_pre_sort + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: emergency_department__generate_encounter_id_pre_sort + description: > + Groups ED claims into encounters by merging overlapping claims at the + same facility for the same patient, producing encounter_id assignments. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'ED1', patient_data_source_id: 1, start_date: '2023-01-01', end_date: '2023-01-01', service_category_2: 'emergency department', facility_npi: 'NPI1', discharge_disposition_code: null, claim_type: 'institutional'} + expect: + rows: + - {patient_data_source_id: 1, claim_id: 'ED1', start_date: '2023-01-01', end_date: '2023-01-01', close_flag: 1} + + # ------------------------------------------------------------------------- + # emergency_department__generate_encounter_id + # ------------------------------------------------------------------------- + + - name: test_gap_ed_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: emergency_department__generate_encounter_id + description: > + Assigns dense_rank encounter_id and claim ordering within each encounter + from the pre-sorted ED claims. + given: + - input: ref('emergency_department__generate_encounter_id_pre_sort') + rows: + - {patient_data_source_id: 1, claim_id: 'ED1', start_date: '2023-01-01', end_date: '2023-01-01', discharge_disposition_code: null, facility_npi: 'NPI1', row_num: 1, close_flag: 1, min_closing_row: 1, encounter_id: 'ED1'} + expect: + rows: + - {patient_data_source_id: 1, claim_id: 'ED1', start_date: '2023-01-01', end_date: '2023-01-01', encounter_claim_number: 1, encounter_id: 1, original_anchor_claim: 'ED1'} + + # ------------------------------------------------------------------------- + # emergency_department__prof_claims + # ------------------------------------------------------------------------- + + - name: test_gap_ed_prof_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: emergency_department__prof_claims + description: > + Matches professional and outpatient institutional claims to ED encounters + by date overlap, producing claim_attribution_number to avoid duplicates. + given: + - input: ref('emergency_department__generate_encounter_id') + rows: + - {encounter_id: 1, patient_data_source_id: 1, claim_id: 'ED_INST1', encounter_claim_number: 1, start_date: '2023-01-01', end_date: '2023-01-01'} + - input: ref('emergency_department__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-01'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, claim_line_id: 'PROF1|1', patient_data_source_id: 1, start_date: '2023-01-01', data_source: 'src1'} + - input: ref('encounters__stg_professional') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, claim_line_id: 'PROF1|1', data_source: 'src1'} + - input: ref('encounters__stg_outpatient_institutional') + rows: [] + expect: + rows: + - {encounter_id: 1, claim_id: 'PROF1', claim_line_number: 1, claim_attribution_number: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - ASC Start/End Dates + # ========================================================================= + + # ------------------------------------------------------------------------- + # asc__start_end_dates + # ------------------------------------------------------------------------- + + - name: test_gap_asc_start_end_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: asc__start_end_dates + description: > + Computes encounter start (min) and end (max) dates for ASC encounters + grouped by patient_data_source_id and old_encounter_id. + given: + - input: ref('asc__generate_encounter_id') + rows: + - {patient_data_source_id: 1, old_encounter_id: 1, start_date: '2023-01-10', end_date: '2023-01-10'} + - {patient_data_source_id: 1, old_encounter_id: 1, start_date: '2023-01-10', end_date: '2023-01-11'} + expect: + rows: + - {patient_data_source_id: 1, old_encounter_id: 1, encounter_start_date: '2023-01-10', encounter_end_date: '2023-01-11'} + + # ========================================================================= + # INTERMEDIATE MODELS - Institutional Claim Lines + # ========================================================================= + + # ------------------------------------------------------------------------- + # encounters__int_institutional_claim_lines + # ------------------------------------------------------------------------- + + - name: test_gap_int_institutional_claim_lines + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__int_institutional_claim_lines + description: > + Unions institutional encounter types (acute inpatient, ED, hospice, etc.) + with their claim_line_number from stg_medical_claim. + given: + - input: ref('acute_inpatient__generate_encounter_id') + rows: + - {claim_id: 'INST1', encounter_id: 1} + - input: ref('emergency_department__generate_encounter_id') + rows: [] + - input: ref('inpatient_hospice__generate_encounter_id') + rows: [] + - input: ref('inpatient_psych__generate_encounter_id') + rows: [] + - input: ref('inpatient_rehab__generate_encounter_id') + rows: [] + - input: ref('inpatient_long_term__generate_encounter_id') + rows: [] + - input: ref('inpatient_snf__generate_encounter_id') + rows: [] + - input: ref('inpatient_substance_use__generate_encounter_id') + rows: [] + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'INST1', claim_line_number: 1} + expect: + rows: + - {claim_id: 'INST1', claim_line_number: 1, encounter_id: 1, encounter_type: 'acute inpatient', encounter_group: 'inpatient', priority_number: 0} + + # ========================================================================= + # INTERMEDIATE MODELS - Combined Claim Line Crosswalk + # ========================================================================= + + # ------------------------------------------------------------------------- + # encounters__combined_claim_line_crosswalk + # ------------------------------------------------------------------------- + + - name: test_gap_combined_claim_line_crosswalk + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__combined_claim_line_crosswalk + description: > + Unions all encounter type crosswalks and assigns new encounter_id via + dense_rank, plus claim_line_attribution_number for deduplication. + given: + - input: ref('acute_inpatient__prof_claims') + rows: [] + - input: ref('emergency_department__prof_claims') + rows: [] + - input: ref('inpatient_psych__prof_claims') + rows: [] + - input: ref('inpatient_rehab__prof_claims') + rows: [] + - input: ref('inpatient_long_term__prof_claims') + rows: [] + - input: ref('inpatient_snf__prof_claims') + rows: [] + - input: ref('inpatient_substance_use__prof_claims') + rows: [] + - input: ref('office_visits__int_office_visits_claim_line') + rows: [] + - input: ref('urgent_care__match_claims_to_anchor') + rows: + - {claim_id: 'UC1', claim_line_number: 1, old_encounter_id: 1} + - input: ref('outpatient_psych__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_rehab__match_claims_to_anchor') + rows: [] + - input: ref('asc__match_claims_to_anchor') + rows: [] + - input: ref('dialysis__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_hospice__match_claims_to_anchor') + rows: [] + - input: ref('home_health__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_surgery__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_injections__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_ptotst__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_substance_use__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_radiology__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_hospital_or_clinic__match_claims_to_anchor') + rows: [] + - input: ref('encounters__int_institutional_claim_lines') + rows: [] + - input: ref('lab__match_claims_to_anchor') + rows: [] + - input: ref('dme__match_claims_to_anchor') + rows: [] + - input: ref('ambulance__match_claims_to_anchor') + rows: [] + expect: + rows: + - {claim_id: 'UC1', claim_line_number: 1, encounter_type: 'urgent care', encounter_group: 'outpatient', priority_number: 9, claim_line_attribution_number: 1} + + - name: test_gap_combined_claim_line_crosswalk_prioritizes_lower_priority_claim_type + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__combined_claim_line_crosswalk + description: > + If the same claim line appears in multiple encounter sources, the + lower priority_number should receive claim_line_attribution_number = 1. + given: + - input: ref('acute_inpatient__prof_claims') + rows: + - {claim_id: 'C1', claim_line_number: 1, encounter_id: 10, claim_attribution_number: 1} + - input: ref('emergency_department__prof_claims') + rows: + - {claim_id: 'C1', claim_line_number: 1, encounter_id: 20, claim_attribution_number: 1} + - input: ref('inpatient_psych__prof_claims') + rows: [] + - input: ref('inpatient_rehab__prof_claims') + rows: [] + - input: ref('inpatient_long_term__prof_claims') + rows: [] + - input: ref('inpatient_snf__prof_claims') + rows: [] + - input: ref('inpatient_substance_use__prof_claims') + rows: [] + - input: ref('office_visits__int_office_visits_claim_line') + rows: [] + - input: ref('urgent_care__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_psych__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_rehab__match_claims_to_anchor') + rows: [] + - input: ref('asc__match_claims_to_anchor') + rows: [] + - input: ref('dialysis__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_hospice__match_claims_to_anchor') + rows: [] + - input: ref('home_health__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_surgery__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_injections__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_ptotst__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_substance_use__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_radiology__match_claims_to_anchor') + rows: [] + - input: ref('outpatient_hospital_or_clinic__match_claims_to_anchor') + rows: [] + - input: ref('encounters__int_institutional_claim_lines') + rows: [] + - input: ref('lab__match_claims_to_anchor') + rows: [] + - input: ref('dme__match_claims_to_anchor') + rows: [] + - input: ref('ambulance__match_claims_to_anchor') + rows: [] + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, old_encounter_id: 10, encounter_id: 1, encounter_type: 'acute inpatient', encounter_group: 'inpatient', priority_number: 0, claim_line_attribution_number: 1} + - {claim_id: 'C1', claim_line_number: 1, old_encounter_id: 10, encounter_id: 2, encounter_type: 'emergency department', encounter_group: 'outpatient', priority_number: 1, claim_line_attribution_number: 2} + - {claim_id: 'C1', claim_line_number: 1, old_encounter_id: 20, encounter_id: 3, encounter_type: 'emergency department', encounter_group: 'outpatient', priority_number: 1, claim_line_attribution_number: 3} + + # ========================================================================= + # INTERMEDIATE MODELS - Office Visits + # ========================================================================= + + # ------------------------------------------------------------------------- + # office_visits__int_office_visits + # ------------------------------------------------------------------------- + + - name: test_gap_office_visits_int_office_visits + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visits__int_office_visits + description: > + Identifies office-based claims from the professional service category + and assigns an old_encounter_id via dense_rank by patient + date. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OV1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-15', service_category_1: 'office-based', service_category_2: 'office-based visit', service_category_3: 'office-based visit'} + - input: ref('service_category__combined_professional') + rows: + - {claim_id: 'OV1', claim_line_number: 1, service_category_1: 'office-based'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV1', claim_line_number: 1, service_category_2: 'office-based visit', service_category_3: 'office-based visit', old_encounter_id: 1} + + # ------------------------------------------------------------------------- + # office_visits__int_office_visits_em + # ------------------------------------------------------------------------- + + - name: test_gap_office_visits_em + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visits__int_office_visits_em + description: > + Filters office visits to those with service_category_2 = 'office-based visit'. + given: + - input: ref('office_visits__int_office_visits') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV1', claim_line_number: 1, service_category_2: 'office-based visit', old_encounter_id: 1} + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV2', claim_line_number: 1, service_category_2: 'office-based surgery', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1} + + # ------------------------------------------------------------------------- + # office_visits__int_office_visits_surgery + # ------------------------------------------------------------------------- + + - name: test_gap_office_visits_surgery + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visits__int_office_visits_surgery + description: > + Filters office visits to those with service_category_2 = 'office-based surgery'. + given: + - input: ref('office_visits__int_office_visits') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV1', claim_line_number: 1, service_category_2: 'office-based surgery', old_encounter_id: 1} + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV2', claim_line_number: 1, service_category_2: 'office-based visit', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1} + + # ------------------------------------------------------------------------- + # office_visits__int_office_visits_ptotst + # ------------------------------------------------------------------------- + + - name: test_gap_office_visits_ptotst + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visits__int_office_visits_ptotst + description: > + Filters office visits to those with service_category_2 = 'office-based pt/ot/st'. + given: + - input: ref('office_visits__int_office_visits') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV1', claim_line_number: 1, service_category_2: 'office-based pt/ot/st', old_encounter_id: 1} + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV2', claim_line_number: 1, service_category_2: 'office-based visit', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1} + + # ------------------------------------------------------------------------- + # office_visits__int_office_visits_telehealth + # ------------------------------------------------------------------------- + + - name: test_gap_office_visits_telehealth + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visits__int_office_visits_telehealth + description: > + Filters office visits to those with service_category_2 = 'telehealth visit'. + given: + - input: ref('office_visits__int_office_visits') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV1', claim_line_number: 1, service_category_2: 'telehealth visit', old_encounter_id: 1} + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV2', claim_line_number: 1, service_category_2: 'office-based visit', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1} + + # ------------------------------------------------------------------------- + # office_visits__int_office_visits_injections + # ------------------------------------------------------------------------- + + - name: test_gap_office_visits_injections + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visits__int_office_visits_injections + description: > + Filters office visits to those with HCPCS codes starting with 'J' (injections). + given: + - input: ref('office_visits__int_office_visits') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV1', claim_line_number: 1, service_category_2: 'office-based visit', old_encounter_id: 1} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OV1', claim_line_number: 1, hcpcs_code: 'J1234'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1} + + # ------------------------------------------------------------------------- + # office_visits__int_office_visits_radiology + # ------------------------------------------------------------------------- + + - name: test_gap_office_visits_radiology + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visits__int_office_visits_radiology + description: > + Identifies radiology claims within office visits by joining to the + service_category radiology model, assigning new encounter IDs. + given: + - input: ref('office_visits__int_office_visits') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'RAD1', claim_line_number: 1, service_category_2: 'office-based visit', old_encounter_id: 1} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'RAD1', claim_line_number: 1, hcpcs_code: '71046'} + - input: ref('service_category__office_based_radiology') + rows: + - {claim_id: 'RAD1', claim_line_number: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-15', claim_id: 'RAD1', claim_line_number: 1, hcpcs_code: '71046'} + + # ------------------------------------------------------------------------- + # office_visits__int_office_visits_union + # ------------------------------------------------------------------------- + + - name: test_gap_office_visits_union + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visits__int_office_visits_union + description: > + Unions all office visit subtypes (radiology, surgery, injections, pt/ot/st, + E/M, telehealth, other) with assigned encounter_type and priority_number. + given: + - input: ref('office_visits__int_office_visits_radiology') + rows: [] + - input: ref('office_visits__int_office_visits_surgery') + rows: [] + - input: ref('office_visits__int_office_visits_injections') + rows: [] + - input: ref('office_visits__int_office_visits_ptotst') + rows: [] + - input: ref('office_visits__int_office_visits_em') + rows: + - {claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1} + - input: ref('office_visits__int_office_visits_telehealth') + rows: [] + - input: ref('office_visits__int_office_visits') + rows: + - {claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1} + expect: + rows: + - {claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1, encounter_type: 'office visit', priority_number: 4} + - {claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1, encounter_type: 'office visit - other', priority_number: 9999} + + # ------------------------------------------------------------------------- + # office_visits__int_office_visits_encounter_ranking + # ------------------------------------------------------------------------- + + - name: test_gap_office_visits_encounter_ranking + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visits__int_office_visits_encounter_ranking + description: > + Ranks encounter types within each old_encounter_id by priority_number, + so the highest priority type (lowest number) gets relative_rank = 1. + given: + - input: ref('office_visits__int_office_visits_union') + rows: + - {claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1, encounter_type: 'office visit', priority_number: 4} + - {claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1, encounter_type: 'office visit - other', priority_number: 9999} + expect: + rows: + - {old_encounter_id: 1, encounter_type: 'office visit', priority_number: 4, relative_rank: 1} + - {old_encounter_id: 1, encounter_type: 'office visit - other', priority_number: 9999, relative_rank: 2} + + # ------------------------------------------------------------------------- + # office_visits__int_office_visits_claim_line + # ------------------------------------------------------------------------- + + - name: test_gap_office_visits_claim_line + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visits__int_office_visits_claim_line + description: > + Assigns the winning encounter_type (relative_rank=1) to each claim line + in the office visits union. + given: + - input: ref('office_visits__int_office_visits_union') + rows: + - {claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1, encounter_type: 'office visit', priority_number: 4} + - {claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1, encounter_type: 'office visit - other', priority_number: 9999} + - input: ref('office_visits__int_office_visits_encounter_ranking') + rows: + - {old_encounter_id: 1, encounter_type: 'office visit', relative_rank: 1} + - {old_encounter_id: 1, encounter_type: 'office visit - other', relative_rank: 2} + expect: + rows: + - {claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1, encounter_type: 'office visit'} + - {claim_id: 'OV1', claim_line_number: 1, old_encounter_id: 1, encounter_type: 'office visit'} + + # ========================================================================= + # FINAL MODELS - Encounter Grain + # ========================================================================= + + # ------------------------------------------------------------------------- + # acute_inpatient__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_acute_inpatient_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: acute_inpatient__encounter_grain + description: > + Produces one row per acute inpatient encounter with demographics, + diagnosis, cost totals, and service category flags. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', patient_data_source_id: 1, start_date: '2023-01-01', end_date: '2023-01-05', diagnosis_code_1: 'J18.9', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '193', admit_source_code: '1', admit_type_code: '1', discharge_disposition_code: '01', paid_amount: 5000.00, allowed_amount: 4500.00, charge_amount: 8000.00, service_category_3: 'medical', data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'C1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'acute inpatient', encounter_group: 'inpatient', claim_line_attribution_number: 1} + - input: ref('acute_inpatient__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-05'} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1960-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'C1', claim_line_number: 1, service_category_2: 'acute inpatient'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__discharge_disposition') + rows: [] + - input: ref('terminology__admit_source') + rows: [] + - input: ref('terminology__admit_type') + rows: [] + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'acute inpatient', encounter_group: 'inpatient', total_paid_amount: 5000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # emergency_department__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_ed_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: emergency_department__encounter_grain + description: > + Produces one row per ED encounter with demographics, costs, and flags. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'ED1', claim_line_number: 1, claim_type: 'institutional', patient_data_source_id: 1, start_date: '2023-01-01', end_date: '2023-01-01', diagnosis_code_1: 'R10.9', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', drg_code_type: null, drg_code: null, admit_source_code: '7', admit_type_code: '1', discharge_disposition_code: '01', paid_amount: 2000.00, allowed_amount: 1800.00, charge_amount: 3500.00, service_category_3: 'emergency department', data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'ED1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'emergency department', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('emergency_department__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-01'} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1960-01-01', gender: 'female', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'ED1', claim_line_number: 1, service_category_2: 'emergency department'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__discharge_disposition') + rows: [] + - input: ref('terminology__admit_source') + rows: [] + - input: ref('terminology__admit_type') + rows: [] + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'emergency department', encounter_group: 'outpatient', total_paid_amount: 2000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # inpatient_hospice__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_hospice_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_hospice__encounter_grain + description: > + Produces one row per inpatient hospice encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'HOS1', claim_line_number: 1, claim_type: 'institutional', patient_data_source_id: 1, start_date: '2023-02-01', end_date: '2023-02-10', diagnosis_code_1: 'C34.90', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', drg_code_type: null, drg_code: null, admit_source_code: '1', admit_type_code: '3', discharge_disposition_code: '40', paid_amount: 8000.00, allowed_amount: 7500.00, charge_amount: 12000.00, service_category_3: 'inpatient hospice', data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'HOS1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'inpatient hospice', encounter_group: 'inpatient', claim_line_attribution_number: 1} + - input: ref('inpatient_hospice__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-02-01', encounter_end_date: '2023-02-10'} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1940-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'HOS1', claim_line_number: 1, service_category_2: 'inpatient hospice'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__discharge_disposition') + rows: [] + - input: ref('terminology__admit_source') + rows: [] + - input: ref('terminology__admit_type') + rows: [] + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'inpatient hospice', encounter_group: 'inpatient', total_paid_amount: 8000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # inpatient_psych__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_psych_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_psych__encounter_grain + description: > + Produces one row per inpatient psych encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PSY1', claim_line_number: 1, claim_type: 'institutional', patient_data_source_id: 1, start_date: '2023-03-01', end_date: '2023-03-14', diagnosis_code_1: 'F32.1', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '885', admit_source_code: '1', admit_type_code: '1', discharge_disposition_code: '01', paid_amount: 9000.00, allowed_amount: 8500.00, charge_amount: 15000.00, service_category_3: 'inpatient psych', data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'PSY1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'inpatient psych', encounter_group: 'inpatient', claim_line_attribution_number: 1} + - input: ref('inpatient_psych__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-03-01', encounter_end_date: '2023-03-14'} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1980-01-01', gender: 'female', race: 'black', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'PSY1', claim_line_number: 1, service_category_2: 'inpatient psych'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__discharge_disposition') + rows: [] + - input: ref('terminology__admit_source') + rows: [] + - input: ref('terminology__admit_type') + rows: [] + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'inpatient psych', encounter_group: 'inpatient', total_paid_amount: 9000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # inpatient_rehab__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_rehab_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_rehab__encounter_grain + description: > + Produces one row per inpatient rehab encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'REH1', claim_line_number: 1, claim_type: 'institutional', patient_data_source_id: 1, start_date: '2023-04-01', end_date: '2023-04-20', diagnosis_code_1: 'I63.9', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '945', admit_source_code: '1', admit_type_code: '1', discharge_disposition_code: '01', paid_amount: 12000.00, allowed_amount: 11000.00, charge_amount: 18000.00, service_category_3: 'inpatient rehab', data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'REH1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'inpatient rehabilitation', encounter_group: 'inpatient', claim_line_attribution_number: 1} + - input: ref('inpatient_rehab__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-04-01', encounter_end_date: '2023-04-20'} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1955-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'REH1', claim_line_number: 1, service_category_2: 'inpatient rehabilitation'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__discharge_disposition') + rows: [] + - input: ref('terminology__admit_source') + rows: [] + - input: ref('terminology__admit_type') + rows: [] + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'inpatient rehabilitation', encounter_group: 'inpatient', total_paid_amount: 12000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # inpatient_long_term__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_long_term_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_long_term__encounter_grain + description: > + Produces one row per inpatient long term acute care encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'LT1', claim_line_number: 1, claim_type: 'institutional', patient_data_source_id: 1, start_date: '2023-05-01', end_date: '2023-05-30', diagnosis_code_1: 'J96.10', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '207', admit_source_code: '4', admit_type_code: '1', discharge_disposition_code: '01', paid_amount: 25000.00, allowed_amount: 24000.00, charge_amount: 40000.00, service_category_3: 'inpatient long term', data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'LT1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'inpatient long term acute care', encounter_group: 'inpatient', claim_line_attribution_number: 1} + - input: ref('inpatient_long_term__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-05-01', encounter_end_date: '2023-05-30'} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1950-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'LT1', claim_line_number: 1, service_category_2: 'inpatient long term'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__discharge_disposition') + rows: [] + - input: ref('terminology__admit_source') + rows: [] + - input: ref('terminology__admit_type') + rows: [] + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'inpatient long term acute care', encounter_group: 'inpatient', total_paid_amount: 25000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # inpatient_snf__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_snf_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_snf__encounter_grain + description: > + Produces one row per inpatient skilled nursing facility encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'SNF1', claim_line_number: 1, claim_type: 'institutional', patient_data_source_id: 1, start_date: '2023-06-01', end_date: '2023-06-21', diagnosis_code_1: 'S72.001A', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '536', admit_source_code: '4', admit_type_code: '3', discharge_disposition_code: '01', paid_amount: 15000.00, allowed_amount: 14000.00, charge_amount: 22000.00, service_category_3: 'inpatient snf', data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'SNF1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'inpatient skilled nursing', encounter_group: 'inpatient', claim_line_attribution_number: 1} + - input: ref('inpatient_snf__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-21'} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1945-01-01', gender: 'female', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'SNF1', claim_line_number: 1, service_category_2: 'inpatient snf'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__discharge_disposition') + rows: [] + - input: ref('terminology__admit_source') + rows: [] + - input: ref('terminology__admit_type') + rows: [] + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'inpatient skilled nursing', encounter_group: 'inpatient', total_paid_amount: 15000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # inpatient_substance_use__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_inpatient_substance_use_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_substance_use__encounter_grain + description: > + Produces one row per inpatient substance use encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'SU1', claim_line_number: 1, claim_type: 'institutional', patient_data_source_id: 1, start_date: '2023-07-01', end_date: '2023-07-14', diagnosis_code_1: 'F10.239', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '896', admit_source_code: '1', admit_type_code: '1', discharge_disposition_code: '01', paid_amount: 7000.00, allowed_amount: 6500.00, charge_amount: 11000.00, service_category_3: 'inpatient substance use', data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'SU1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'inpatient substance use', encounter_group: 'inpatient', claim_line_attribution_number: 1} + - input: ref('inpatient_substance_use__start_end_dates') + rows: + - {encounter_id: 1, encounter_start_date: '2023-07-01', encounter_end_date: '2023-07-14'} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1985-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'SU1', claim_line_number: 1, service_category_2: 'inpatient substance use'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__discharge_disposition') + rows: [] + - input: ref('terminology__admit_source') + rows: [] + - input: ref('terminology__admit_type') + rows: [] + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'inpatient substance use', encounter_group: 'inpatient', total_paid_amount: 7000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # ambulance__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_ambulance_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ambulance__encounter_grain + description: > + Produces one row per orphaned ambulance encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ambulance__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-01-01'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'AMB1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-01-01', end_date: '2023-01-01', diagnosis_code_1: 'R06.9', diagnosis_code_type: 'icd-10-cm', facility_npi: null, place_of_service_code: '41', place_of_service_description: 'Ambulance - Land', paid_amount: 800.00, allowed_amount: 700.00, charge_amount: 1200.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'AMB1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'ambulance - orphaned', encounter_group: 'other', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1970-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'AMB1', claim_line_number: 1, service_category_2: 'ambulance'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'ambulance - orphaned', encounter_group: 'other', total_paid_amount: 800.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # asc__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_asc_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: asc__encounter_grain + description: > + Produces one row per ambulatory surgery center encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('asc__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-01-10'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'ASC1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-01-10', end_date: '2023-01-10', diagnosis_code_1: 'M17.11', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', place_of_service_code: '24', place_of_service_description: 'ASC', paid_amount: 3000.00, allowed_amount: 2800.00, charge_amount: 5000.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'ASC1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'ambulatory surgery center', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1965-01-01', gender: 'female', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'ASC1', claim_line_number: 1, service_category_2: 'ambulatory surgery center'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + - input: ref('asc__start_end_dates') + rows: + - {patient_data_source_id: 1, old_encounter_id: 1, encounter_start_date: '2023-01-10', encounter_end_date: '2023-01-10'} + expect: + rows: + - {encounter_id: 1, encounter_type: 'ambulatory surgery center', encounter_group: 'outpatient', total_paid_amount: 3000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # dialysis__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_dialysis_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: dialysis__encounter_grain + description: > + Produces one row per dialysis encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('dialysis__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-01-05'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'DIA1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-01-05', end_date: '2023-01-05', diagnosis_code_1: 'N18.6', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', paid_amount: 500.00, allowed_amount: 450.00, charge_amount: 800.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'DIA1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'dialysis', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1960-01-01', gender: 'male', race: 'black', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'DIA1', claim_line_number: 1, service_category_2: 'dialysis'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'dialysis', encounter_group: 'outpatient', total_paid_amount: 500.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # dme__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_dme_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: dme__encounter_grain + description: > + Produces one row per orphaned DME encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('dme__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-01-20'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'DME1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-01-20', end_date: '2023-01-20', diagnosis_code_1: 'J44.1', diagnosis_code_type: 'icd-10-cm', facility_npi: null, place_of_service_code: '12', place_of_service_description: 'Home', paid_amount: 200.00, allowed_amount: 180.00, charge_amount: 350.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'DME1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'dme - orphaned', encounter_group: 'other', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1955-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'DME1', claim_line_number: 1, service_category_2: 'durable medical equipment'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'dme - orphaned', encounter_group: 'other', total_paid_amount: 200.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # home_health__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_home_health_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: home_health__encounter_grain + description: > + Produces one row per home health encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('home_health__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-02-15'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'HH1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-02-15', end_date: '2023-02-15', diagnosis_code_1: 'I50.9', diagnosis_code_type: 'icd-10-cm', facility_npi: null, paid_amount: 300.00, allowed_amount: 280.00, charge_amount: 450.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'HH1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'home health', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1950-01-01', gender: 'female', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'HH1', claim_line_number: 1, service_category_2: 'home health'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'home health', encounter_group: 'outpatient', total_paid_amount: 300.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # lab__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_lab_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: lab__encounter_grain + description: > + Produces one row per orphaned lab encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('lab__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-03-10'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'LAB1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-03-10', end_date: '2023-03-10', diagnosis_code_1: 'R73.09', diagnosis_code_type: 'icd-10-cm', facility_npi: null, place_of_service_code: '81', place_of_service_description: 'Independent Lab', paid_amount: 50.00, allowed_amount: 45.00, charge_amount: 80.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'LAB1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'lab - orphaned', encounter_group: 'other', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1975-01-01', gender: 'female', race: 'asian', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'LAB1', claim_line_number: 1, service_category_2: 'lab'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'lab - orphaned', encounter_group: 'other', total_paid_amount: 50.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # outpatient_hospice__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_outpatient_hospice_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_hospice__encounter_grain + description: > + Produces one row per outpatient hospice encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('outpatient_hospice__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-04-01'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OHOS1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-04-01', end_date: '2023-04-01', diagnosis_code_1: 'C25.9', diagnosis_code_type: 'icd-10-cm', facility_npi: null, paid_amount: 400.00, allowed_amount: 380.00, charge_amount: 600.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'OHOS1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'outpatient hospice', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1940-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'OHOS1', claim_line_number: 1, service_category_2: 'outpatient hospice'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'outpatient hospice', encounter_group: 'outpatient', total_paid_amount: 400.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # outpatient_hospital_or_clinic__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_outpatient_hospital_or_clinic_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_hospital_or_clinic__encounter_grain + description: > + Produces one row per outpatient hospital or clinic encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('outpatient_hospital_or_clinic__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-04-15'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OHC1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-04-15', end_date: '2023-04-15', diagnosis_code_1: 'M54.5', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', place_of_service_code: '22', place_of_service_description: 'Outpatient Hospital', paid_amount: 250.00, allowed_amount: 230.00, charge_amount: 400.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'OHC1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'outpatient hospital or clinic', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1970-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'OHC1', claim_line_number: 1, service_category_2: 'outpatient hospital or clinic'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'outpatient hospital or clinic', encounter_group: 'outpatient', total_paid_amount: 250.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # outpatient_psych__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_outpatient_psych_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_psych__encounter_grain + description: > + Produces one row per outpatient psych encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('outpatient_psych__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-05-01'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OPS1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-05-01', end_date: '2023-05-01', diagnosis_code_1: 'F41.1', diagnosis_code_type: 'icd-10-cm', facility_npi: null, place_of_service_code: '53', place_of_service_description: 'Community MH Center', paid_amount: 150.00, allowed_amount: 140.00, charge_amount: 250.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'OPS1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'outpatient psych', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1990-01-01', gender: 'female', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'OPS1', claim_line_number: 1, service_category_2: 'outpatient psych'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'outpatient psych', encounter_group: 'outpatient', total_paid_amount: 150.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # outpatient_rehab__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_outpatient_rehab_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_rehab__encounter_grain + description: > + Produces one row per outpatient rehab encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('outpatient_rehab__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-05-15'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OR1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-05-15', end_date: '2023-05-15', diagnosis_code_1: 'M79.3', diagnosis_code_type: 'icd-10-cm', facility_npi: null, place_of_service_code: '62', place_of_service_description: 'CORF', paid_amount: 120.00, allowed_amount: 110.00, charge_amount: 200.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'OR1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'outpatient rehabilitation', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1980-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'OR1', claim_line_number: 1, service_category_2: 'outpatient rehabilitation'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'outpatient rehabilitation', encounter_group: 'outpatient', total_paid_amount: 120.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # outpatient_surgery__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_outpatient_surgery_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_surgery__encounter_grain + description: > + Produces one row per outpatient surgery encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('outpatient_surgery__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-06-01'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OSURG1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-06-01', end_date: '2023-06-01', diagnosis_code_1: 'H25.10', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', place_of_service_code: '22', place_of_service_description: 'Outpatient Hospital', paid_amount: 2500.00, allowed_amount: 2300.00, charge_amount: 4000.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'OSURG1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'outpatient surgery', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1958-01-01', gender: 'female', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'OSURG1', claim_line_number: 1, service_category_2: 'outpatient surgery'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'outpatient surgery', encounter_group: 'outpatient', total_paid_amount: 2500.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # outpatient_injections__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_outpatient_injections_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_injections__encounter_grain + description: > + Produces one row per outpatient injections encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('outpatient_injections__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-06-15'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'INJ1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-06-15', end_date: '2023-06-15', diagnosis_code_1: 'M25.50', diagnosis_code_type: 'icd-10-cm', facility_npi: null, place_of_service_code: '11', place_of_service_description: 'Office', paid_amount: 350.00, allowed_amount: 320.00, charge_amount: 550.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'INJ1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'outpatient injections', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1970-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'INJ1', claim_line_number: 1, service_category_2: 'outpatient injections'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'outpatient injections', encounter_group: 'outpatient', total_paid_amount: 350.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # outpatient_ptotst__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_outpatient_ptotst_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_ptotst__encounter_grain + description: > + Produces one row per outpatient PT/OT/ST encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('outpatient_ptotst__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-07-01'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PT1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-07-01', end_date: '2023-07-01', diagnosis_code_1: 'M54.5', diagnosis_code_type: 'icd-10-cm', facility_npi: null, place_of_service_code: '11', place_of_service_description: 'Office', paid_amount: 100.00, allowed_amount: 90.00, charge_amount: 160.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'PT1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'outpatient pt/ot/st', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1985-01-01', gender: 'female', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'PT1', claim_line_number: 1, service_category_2: 'outpatient pt/ot/st'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'outpatient pt/ot/st', encounter_group: 'outpatient', total_paid_amount: 100.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # outpatient_radiology__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_outpatient_radiology_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_radiology__encounter_grain + description: > + Produces one row per outpatient radiology encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('outpatient_radiology__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-07-15'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'RAD1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-07-15', end_date: '2023-07-15', diagnosis_code_1: 'R10.9', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', place_of_service_code: '22', place_of_service_description: 'Outpatient Hospital', paid_amount: 600.00, allowed_amount: 550.00, charge_amount: 900.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'RAD1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'outpatient radiology', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1975-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'RAD1', claim_line_number: 1, service_category_2: 'outpatient radiology'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'outpatient radiology', encounter_group: 'outpatient', total_paid_amount: 600.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # outpatient_substance_use__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_outpatient_substance_use_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_substance_use__encounter_grain + description: > + Produces one row per outpatient substance use encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('outpatient_substance_use__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-08-01'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OSU1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-08-01', end_date: '2023-08-01', diagnosis_code_1: 'F10.10', diagnosis_code_type: 'icd-10-cm', facility_npi: null, place_of_service_code: '57', place_of_service_description: 'Non-res SU Facility', paid_amount: 200.00, allowed_amount: 180.00, charge_amount: 320.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'OSU1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'outpatient substance use', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1990-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'OSU1', claim_line_number: 1, service_category_2: 'outpatient substance use'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'outpatient substance use', encounter_group: 'outpatient', total_paid_amount: 200.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # urgent_care__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_urgent_care_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: urgent_care__encounter_grain + description: > + Produces one row per urgent care encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('urgent_care__generate_encounter_id') + rows: + - {old_encounter_id: 1, start_date: '2023-08-15'} + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'UC1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-08-15', end_date: '2023-08-15', diagnosis_code_1: 'J06.9', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', place_of_service_code: '20', place_of_service_description: 'Urgent Care', paid_amount: 180.00, allowed_amount: 160.00, charge_amount: 280.00, data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'UC1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'urgent care', encounter_group: 'outpatient', claim_line_attribution_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1995-01-01', gender: 'female', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'UC1', claim_line_number: 1, service_category_2: 'urgent care'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'urgent care', encounter_group: 'outpatient', total_paid_amount: 180.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # office_visit__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_office_visit_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visit__encounter_grain + description: > + Produces one row per office visit encounter, using the detail_values + intermediate model. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('office_visits__int_detail_values') + rows: + - {claim_id: 'OV1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, encounter_id: 1, encounter_start_date: '2023-01-15', encounter_type: 'office visit', encounter_group: 'office based', diagnosis_code_1: 'J06.9', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', billing_npi: 'NPI2', hcpcs_code: '99213', ccs_category: '126', ccs_category_description: 'Other upper respiratory infections', paid_amount: 150.00, allowed_amount: 130.00, charge_amount: 250.00, data_source: 'src1', encounter_row_number: 1} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1985-01-01', gender: 'female', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'OV1', claim_line_number: 1, service_category_2: 'office-based visit'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'office visit', encounter_group: 'office based', total_paid_amount: 150.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # orphaned_claim__encounter_grain + # ------------------------------------------------------------------------- + + - name: test_gap_orphaned_claim_encounter_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: orphaned_claim__encounter_grain + description: > + Produces one row per orphaned claim encounter. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'ORPH1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-09-01', end_date: '2023-09-01', diagnosis_code_1: 'Z00.00', diagnosis_code_type: 'icd-10-cm', facility_npi: null, place_of_service_code: '99', place_of_service_description: 'Other', paid_amount: 75.00, allowed_amount: 70.00, charge_amount: 120.00, data_source: 'src1'} + - input: ref('encounters__orphaned_claims') + rows: + - {claim_id: 'ORPH1', claim_line_number: 1, encounter_id: 1, encounter_type: 'orphaned claim', encounter_group: 'other'} + - input: ref('encounters__stg_eligibility') + rows: + - {patient_data_source_id: 1, birth_date: '1980-01-01', gender: 'male', race: 'white', patient_row_num: 1} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'ORPH1', claim_line_number: 1, service_category_2: 'other'} + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + expect: + rows: + - {encounter_id: 1, encounter_type: 'orphaned claim', encounter_group: 'other', total_paid_amount: 75.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS - Office Visits Detail Values + # ========================================================================= + + # ------------------------------------------------------------------------- + # office_visits__int_detail_values + # ------------------------------------------------------------------------- + + - name: test_gap_office_visits_int_detail_values + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: office_visits__int_detail_values + description: > + Joins office-based claims from stg_medical_claim to the combined + crosswalk and encounter dates, producing detail values for final + office visit encounter grain. + given: + - input: ref('office_visits__int_office_visits_surgery') + rows: [] + - input: ref('office_visits__int_office_visits_injections') + rows: [] + - input: ref('office_visits__int_office_visits_radiology') + rows: [] + - input: ref('office_visits__int_office_visits') + rows: + - {old_encounter_id: 1, start_date: '2023-01-15'} + - input: ref('office_visits__int_office_visits_em') + rows: [] + - input: ref('office_visits__int_office_visits_telehealth') + rows: [] + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OV1', claim_line_number: 1, claim_type: 'professional', patient_data_source_id: 1, start_date: '2023-01-15', end_date: '2023-01-15', paid_amount: 150.00, allowed_amount: 130.00, charge_amount: 250.00, diagnosis_code_1: 'J06.9', diagnosis_code_type: 'icd-10-cm', facility_npi: 'NPI1', billing_npi: 'NPI2', hcpcs_code: '99213', ccs_category: '126', ccs_category_description: 'URI', data_source: 'src1'} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'OV1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'office visit - other', encounter_group: 'office based', claim_line_attribution_number: 1} + expect: + rows: + - {claim_id: 'OV1', claim_line_number: 1, encounter_id: 1, encounter_type: 'office visit - other', encounter_group: 'office based', paid_amount: 150.00} diff --git a/models/claims_preprocessing/encounters/encounter_unit_tests.yml b/models/claims_preprocessing/encounters/encounter_unit_tests.yml new file mode 100644 index 000000000..1a3741158 --- /dev/null +++ b/models/claims_preprocessing/encounters/encounter_unit_tests.yml @@ -0,0 +1,1189 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGING MODELS + # ========================================================================= + + # ------------------------------------------------------------------------- + # encounters__patient_data_source_id + # ------------------------------------------------------------------------- + + - name: test_patient_data_source_id_assigns_ids + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__patient_data_source_id + description: > + Assigns a dense_rank patient_data_source_id per unique + person_id + data_source combination from medical claims and eligibility. + given: + - input: ref('normalized_input__medical_claim') + rows: + - {person_id: 'P1', data_source: 'src1'} + - {person_id: 'P2', data_source: 'src1'} + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', data_source: 'src1'} + - {person_id: 'P3', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', data_source: 'src1'} + - {person_id: 'P2', data_source: 'src1'} + - {person_id: 'P3', data_source: 'src1'} + + # ------------------------------------------------------------------------- + # encounters__stg_eligibility + # ------------------------------------------------------------------------- + + - name: test_stg_eligibility_row_numbering + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__stg_eligibility + description: > + Patient eligibility rows are numbered by enrollment_start_date desc, + so the most recent enrollment gets patient_row_num = 1. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', birth_date: '1960-01-01', gender: 'male', race: 'white', enrollment_start_date: '2022-01-01', data_source: 'src1'} + - {person_id: 'P1', birth_date: '1960-01-01', gender: 'male', race: 'white', enrollment_start_date: '2023-06-01', data_source: 'src1'} + - input: ref('encounters__patient_data_source_id') + rows: + - {person_id: 'P1', data_source: 'src1', patient_data_source_id: 1} + expect: + rows: + - {person_id: 'P1', birth_date: '1960-01-01', gender: 'male', race: 'white', patient_data_source_id: 1, patient_row_num: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', birth_date: '1960-01-01', gender: 'male', race: 'white', patient_data_source_id: 1, patient_row_num: 2, tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # encounters__stg_inpatient_institutional + # ------------------------------------------------------------------------- + + - name: test_stg_inpatient_institutional_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__stg_inpatient_institutional + description: > + Passes through claim_id and service_type from the upstream + stg_inpatient_institutional model. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_inpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # encounters__stg_outpatient_institutional + # ------------------------------------------------------------------------- + + - name: test_stg_outpatient_institutional_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__stg_outpatient_institutional + description: > + Passes through claim_id and service_type from the upstream + stg_outpatient_institutional model. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # encounters__stg_professional + # ------------------------------------------------------------------------- + + - name: test_stg_professional_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__stg_professional + description: > + Passes through claim_id, claim_line_number, claim_line_id, service_type, + and data_source from the upstream stg_professional model. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', service_type: 'professional', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # encounters__prof_and_lower_priority + # ------------------------------------------------------------------------- + + - name: test_prof_and_lower_priority_unions_sources + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__prof_and_lower_priority + description: > + Unions professional claims with lower-priority institutional claims + (lab, dme, ambulance) from the service_category grouper. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_professional') + rows: + - {claim_id: 'PROF1', claim_line_number: 1, data_source: 'src1'} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'INST1', claim_line_number: 1, data_source: 'src1', duplicate_row_number: 1, service_category_2: 'lab'} + - {claim_id: 'INST2', claim_line_number: 1, data_source: 'src1', duplicate_row_number: 1, service_category_2: 'durable medical equipment'} + - {claim_id: 'INST3', claim_line_number: 1, data_source: 'src1', duplicate_row_number: 1, service_category_2: 'ambulance'} + - {claim_id: 'INST4', claim_line_number: 1, data_source: 'src1', duplicate_row_number: 1, service_category_2: 'acute inpatient'} + - {claim_id: 'INST5', claim_line_number: 1, data_source: 'src1', duplicate_row_number: 2, service_category_2: 'lab'} + expect: + rows: + - {claim_id: 'PROF1', claim_line_number: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'INST1', claim_line_number: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'INST2', claim_line_number: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'INST3', claim_line_number: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS - Acute Inpatient + # ========================================================================= + + # ------------------------------------------------------------------------- + # acute_inpatient__start_end_dates + # ------------------------------------------------------------------------- + + - name: test_acute_inpatient_start_end_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: acute_inpatient__start_end_dates + description: > + Computes encounter start (min) and end (max) dates from the + generate_encounter_id model. + given: + - input: ref('acute_inpatient__generate_encounter_id') + rows: + - {encounter_id: 1, start_date: '2023-01-01', end_date: '2023-01-05'} + - {encounter_id: 1, start_date: '2023-01-02', end_date: '2023-01-07'} + - {encounter_id: 2, start_date: '2023-02-01', end_date: '2023-02-03'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-07'} + - {encounter_id: 2, encounter_start_date: '2023-02-01', encounter_end_date: '2023-02-03'} + + # ========================================================================= + # INTERMEDIATE MODELS - Ambulance (anchor/generate/match pattern) + # ========================================================================= + + # ------------------------------------------------------------------------- + # ambulance__anchor_events + # ------------------------------------------------------------------------- + + - name: test_ambulance_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ambulance__anchor_events + description: > + Identifies distinct claim_ids that have service_category_2 = 'ambulance'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'AMB1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'ambulance'} + - {claim_id: 'AMB1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'ambulance'} + - {claim_id: 'NON1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'lab'} + expect: + rows: + - {claim_id: 'AMB1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # ambulance__generate_encounter_id + # ------------------------------------------------------------------------- + + - name: test_ambulance_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ambulance__generate_encounter_id + description: > + Generates old_encounter_id using dense_rank over + patient_data_source_id and start_date. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'AMB1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'ambulance'} + - {claim_id: 'AMB2', patient_data_source_id: 1, start_date: '2023-02-15', service_category_2: 'ambulance'} + - input: ref('ambulance__anchor_events') + rows: + - {claim_id: 'AMB1'} + - {claim_id: 'AMB2'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'AMB1', old_encounter_id: 1} + - {patient_data_source_id: 1, start_date: '2023-02-15', claim_id: 'AMB2', old_encounter_id: 2} + + # ------------------------------------------------------------------------- + # ambulance__match_claims_to_anchor + # ------------------------------------------------------------------------- + + - name: test_ambulance_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ambulance__match_claims_to_anchor + description: > + Matches medical claim lines to ambulance anchor encounters by + patient_data_source_id, start_date, and service_category_2. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'AMB1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'ambulance'} + - {claim_id: 'AMB1', claim_line_number: 2, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'ambulance'} + - input: ref('ambulance__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'AMB1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'AMB1', claim_line_number: 1, old_encounter_id: 1} + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'AMB1', claim_line_number: 2, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Lab (anchor/generate/match pattern) + # ========================================================================= + + - name: test_lab_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: lab__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'lab'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'LAB1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'lab'} + - {claim_id: 'NON1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'office-based visit'} + expect: + rows: + - {claim_id: 'LAB1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_lab_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: lab__generate_encounter_id + description: > + Generates old_encounter_id for lab claims using dense_rank over + patient_data_source_id and start_date. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'LAB1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'lab'} + - input: ref('lab__anchor_events') + rows: + - {claim_id: 'LAB1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'LAB1', old_encounter_id: 1} + + - name: test_lab_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: lab__match_claims_to_anchor + description: > + Matches lab claim lines to lab anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'LAB1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'lab'} + - input: ref('lab__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'LAB1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'LAB1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - DME (anchor/generate/match pattern) + # ========================================================================= + + - name: test_dme_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: dme__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'durable medical equipment'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'DME1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'durable medical equipment'} + expect: + rows: + - {claim_id: 'DME1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_dme_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: dme__generate_encounter_id + description: > + Generates old_encounter_id for DME claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'DME1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'durable medical equipment'} + - input: ref('dme__anchor_events') + rows: + - {claim_id: 'DME1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'DME1', old_encounter_id: 1} + + - name: test_dme_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: dme__match_claims_to_anchor + description: > + Matches DME claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'DME1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'durable medical equipment'} + - input: ref('dme__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'DME1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'DME1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Dialysis (anchor/generate/match pattern) + # ========================================================================= + + - name: test_dialysis_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: dialysis__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'dialysis'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'DIA1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'dialysis'} + expect: + rows: + - {claim_id: 'DIA1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_dialysis_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: dialysis__generate_encounter_id + description: > + Generates old_encounter_id for dialysis claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'DIA1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'dialysis'} + - input: ref('dialysis__anchor_events') + rows: + - {claim_id: 'DIA1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'DIA1', old_encounter_id: 1} + + - name: test_dialysis_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: dialysis__match_claims_to_anchor + description: > + Matches dialysis claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'DIA1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'dialysis'} + - input: ref('dialysis__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'DIA1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'DIA1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - ASC (anchor/generate/match pattern) + # ========================================================================= + + - name: test_asc_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: asc__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'ambulatory surgery center'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'ASC1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'ambulatory surgery center'} + expect: + rows: + - {claim_id: 'ASC1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_asc_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: asc__generate_encounter_id + description: > + Generates old_encounter_id for ASC claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'ASC1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'ambulatory surgery center'} + - input: ref('asc__anchor_events') + rows: + - {claim_id: 'ASC1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'ASC1', old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Home Health (anchor/generate/match pattern) + # ========================================================================= + + - name: test_home_health_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: home_health__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'home health'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'HH1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'home health'} + expect: + rows: + - {claim_id: 'HH1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_home_health_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: home_health__generate_encounter_id + description: > + Generates old_encounter_id for home health claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'HH1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'home health'} + - input: ref('home_health__anchor_events') + rows: + - {claim_id: 'HH1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'HH1', old_encounter_id: 1} + + - name: test_home_health_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: home_health__match_claims_to_anchor + description: > + Matches home health claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'HH1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'home health'} + - input: ref('home_health__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'HH1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'HH1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Outpatient Hospice (anchor/generate/match pattern) + # ========================================================================= + + - name: test_outpatient_hospice_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_hospice__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'outpatient hospice'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OH1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient hospice'} + expect: + rows: + - {claim_id: 'OH1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_outpatient_hospice_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_hospice__generate_encounter_id + description: > + Generates old_encounter_id for outpatient hospice claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OH1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient hospice'} + - input: ref('outpatient_hospice__anchor_events') + rows: + - {claim_id: 'OH1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OH1', old_encounter_id: 1} + + - name: test_outpatient_hospice_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_hospice__match_claims_to_anchor + description: > + Matches outpatient hospice claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OH1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient hospice'} + - input: ref('outpatient_hospice__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OH1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OH1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Outpatient Hospital or Clinic + # ========================================================================= + + - name: test_outpatient_hospital_or_clinic_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_hospital_or_clinic__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'outpatient hospital or clinic'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OHC1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient hospital or clinic'} + expect: + rows: + - {claim_id: 'OHC1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_outpatient_hospital_or_clinic_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_hospital_or_clinic__generate_encounter_id + description: > + Generates old_encounter_id for outpatient hospital or clinic claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OHC1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient hospital or clinic'} + - input: ref('outpatient_hospital_or_clinic__anchor_events') + rows: + - {claim_id: 'OHC1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OHC1', old_encounter_id: 1} + + - name: test_outpatient_hospital_or_clinic_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_hospital_or_clinic__match_claims_to_anchor + description: > + Matches outpatient hospital or clinic claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OHC1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient hospital or clinic'} + - input: ref('outpatient_hospital_or_clinic__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OHC1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OHC1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Urgent Care + # ========================================================================= + + - name: test_urgent_care_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: urgent_care__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'urgent care'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'UC1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'urgent care'} + expect: + rows: + - {claim_id: 'UC1'} + + - name: test_urgent_care_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: urgent_care__generate_encounter_id + description: > + Generates old_encounter_id for urgent care claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'UC1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'urgent care'} + - input: ref('urgent_care__anchor_events') + rows: + - {claim_id: 'UC1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'UC1', old_encounter_id: 1} + + - name: test_urgent_care_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: urgent_care__match_claims_to_anchor + description: > + Matches urgent care claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'UC1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'urgent care'} + - input: ref('urgent_care__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'UC1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'UC1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Outpatient Psych + # ========================================================================= + + - name: test_outpatient_psych_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_psych__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'outpatient psychiatric'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OP1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient psychiatric'} + expect: + rows: + - {claim_id: 'OP1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_outpatient_psych_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_psych__generate_encounter_id + description: > + Generates old_encounter_id for outpatient psych claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OP1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient psychiatric'} + - input: ref('outpatient_psych__anchor_events') + rows: + - {claim_id: 'OP1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OP1', old_encounter_id: 1} + + - name: test_outpatient_psych_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_psych__match_claims_to_anchor + description: > + Matches outpatient psych claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OP1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient psychiatric'} + - input: ref('outpatient_psych__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OP1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OP1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Outpatient Rehab + # ========================================================================= + + - name: test_outpatient_rehab_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_rehab__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'outpatient rehabilitation'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OR1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient rehabilitation'} + expect: + rows: + - {claim_id: 'OR1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_outpatient_rehab_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_rehab__generate_encounter_id + description: > + Generates old_encounter_id for outpatient rehabilitation claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OR1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient rehabilitation'} + - input: ref('outpatient_rehab__anchor_events') + rows: + - {claim_id: 'OR1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OR1', old_encounter_id: 1} + + - name: test_outpatient_rehab_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_rehab__match_claims_to_anchor + description: > + Matches outpatient rehabilitation claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OR1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient rehabilitation'} + - input: ref('outpatient_rehab__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OR1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OR1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Outpatient Surgery + # ========================================================================= + + - name: test_outpatient_surgery_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_surgery__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'outpatient surgery'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OS1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient surgery'} + expect: + rows: + - {claim_id: 'OS1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_outpatient_surgery_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_surgery__generate_encounter_id + description: > + Generates old_encounter_id for outpatient surgery claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OS1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient surgery'} + - input: ref('outpatient_surgery__anchor_events') + rows: + - {claim_id: 'OS1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OS1', old_encounter_id: 1} + + - name: test_outpatient_surgery_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_surgery__match_claims_to_anchor + description: > + Matches outpatient surgery claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'OS1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient surgery'} + - input: ref('outpatient_surgery__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OS1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'OS1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Outpatient Injections + # ========================================================================= + + - name: test_outpatient_injections_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_injections__generate_encounter_id + description: > + Generates old_encounter_id for outpatient injection claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'INJ1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient injections'} + - input: ref('outpatient_injections__anchor_events') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', old_encounter_id: 1} + + - name: test_outpatient_injections_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_injections__match_claims_to_anchor + description: > + Matches outpatient injection claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'INJ1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient injections'} + - input: ref('outpatient_injections__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'INJ1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Outpatient PT/OT/ST + # ========================================================================= + + - name: test_outpatient_ptotst_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_ptotst__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'outpatient pt/ot/st'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PT1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient pt/ot/st'} + expect: + rows: + - {claim_id: 'PT1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_outpatient_ptotst_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_ptotst__generate_encounter_id + description: > + Generates old_encounter_id for PT/OT/ST claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PT1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient pt/ot/st'} + - input: ref('outpatient_ptotst__anchor_events') + rows: + - {claim_id: 'PT1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'PT1', old_encounter_id: 1} + + - name: test_outpatient_ptotst_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_ptotst__match_claims_to_anchor + description: > + Matches PT/OT/ST claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'PT1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient pt/ot/st'} + - input: ref('outpatient_ptotst__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'PT1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'PT1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Outpatient Radiology + # ========================================================================= + + - name: test_outpatient_radiology_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_radiology__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'outpatient radiology'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'RAD1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient radiology'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_outpatient_radiology_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_radiology__generate_encounter_id + description: > + Generates old_encounter_id for outpatient radiology claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'RAD1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient radiology'} + - input: ref('outpatient_radiology__anchor_events') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Outpatient Substance Use + # ========================================================================= + + - name: test_outpatient_substance_use_anchor_events + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_substance_use__anchor_events + description: > + Identifies distinct claim_ids with service_category_2 = 'outpatient substance use'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'SU1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient substance use'} + expect: + rows: [] + + - name: test_outpatient_substance_use_generate_encounter_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_substance_use__generate_encounter_id + description: > + Generates old_encounter_id for outpatient substance use claims. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'SU1', patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient substance use'} + - input: ref('outpatient_substance_use__anchor_events') + rows: + - {claim_id: 'SU1'} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'SU1', old_encounter_id: 1} + + - name: test_outpatient_substance_use_match_claims_to_anchor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: outpatient_substance_use__match_claims_to_anchor + description: > + Matches outpatient substance use claim lines to anchor encounters. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'SU1', claim_line_number: 1, patient_data_source_id: 1, start_date: '2023-01-01', service_category_2: 'outpatient substance use'} + - input: ref('outpatient_substance_use__generate_encounter_id') + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'SU1', old_encounter_id: 1} + expect: + rows: + - {patient_data_source_id: 1, start_date: '2023-01-01', claim_id: 'SU1', claim_line_number: 1, old_encounter_id: 1} + + # ========================================================================= + # INTERMEDIATE MODELS - Inpatient types (start_end_dates pattern) + # ========================================================================= + + # ------------------------------------------------------------------------- + # emergency_department__start_end_dates + # ------------------------------------------------------------------------- + + - name: test_emergency_department_start_end_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: emergency_department__start_end_dates + description: > + Computes encounter start (min) and end (max) dates for ED encounters. + given: + - input: ref('emergency_department__generate_encounter_id') + rows: + - {encounter_id: 1, start_date: '2023-01-01', end_date: '2023-01-01'} + - {encounter_id: 1, start_date: '2023-01-01', end_date: '2023-01-02'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-02'} + + # ------------------------------------------------------------------------- + # inpatient_hospice__start_end_dates + # ------------------------------------------------------------------------- + + - name: test_inpatient_hospice_start_end_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_hospice__start_end_dates + description: > + Computes encounter start/end dates for inpatient hospice encounters. + given: + - input: ref('inpatient_hospice__generate_encounter_id') + rows: + - {encounter_id: 1, start_date: '2023-01-01', end_date: '2023-01-10'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-10'} + + # ------------------------------------------------------------------------- + # inpatient_psych__start_end_dates + # ------------------------------------------------------------------------- + + - name: test_inpatient_psych_start_end_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_psych__start_end_dates + description: > + Computes encounter start/end dates for inpatient psych encounters. + given: + - input: ref('inpatient_psych__generate_encounter_id') + rows: + - {encounter_id: 1, start_date: '2023-01-01', end_date: '2023-01-14'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-14'} + + # ------------------------------------------------------------------------- + # inpatient_rehab__start_end_dates + # ------------------------------------------------------------------------- + + - name: test_inpatient_rehab_start_end_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_rehab__start_end_dates + description: > + Computes encounter start/end dates for inpatient rehab encounters. + given: + - input: ref('inpatient_rehab__generate_encounter_id') + rows: + - {encounter_id: 1, start_date: '2023-01-01', end_date: '2023-01-21'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-21'} + + # ------------------------------------------------------------------------- + # inpatient_long_term__start_end_dates + # ------------------------------------------------------------------------- + + - name: test_inpatient_long_term_start_end_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_long_term__start_end_dates + description: > + Computes encounter start/end dates for inpatient long term encounters. + given: + - input: ref('inpatient_long_term__generate_encounter_id') + rows: + - {encounter_id: 1, start_date: '2023-01-01', end_date: '2023-03-01'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-03-01'} + + # ------------------------------------------------------------------------- + # inpatient_snf__start_end_dates + # ------------------------------------------------------------------------- + + - name: test_inpatient_snf_start_end_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_snf__start_end_dates + description: > + Computes encounter start/end dates for inpatient SNF encounters. + given: + - input: ref('inpatient_snf__generate_encounter_id') + rows: + - {encounter_id: 1, start_date: '2023-01-01', end_date: '2023-01-30'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-30'} + + # ------------------------------------------------------------------------- + # inpatient_substance_use__start_end_dates + # ------------------------------------------------------------------------- + + - name: test_inpatient_substance_use_start_end_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: inpatient_substance_use__start_end_dates + description: > + Computes encounter start/end dates for inpatient substance use encounters. + given: + - input: ref('inpatient_substance_use__generate_encounter_id') + rows: + - {encounter_id: 1, start_date: '2023-01-01', end_date: '2023-01-14'} + expect: + rows: + - {encounter_id: 1, encounter_start_date: '2023-01-01', encounter_end_date: '2023-01-14'} + + # ========================================================================= + # INTERMEDIATE MODELS - encounters__orphaned_claims + # ========================================================================= + + - name: test_orphaned_claims_identifies_unmatched + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: encounters__orphaned_claims + description: > + Claims not found in the combined_claim_line_crosswalk are flagged as + orphaned and assigned a new encounter_id above the max existing id. + given: + - input: ref('encounters__stg_medical_claim') + rows: + - {claim_id: 'ORPH1', claim_line_number: 1, service_category_1: 'other', service_category_2: 'other', service_category_3: 'other', claim_type: 'professional', claim_start_date: '2023-01-01', claim_end_date: '2023-01-01', start_date: '2023-01-01', end_date: '2023-01-01', patient_data_source_id: 1} + - {claim_id: 'MATCHED1', claim_line_number: 1, service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: 'medical', claim_type: 'institutional', claim_start_date: '2023-01-01', claim_end_date: '2023-01-05', start_date: '2023-01-01', end_date: '2023-01-05', patient_data_source_id: 1} + - input: ref('encounters__combined_claim_line_crosswalk') + rows: + - {claim_id: 'MATCHED1', claim_line_number: 1, encounter_id: 1, old_encounter_id: 1, encounter_type: 'acute inpatient', encounter_group: 'inpatient', priority_number: 0, anchor_claim_id: null, claim_line_attribution_number: 1} + expect: + rows: + - {claim_id: 'ORPH1', claim_line_number: 1, encounter_type: 'orphaned claim', encounter_group: 'other'} diff --git a/models/claims_preprocessing/service_category/service_category_gap_unit_tests.yml b/models/claims_preprocessing/service_category/service_category_gap_unit_tests.yml new file mode 100644 index 000000000..b6983acc2 --- /dev/null +++ b/models/claims_preprocessing/service_category/service_category_gap_unit_tests.yml @@ -0,0 +1,266 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGING MODELS + # ========================================================================= + + # ------------------------------------------------------------------------- + # service_category__stg_inpatient_institutional + # ------------------------------------------------------------------------- + + - name: test_gap_sc_stg_inpatient_institutional_bill_type + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__stg_inpatient_institutional + description: > + Institutional claims with inpatient bill type codes (e.g., '11') + are classified as inpatient service_type. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', bill_type_code: '111', drg_code_type: null, drg_code: null, data_source: 'src1'} + - {claim_id: 'C2', claim_line_number: 1, claim_type: 'institutional', bill_type_code: '131', drg_code_type: null, drg_code: null, data_source: 'src1'} + - {claim_id: 'C3', claim_line_number: 1, claim_type: 'professional', bill_type_code: null, drg_code_type: null, drg_code: null, data_source: 'src1'} + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__stg_medical_claim + # ------------------------------------------------------------------------- + + - name: test_gap_sc_stg_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__stg_medical_claim + description: > + Passes through normalized medical claim data enriched with terminology + lookups for CCS, provider, revenue center, place of service, and bill type. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'professional', admission_date: null, discharge_date: null, claim_start_date: '2023-01-01', claim_end_date: '2023-01-01', claim_line_start_date: '2023-01-01', claim_line_end_date: '2023-01-01', bill_type_code: null, hcpcs_code: '99213', drg_code_type: null, drg_code: null, drg_description: null, place_of_service_code: '11', revenue_center_code: null, diagnosis_code_1: 'J06.9', facility_npi: null, rendering_npi: null, data_source: 'src1'} + - input: ref('ccsr__dxccsr_v2023_1_cleaned_map') + rows: [] + - input: ref('terminology__provider') + rows: [] + - input: ref('terminology__nitos') + rows: [] + - input: ref('terminology__revenue_center') + rows: [] + - input: ref('terminology__place_of_service') + rows: [] + - input: ref('terminology__bill_type') + rows: [] + - input: ref('terminology__ccs_services_procedures') + rows: [] + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'professional', hcpcs_code: '99213', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS - Institutional Categories + # ========================================================================= + + # ------------------------------------------------------------------------- + # service_category__acute_inpatient_institutional_maternity + # ------------------------------------------------------------------------- + + - name: test_gap_sc_acute_inpatient_institutional_maternity + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__acute_inpatient_institutional_maternity + description: > + Inpatient claims with maternity-related MS-DRG codes (MDC 14/15) are + classified with specific L&D service_category_3 values. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', drg_code: '768', drg_code_type: 'ms-drg', revenue_center_code: null, data_source: 'src1'} + - input: ref('service_category__stg_inpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__ms_drg') + rows: + - {ms_drg_code: '768', mdc_code: '14', ms_drg_description: 'Vaginal delivery', medical_surgical: 'P'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: 'l/d - vaginal delivery', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__acute_inpatient_institutional_med_surg + # ------------------------------------------------------------------------- + + - name: test_gap_sc_acute_inpatient_institutional_med_surg + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__acute_inpatient_institutional_med_surg + description: > + Inpatient claims with valid DRG codes are classified as medical or + surgical based on the DRG medical_surgical flag. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', drg_code: '193', drg_code_type: 'ms-drg', data_source: 'src1'} + - input: ref('service_category__stg_inpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__ms_drg') + rows: + - {ms_drg_code: '193', mdc_code: '04', ms_drg_description: 'Pneumonia', medical_surgical: 'M'} + - input: ref('terminology__apr_drg') + rows: [] + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: 'medical', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS - Office-Based Categories + # ========================================================================= + + # ------------------------------------------------------------------------- + # service_category__office_based_surgery_professional + # ------------------------------------------------------------------------- + + - name: test_gap_sc_office_based_surgery_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__office_based_surgery_professional + description: > + Office-based professional claims with numeric HCPCS codes between + 10021 and 69999 are classified as office-based surgery. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', hcpcs_code: '11102', data_source: 'src1'} + - input: ref('service_category__stg_office_based') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'office based', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: [] + + # ------------------------------------------------------------------------- + # service_category__office_based_other_professional + # ------------------------------------------------------------------------- + + - name: test_gap_sc_office_based_other_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__office_based_other_professional + description: > + Office-based claims not matched by any specific office-based subcategory + (pharmacy, radiology, visit, surgery, PT) fall into office-based other. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_office_based') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'office based', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('service_category__pharmacy_professional') + rows: [] + - input: ref('service_category__office_based_radiology') + rows: [] + - input: ref('service_category__office_based_visit_professional') + rows: [] + - input: ref('service_category__office_based_surgery_professional') + rows: [] + - input: ref('service_category__office_based_physical_therapy_professional') + rows: [] + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'office-based', service_category_2: 'office-based other', service_category_3: 'office-based other', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS - Combined + # ========================================================================= + + # ========================================================================= + # FINAL MODEL + # ========================================================================= + + # ------------------------------------------------------------------------- + # service_category__service_category_grouper + # ------------------------------------------------------------------------- + + - name: test_gap_sc_service_category_grouper + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__service_category_grouper + description: > + Combines professional, institutional header, and institutional line + service categories, deduplicates by priority, and produces the final + service category assignment per claim line. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'professional', data_source: 'src1'} + - input: ref('service_category__combined_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'emergency department', service_category_3: 'emergency department', source_model_name: 'service_category__emergency_department_professional', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('service_category__combined_institutional_header_level') + rows: [] + - input: ref('service_category__combined_institutional_line_level') + rows: [] + - input: ref('service_category__service_categories') + rows: + - {service_category_1: 'outpatient', service_category_2: 'emergency department', service_category_3: 'emergency department', priority: 2} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_type: 'professional', service_category_1: 'outpatient', service_category_2: 'emergency department', service_category_3: 'emergency department', duplicate_row_number: 1} + + - name: test_gap_sc_service_category_grouper_prioritizes_institutional_line_level + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__service_category_grouper + description: > + Institutional claims can match both header and line-level service + categories; the lower priority_number should receive duplicate_row_number + 1 so downstream encounter models do not fan out. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', data_source: 'src1'} + - input: ref('service_category__combined_professional') + rows: [] + - input: ref('service_category__combined_institutional_header_level') + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: 'acute inpatient - other', source_model_name: 'service_category__acute_inpatient_institutional_other'} + - input: ref('service_category__combined_institutional_line_level') + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', service_category_1: 'ancillary', service_category_2: 'ambulance', service_category_3: 'ambulance', source_model_name: 'service_category__ambulance_institutional'} + - input: ref('service_category__service_categories') + rows: + - {service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: 'acute inpatient - other', priority: 20} + - {service_category_1: 'ancillary', service_category_2: 'ambulance', service_category_3: 'ambulance', priority: 1} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_type: 'institutional', service_category_1: 'ancillary', service_category_2: 'ambulance', service_category_3: 'ambulance', duplicate_row_number: 1, source_model_name: 'service_category__ambulance_institutional'} + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_type: 'institutional', service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: 'acute inpatient - other', duplicate_row_number: 2, source_model_name: 'service_category__acute_inpatient_institutional_other'} diff --git a/models/claims_preprocessing/service_category/service_category_unit_tests.yml b/models/claims_preprocessing/service_category/service_category_unit_tests.yml new file mode 100644 index 000000000..aea1de783 --- /dev/null +++ b/models/claims_preprocessing/service_category/service_category_unit_tests.yml @@ -0,0 +1,1401 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGING MODELS + # ========================================================================= + + # ------------------------------------------------------------------------- + # service_category__stg_professional + # ------------------------------------------------------------------------- + + - name: test_sc_stg_professional_filters_professional_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__stg_professional + description: > + Only claims with claim_type = 'professional' pass through. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', data_source: 'src1'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', claim_type: 'institutional', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', service_type: 'professional', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__stg_outpatient_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_stg_outpatient_institutional_excludes_inpatient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__stg_outpatient_institutional + description: > + Institutional claims not classified as inpatient are outpatient. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', data_source: 'src1'} + - {claim_id: 'C2', claim_type: 'institutional', data_source: 'src1'} + - {claim_id: 'C3', claim_type: 'professional', data_source: 'src1'} + - input: ref('service_category__stg_inpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C2', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__stg_office_based + # ------------------------------------------------------------------------- + + - name: test_sc_stg_office_based_filters_by_pos + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__stg_office_based + description: > + Professional claims with place_of_service_code 11, 02, or 10 are + classified as office-based. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '11', data_source: 'src1'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', claim_type: 'professional', place_of_service_code: '02', data_source: 'src1'} + - {claim_id: 'C3', claim_line_number: 1, claim_line_id: 'C3|1', claim_type: 'professional', place_of_service_code: '23', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C3', claim_line_number: 1, claim_line_id: 'C3|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', service_type: 'office based', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', service_type: 'office based', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS - Professional claim type + # ========================================================================= + + # ------------------------------------------------------------------------- + # service_category__acute_inpatient_professional + # ------------------------------------------------------------------------- + + - name: test_sc_acute_inpatient_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__acute_inpatient_professional + description: > + Professional claims with place_of_service_code = '21' are classified + as acute inpatient. HCPCS codes determine delivery type. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '21', hcpcs_code: '99213', data_source: 'src1'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', claim_type: 'professional', place_of_service_code: '21', hcpcs_code: '59400', data_source: 'src1'} + - {claim_id: 'C3', claim_line_number: 1, claim_line_id: 'C3|1', claim_type: 'professional', place_of_service_code: '11', hcpcs_code: '99213', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: 'acute inpatient - other', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C2|1', service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: 'l/d - vaginal delivery', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__ambulance_professional + # ------------------------------------------------------------------------- + + - name: test_sc_ambulance_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__ambulance_professional + description: > + Professional claims with ambulance HCPCS codes (A0425-A0436) or + POS 41/42 are classified as ambulance. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', hcpcs_code: 'A0429', place_of_service_code: '11', data_source: 'src1'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', claim_type: 'professional', hcpcs_code: '99213', place_of_service_code: '41', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'ancillary', service_category_2: 'ambulance', service_category_3: 'ambulance', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C2|1', service_category_1: 'ancillary', service_category_2: 'ambulance', service_category_3: 'ambulance', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__ambulatory_surgery_professional + # ------------------------------------------------------------------------- + + - name: test_sc_ambulatory_surgery_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__ambulatory_surgery_professional + description: > + Professional claims with POS = '24' are classified as ASC. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '24', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'ambulatory surgery center', service_category_3: 'ambulatory surgery center', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__emergency_department_professional + # ------------------------------------------------------------------------- + + - name: test_sc_emergency_department_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__emergency_department_professional + description: > + Professional claims with POS 23 or ED HCPCS codes are classified + as emergency department. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '23', hcpcs_code: '99213', data_source: 'src1'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', claim_type: 'professional', place_of_service_code: '11', hcpcs_code: '99284', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'emergency department', service_category_3: 'emergency department', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C2|1', service_category_1: 'outpatient', service_category_2: 'emergency department', service_category_3: 'emergency department', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__home_health_professional + # ------------------------------------------------------------------------- + + - name: test_sc_home_health_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__home_health_professional + description: > + Professional claims with POS 12 are classified as home health. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '12', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'home health', service_category_3: 'home health', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__inpatient_hospice_professional + # ------------------------------------------------------------------------- + + - name: test_sc_inpatient_hospice_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__inpatient_hospice_professional + description: > + Professional claims with POS 34 are classified as inpatient hospice. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '34', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'inpatient', service_category_2: 'inpatient hospice', service_category_3: 'inpatient hospice', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_hospice_professional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_hospice_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_hospice_professional + description: > + Professional claims with hospice HCPCS codes are classified as outpatient hospice. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', hcpcs_code: 'Q5001', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'outpatient hospice', service_category_3: 'outpatient hospice', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__inpatient_psychiatric_professional + # ------------------------------------------------------------------------- + + - name: test_sc_inpatient_psychiatric_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__inpatient_psychiatric_professional + description: > + Professional claims with POS 51 or 56 are classified as inpatient psychiatric. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '51', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'inpatient', service_category_2: 'inpatient psychiatric', service_category_3: 'inpatient psychiatric', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__inpatient_rehab_professional + # ------------------------------------------------------------------------- + + - name: test_sc_inpatient_rehab_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__inpatient_rehab_professional + description: > + Professional claims with POS 61 are classified as inpatient rehabilitation. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '61', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'inpatient', service_category_2: 'inpatient rehabilitation', service_category_3: 'inpatient rehabilitation', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__inpatient_substance_use_professional + # ------------------------------------------------------------------------- + + - name: test_sc_inpatient_substance_use_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__inpatient_substance_use_professional + description: > + Professional claims with POS 55 are classified as inpatient substance use. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '55', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'inpatient', service_category_2: 'inpatient substance use', service_category_3: 'inpatient substance use', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_psychiatric_professional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_psychiatric_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_psychiatric_professional + description: > + Professional claims with POS 52 or 53 are classified as outpatient psychiatric. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '52', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'outpatient psychiatric', service_category_3: 'outpatient psychiatric', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_rehab_professional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_rehab_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_rehab_professional + description: > + Professional claims with POS 62 are classified as outpatient rehabilitation. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '62', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'outpatient rehabilitation', service_category_3: 'outpatient rehabilitation', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_hospital_or_clinic_professional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_hospital_or_clinic_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_hospital_or_clinic_professional + description: > + Professional claims with outpatient hospital/clinic POS codes + are classified as outpatient hospital or clinic. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '22', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'outpatient hospital or clinic', service_category_3: 'outpatient hospital or clinic', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__lab_professional + # ------------------------------------------------------------------------- + + - name: test_sc_lab_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__lab_professional + description: > + Professional claims with POS 81 or lab CCS categories are classified as lab. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '81', ccs_category: '999', data_source: 'src1'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', claim_type: 'professional', place_of_service_code: '11', ccs_category: '233', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'ancillary', service_category_2: 'lab', service_category_3: 'lab', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C2|1', service_category_1: 'ancillary', service_category_2: 'lab', service_category_3: 'lab', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__dme_professional + # ------------------------------------------------------------------------- + + - name: test_sc_dme_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__dme_professional + description: > + Professional claims with CCS category 243 are classified as DME. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', ccs_category: '243', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'ancillary', service_category_2: 'durable medical equipment', service_category_3: 'durable medical equipment', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__dialysis_professional + # ------------------------------------------------------------------------- + + - name: test_sc_dialysis_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__dialysis_professional + description: > + Professional claims with POS 65 or dialysis CCS categories are + classified as dialysis. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '65', ccs_category: null, data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'dialysis', service_category_3: 'dialysis', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__urgent_care_professional + # ------------------------------------------------------------------------- + + - name: test_sc_urgent_care_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__urgent_care_professional + description: > + Professional claims with POS 20 or urgent care HCPCS codes are + classified as urgent care. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '20', hcpcs_code: '99213', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'urgent care', service_category_3: 'urgent care', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__pharmacy_professional + # ------------------------------------------------------------------------- + + - name: test_sc_pharmacy_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__pharmacy_professional + description: > + Professional claims with CCS category 240 are classified as pharmacy. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', ccs_category: '240', place_of_service_code: '11', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'office-based', service_category_2: 'pharmacy', service_category_3: 'pharmacy', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__observation_professional + # ------------------------------------------------------------------------- + + - name: test_sc_observation_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__observation_professional + description: > + Professional claims with observation HCPCS codes are classified as observation. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', hcpcs_code: 'G0378', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'observation', service_category_3: 'observation', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_substance_use_professional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_substance_use_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_substance_use_professional + description: > + Professional claims with POS 57/58 are classified as outpatient substance use. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '57', default_ccsr_category_description_op: null, data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'outpatient substance use', service_category_3: 'outpatient substance use', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_radiology_professional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_radiology_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_radiology_professional + description: > + Professional claims with non-null modality and POS != 11 are + classified as outpatient radiology with modality-based service_category_3. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', modality: 'Magnetic resonance', place_of_service_code: '22', data_source: 'src1'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', claim_type: 'professional', modality: 'Nuclear medicine', place_of_service_code: '22', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'outpatient radiology', service_category_3: 'mri', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C2|1', service_category_1: 'outpatient', service_category_2: 'outpatient radiology', service_category_3: 'pet', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__inpatient_skilled_nursing_professional + # ------------------------------------------------------------------------- + + - name: test_sc_inpatient_skilled_nursing_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__inpatient_skilled_nursing_professional + description: > + Professional claims with POS 31/32 that are not DME are classified + as skilled nursing. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '31', data_source: 'src1'} + - input: ref('service_category__dme_professional') + rows: [] + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'inpatient', service_category_2: 'skilled nursing', service_category_3: 'skilled nursing', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS - Institutional claim type (header level) + # ========================================================================= + + # ------------------------------------------------------------------------- + # service_category__acute_inpatient_institutional_other + # ------------------------------------------------------------------------- + + - name: test_sc_acute_inpatient_institutional_other + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__acute_inpatient_institutional_other + description: > + All inpatient institutional claims get a fallback classification + of acute inpatient - other. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', data_source: 'src1'} + - input: ref('service_category__stg_inpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: 'acute inpatient - other', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__inpatient_psychiatric_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_inpatient_psychiatric_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__inpatient_psychiatric_institutional + description: > + Inpatient institutional claims with psychiatric taxonomy codes + are classified as inpatient psychiatric. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', primary_taxonomy_code: '283Q00000X', data_source: 'src1'} + - input: ref('service_category__stg_inpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'inpatient psychiatric', service_category_3: 'inpatient psychiatric', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__inpatient_rehab_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_inpatient_rehab_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__inpatient_rehab_institutional + description: > + Inpatient institutional claims with rehabilitation taxonomy codes + are classified as inpatient rehabilitation. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', primary_taxonomy_code: '283X00000X', data_source: 'src1'} + - input: ref('service_category__stg_inpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'inpatient rehabilitation', service_category_3: 'inpatient rehabilitation', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__inpatient_long_term_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_inpatient_long_term_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__inpatient_long_term_institutional + description: > + Inpatient institutional claims with LTAC taxonomy code are classified + as inpatient long term acute care. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', primary_taxonomy_code: '282E00000X', data_source: 'src1'} + - input: ref('service_category__stg_inpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'inpatient long term acute care', service_category_3: 'inpatient long term acute care', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__inpatient_hospice_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_inpatient_hospice_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__inpatient_hospice_institutional + description: > + Inpatient institutional claims with bill type code starting with '82' + are classified as inpatient hospice. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', bill_type_code: '821', revenue_center_code: null, data_source: 'src1'} + - input: ref('service_category__stg_inpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'inpatient hospice', service_category_3: 'inpatient hospice', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__inpatient_skilled_nursing_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_inpatient_skilled_nursing_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__inpatient_skilled_nursing_institutional + description: > + Institutional claims with bill type starting with '21' are Part A + and '22' are Part B skilled nursing. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', bill_type_code: '211', data_source: 'src1'} + - {claim_id: 'C2', claim_type: 'institutional', bill_type_code: '221', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'skilled nursing', service_category_3: 'inpatient part A', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'skilled nursing', service_category_3: 'inpatient part B', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__inpatient_substance_use_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_inpatient_substance_use_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__inpatient_substance_use_institutional + description: > + Inpatient institutional claims with substance use taxonomy codes + are classified as inpatient substance use. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', primary_taxonomy_code: '324500000X', default_ccsr_category_description_ip: null, data_source: 'src1'} + - input: ref('service_category__stg_inpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'inpatient substance use', service_category_3: 'inpatient substance use', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS - Outpatient Institutional (header level) + # ========================================================================= + + # ------------------------------------------------------------------------- + # service_category__home_health_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_home_health_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__home_health_institutional + description: > + Institutional claims with home health bill type codes (32-38) are + classified as home health. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', bill_type_code: '321', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'home health', service_category_3: 'home health', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_skilled_nursing_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_skilled_nursing_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_skilled_nursing_institutional + description: > + Institutional claims with bill type starting with '23' or '28' + are classified as outpatient skilled nursing. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', bill_type_code: '231', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'skilled nursing', service_category_3: 'skilled nursing', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_substance_use_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_substance_use_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_substance_use_institutional + description: > + Outpatient institutional claims with substance use taxonomy codes or + CCSR categories are classified as outpatient substance use. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', primary_taxonomy_code: '324500000X', default_ccsr_category_description_op: null, data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'outpatient substance use', service_category_3: 'outpatient substance use', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_surgery_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_surgery_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_surgery_institutional + description: > + Outpatient institutional claims with surgical CCS categories are + classified as outpatient surgery. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', ccs_category: '50', data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: [] + + # ------------------------------------------------------------------------- + # service_category__outpatient_radiology_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_radiology_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_radiology_institutional + description: > + Outpatient institutional claims with non-null modality are classified + as outpatient radiology with modality-based service_category_3. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', modality: 'Computerized tomography', data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'outpatient radiology', service_category_3: 'ct', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_physical_therapy_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_physical_therapy_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_physical_therapy_institutional + description: > + Outpatient institutional claims with PT/OT/ST CCS categories are + classified as outpatient pt/ot/st. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', ccs_category: '213', data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'outpatient pt/ot/st', service_category_3: 'outpatient pt/ot/st', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_rehab_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_rehab_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_rehab_institutional + description: > + Outpatient institutional claims with rehabilitation taxonomy codes + are classified as outpatient rehabilitation. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', primary_taxonomy_code: '283X00000X', data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'outpatient rehabilitation', service_category_3: 'outpatient rehabilitation', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_psychiatric_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_psychiatric_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_psychiatric_institutional + description: > + Outpatient institutional claims with psychiatric revenue center codes + or taxonomy codes are classified as outpatient psychiatric. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', revenue_center_code: '0905', primary_taxonomy_code: null, data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'outpatient psychiatric', service_category_3: 'outpatient psychiatric', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS - Line-level institutional + # ========================================================================= + + # ------------------------------------------------------------------------- + # service_category__ambulance_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_ambulance_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__ambulance_institutional + description: > + Outpatient institutional claims with ambulance HCPCS codes or + revenue center 0540 are classified as ambulance. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'institutional', hcpcs_code: 'A0429', revenue_center_code: null, data_source: 'src1'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', claim_type: 'institutional', hcpcs_code: null, revenue_center_code: '0540', data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'ancillary', service_category_2: 'ambulance', service_category_3: 'ambulance', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C2|1', service_category_1: 'ancillary', service_category_2: 'ambulance', service_category_3: 'ambulance', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__dme_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_dme_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__dme_institutional + description: > + Outpatient institutional claims with CCS category 243 are classified as DME. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'institutional', ccs_category: '243', data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'ancillary', service_category_2: 'durable medical equipment', service_category_3: 'durable medical equipment', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__lab_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_lab_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__lab_institutional + description: > + Outpatient institutional claims with lab bill type or CCS categories + are classified as lab. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', bill_type_code: '141', ccs_category: null, data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', service_category_1: 'ancillary', service_category_2: 'lab', service_category_3: 'lab', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__observation_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_observation_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__observation_institutional + description: > + Institutional claims with observation revenue center code or HCPCS + are classified as observation. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', revenue_center_code: '0762', hcpcs_code: null, data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'observation', service_category_3: 'observation', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS - Office-based (professional subcategories) + # ========================================================================= + + # ------------------------------------------------------------------------- + # service_category__office_based_visit_professional + # ------------------------------------------------------------------------- + + - name: test_sc_office_based_visit_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__office_based_visit_professional + description: > + Office-based claims with POS 11 and CCS 227 are classified as + office-based visit; POS 02/10 as telehealth visit. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '11', ccs_category: '227', data_source: 'src1'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', claim_type: 'professional', place_of_service_code: '02', ccs_category: null, data_source: 'src1'} + - input: ref('service_category__stg_office_based') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'office based', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, claim_line_id: 'C2|1', data_source: 'src1', service_type: 'office based', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'office-based', service_category_2: 'office-based visit', service_category_3: 'office-based visit', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'C2', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C2|1', service_category_1: 'office-based', service_category_2: 'telehealth visit', service_category_3: 'telehealth visit', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__office_based_radiology + # ------------------------------------------------------------------------- + + - name: test_sc_office_based_radiology + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__office_based_radiology + description: > + Office-based claims with modality and POS 11 are classified with + modality-specific service_category_3. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '11', modality: 'Magnetic resonance', data_source: 'src1'} + - input: ref('service_category__stg_office_based') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'office based', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'office-based', service_category_2: 'office-based radiology', service_category_3: 'mri', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__office_based_physical_therapy_professional + # ------------------------------------------------------------------------- + + - name: test_sc_office_based_physical_therapy_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__office_based_physical_therapy_professional + description: > + Office-based claims with PT/OT/ST CCS categories and POS 11 are + classified as office-based pt/ot/st. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '11', ccs_category: '213', rend_primary_specialty_description: null, data_source: 'src1'} + - input: ref('service_category__stg_office_based') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'office based', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'office-based', service_category_2: 'office-based pt/ot/st', service_category_3: 'office-based pt/ot/st', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_physical_therapy_professional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_physical_therapy_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_physical_therapy_professional + description: > + Professional claims with PT/OT/ST CCS categories and POS != 11 + are classified as outpatient pt/ot/st. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', claim_type: 'professional', place_of_service_code: '22', ccs_category: '213', primary_specialty_description: null, data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', claim_line_id: 'C1|1', service_category_1: 'outpatient', service_category_2: 'outpatient pt/ot/st', service_category_3: 'outpatient pt/ot/st', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_surgery_professional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_surgery_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_surgery_professional + description: > + Professional claims with surgical CCS categories and outpatient + POS codes are classified as outpatient surgery. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'professional', ccs_category: '50', place_of_service_code: '22', data_source: 'src1'} + - input: ref('service_category__stg_professional') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_line_id: 'C1|1', data_source: 'src1', service_type: 'professional', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: [] + + # ------------------------------------------------------------------------- + # service_category__dialysis_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_dialysis_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__dialysis_institutional + description: > + Outpatient institutional claims with dialysis bill type code (72) + are classified as dialysis. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', bill_type_code: '721', primary_taxonomy_code: null, ccs_category: null, revenue_center_code: null, data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'dialysis', service_category_3: 'dialysis', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__emergency_department_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_emergency_department_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__emergency_department_institutional + description: > + Outpatient institutional claims with ED revenue center codes are + classified as emergency department. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', revenue_center_code: '0450', hcpcs_code: null, data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('service_category__stg_inpatient_institutional') + rows: [] + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'emergency department', service_category_3: 'emergency department', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_hospice_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_hospice_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_hospice_institutional + description: > + Outpatient institutional claims with bill type starting with '81' + are classified as outpatient hospice. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', bill_type_code: '811', hcpcs_code: null, revenue_center_code: null, data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('service_category__home_health_institutional') + rows: [] + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'outpatient hospice', service_category_3: 'outpatient hospice', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__ambulatory_surgery_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_ambulatory_surgery_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__ambulatory_surgery_institutional + description: > + Outpatient institutional claims with ASC revenue center codes (0490/0499) + or ASC taxonomy code are classified as ambulatory surgery center. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', revenue_center_code: '0490', primary_taxonomy_code: null, data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'ambulatory surgery center', service_category_3: 'ambulatory surgery center', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__urgent_care_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_urgent_care_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__urgent_care_institutional + description: > + Institutional claims with urgent care revenue center and bill type + are classified as urgent care. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', revenue_center_code: '0456', bill_type_code: '131', hcpcs_code: null, data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'urgent care', service_category_3: 'urgent care', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__outpatient_hospital_or_clinic_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_outpatient_hospital_or_clinic_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__outpatient_hospital_or_clinic_institutional + description: > + Outpatient institutional claims with hospital outpatient bill type + codes (13, 71, etc.) are classified as outpatient hospital or clinic. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_type: 'institutional', bill_type_code: '131', ccs_category: null, data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {claim_id: 'C1', data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'outpatient hospital or clinic', service_category_3: 'outpatient hospital or clinic', tuva_last_run: '2024-01-01 00:00:00'} + + # ------------------------------------------------------------------------- + # service_category__pharmacy_institutional + # ------------------------------------------------------------------------- + + - name: test_sc_pharmacy_institutional_outpatient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: service_category__pharmacy_institutional + description: > + Outpatient institutional claims with pharmacy revenue center codes + are classified as pharmacy. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__stg_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', revenue_center_code: '0250', ccs_category: null, data_source: 'src1'} + - input: ref('service_category__stg_outpatient_institutional') + rows: + - {claim_id: 'C1', data_source: 'src1', service_type: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('service_category__stg_inpatient_institutional') + rows: [] + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', service_category_1: 'outpatient', service_category_2: 'pharmacy', service_category_3: 'pharmacy', tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/core/core_gap_unit_tests.yml b/models/core/core_gap_unit_tests.yml new file mode 100644 index 000000000..e9de2ce18 --- /dev/null +++ b/models/core/core_gap_unit_tests.yml @@ -0,0 +1,397 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # CORE - STAGING: stg_claims_patient + # Note: Row_number should prefer the latest enrollment period, including + # open-ended rows where enrollment_end_date is null. + # ========================================================================= + + - name: test_core_stg_claims_patient_prefers_open_ended_enrollment + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_claims_patient + description: > + When a person has multiple enrollment periods, the open-ended row wins + because the row_number ordering treats null enrollment_end_date as the + latest possible date. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', name_suffix: null, first_name: 'Old', middle_name: null, last_name: 'Member', gender: 'male', race: 'white', birth_date: '1960-03-15', death_date: null, death_flag: 0, social_security_number: null, address: null, city: null, state: null, zip_code: null, phone: null, email: null, ethnicity: null, data_source: 'src1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-06-30'} + - {person_id: 'P1', name_suffix: null, first_name: 'Current', middle_name: null, last_name: 'Member', gender: 'male', race: 'white', birth_date: '1960-03-15', death_date: null, death_flag: 0, social_security_number: null, address: null, city: null, state: null, zip_code: null, phone: null, email: null, ethnicity: null, data_source: 'src1', enrollment_start_date: '2023-07-01', enrollment_end_date: null} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', first_name: 'Current', last_name: 'Member', birth_date: '1960-03-15', age: 63, age_group: '60-69', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CORE - STAGING: stg_claims_medical_claim + # Fanout prevention depends on claim_line_attribution_number = 1 and + # duplicate_row_number = 1 joins. + # ========================================================================= + + # ========================================================================= + # CORE - STAGING: stg_claims_pharmacy_claim + # Tests enrollment flag logic and pharmacy_claim_id generation. + # ========================================================================= + + - name: test_stg_claims_pharmacy_claim_generates_pk_and_enrollment_flag + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_claims_pharmacy_claim + description: > + The staging model generates pharmacy_claim_id from claim_id, claim_line_number, + and data_source. The enrollment_flag is set to 1 when enrollment data matches. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('normalized_input__pharmacy_claim') + rows: + - {claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', prescribing_provider_id: 'NPI1', prescribing_provider_name: 'Dr Smith', dispensing_provider_id: 'NPI2', dispensing_provider_name: 'CVS', dispensing_date: '2023-06-01', ndc_code: '12345678901', ndc_description: 'Test Drug', quantity: 30, days_supply: 30, refills: 3, paid_date: '2023-06-15', paid_amount: 50.00, allowed_amount: 45.00, charge_amount: 60.00, coinsurance_amount: 5.00, copayment_amount: 10.00, deductible_amount: 0, in_network_flag: 1, data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null} + - {claim_id: 'RX2', claim_line_number: 1, person_id: 'P2', member_id: 'M2', payer: 'MCR', plan: 'PlanB', prescribing_provider_id: null, prescribing_provider_name: null, dispensing_provider_id: null, dispensing_provider_name: null, dispensing_date: '2023-07-01', ndc_code: '99999999999', ndc_description: null, quantity: 60, days_supply: 60, refills: 0, paid_date: null, paid_amount: 100.00, allowed_amount: null, charge_amount: null, coinsurance_amount: null, copayment_amount: null, deductible_amount: null, in_network_flag: 0, data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null} + - input: ref('claims_enrollment__flag_rx_claims_with_enrollment') + rows: + - {claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', member_month_key: 'MM1'} + - input: ref('input_layer__pharmacy_claim') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {pharmacy_claim_id: 'RX1-1-src1', claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', ndc_code: '12345678901', enrollment_flag: 1, member_month_key: 'MM1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {pharmacy_claim_id: 'RX2-1-src1', claim_id: 'RX2', claim_line_number: 1, person_id: 'P2', ndc_code: '99999999999', enrollment_flag: 0, member_month_key: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CORE - STAGING: stg_claims_practitioner + # Filters provider terminology to individual entity types and enriches + # with specialty data. + # ========================================================================= + + - name: test_stg_claims_practitioner_filters_individual_providers + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_claims_practitioner + description: > + The staging model joins NPIs from medical and pharmacy claims to the + provider terminology table and filters to only individual providers. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('core__stg_claims_medical_claim') + rows: + - {facility_npi: 'NPI_ORG', rendering_npi: 'NPI_IND', billing_npi: null} + - input: ref('core__stg_claims_pharmacy_claim') + rows: + - {prescribing_provider_id: 'NPI_IND', dispensing_provider_id: 'NPI_ORG'} + - input: ref('terminology__provider') + rows: + - {npi: 'NPI_IND', entity_type_description: 'Individual', provider_first_name: 'Jane', provider_last_name: 'Doe', parent_organization_name: 'Health Corp', primary_specialty_description: 'Family Medicine', provider_organization_name: null, practice_address_line_1: null, practice_city: null, practice_state: null, practice_zip_code: null, entity_type_code: '1'} + - {npi: 'NPI_ORG', entity_type_description: 'Organization', provider_first_name: null, provider_last_name: null, parent_organization_name: 'Big Hospital', primary_specialty_description: null, provider_organization_name: 'Big Hospital', practice_address_line_1: '100 Main St', practice_city: 'Anytown', practice_state: 'NY', practice_zip_code: '10001', entity_type_code: '2'} + expect: + rows: + - {practitioner_id: 'NPI_IND', npi: 'NPI_IND', first_name: 'Jane', last_name: 'Doe', practice_affiliation: 'Health Corp', specialty: 'Family Medicine', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CORE - STAGING: stg_claims_location + # Filters provider terminology to organization entity types. + # ========================================================================= + + - name: test_stg_claims_location_filters_organization_providers + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_claims_location + description: > + The staging model joins NPIs from medical and pharmacy claims to the + provider terminology table and filters to only organization providers + to produce location records. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('core__stg_claims_medical_claim') + rows: + - {facility_npi: 'NPI_ORG', rendering_npi: 'NPI_IND', billing_npi: null} + - input: ref('core__stg_claims_pharmacy_claim') + rows: + - {prescribing_provider_id: 'NPI_IND', dispensing_provider_id: 'NPI_ORG'} + - input: ref('terminology__provider') + rows: + - {npi: 'NPI_IND', entity_type_description: 'Individual', provider_first_name: 'Jane', provider_last_name: 'Doe', parent_organization_name: null, primary_specialty_description: 'Family Medicine', provider_organization_name: null, practice_address_line_1: null, practice_city: null, practice_state: null, practice_zip_code: null, entity_type_code: '1'} + - {npi: 'NPI_ORG', entity_type_description: 'Organization', provider_first_name: null, provider_last_name: null, parent_organization_name: 'Big Health System', primary_specialty_description: null, provider_organization_name: 'Community Hospital', practice_address_line_1: '200 Hospital Blvd', practice_city: 'Metropolis', practice_state: 'CA', practice_zip_code: '90210', entity_type_code: '2'} + expect: + rows: + - {location_id: 'NPI_ORG', npi: 'NPI_ORG', name: 'Community Hospital', parent_organization: 'Big Health System', address: '200 Hospital Blvd', city: 'Metropolis', state: 'CA', zip_code: '90210', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CORE - FINAL: core__encounter — Clinical-only passthrough + # ========================================================================= + + - name: test_encounter_clinical_only_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__encounter + description: > + In clinical-only mode, encounter model passes through from + the clinical staging model. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: false + clinical_enabled: true + given: + - input: ref('core__stg_clinical_encounter') + rows: + - {encounter_id: 'CENC1', person_id: 'P1', encounter_type: 'ambulatory', encounter_group: 'clinical', encounter_start_date: '2023-06-15', encounter_end_date: '2023-06-15', length_of_stay: 0, admit_source_code: null, admit_source_description: null, admit_type_code: null, admit_type_description: null, discharge_disposition_code: null, discharge_disposition_description: null, attending_provider_id: 'NPI1', attending_provider_name: 'Dr. Smith', facility_npi: null, facility_name: 'Clinic A', facility_type: null, observation_flag: null, lab_flag: null, dme_flag: null, ambulance_flag: null, pharmacy_flag: null, ed_flag: null, delivery_flag: null, delivery_type: null, newborn_flag: null, nicu_flag: null, snf_part_b_flag: null, primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'J06.9', primary_diagnosis_description: 'URI', drg_code_type: null, drg_code: null, drg_description: null, paid_amount: null, allowed_amount: null, charge_amount: null, claim_count: null, inst_claim_count: null, prof_claim_count: null, source_model: null, encounter_source_type: 'clinical', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__encounter') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {encounter_id: 'CENC1', person_id: 'P1', encounter_type: 'ambulatory', encounter_group: 'clinical', encounter_start_date: '2023-06-15', primary_diagnosis_code: 'J06.9', encounter_source_type: 'clinical', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CORE - FINAL: core__patient — Clinical-only passthrough + # ========================================================================= + + - name: test_patient_clinical_only_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__patient + description: > + In clinical-only mode, patient model passes through from clinical staging. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: false + clinical_enabled: true + given: + - input: ref('core__stg_clinical_patient') + rows: + - {person_id: 'P1', name_suffix: null, first_name: 'Alice', middle_name: null, last_name: 'Jones', sex: 'female', race: 'white', birth_date: '1985-04-20', death_date: null, death_flag: 0, social_security_number: null, address: '100 Pine St', city: 'Portland', state: 'OR', zip_code: '97201', county: null, latitude: null, longitude: null, phone: '5035551234', email: 'alice@example.com', ethnicity: 'not hispanic or latino', age: 38, age_group: '30-39', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__patient') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', first_name: 'Alice', last_name: 'Jones', sex: 'female', birth_date: '1985-04-20', age: 38, age_group: '30-39', city: 'Portland', state: 'OR', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CORE - FINAL: core__person_id_crosswalk — Clinical-only path + # ========================================================================= + + - name: test_person_id_crosswalk_clinical_only + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__person_id_crosswalk + description: > + In clinical-only mode, produces distinct person_id / patient_id + combinations from the patient input layer with null claims-side fields. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: false + clinical_enabled: true + given: + - input: ref('input_layer__patient') + rows: + - {person_id: 'P1', patient_id: 'PAT1', data_source: 'clinical_src'} + - {person_id: 'P2', patient_id: 'PAT2', data_source: 'clinical_src'} + - {person_id: 'P1', patient_id: 'PAT1', data_source: 'clinical_src'} + expect: + rows: + - {person_id: 'P1', patient_id: 'PAT1', member_id: null, payer: null, plan: null, data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', patient_id: 'PAT2', member_id: null, payer: null, plan: null, data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CORE - FINAL: core__procedure — Manual normalization takes priority + # ========================================================================= + + - name: test_procedure_manual_normalization_takes_priority + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__procedure + description: > + When the staging model already has normalized_code populated, + manual mapping takes priority over automatic terminology lookup. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + enable_normalize_engine: false + given: + - input: ref('core__stg_claims_procedure') + rows: + - {procedure_id: 'PR4', person_id: 'P1', member_id: 'M1', patient_id: null, encounter_id: null, claim_id: 'CLM4', procedure_date: '2023-06-15', source_code_type: 'hcpcs', source_code: '99213', source_description: null, normalized_code_type: 'hcpcs', normalized_code: '99214', normalized_description: 'Office visit level 4', modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, practitioner_id: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_pcs') + rows: [] + - input: ref('terminology__icd_9_pcs') + rows: [] + - input: ref('terminology__hcpcs_level_2') + rows: + - {hcpcs: '99213', short_description: 'Office visit est patient'} + - input: ref('terminology__snomed_ct') + rows: [] + expect: + rows: + - {procedure_id: 'PR4', person_id: 'P1', source_code_type: 'hcpcs', source_code: '99213', normalized_code_type: 'hcpcs', normalized_code: '99214', normalized_description: 'Office visit level 4', mapping_method: 'manual', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CORE - FINAL: core__lab_result — Component normalization + # ========================================================================= + + - name: test_lab_result_normalizes_loinc_component + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__lab_result + description: > + When source_component_type is loinc and matches terminology, + the normalized component fields should be populated. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_lab_result') + rows: + - {lab_result_id: 'LR3', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', accession_number: 'ACC3', source_order_type: null, source_order_code: null, source_order_description: null, source_component_type: 'loinc', source_component_code: '2345-7', source_component_description: 'Glucose', normalized_order_type: null, normalized_order_code: null, normalized_order_description: null, normalized_component_type: null, normalized_component_code: null, normalized_component_description: null, status: 'final', result: '95', result_datetime: '2023-07-01 08:00:00', collection_datetime: '2023-07-01 07:00:00', source_units: 'mg/dL', normalized_units: null, source_reference_range_low: '70', source_reference_range_high: '100', normalized_reference_range_low: null, normalized_reference_range_high: null, source_abnormal_flag: null, normalized_abnormal_flag: null, specimen: 'blood', ordering_practitioner_id: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__loinc') + rows: + - {loinc: '2345-7', long_common_name: 'Glucose [Mass/volume] in Serum or Plasma'} + - input: ref('terminology__snomed_ct') + rows: [] + - input: ref('input_layer__lab_result') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {lab_result_id: 'LR3', person_id: 'P1', normalized_component_type: 'loinc', normalized_component_code: '2345-7', normalized_component_description: 'Glucose [Mass/volume] in Serum or Plasma', mapping_method: 'automatic', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CORE - FINAL: core__medication — Manual NDC takes priority + # ========================================================================= + + - name: test_medication_manual_ndc_takes_priority + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__medication + description: > + When the staging model has ndc_code already populated (manual mapping), + that value takes priority over the terminology lookup. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_medication') + rows: + - {medication_id: 'MED3', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', dispensing_date: '2023-06-15', prescribing_date: null, source_code_type: 'ndc', source_code: '00002323201', source_description: null, ndc_code: '99999999999', ndc_description: 'Manual NDC Desc', rxnorm_code: null, rxnorm_description: null, atc_code: null, atc_description: null, route: null, strength: null, quantity: null, quantity_unit: null, days_supply: null, practitioner_id: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__ndc') + rows: + - {ndc: '00002323201', fda_description: 'Metformin HCL 500mg', rxnorm_description: 'Metformin 500 MG', rxcui: '860974'} + - input: ref('terminology__rxnorm_to_atc') + rows: [] + - input: ref('input_layer__medication') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {medication_id: 'MED3', person_id: 'P1', ndc_code: '99999999999', ndc_description: 'Manual NDC Desc', ndc_mapping_method: 'manual', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CORE - FINAL: core__observation — LOINC normalization + # ========================================================================= + + - name: test_observation_normalizes_loinc_code + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__observation + description: > + When source_code_type is loinc and matches terminology, + normalized fields should be populated via automatic mapping. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_observation') + rows: + - {observation_id: 'OB3', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', panel_id: null, observation_date: '2023-06-15', observation_type: 'vital-signs', source_code_type: 'loinc', source_code: '8480-6', source_description: 'Systolic BP', normalized_code_type: null, normalized_code: null, normalized_description: null, result: '130', source_units: 'mmHg', normalized_units: null, source_reference_range_low: null, source_reference_range_high: null, normalized_reference_range_low: null, normalized_reference_range_high: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + - input: ref('terminology__icd_10_pcs') + rows: [] + - input: ref('terminology__icd_9_pcs') + rows: [] + - input: ref('terminology__hcpcs_level_2') + rows: [] + - input: ref('terminology__snomed_ct') + rows: [] + - input: ref('terminology__loinc') + rows: + - {loinc: '8480-6', long_common_name: 'Systolic blood pressure'} + - input: ref('terminology__observation_type') + rows: + - {observation_type: 'vital-signs'} + - input: ref('input_layer__observation') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {observation_id: 'OB3', person_id: 'P1', source_code_type: 'loinc', source_code: '8480-6', normalized_code_type: 'loinc', normalized_code: '8480-6', normalized_description: 'Systolic blood pressure', mapping_method: 'automatic', observation_type: 'vital-signs', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CORE - FINAL: core__immunization — Body site and route enrichment + # ========================================================================= + + - name: test_immunization_body_site_and_route_enrichment + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__immunization + description: > + Body site and route fields are enriched from the terminology + tables when matching codes exist. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_immunization') + rows: + - {immunization_id: 'IM3', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', source_code_type: 'cvx', source_code: '999', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, status: null, status_reason: null, occurrence_date: '2023-06-15', source_dose: null, normalized_dose: null, lot_number: null, body_site: 'LA', route: 'IM', location_id: null, practitioner_id: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__cvx') + rows: [] + - input: ref('terminology__immunization_status') + rows: [] + - input: ref('terminology__immunization_status_reason') + rows: [] + - input: ref('terminology__act_site') + rows: + - {body_code: 'LA', description: 'Left arm'} + - input: ref('terminology__immunization_route_code') + rows: + - {route_code: 'IM', description: 'Intramuscular'} + - input: ref('input_layer__immunization') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {immunization_id: 'IM3', person_id: 'P1', body_site: 'Left arm', route: 'Intramuscular', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/core/core_unit_tests.yml b/models/core/core_unit_tests.yml new file mode 100644 index 000000000..c66a9e83d --- /dev/null +++ b/models/core/core_unit_tests.yml @@ -0,0 +1,1588 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # core__condition — Normalization logic and terminology joins + # ========================================================================= + + - name: test_condition_normalizes_icd10_code + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__condition + description: > + When source_code_type is icd-10-cm and the code matches terminology, + the normalized fields should be populated via automatic mapping. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + enable_normalize_engine: false + given: + - input: ref('core__stg_claims_condition') + rows: + - {condition_id: 'C1', payer: 'MCR', person_id: 'P1', member_id: 'M1', patient_id: null, encounter_id: null, claim_id: 'CLM1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', condition_type: 'discharge_diagnosis', source_code_type: 'icd-10-cm', source_code: 'E1165', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, condition_rank: 1, present_on_admit_code: null, present_on_admit_description: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'E1165', short_description: 'Type 2 DM w hyperglycemia', long_description: 'Type 2 diabetes mellitus with hyperglycemia'} + - input: ref('terminology__icd_9_cm') + rows: [] + - input: ref('terminology__snomed_ct') + rows: [] + expect: + rows: + - {condition_id: 'C1', payer: 'MCR', person_id: 'P1', member_id: 'M1', patient_id: null, encounter_id: null, claim_id: 'CLM1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', condition_type: 'discharge_diagnosis', source_code_type: 'icd-10-cm', source_code: 'E1165', source_description: null, normalized_code_type: 'icd-10-cm', normalized_code: 'E1165', normalized_description: 'Type 2 DM w hyperglycemia', mapping_method: 'automatic', condition_rank: 1, present_on_admit_code: null, present_on_admit_description: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_condition_manual_normalization_takes_priority + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__condition + description: > + When the staging model already has normalized_code populated, + the manual mapping takes priority over automatic terminology lookup. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + enable_normalize_engine: false + given: + - input: ref('core__stg_claims_condition') + rows: + - {condition_id: 'C1', payer: 'MCR', person_id: 'P1', member_id: 'M1', patient_id: null, encounter_id: null, claim_id: 'CLM1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', condition_type: 'discharge_diagnosis', source_code_type: 'icd-10-cm', source_code: 'E1165', source_description: null, normalized_code_type: 'icd-10-cm', normalized_code: 'E119', normalized_description: 'DM type 2 without complications', condition_rank: 1, present_on_admit_code: null, present_on_admit_description: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'E1165', short_description: 'Type 2 DM w hyperglycemia', long_description: 'Type 2 diabetes mellitus with hyperglycemia'} + - input: ref('terminology__icd_9_cm') + rows: [] + - input: ref('terminology__snomed_ct') + rows: [] + expect: + rows: + - {condition_id: 'C1', payer: 'MCR', person_id: 'P1', member_id: 'M1', patient_id: null, encounter_id: null, claim_id: 'CLM1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', condition_type: 'discharge_diagnosis', source_code_type: 'icd-10-cm', source_code: 'E1165', source_description: null, normalized_code_type: 'icd-10-cm', normalized_code: 'E119', normalized_description: 'DM type 2 without complications', mapping_method: 'manual', condition_rank: 1, present_on_admit_code: null, present_on_admit_description: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_condition_no_terminology_match_yields_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__condition + description: > + When source_code does not match any terminology table, + normalized fields should be null and mapping_method should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + enable_normalize_engine: false + given: + - input: ref('core__stg_claims_condition') + rows: + - {condition_id: 'C1', payer: 'MCR', person_id: 'P1', member_id: 'M1', patient_id: null, encounter_id: null, claim_id: 'CLM1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', condition_type: 'discharge_diagnosis', source_code_type: 'icd-10-cm', source_code: 'ZZZZZ', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, condition_rank: 1, present_on_admit_code: null, present_on_admit_description: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + - input: ref('terminology__snomed_ct') + rows: [] + expect: + rows: + - {condition_id: 'C1', payer: 'MCR', person_id: 'P1', member_id: 'M1', patient_id: null, encounter_id: null, claim_id: 'CLM1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', condition_type: 'discharge_diagnosis', source_code_type: 'icd-10-cm', source_code: 'ZZZZZ', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, mapping_method: null, condition_rank: 1, present_on_admit_code: null, present_on_admit_description: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__eligibility — Passthrough from staging + # ========================================================================= + + - name: test_eligibility_passthrough_basic + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__eligibility + description: > + Eligibility model passes through all columns from staging. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('core__stg_claims_eligibility') + rows: + - {eligibility_id: 'E1', person_id: 'P1', member_id: 'M1', subscriber_id: 'S1', birth_date: '1960-01-01', death_date: null, enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', payer_type: 'medicare', plan: 'PlanA', original_reason_entitlement_code: '0', dual_status_code: null, medicare_status_code: '10', enrollment_status: null, hospice_flag: 0, snp_type: null, medicaid_indicator: null, long_term_institutional_flag: null, part_d_raf_type: null, low_income_subsidy_indicator: null, metal_level: null, csr_indicator: null, enrollment_duration_months: 12, esrd_status: null, transplant_duration_months: null, subscriber_relation: null, group_id: null, group_name: null, normalized_state_name: null, fips_state_code: null, fips_state_abbreviation: null, data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {eligibility_id: 'E1', person_id: 'P1', member_id: 'M1', subscriber_id: 'S1', birth_date: '1960-01-01', death_date: null, enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', payer_type: 'medicare', plan: 'PlanA', original_reason_entitlement_code: '0', dual_status_code: null, medicare_status_code: '10', enrollment_status: null, hospice_flag: 0, snp_type: null, medicaid_indicator: null, long_term_institutional_flag: null, part_d_raf_type: null, low_income_subsidy_indicator: null, metal_level: null, csr_indicator: null, enrollment_duration_months: 12, esrd_status: null, transplant_duration_months: null, subscriber_relation: null, group_id: null, group_name: null, normalized_state_name: null, fips_state_code: null, fips_state_abbreviation: null, data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_eligibility_multiple_records_preserved + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__eligibility + description: > + Multiple eligibility records for different enrollment periods + are all passed through without deduplication. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('core__stg_claims_eligibility') + rows: + - {eligibility_id: 'E1', person_id: 'P1', member_id: 'M1', subscriber_id: null, birth_date: '1960-01-01', death_date: null, enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-06-30', payer: 'MCR', payer_type: 'medicare', plan: 'PlanA', original_reason_entitlement_code: '0', dual_status_code: null, medicare_status_code: null, enrollment_status: null, hospice_flag: null, snp_type: null, medicaid_indicator: null, long_term_institutional_flag: null, part_d_raf_type: null, low_income_subsidy_indicator: null, metal_level: null, csr_indicator: null, enrollment_duration_months: 6, esrd_status: null, transplant_duration_months: null, subscriber_relation: null, group_id: null, group_name: null, normalized_state_name: null, fips_state_code: null, fips_state_abbreviation: null, data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null, tuva_last_run: '2024-01-01 00:00:00'} + - {eligibility_id: 'E2', person_id: 'P1', member_id: 'M1', subscriber_id: null, birth_date: '1960-01-01', death_date: null, enrollment_start_date: '2023-07-01', enrollment_end_date: '2023-12-31', payer: 'MCR', payer_type: 'medicare', plan: 'PlanB', original_reason_entitlement_code: '0', dual_status_code: null, medicare_status_code: null, enrollment_status: null, hospice_flag: null, snp_type: null, medicaid_indicator: null, long_term_institutional_flag: null, part_d_raf_type: null, low_income_subsidy_indicator: null, metal_level: null, csr_indicator: null, enrollment_duration_months: 6, esrd_status: null, transplant_duration_months: null, subscriber_relation: null, group_id: null, group_name: null, normalized_state_name: null, fips_state_code: null, fips_state_abbreviation: null, data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {eligibility_id: 'E1', person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-06-30', payer: 'MCR', plan: 'PlanA', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {eligibility_id: 'E2', person_id: 'P1', enrollment_start_date: '2023-07-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanB', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__member_months — Passthrough from staging + # ========================================================================= + + - name: test_member_months_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__member_months + description: > + Member months passes through all fields from staging. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('core__stg_claims_member_months') + rows: + - {member_month_key: 'MM1', person_id: 'P1', member_id: 'M1', year_month: '2023-01', payer: 'MCR', plan: 'PlanA', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {member_month_key: 'MM1', person_id: 'P1', member_id: 'M1', year_month: '2023-01', payer: 'MCR', plan: 'PlanA', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_member_months_multiple_months_preserved + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__member_months + description: > + Multiple member months for the same person are all passed through. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('core__stg_claims_member_months') + rows: + - {member_month_key: 'MM1', person_id: 'P1', member_id: 'M1', year_month: '2023-01', payer: 'MCR', plan: 'PlanA', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {member_month_key: 'MM2', person_id: 'P1', member_id: 'M1', year_month: '2023-02', payer: 'MCR', plan: 'PlanA', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {member_month_key: 'MM3', person_id: 'P2', member_id: 'M2', year_month: '2023-01', payer: 'MCR', plan: 'PlanA', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {member_month_key: 'MM1', person_id: 'P1', year_month: '2023-01', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {member_month_key: 'MM2', person_id: 'P1', year_month: '2023-02', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {member_month_key: 'MM3', person_id: 'P2', year_month: '2023-01', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__medical_claim — Passthrough from staging + # ========================================================================= + + - name: test_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__medical_claim + description: > + Medical claim model passes through columns from staging. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('core__stg_claims_medical_claim') + rows: + - {medical_claim_id: 'MC1', claim_id: 'CLM1', claim_line_number: 1, encounter_id: 'ENC1', encounter_type: 'acute inpatient', encounter_group: 'inpatient', claim_type: 'institutional', person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', claim_start_date: '2023-06-01', claim_end_date: '2023-06-05', claim_line_start_date: '2023-06-01', claim_line_end_date: '2023-06-05', admission_date: '2023-06-01', discharge_date: '2023-06-05', service_category_1: 'inpatient', service_category_2: 'acute', service_category_3: null, admit_source_code: '1', admit_source_description: null, admit_type_code: '1', admit_type_description: null, discharge_disposition_code: '01', discharge_disposition_description: null, place_of_service_code: '21', place_of_service_description: null, bill_type_code: '111', bill_type_description: null, drg_code_type: 'ms-drg', drg_code: '470', drg_description: null, revenue_center_code: '0100', revenue_center_description: null, service_unit_quantity: 1, hcpcs_code: '99213', hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null, rendering_npi: 'NPI1', rendering_tin: null, rendering_name: null, billing_npi: 'NPI2', billing_tin: null, billing_name: null, facility_npi: 'NPI3', facility_name: null, paid_date: '2023-07-01', paid_amount: 5000.00, allowed_amount: 4500.00, charge_amount: 6000.00, coinsurance_amount: 100.00, copayment_amount: 50.00, deductible_amount: 200.00, total_cost_amount: 5350.00, in_network_flag: 1, enrollment_flag: 1, member_month_key: 'MM1', data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'C1', data_source: 'src1'} + expect: + rows: + - {medical_claim_id: 'MC1', claim_id: 'CLM1', claim_line_number: 1, person_id: 'P1', payer: 'MCR', paid_amount: 5000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_medical_claim_multiple_lines_preserved + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__medical_claim + description: > + Multiple claim lines for the same claim are preserved as separate rows, + testing that the PK (medical_claim_id) remains unique. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('core__stg_claims_medical_claim') + rows: + - {medical_claim_id: 'MC1', claim_id: 'CLM1', claim_line_number: 1, encounter_id: 'ENC1', encounter_type: 'office visit', encounter_group: 'outpatient', claim_type: 'professional', person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', claim_line_start_date: '2023-06-01', claim_line_end_date: '2023-06-01', admission_date: null, discharge_date: null, service_category_1: 'office visit', service_category_2: null, service_category_3: null, admit_source_code: null, admit_source_description: null, admit_type_code: null, admit_type_description: null, discharge_disposition_code: null, discharge_disposition_description: null, place_of_service_code: '11', place_of_service_description: null, bill_type_code: null, bill_type_description: null, drg_code_type: null, drg_code: null, drg_description: null, revenue_center_code: null, revenue_center_description: null, service_unit_quantity: 1, hcpcs_code: '99213', hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null, rendering_npi: 'NPI1', rendering_tin: null, rendering_name: null, billing_npi: null, billing_tin: null, billing_name: null, facility_npi: null, facility_name: null, paid_date: null, paid_amount: 100.00, allowed_amount: 90.00, charge_amount: 120.00, coinsurance_amount: null, copayment_amount: null, deductible_amount: null, total_cost_amount: null, in_network_flag: 1, enrollment_flag: 1, member_month_key: 'MM1', data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null, tuva_last_run: '2024-01-01 00:00:00'} + - {medical_claim_id: 'MC2', claim_id: 'CLM1', claim_line_number: 2, encounter_id: 'ENC1', encounter_type: 'office visit', encounter_group: 'outpatient', claim_type: 'professional', person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', claim_line_start_date: '2023-06-01', claim_line_end_date: '2023-06-01', admission_date: null, discharge_date: null, service_category_1: 'office visit', service_category_2: null, service_category_3: null, admit_source_code: null, admit_source_description: null, admit_type_code: null, admit_type_description: null, discharge_disposition_code: null, discharge_disposition_description: null, place_of_service_code: '11', place_of_service_description: null, bill_type_code: null, bill_type_description: null, drg_code_type: null, drg_code: null, drg_description: null, revenue_center_code: null, revenue_center_description: null, service_unit_quantity: 1, hcpcs_code: '36415', hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null, rendering_npi: 'NPI1', rendering_tin: null, rendering_name: null, billing_npi: null, billing_tin: null, billing_name: null, facility_npi: null, facility_name: null, paid_date: null, paid_amount: 25.00, allowed_amount: 20.00, charge_amount: 30.00, coinsurance_amount: null, copayment_amount: null, deductible_amount: null, total_cost_amount: null, in_network_flag: 1, enrollment_flag: 1, member_month_key: 'MM1', data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'C1', data_source: 'src1'} + expect: + rows: + - {medical_claim_id: 'MC1', claim_id: 'CLM1', claim_line_number: 1, person_id: 'P1', hcpcs_code: '99213', paid_amount: 100.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {medical_claim_id: 'MC2', claim_id: 'CLM1', claim_line_number: 2, person_id: 'P1', hcpcs_code: '36415', paid_amount: 25.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__pharmacy_claim — Passthrough from staging + # ========================================================================= + + - name: test_pharmacy_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__pharmacy_claim + description: > + Pharmacy claim model passes through columns from staging. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('core__stg_claims_pharmacy_claim') + rows: + - {pharmacy_claim_id: 'RX1', claim_id: 'RXCLM1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', prescribing_provider_id: 'NPI1', prescribing_provider_name: 'Dr Smith', dispensing_provider_id: 'NPI2', dispensing_provider_name: 'CVS', dispensing_date: '2023-06-01', ndc_code: '00000000001', ndc_description: 'Test Drug', quantity: 30, days_supply: 30, refills: 3, paid_date: '2023-06-15', paid_amount: 50.00, allowed_amount: 45.00, charge_amount: 60.00, coinsurance_amount: 5.00, copayment_amount: 10.00, deductible_amount: 0, in_network_flag: 1, enrollment_flag: 1, member_month_key: 'MM1', data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__pharmacy_claim') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {pharmacy_claim_id: 'RX1', claim_id: 'RXCLM1', claim_line_number: 1, person_id: 'P1', ndc_code: '00000000001', days_supply: 30, paid_amount: 50.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_pharmacy_claim_pk_uniqueness + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__pharmacy_claim + description: > + Each pharmacy claim line produces a unique pharmacy_claim_id, + even for different lines on the same claim. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('core__stg_claims_pharmacy_claim') + rows: + - {pharmacy_claim_id: 'RX1', claim_id: 'RXCLM1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', prescribing_provider_id: null, prescribing_provider_name: null, dispensing_provider_id: null, dispensing_provider_name: null, dispensing_date: '2023-06-01', ndc_code: '11111111111', ndc_description: null, quantity: 30, days_supply: 30, refills: 0, paid_date: null, paid_amount: 50.00, allowed_amount: null, charge_amount: null, coinsurance_amount: null, copayment_amount: null, deductible_amount: null, in_network_flag: 1, enrollment_flag: 1, member_month_key: 'MM1', data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null, tuva_last_run: '2024-01-01 00:00:00'} + - {pharmacy_claim_id: 'RX2', claim_id: 'RXCLM1', claim_line_number: 2, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', prescribing_provider_id: null, prescribing_provider_name: null, dispensing_provider_id: null, dispensing_provider_name: null, dispensing_date: '2023-06-01', ndc_code: '22222222222', ndc_description: null, quantity: 60, days_supply: 60, refills: 0, paid_date: null, paid_amount: 100.00, allowed_amount: null, charge_amount: null, coinsurance_amount: null, copayment_amount: null, deductible_amount: null, in_network_flag: 1, enrollment_flag: 1, member_month_key: 'MM1', data_source: 'src1', file_date: null, ingest_datetime: null, file_name: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__pharmacy_claim') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {pharmacy_claim_id: 'RX1', claim_id: 'RXCLM1', claim_line_number: 1, ndc_code: '11111111111', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {pharmacy_claim_id: 'RX2', claim_id: 'RXCLM1', claim_line_number: 2, ndc_code: '22222222222', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__patient — Claims-only path with deduplication + # ========================================================================= + + - name: test_patient_claims_only_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__patient + description: > + Patient model in claims-only mode passes through from staging. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + given: + - input: ref('core__stg_claims_patient') + rows: + - {person_id: 'P1', name_suffix: null, first_name: 'John', middle_name: null, last_name: 'Doe', sex: 'male', race: 'white', birth_date: '1960-03-15', death_date: null, death_flag: 0, social_security_number: null, address: '123 Main St', city: 'Anytown', state: 'NY', zip_code: '10001', county: null, latitude: null, longitude: null, phone: null, email: null, ethnicity: null, age: 63, age_group: '60-69', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', first_name: 'John', last_name: 'Doe', sex: 'male', birth_date: '1960-03-15', age: 63, age_group: '60-69', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_patient_pk_uniqueness_one_row_per_person + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__patient + description: > + Patient model should produce exactly one row per person_id + when claims-only mode is active. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + given: + - input: ref('core__stg_claims_patient') + rows: + - {person_id: 'P1', name_suffix: null, first_name: 'John', middle_name: null, last_name: 'Doe', sex: 'male', race: null, birth_date: '1960-03-15', death_date: null, death_flag: 0, social_security_number: null, address: null, city: null, state: null, zip_code: null, county: null, latitude: null, longitude: null, phone: null, email: null, ethnicity: null, age: 63, age_group: '60-69', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', name_suffix: null, first_name: 'Jane', middle_name: null, last_name: 'Smith', sex: 'female', race: null, birth_date: '1955-07-20', death_date: null, death_flag: 0, social_security_number: null, address: null, city: null, state: null, zip_code: null, county: null, latitude: null, longitude: null, phone: null, email: null, ethnicity: null, age: 68, age_group: '60-69', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', first_name: 'John', sex: 'male', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', first_name: 'Jane', sex: 'female', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__procedure — Normalization logic and terminology joins + # ========================================================================= + + - name: test_procedure_normalizes_hcpcs + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__procedure + description: > + When source_code_type is hcpcs and the code matches terminology, + normalized fields are populated via automatic mapping. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + enable_normalize_engine: false + given: + - input: ref('core__stg_claims_procedure') + rows: + - {procedure_id: 'PR1', person_id: 'P1', member_id: 'M1', patient_id: null, encounter_id: null, claim_id: 'CLM1', procedure_date: '2023-06-15', source_code_type: 'hcpcs', source_code: '99213', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, practitioner_id: 'NPI1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_pcs') + rows: [] + - input: ref('terminology__icd_9_pcs') + rows: [] + - input: ref('terminology__hcpcs_level_2') + rows: + - {hcpcs: '99213', short_description: 'Office visit est patient', long_description: 'Office or other outpatient visit for the evaluation and management of an established patient'} + - input: ref('terminology__snomed_ct') + rows: [] + expect: + rows: + - {procedure_id: 'PR1', person_id: 'P1', member_id: 'M1', patient_id: null, encounter_id: null, claim_id: 'CLM1', procedure_date: '2023-06-15', source_code_type: 'hcpcs', source_code: '99213', source_description: null, normalized_code_type: 'hcpcs', normalized_code: '99213', normalized_description: 'Office visit est patient', mapping_method: 'automatic', modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, practitioner_id: 'NPI1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_procedure_icd10_pcs_normalization + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__procedure + description: > + When source_code_type is icd-10-pcs, the ICD-10 PCS terminology + is used for normalization. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + enable_normalize_engine: false + given: + - input: ref('core__stg_claims_procedure') + rows: + - {procedure_id: 'PR2', person_id: 'P1', member_id: 'M1', patient_id: null, encounter_id: null, claim_id: 'CLM2', procedure_date: '2023-07-01', source_code_type: 'icd-10-pcs', source_code: '0DBN4ZX', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, practitioner_id: 'NPI2', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_pcs') + rows: + - {icd_10_pcs: '0DBN4ZX', description: 'Excision of sigmoid colon percutaneous endoscopic diagnostic'} + - input: ref('terminology__icd_9_pcs') + rows: [] + - input: ref('terminology__hcpcs_level_2') + rows: [] + - input: ref('terminology__snomed_ct') + rows: [] + expect: + rows: + - {procedure_id: 'PR2', person_id: 'P1', source_code_type: 'icd-10-pcs', source_code: '0DBN4ZX', normalized_code_type: 'icd-10-pcs', normalized_code: '0DBN4ZX', normalized_description: 'Excision of sigmoid colon percutaneous endoscopic diagnostic', mapping_method: 'automatic', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_procedure_no_match_yields_null_normalization + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__procedure + description: > + When source_code does not match any terminology table, + normalized fields should all be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + enable_normalize_engine: false + given: + - input: ref('core__stg_claims_procedure') + rows: + - {procedure_id: 'PR3', person_id: 'P1', member_id: 'M1', patient_id: null, encounter_id: null, claim_id: 'CLM3', procedure_date: '2023-08-01', source_code_type: 'hcpcs', source_code: 'XXXXX', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, practitioner_id: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_pcs') + rows: [] + - input: ref('terminology__icd_9_pcs') + rows: [] + - input: ref('terminology__hcpcs_level_2') + rows: [] + - input: ref('terminology__snomed_ct') + rows: [] + expect: + rows: + - {procedure_id: 'PR3', person_id: 'P1', source_code_type: 'hcpcs', source_code: 'XXXXX', normalized_code_type: null, normalized_code: null, normalized_description: null, mapping_method: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__lab_result — Normalization with order and component joins + # ========================================================================= + + - name: test_lab_result_normalizes_loinc_order + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__lab_result + description: > + When source_order_type is loinc and matches terminology, + the normalized order fields should be populated. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_lab_result') + rows: + - {lab_result_id: 'LR1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', accession_number: 'ACC1', source_order_type: 'loinc', source_order_code: '2093-3', source_order_description: 'Cholesterol total', source_component_type: null, source_component_code: null, source_component_description: null, normalized_order_type: null, normalized_order_code: null, normalized_order_description: null, normalized_component_type: null, normalized_component_code: null, normalized_component_description: null, status: 'final', result: '200', result_datetime: '2023-06-15 10:00:00', collection_datetime: '2023-06-15 09:00:00', source_units: 'mg/dL', normalized_units: null, source_reference_range_low: '100', source_reference_range_high: '240', normalized_reference_range_low: null, normalized_reference_range_high: null, source_abnormal_flag: null, normalized_abnormal_flag: null, specimen: 'blood', ordering_practitioner_id: 'NPI1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__loinc') + rows: + - {loinc: '2093-3', long_common_name: 'Cholesterol [Mass/volume] in Serum or Plasma'} + - input: ref('terminology__snomed_ct') + rows: [] + - input: ref('input_layer__lab_result') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {lab_result_id: 'LR1', person_id: 'P1', source_order_code: '2093-3', normalized_order_type: 'loinc', normalized_order_code: '2093-3', normalized_order_description: 'Cholesterol [Mass/volume] in Serum or Plasma', mapping_method: 'automatic', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_lab_result_manual_normalization_priority + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__lab_result + description: > + When normalized_order_code is already populated (manual mapping), + it takes priority over terminology lookup. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_lab_result') + rows: + - {lab_result_id: 'LR2', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', accession_number: 'ACC2', source_order_type: 'loinc', source_order_code: '2093-3', source_order_description: 'Cholesterol', source_component_type: null, source_component_code: null, source_component_description: null, normalized_order_type: 'loinc', normalized_order_code: '2093-3', normalized_order_description: 'Manual cholesterol desc', normalized_component_type: null, normalized_component_code: null, normalized_component_description: null, status: 'final', result: '210', result_datetime: '2023-06-15 10:00:00', collection_datetime: '2023-06-15 09:00:00', source_units: 'mg/dL', normalized_units: null, source_reference_range_low: null, source_reference_range_high: null, normalized_reference_range_low: null, normalized_reference_range_high: null, source_abnormal_flag: null, normalized_abnormal_flag: null, specimen: null, ordering_practitioner_id: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__loinc') + rows: + - {loinc: '2093-3', long_common_name: 'Cholesterol [Mass/volume] in Serum or Plasma'} + - input: ref('terminology__snomed_ct') + rows: [] + - input: ref('input_layer__lab_result') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {lab_result_id: 'LR2', person_id: 'P1', normalized_order_type: 'loinc', normalized_order_code: '2093-3', normalized_order_description: 'Manual cholesterol desc', mapping_method: 'manual', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__observation — Normalization with multiple code systems + # ========================================================================= + + - name: test_observation_normalizes_snomed_code + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__observation + description: > + When source_code_type is snomed-ct and matches terminology, + normalized fields should be populated. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_observation') + rows: + - {observation_id: 'OB1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', panel_id: null, observation_date: '2023-06-15', observation_type: 'vital-signs', source_code_type: 'snomed-ct', source_code: '271649006', source_description: 'Systolic BP', normalized_code_type: null, normalized_code: null, normalized_description: null, result: '120', source_units: 'mmHg', normalized_units: null, source_reference_range_low: null, source_reference_range_high: null, normalized_reference_range_low: null, normalized_reference_range_high: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + - input: ref('terminology__icd_10_pcs') + rows: [] + - input: ref('terminology__icd_9_pcs') + rows: [] + - input: ref('terminology__hcpcs_level_2') + rows: [] + - input: ref('terminology__snomed_ct') + rows: + - {snomed_ct: '271649006', description: 'Systolic blood pressure'} + - input: ref('terminology__loinc') + rows: [] + - input: ref('terminology__observation_type') + rows: + - {observation_type: 'vital-signs'} + - input: ref('input_layer__observation') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {observation_id: 'OB1', person_id: 'P1', source_code_type: 'snomed-ct', source_code: '271649006', normalized_code_type: 'snomed-ct', normalized_code: '271649006', normalized_description: 'Systolic blood pressure', mapping_method: 'automatic', observation_type: 'vital-signs', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_observation_observation_type_normalization + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__observation + description: > + The observation_type field is normalized against the + terminology__observation_type lookup table. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_observation') + rows: + - {observation_id: 'OB2', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', panel_id: null, observation_date: '2023-06-15', observation_type: 'Vital-Signs', source_code_type: 'loinc', source_code: 'XXXXX', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, result: '98.6', source_units: 'F', normalized_units: null, source_reference_range_low: null, source_reference_range_high: null, normalized_reference_range_low: null, normalized_reference_range_high: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + - input: ref('terminology__icd_10_pcs') + rows: [] + - input: ref('terminology__icd_9_pcs') + rows: [] + - input: ref('terminology__hcpcs_level_2') + rows: [] + - input: ref('terminology__snomed_ct') + rows: [] + - input: ref('terminology__loinc') + rows: [] + - input: ref('terminology__observation_type') + rows: + - {observation_type: 'vital-signs'} + - input: ref('input_layer__observation') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {observation_id: 'OB2', person_id: 'P1', observation_type: 'vital-signs', normalized_code_type: null, normalized_code: null, mapping_method: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__immunization — CVX normalization and status enrichment + # ========================================================================= + + - name: test_immunization_normalizes_cvx_code + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__immunization + description: > + When source_code_type is cvx and matches terminology, + normalized code fields should be populated. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_immunization') + rows: + - {immunization_id: 'IM1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', source_code_type: 'cvx', source_code: '208', source_description: 'COVID-19 vaccine', normalized_code_type: null, normalized_code: null, normalized_description: null, status: 'completed', status_reason: null, occurrence_date: '2023-06-15', source_dose: '0.3 mL', normalized_dose: null, lot_number: 'LOT123', body_site: null, route: null, location_id: null, practitioner_id: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__cvx') + rows: + - {cvx: '208', long_description: 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose'} + - input: ref('terminology__immunization_status') + rows: + - {status_code: 'completed', status: 'completed'} + - input: ref('terminology__immunization_status_reason') + rows: [] + - input: ref('terminology__act_site') + rows: [] + - input: ref('terminology__immunization_route_code') + rows: [] + - input: ref('input_layer__immunization') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {immunization_id: 'IM1', person_id: 'P1', source_code_type: 'cvx', source_code: '208', normalized_code_type: 'cvx', normalized_code: '208', normalized_description: 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose', mapping_method: 'automatic', status: 'completed', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_immunization_status_reason_enrichment + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__immunization + description: > + The status_reason field is enriched from the + terminology__immunization_status_reason table when matching. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_immunization') + rows: + - {immunization_id: 'IM2', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', source_code_type: 'cvx', source_code: '999', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, status: 'not-done', status_reason: 'MEDPREC', occurrence_date: '2023-06-15', source_dose: null, normalized_dose: null, lot_number: null, body_site: null, route: null, location_id: null, practitioner_id: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__cvx') + rows: [] + - input: ref('terminology__immunization_status') + rows: + - {status_code: 'not-done', status: 'not-done'} + - input: ref('terminology__immunization_status_reason') + rows: + - {reason_code: 'MEDPREC', description: 'medical precaution', code_type: 'actreason'} + - input: ref('terminology__act_site') + rows: [] + - input: ref('terminology__immunization_route_code') + rows: [] + - input: ref('input_layer__immunization') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {immunization_id: 'IM2', person_id: 'P1', normalized_code_type: null, normalized_code: null, mapping_method: null, status: 'not-done', status_reason: 'medical precaution', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__medication — NDC and RxNorm normalization chain + # ========================================================================= + + - name: test_medication_normalizes_ndc_code + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__medication + description: > + When source_code_type is ndc and matches terminology, + the ndc_code and ndc_description are populated. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_medication') + rows: + - {medication_id: 'MED1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', dispensing_date: '2023-06-15', prescribing_date: '2023-06-10', source_code_type: 'ndc', source_code: '00002323201', source_description: 'Metformin 500mg', ndc_code: null, ndc_description: null, rxnorm_code: null, rxnorm_description: null, atc_code: null, atc_description: null, route: 'oral', strength: '500mg', quantity: 60, quantity_unit: 'tablets', days_supply: 30, practitioner_id: 'NPI1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__ndc') + rows: + - {ndc: '00002323201', fda_description: 'Metformin HCL 500mg tablet', rxnorm_description: 'Metformin Hydrochloride 500 MG Oral Tablet', rxcui: '860974'} + - input: ref('terminology__rxnorm_to_atc') + rows: + - {rxcui: '860974', rxnorm_description: 'Metformin Hydrochloride 500 MG Oral Tablet', atc_3_code: 'A10BA', atc_3_name: 'Biguanides', atc_4_name: 'Metformin'} + - input: ref('input_layer__medication') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {medication_id: 'MED1', person_id: 'P1', source_code_type: 'ndc', source_code: '00002323201', ndc_code: '00002323201', ndc_description: 'Metformin HCL 500mg tablet', ndc_mapping_method: 'automatic', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_medication_rxnorm_atc_chain_from_ndc + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__medication + description: > + When an NDC matches, the rxnorm and ATC codes are resolved + through the NDC-to-RxNorm-to-ATC chain. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_medication') + rows: + - {medication_id: 'MED2', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', dispensing_date: '2023-06-15', prescribing_date: null, source_code_type: 'ndc', source_code: '00002323201', source_description: null, ndc_code: null, ndc_description: null, rxnorm_code: null, rxnorm_description: null, atc_code: null, atc_description: null, route: null, strength: null, quantity: null, quantity_unit: null, days_supply: null, practitioner_id: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__ndc') + rows: + - {ndc: '00002323201', fda_description: 'Metformin HCL 500mg', rxnorm_description: 'Metformin 500 MG', rxcui: '860974'} + - input: ref('terminology__rxnorm_to_atc') + rows: + - {rxcui: '860974', rxnorm_description: 'Metformin 500 MG', atc_3_code: 'A10BA', atc_3_name: 'Biguanides', atc_4_name: 'Metformin'} + - input: ref('input_layer__medication') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {medication_id: 'MED2', person_id: 'P1', ndc_code: '00002323201', rxnorm_code: '860974', atc_code: 'A10BA', atc_description: 'Biguanides', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__appointment — Normalization with multiple terminology joins + # ========================================================================= + + - name: test_appointment_no_terminology_match + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__appointment + description: > + When source codes do not match any terminology tables, + normalized fields should fall back to the staging values or null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + enable_normalize_engine: false + given: + - input: ref('core__stg_clinical_appointment') + rows: + - {appointment_id: 'AP2', person_id: 'P1', patient_id: 'PT1', encounter_id: null, source_appointment_type_code: 'CUSTOM_TYPE', source_appointment_type_description: 'Custom', normalized_appointment_type_code: null, normalized_appointment_type_description: null, start_datetime: '2023-07-01 14:00:00', end_datetime: '2023-07-01 15:00:00', duration: 60, location_id: null, practitioner_id: null, source_status: 'custom_status', normalized_status: null, appointment_specialty: null, reason: null, source_reason_code_type: null, source_reason_code: null, source_reason_description: null, normalized_reason_code_type: null, normalized_reason_code: null, normalized_reason_description: null, cancellation_reason: null, source_cancellation_reason_code_type: null, source_cancellation_reason_code: null, source_cancellation_reason_description: null, normalized_cancellation_reason_code_type: null, normalized_cancellation_reason_code: null, normalized_cancellation_reason_description: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__appointment_cancellation_reason') + rows: [] + - input: ref('terminology__appointment_status') + rows: [] + - input: ref('terminology__appointment_type') + rows: [] + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('terminology__icd_9_cm') + rows: [] + - input: ref('terminology__snomed_ct') + rows: [] + - input: ref('input_layer__appointment') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {appointment_id: 'AP2', person_id: 'P1', normalized_appointment_type_code: null, normalized_appointment_type_description: null, normalized_status: null, normalized_reason_code_type: null, normalized_reason_code: null, mapping_method: null, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__location — Passthrough (claims-only path) + # ========================================================================= + + - name: test_location_claims_only_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__location + description: > + Location model in claims-only mode passes through from staging. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + given: + - input: ref('core__stg_claims_location') + rows: + - {location_id: 'LOC1', npi: '1234567890', name: 'General Hospital', facility_type: null, parent_organization: 'Health System', address: '100 Hospital Dr', city: 'Anytown', state: 'NY', zip_code: '10001', latitude: null, longitude: null, data_source: null, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {location_id: 'LOC1', npi: '1234567890', name: 'General Hospital', city: 'Anytown', state: 'NY', zip_code: '10001', data_source: null, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_location_clinical_only_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__location + description: > + Location model in clinical-only mode passes through from clinical staging. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + claims_enabled: false + given: + - input: ref('core__stg_clinical_location') + rows: + - {location_id: 'CLOC1', npi: '9876543210', name: 'Community Clinic', facility_type: 'clinic', parent_organization: null, address: '200 Clinic Rd', city: 'Smalltown', state: 'CA', zip_code: '90001', latitude: 34.05, longitude: -118.25, data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__location') + rows: + - {location_id: 'L1', data_source: 'src1'} + expect: + rows: + - {location_id: 'CLOC1', npi: '9876543210', name: 'Community Clinic', facility_type: 'clinic', city: 'Smalltown', state: 'CA', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__practitioner — Passthrough (claims-only and clinical-only paths) + # ========================================================================= + + - name: test_practitioner_claims_only_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__practitioner + description: > + Practitioner model in claims-only mode passes through from staging. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + given: + - input: ref('core__stg_claims_practitioner') + rows: + - {practitioner_id: 'PRAC1', npi: '1111111111', first_name: 'Alice', last_name: 'Johnson', practice_affiliation: 'Big Health System', specialty: 'Internal Medicine', sub_specialty: null, data_source: null, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {practitioner_id: 'PRAC1', npi: '1111111111', first_name: 'Alice', last_name: 'Johnson', specialty: 'Internal Medicine', data_source: null, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_practitioner_clinical_only_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__practitioner + description: > + Practitioner model in clinical-only mode passes through from clinical staging. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + claims_enabled: false + given: + - input: ref('core__stg_clinical_practitioner') + rows: + - {practitioner_id: 'CPRAC1', npi: '2222222222', first_name: 'Bob', last_name: 'Williams', practice_affiliation: null, specialty: 'Cardiology', sub_specialty: 'Interventional', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('input_layer__practitioner') + rows: + - {practitioner_id: 'PRAC1', data_source: 'src1'} + expect: + rows: + - {practitioner_id: 'CPRAC1', npi: '2222222222', first_name: 'Bob', last_name: 'Williams', specialty: 'Cardiology', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__encounter — Claims-only passthrough + # ========================================================================= + + - name: test_encounter_claims_only_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__encounter + description: > + Encounter model in claims-only mode passes through from staging. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + given: + - input: ref('core__stg_claims_encounter') + rows: + - {encounter_id: 'ENC1', person_id: 'P1', encounter_type: 'acute inpatient', encounter_group: 'inpatient', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, admit_source_code: '1', admit_source_description: null, admit_type_code: '1', admit_type_description: null, discharge_disposition_code: '01', discharge_disposition_description: null, attending_provider_id: null, attending_provider_name: null, facility_npi: 'NPI3', facility_name: 'General Hospital', facility_type: 'acute care hospital', observation_flag: 0, lab_flag: 1, dme_flag: 0, ambulance_flag: 0, pharmacy_flag: 1, ed_flag: 0, delivery_flag: 0, delivery_type: null, newborn_flag: 0, nicu_flag: 0, snf_part_b_flag: 0, primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'J18.9', primary_diagnosis_description: 'Pneumonia', drg_code_type: 'ms-drg', drg_code: '193', drg_description: null, paid_amount: 15000.00, allowed_amount: 14000.00, charge_amount: 20000.00, claim_count: 2, inst_claim_count: 1, prof_claim_count: 1, source_model: null, encounter_source_type: 'claim', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'ENC1', person_id: 'P1', encounter_type: 'acute inpatient', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, paid_amount: 15000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_encounter_pk_uniqueness_multiple_encounters + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__encounter + description: > + Multiple encounters for the same person should each have unique + encounter_ids and be preserved. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + given: + - input: ref('core__stg_claims_encounter') + rows: + - {encounter_id: 'ENC1', person_id: 'P1', encounter_type: 'acute inpatient', encounter_group: 'inpatient', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, admit_source_code: null, admit_source_description: null, admit_type_code: null, admit_type_description: null, discharge_disposition_code: null, discharge_disposition_description: null, attending_provider_id: null, attending_provider_name: null, facility_npi: null, facility_name: null, facility_type: null, observation_flag: 0, lab_flag: 0, dme_flag: 0, ambulance_flag: 0, pharmacy_flag: 0, ed_flag: 0, delivery_flag: 0, delivery_type: null, newborn_flag: 0, nicu_flag: 0, snf_part_b_flag: 0, primary_diagnosis_code_type: null, primary_diagnosis_code: null, primary_diagnosis_description: null, drg_code_type: null, drg_code: null, drg_description: null, paid_amount: 10000.00, allowed_amount: null, charge_amount: null, claim_count: 1, inst_claim_count: 1, prof_claim_count: 0, source_model: null, encounter_source_type: 'claim', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'ENC2', person_id: 'P1', encounter_type: 'office visit', encounter_group: 'outpatient', encounter_start_date: '2023-07-15', encounter_end_date: '2023-07-15', length_of_stay: 0, admit_source_code: null, admit_source_description: null, admit_type_code: null, admit_type_description: null, discharge_disposition_code: null, discharge_disposition_description: null, attending_provider_id: null, attending_provider_name: null, facility_npi: null, facility_name: null, facility_type: null, observation_flag: 0, lab_flag: 0, dme_flag: 0, ambulance_flag: 0, pharmacy_flag: 0, ed_flag: 0, delivery_flag: 0, delivery_type: null, newborn_flag: 0, nicu_flag: 0, snf_part_b_flag: 0, primary_diagnosis_code_type: null, primary_diagnosis_code: null, primary_diagnosis_description: null, drg_code_type: null, drg_code: null, drg_description: null, paid_amount: 200.00, allowed_amount: null, charge_amount: null, claim_count: 1, inst_claim_count: 0, prof_claim_count: 1, source_model: null, encounter_source_type: 'claim', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'ENC1', person_id: 'P1', encounter_type: 'acute inpatient', paid_amount: 10000.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'ENC2', person_id: 'P1', encounter_type: 'office visit', paid_amount: 200.00, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # core__person_id_crosswalk — Claims-only distinct crosswalk + # ========================================================================= + + - name: test_person_id_crosswalk_claims_only + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__person_id_crosswalk + description: > + In claims-only mode, produces distinct person_id / member_id / payer + combinations from eligibility data. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P2', member_id: 'M2', payer: 'MCR', plan: 'PlanB', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', patient_id: null, member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', patient_id: null, member_id: 'M2', payer: 'MCR', plan: 'PlanB', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_person_id_crosswalk_deduplicates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__person_id_crosswalk + description: > + Duplicate rows in eligibility are deduplicated in the crosswalk output + (SELECT DISTINCT). + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', patient_id: null, member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_person_id_crosswalk_claims_and_clinical_keep_both_sources + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__person_id_crosswalk + description: > + In combined mode, claims and clinical rows are deduplicated within each + source family, but both source families still contribute rows. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: true + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'claims_src'} + - {person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'claims_src'} + - input: ref('input_layer__patient') + rows: + - {person_id: 'P2', patient_id: 'PAT2', data_source: 'clinical_src'} + - {person_id: 'P2', patient_id: 'PAT2', data_source: 'clinical_src'} + expect: + rows: + - {person_id: 'P1', patient_id: null, member_id: 'M1', payer: 'MCR', plan: 'PlanA', data_source: 'claims_src', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', patient_id: 'PAT2', member_id: null, payer: null, plan: null, data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_claims_condition + # ========================================================================= + + - name: test_stg_claims_condition_joins_diagnosis_and_poa + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_claims_condition + description: > + The staging model joins diagnosis codes with medical claims + and produces a condition_id from the concatenated key fields. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('normalized_input__int_diagnosis_code_intermediate') + rows: + - {claim_id: 'CLM1', data_source: 'src1', diagnosis_code_type: 'icd-10-cm', diagnosis_code: 'E1165', column_name: 'diagnosis_code_1'} + - input: ref('normalized_input__int_present_on_admit_voting') + rows: + - {claim_id: 'CLM1', data_source: 'src1', column_name: 'present_on_admit_code_1', normalized_code: 'Y'} + - input: ref('normalized_input__medical_claim') + rows: + - {claim_id: 'CLM1', claim_line_number: 1, data_source: 'src1', payer: 'MCR', person_id: 'P1', member_id: 'M1', admission_date: '2023-06-01', claim_start_date: '2023-06-01', discharge_date: '2023-06-05', claim_end_date: '2023-06-05'} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'E1165', short_description: 'Type 2 DM w hyperglycemia', long_description: 'Type 2 diabetes mellitus with hyperglycemia'} + - input: ref('terminology__icd_9_cm') + rows: [] + - input: ref('terminology__present_on_admission') + rows: + - {present_on_admit_code: 'Y', present_on_admit_description: 'Yes'} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', claim_id: 'CLM1', source_code_type: 'icd-10-cm', source_code: 'E1165', condition_type: 'discharge_diagnosis', condition_rank: 1, present_on_admit_code: 'Y', present_on_admit_description: 'Yes', normalized_code_type: 'icd-10-cm', normalized_code: 'E1165', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_claims_condition_null_diagnosis_filtered + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_claims_condition + description: > + Rows where diagnosis_code is null should be filtered out + by the WHERE source_code IS NOT NULL clause. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('normalized_input__int_diagnosis_code_intermediate') + rows: + - {claim_id: 'CLM1', data_source: 'src1', diagnosis_code_type: 'icd-10-cm', diagnosis_code: null, column_name: 'diagnosis_code_1'} + - {claim_id: 'CLM2', data_source: 'src1', diagnosis_code_type: 'icd-10-cm', diagnosis_code: 'J189', column_name: 'diagnosis_code_1'} + - input: ref('normalized_input__int_present_on_admit_voting') + rows: [] + - input: ref('normalized_input__medical_claim') + rows: + - {claim_id: 'CLM1', claim_line_number: 1, data_source: 'src1', payer: 'MCR', person_id: 'P1', member_id: 'M1', admission_date: null, claim_start_date: '2023-06-01', discharge_date: null, claim_end_date: '2023-06-01'} + - {claim_id: 'CLM2', claim_line_number: 1, data_source: 'src1', payer: 'MCR', person_id: 'P2', member_id: 'M2', admission_date: null, claim_start_date: '2023-07-01', discharge_date: null, claim_end_date: '2023-07-01'} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'J189', short_description: 'Pneumonia unspecified organism', long_description: 'Pneumonia, unspecified organism'} + - input: ref('terminology__icd_9_cm') + rows: [] + - input: ref('terminology__present_on_admission') + rows: [] + expect: + rows: + - {person_id: 'P2', claim_id: 'CLM2', source_code: 'J189', source_code_type: 'icd-10-cm', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_claims_eligibility + # ========================================================================= + + - name: test_stg_claims_eligibility_generates_eligibility_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_claims_eligibility + description: > + The eligibility_id is generated from a concatenation of key fields. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', subscriber_id: null, birth_date: '1960-01-01', death_date: null, enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', payer_type: 'medicare', plan: 'PlanA', original_reason_entitlement_code: '0', dual_status_code: null, medicare_status_code: '10', enrollment_status: null, hospice_flag: null, snp_type: null, medicaid_indicator: null, long_term_institutional_flag: null, part_d_raf_type: null, low_income_subsidy_indicator: null, metal_level: null, csr_indicator: null, enrollment_duration_months: 12, esrd_status: null, transplant_duration_months: null, subscriber_relation: null, group_id: null, group_name: null, normalized_state_name: null, fips_state_code: null, fips_state_abbreviation: null, data_source: 'src1', file_date: null, file_name: null, ingest_datetime: null, gender: null, race: null, state: null, zip_code: null, address: null, city: null, phone: null, email: null, first_name: null, middle_name: null, last_name: null, name_suffix: null, social_security_number: null, ethnicity: null, death_flag: null} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', payer_type: 'medicare', plan: 'PlanA', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_claims_eligibility_preserves_all_enrollment_periods + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_claims_eligibility + description: > + Multiple enrollment periods for the same person are all preserved. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', subscriber_id: null, birth_date: '1960-01-01', death_date: null, enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-06-30', payer: 'MCR', payer_type: 'medicare', plan: 'PlanA', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, hospice_flag: null, snp_type: null, medicaid_indicator: null, long_term_institutional_flag: null, part_d_raf_type: null, low_income_subsidy_indicator: null, metal_level: null, csr_indicator: null, enrollment_duration_months: 6, esrd_status: null, transplant_duration_months: null, subscriber_relation: null, group_id: null, group_name: null, normalized_state_name: null, fips_state_code: null, fips_state_abbreviation: null, data_source: 'src1', file_date: null, file_name: null, ingest_datetime: null, gender: null, race: null, state: null, zip_code: null, address: null, city: null, phone: null, email: null, first_name: null, middle_name: null, last_name: null, name_suffix: null, social_security_number: null, ethnicity: null, death_flag: null} + - {person_id: 'P1', member_id: 'M1', subscriber_id: null, birth_date: '1960-01-01', death_date: null, enrollment_start_date: '2023-07-01', enrollment_end_date: '2023-12-31', payer: 'MCR', payer_type: 'medicare', plan: 'PlanB', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, hospice_flag: null, snp_type: null, medicaid_indicator: null, long_term_institutional_flag: null, part_d_raf_type: null, low_income_subsidy_indicator: null, metal_level: null, csr_indicator: null, enrollment_duration_months: 6, esrd_status: null, transplant_duration_months: null, subscriber_relation: null, group_id: null, group_name: null, normalized_state_name: null, fips_state_code: null, fips_state_abbreviation: null, data_source: 'src1', file_date: null, file_name: null, ingest_datetime: null, gender: null, race: null, state: null, zip_code: null, address: null, city: null, phone: null, email: null, first_name: null, middle_name: null, last_name: null, name_suffix: null, social_security_number: null, ethnicity: null, death_flag: null} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-06-30', payer: 'MCR', plan: 'PlanA', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', enrollment_start_date: '2023-07-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanB', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_claims_member_months + # ========================================================================= + + # ========================================================================= + # STAGING MODELS — core__stg_claims_patient + # ========================================================================= + + - name: test_stg_claims_patient_picks_latest_enrollment + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_claims_patient + description: > + The staging model picks the row with the latest enrollment_end_date + per person_id (row_sequence = 1). + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', subscriber_id: null, birth_date: '1960-01-01', death_date: null, enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-06-30', payer: 'MCR', payer_type: 'medicare', plan: 'PlanA', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, hospice_flag: null, snp_type: null, medicaid_indicator: null, long_term_institutional_flag: null, part_d_raf_type: null, low_income_subsidy_indicator: null, metal_level: null, csr_indicator: null, enrollment_duration_months: 6, esrd_status: null, transplant_duration_months: null, subscriber_relation: null, group_id: null, group_name: null, normalized_state_name: null, fips_state_code: null, fips_state_abbreviation: null, data_source: 'src1', file_date: null, file_name: null, ingest_datetime: null, gender: 'male', race: null, state: 'NY', zip_code: '10001', address: null, city: 'Anytown', phone: null, email: null, first_name: 'John', middle_name: null, last_name: 'Doe', name_suffix: null, social_security_number: null, ethnicity: null, death_flag: 0} + - {person_id: 'P1', member_id: 'M1', subscriber_id: null, birth_date: '1960-01-01', death_date: null, enrollment_start_date: '2023-07-01', enrollment_end_date: '2023-12-31', payer: 'MCR', payer_type: 'medicare', plan: 'PlanB', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, hospice_flag: null, snp_type: null, medicaid_indicator: null, long_term_institutional_flag: null, part_d_raf_type: null, low_income_subsidy_indicator: null, metal_level: null, csr_indicator: null, enrollment_duration_months: 6, esrd_status: null, transplant_duration_months: null, subscriber_relation: null, group_id: null, group_name: null, normalized_state_name: null, fips_state_code: null, fips_state_abbreviation: null, data_source: 'src1', file_date: null, file_name: null, ingest_datetime: null, gender: 'male', race: null, state: 'NY', zip_code: '10001', address: null, city: 'Anytown', phone: null, email: null, first_name: 'John', middle_name: null, last_name: 'Doe', name_suffix: null, social_security_number: null, ethnicity: null, death_flag: 0} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', first_name: 'John', last_name: 'Doe', sex: 'male', birth_date: '1960-01-01', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_claims_patient_null_enrollment_end_date_treated_as_far_future + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_claims_patient + description: > + A null enrollment_end_date is treated as 2050-01-01 for sorting, + so it should be selected as the latest record. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('normalized_input__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', subscriber_id: null, birth_date: '1960-01-01', death_date: null, enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', payer_type: 'medicare', plan: 'PlanA', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, hospice_flag: null, snp_type: null, medicaid_indicator: null, long_term_institutional_flag: null, part_d_raf_type: null, low_income_subsidy_indicator: null, metal_level: null, csr_indicator: null, enrollment_duration_months: null, esrd_status: null, transplant_duration_months: null, subscriber_relation: null, group_id: null, group_name: null, normalized_state_name: null, fips_state_code: null, fips_state_abbreviation: null, data_source: 'src1', file_date: null, file_name: null, ingest_datetime: null, gender: 'female', race: null, state: 'CA', zip_code: '90001', address: '456 Oak Ave', city: 'Los Angeles', phone: null, email: null, first_name: 'Jane', middle_name: null, last_name: 'Smith', name_suffix: null, social_security_number: null, ethnicity: null, death_flag: 0} + - {person_id: 'P1', member_id: 'M1', subscriber_id: null, birth_date: '1960-01-01', death_date: null, enrollment_start_date: '2024-01-01', enrollment_end_date: null, payer: 'MCR', payer_type: 'medicare', plan: 'PlanB', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, hospice_flag: null, snp_type: null, medicaid_indicator: null, long_term_institutional_flag: null, part_d_raf_type: null, low_income_subsidy_indicator: null, metal_level: null, csr_indicator: null, enrollment_duration_months: null, esrd_status: null, transplant_duration_months: null, subscriber_relation: null, group_id: null, group_name: null, normalized_state_name: null, fips_state_code: null, fips_state_abbreviation: null, data_source: 'src1', file_date: null, file_name: null, ingest_datetime: null, gender: 'female', race: null, state: 'CA', zip_code: '90002', address: '789 Pine St', city: 'LA', phone: null, email: null, first_name: 'Jane', middle_name: 'M', last_name: 'Smith', name_suffix: null, social_security_number: null, ethnicity: null, death_flag: 0} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', first_name: 'Jane', last_name: 'Smith', sex: 'female', city: 'LA', zip_code: '90002', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_clinical_condition + # ========================================================================= + + - name: test_stg_clinical_condition_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_condition + description: > + Clinical condition staging passes through all columns from the input layer. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__condition') + rows: + - {condition_id: 'CC1', payer: null, person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', claim_id: null, recorded_date: '2023-06-15', onset_date: '2023-06-10', resolved_date: null, status: 'active', condition_type: 'encounter-diagnosis', source_code_type: 'icd-10-cm', source_code: 'E11.65', source_description: 'Type 2 DM with hyperglycemia', normalized_code_type: null, normalized_code: null, normalized_description: null, condition_rank: null, present_on_admit_code: null, present_on_admit_description: null, data_source: 'clinical_src'} + expect: + rows: + - {condition_id: 'CC1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', source_code_type: 'icd-10-cm', source_code: 'E11.65', status: 'active', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_clinical_condition_multiple_conditions + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_condition + description: > + Multiple clinical conditions for same patient are all passed through + maintaining unique condition_ids. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__condition') + rows: + - {condition_id: 'CC1', payer: null, person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', claim_id: null, recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', condition_type: 'problem-list-item', source_code_type: 'icd-10-cm', source_code: 'E11.65', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, condition_rank: null, present_on_admit_code: null, present_on_admit_description: null, data_source: 'clinical_src'} + - {condition_id: 'CC2', payer: null, person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', claim_id: null, recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', condition_type: 'problem-list-item', source_code_type: 'icd-10-cm', source_code: 'I10', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, condition_rank: null, present_on_admit_code: null, present_on_admit_description: null, data_source: 'clinical_src'} + expect: + rows: + - {condition_id: 'CC1', person_id: 'P1', source_code: 'E11.65', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - {condition_id: 'CC2', person_id: 'P1', source_code: 'I10', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_clinical_patient + # ========================================================================= + + - name: test_stg_clinical_patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_patient + description: > + Clinical patient staging passes through columns and computes age. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__patient') + rows: + - {person_id: 'P1', name_suffix: null, first_name: 'Alice', middle_name: null, last_name: 'Brown', sex: 'female', race: 'white', birth_date: '1990-06-15', death_date: null, death_flag: 0, social_security_number: null, address: null, city: null, state: null, zip_code: null, county: null, latitude: null, longitude: null, phone: null, email: null, ethnicity: null, data_source: 'clinical_src'} + expect: + rows: + - {person_id: 'P1', first_name: 'Alice', last_name: 'Brown', sex: 'female', birth_date: '1990-06-15', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_clinical_patient_age_group_calculation + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_patient + description: > + The age_group is correctly calculated based on birth_date relative + to tuva_last_run. A person born 1960-01-01 with tuva_last_run + 2024-01-01 should be age 64, in the 60-69 group. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__patient') + rows: + - {person_id: 'P1', name_suffix: null, first_name: 'Bob', middle_name: null, last_name: 'Jones', sex: 'male', race: null, birth_date: '1960-01-01', death_date: null, death_flag: 0, social_security_number: null, address: null, city: null, state: null, zip_code: null, county: null, latitude: null, longitude: null, phone: null, email: null, ethnicity: null, data_source: 'clinical_src'} + expect: + rows: + - {person_id: 'P1', birth_date: '1960-01-01', age: 64, age_group: '60-69', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_clinical_encounter + # ========================================================================= + + - name: test_stg_clinical_encounter_sets_clinical_group + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_encounter + description: > + Clinical encounter staging sets encounter_group to 'clinical' + and encounter_source_type to 'clinical'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__encounter') + rows: + - {encounter_id: 'CENC1', person_id: 'P1', encounter_type: 'office visit', encounter_start_date: '2023-06-15', encounter_end_date: '2023-06-15', length_of_stay: 0, admit_source_code: null, admit_source_description: null, admit_type_code: null, admit_type_description: null, discharge_disposition_code: null, discharge_disposition_description: null, attending_provider_id: 'NPI1', attending_provider_name: 'Dr Smith', facility_npi: null, facility_name: null, primary_diagnosis_code_type: null, primary_diagnosis_code: null, primary_diagnosis_description: null, drg_code_type: null, drg_code: null, drg_description: null, paid_amount: null, allowed_amount: null, charge_amount: null, data_source: 'clinical_src'} + expect: + rows: + - {encounter_id: 'CENC1', person_id: 'P1', encounter_type: 'office visit', encounter_group: 'clinical', encounter_source_type: 'clinical', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_clinical_encounter_nulls_claims_only_flags + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_encounter + description: > + Clinical encounters set claims-specific flags (observation_flag, + lab_flag, etc.) to null since they are not applicable. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__encounter') + rows: + - {encounter_id: 'CENC2', person_id: 'P1', encounter_type: 'inpatient', encounter_start_date: '2023-07-01', encounter_end_date: '2023-07-05', length_of_stay: 4, admit_source_code: '1', admit_source_description: null, admit_type_code: null, admit_type_description: null, discharge_disposition_code: null, discharge_disposition_description: null, attending_provider_id: null, attending_provider_name: null, facility_npi: 'NPI3', facility_name: 'Hospital', primary_diagnosis_code_type: null, primary_diagnosis_code: null, primary_diagnosis_description: null, drg_code_type: null, drg_code: null, drg_description: null, paid_amount: null, allowed_amount: null, charge_amount: null, data_source: 'clinical_src'} + expect: + rows: + - {encounter_id: 'CENC2', person_id: 'P1', encounter_group: 'clinical', observation_flag: null, lab_flag: null, dme_flag: null, ambulance_flag: null, pharmacy_flag: null, ed_flag: null, delivery_flag: null, newborn_flag: null, nicu_flag: null, snf_part_b_flag: null, claim_count: null, inst_claim_count: null, prof_claim_count: null, source_model: null, encounter_source_type: 'clinical', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_clinical_lab_result + # ========================================================================= + + - name: test_stg_clinical_lab_result_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_lab_result + description: > + Clinical lab result staging passes through all columns from the input layer. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__lab_result') + rows: + - {lab_result_id: 'LR1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', accession_number: 'ACC1', source_order_type: 'loinc', source_order_code: '2093-3', source_order_description: 'Cholesterol', source_component_type: null, source_component_code: null, source_component_description: null, normalized_order_type: null, normalized_order_code: null, normalized_order_description: null, normalized_component_type: null, normalized_component_code: null, normalized_component_description: null, status: 'final', result: '200', result_datetime: '2023-06-15 10:00:00', collection_datetime: '2023-06-15 09:00:00', source_units: 'mg/dL', normalized_units: null, source_reference_range_low: '100', source_reference_range_high: '240', normalized_reference_range_low: null, normalized_reference_range_high: null, source_abnormal_flag: null, normalized_abnormal_flag: null, specimen: 'blood', ordering_practitioner_id: 'NPI1', data_source: 'clinical_src'} + expect: + rows: + - {lab_result_id: 'LR1', person_id: 'P1', source_order_code: '2093-3', result: '200', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_clinical_lab_result_multiple_results + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_lab_result + description: > + Multiple lab results maintain unique lab_result_ids. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__lab_result') + rows: + - {lab_result_id: 'LR1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', accession_number: 'ACC1', source_order_type: 'loinc', source_order_code: '2093-3', source_order_description: null, source_component_type: null, source_component_code: null, source_component_description: null, normalized_order_type: null, normalized_order_code: null, normalized_order_description: null, normalized_component_type: null, normalized_component_code: null, normalized_component_description: null, status: 'final', result: '200', result_datetime: null, collection_datetime: null, source_units: 'mg/dL', normalized_units: null, source_reference_range_low: null, source_reference_range_high: null, normalized_reference_range_low: null, normalized_reference_range_high: null, source_abnormal_flag: null, normalized_abnormal_flag: null, specimen: null, ordering_practitioner_id: null, data_source: 'clinical_src'} + - {lab_result_id: 'LR2', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', accession_number: 'ACC1', source_order_type: 'loinc', source_order_code: '2571-8', source_order_description: null, source_component_type: null, source_component_code: null, source_component_description: null, normalized_order_type: null, normalized_order_code: null, normalized_order_description: null, normalized_component_type: null, normalized_component_code: null, normalized_component_description: null, status: 'final', result: '90', result_datetime: null, collection_datetime: null, source_units: 'mg/dL', normalized_units: null, source_reference_range_low: null, source_reference_range_high: null, normalized_reference_range_low: null, normalized_reference_range_high: null, source_abnormal_flag: null, normalized_abnormal_flag: null, specimen: null, ordering_practitioner_id: null, data_source: 'clinical_src'} + expect: + rows: + - {lab_result_id: 'LR1', person_id: 'P1', source_order_code: '2093-3', result: '200', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - {lab_result_id: 'LR2', person_id: 'P1', source_order_code: '2571-8', result: '90', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_clinical_medication + # ========================================================================= + + - name: test_stg_clinical_medication_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_medication + description: > + Clinical medication staging passes through all columns. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__medication') + rows: + - {medication_id: 'MED1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', dispensing_date: '2023-06-15', prescribing_date: '2023-06-10', source_code_type: 'ndc', source_code: '00002323201', source_description: 'Metformin', ndc_code: null, ndc_description: null, rxnorm_code: null, rxnorm_description: null, atc_code: null, atc_description: null, route: 'oral', strength: '500mg', quantity: 60, quantity_unit: 'tablets', days_supply: 30, practitioner_id: 'NPI1', data_source: 'clinical_src'} + expect: + rows: + - {medication_id: 'MED1', person_id: 'P1', source_code_type: 'ndc', source_code: '00002323201', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_clinical_medication_preserves_all_records + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_medication + description: > + Multiple medication records are all passed through, preserving PK uniqueness. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__medication') + rows: + - {medication_id: 'MED1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', dispensing_date: '2023-06-15', prescribing_date: null, source_code_type: 'ndc', source_code: '11111111111', source_description: null, ndc_code: null, ndc_description: null, rxnorm_code: null, rxnorm_description: null, atc_code: null, atc_description: null, route: null, strength: null, quantity: null, quantity_unit: null, days_supply: null, practitioner_id: null, data_source: 'clinical_src'} + - {medication_id: 'MED2', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', dispensing_date: '2023-06-15', prescribing_date: null, source_code_type: 'rxnorm', source_code: '860974', source_description: null, ndc_code: null, ndc_description: null, rxnorm_code: null, rxnorm_description: null, atc_code: null, atc_description: null, route: null, strength: null, quantity: null, quantity_unit: null, days_supply: null, practitioner_id: null, data_source: 'clinical_src'} + expect: + rows: + - {medication_id: 'MED1', person_id: 'P1', source_code: '11111111111', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - {medication_id: 'MED2', person_id: 'P1', source_code: '860974', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_clinical_observation + # ========================================================================= + + - name: test_stg_clinical_observation_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_observation + description: > + Clinical observation staging passes through all columns. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__observation') + rows: + - {observation_id: 'OB1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', panel_id: null, observation_date: '2023-06-15', observation_type: 'vital-signs', source_code_type: 'loinc', source_code: '8480-6', source_description: 'Systolic BP', normalized_code_type: null, normalized_code: null, normalized_description: null, result: '120', source_units: 'mmHg', normalized_units: null, source_reference_range_low: null, source_reference_range_high: null, normalized_reference_range_low: null, normalized_reference_range_high: null, data_source: 'clinical_src'} + expect: + rows: + - {observation_id: 'OB1', person_id: 'P1', observation_type: 'vital-signs', source_code: '8480-6', result: '120', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_clinical_observation_multiple_obs_preserved + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_observation + description: > + Multiple observations for same encounter are all preserved. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__observation') + rows: + - {observation_id: 'OB1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', panel_id: null, observation_date: '2023-06-15', observation_type: 'vital-signs', source_code_type: 'loinc', source_code: '8480-6', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, result: '120', source_units: 'mmHg', normalized_units: null, source_reference_range_low: null, source_reference_range_high: null, normalized_reference_range_low: null, normalized_reference_range_high: null, data_source: 'clinical_src'} + - {observation_id: 'OB2', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', panel_id: null, observation_date: '2023-06-15', observation_type: 'vital-signs', source_code_type: 'loinc', source_code: '8462-4', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, result: '80', source_units: 'mmHg', normalized_units: null, source_reference_range_low: null, source_reference_range_high: null, normalized_reference_range_low: null, normalized_reference_range_high: null, data_source: 'clinical_src'} + expect: + rows: + - {observation_id: 'OB1', source_code: '8480-6', result: '120', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - {observation_id: 'OB2', source_code: '8462-4', result: '80', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_clinical_immunization + # ========================================================================= + + - name: test_stg_clinical_immunization_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_immunization + description: > + Clinical immunization staging passes through all columns. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__immunization') + rows: + - {immunization_id: 'IM1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', source_code_type: 'cvx', source_code: '208', source_description: 'COVID-19 vaccine', normalized_code_type: null, normalized_code: null, normalized_description: null, status: 'completed', status_reason: null, occurrence_date: '2023-06-15', source_dose: '0.3 mL', normalized_dose: null, lot_number: 'LOT123', body_site: null, route: null, location_id: null, practitioner_id: null, data_source: 'clinical_src'} + expect: + rows: + - {immunization_id: 'IM1', person_id: 'P1', source_code: '208', status: 'completed', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_clinical_immunization_multiple_vaccines + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_immunization + description: > + Multiple immunizations are all preserved with unique IDs. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__immunization') + rows: + - {immunization_id: 'IM1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', source_code_type: 'cvx', source_code: '208', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, status: 'completed', status_reason: null, occurrence_date: '2023-01-15', source_dose: null, normalized_dose: null, lot_number: null, body_site: null, route: null, location_id: null, practitioner_id: null, data_source: 'clinical_src'} + - {immunization_id: 'IM2', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC2', source_code_type: 'cvx', source_code: '140', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, status: 'completed', status_reason: null, occurrence_date: '2023-09-01', source_dose: null, normalized_dose: null, lot_number: null, body_site: null, route: null, location_id: null, practitioner_id: null, data_source: 'clinical_src'} + expect: + rows: + - {immunization_id: 'IM1', source_code: '208', occurrence_date: '2023-01-15', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - {immunization_id: 'IM2', source_code: '140', occurrence_date: '2023-09-01', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_clinical_procedure + # ========================================================================= + + - name: test_stg_clinical_procedure_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_procedure + description: > + Clinical procedure staging passes through all columns. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__procedure') + rows: + - {procedure_id: 'CPR1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', claim_id: null, procedure_date: '2023-06-15', source_code_type: 'hcpcs', source_code: '99213', source_description: 'Office visit', normalized_code_type: null, normalized_code: null, normalized_description: null, modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, practitioner_id: 'NPI1', data_source: 'clinical_src'} + expect: + rows: + - {procedure_id: 'CPR1', person_id: 'P1', source_code: '99213', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_clinical_procedure_sets_member_id_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_procedure + description: > + Clinical procedures set member_id to null since it is claims-only. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__procedure') + rows: + - {procedure_id: 'CPR2', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', claim_id: null, procedure_date: '2023-07-01', source_code_type: 'icd-10-pcs', source_code: '0DBN4ZX', source_description: null, normalized_code_type: null, normalized_code: null, normalized_description: null, modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, practitioner_id: null, data_source: 'clinical_src'} + expect: + rows: + - {procedure_id: 'CPR2', person_id: 'P1', member_id: null, patient_id: 'PT1', source_code: '0DBN4ZX', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_clinical_location + # ========================================================================= + + - name: test_stg_clinical_location_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_location + description: > + Clinical location staging passes through all columns. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__location') + rows: + - {location_id: 'CLOC1', npi: '9876543210', name: 'Community Clinic', facility_type: 'clinic', parent_organization: null, address: '200 Clinic Rd', city: 'Smalltown', state: 'CA', zip_code: '90001', latitude: 34.05, longitude: -118.25, data_source: 'clinical_src'} + expect: + rows: + - {location_id: 'CLOC1', npi: '9876543210', name: 'Community Clinic', city: 'Smalltown', state: 'CA', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_clinical_location_multiple_locations + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_location + description: > + Multiple locations are preserved with unique location_ids. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__location') + rows: + - {location_id: 'CLOC1', npi: '1111111111', name: 'Clinic A', facility_type: 'clinic', parent_organization: null, address: null, city: 'CityA', state: 'NY', zip_code: '10001', latitude: null, longitude: null, data_source: 'clinical_src'} + - {location_id: 'CLOC2', npi: '2222222222', name: 'Clinic B', facility_type: 'clinic', parent_organization: null, address: null, city: 'CityB', state: 'CA', zip_code: '90001', latitude: null, longitude: null, data_source: 'clinical_src'} + expect: + rows: + - {location_id: 'CLOC1', name: 'Clinic A', city: 'CityA', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - {location_id: 'CLOC2', name: 'Clinic B', city: 'CityB', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_clinical_practitioner + # ========================================================================= + + - name: test_stg_clinical_practitioner_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_practitioner + description: > + Clinical practitioner staging passes through all columns. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__practitioner') + rows: + - {practitioner_id: 'CPRAC1', npi: '3333333333', first_name: 'Alice', last_name: 'Johnson', practice_affiliation: 'Big Health', specialty: 'Family Medicine', sub_specialty: null, data_source: 'clinical_src'} + expect: + rows: + - {practitioner_id: 'CPRAC1', npi: '3333333333', first_name: 'Alice', specialty: 'Family Medicine', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_clinical_practitioner_multiple_practitioners + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_practitioner + description: > + Multiple practitioners are preserved with unique IDs. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__practitioner') + rows: + - {practitioner_id: 'CPRAC1', npi: '1111111111', first_name: 'Alice', last_name: 'Johnson', practice_affiliation: null, specialty: 'Family Medicine', sub_specialty: null, data_source: 'clinical_src'} + - {practitioner_id: 'CPRAC2', npi: '2222222222', first_name: 'Bob', last_name: 'Williams', practice_affiliation: null, specialty: 'Cardiology', sub_specialty: null, data_source: 'clinical_src'} + expect: + rows: + - {practitioner_id: 'CPRAC1', first_name: 'Alice', specialty: 'Family Medicine', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - {practitioner_id: 'CPRAC2', first_name: 'Bob', specialty: 'Cardiology', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING MODELS — core__stg_clinical_appointment + # ========================================================================= + + - name: test_stg_clinical_appointment_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_appointment + description: > + Clinical appointment staging passes through all columns. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__appointment') + rows: + - {appointment_id: 'CAP1', person_id: 'P1', patient_id: 'PT1', encounter_id: 'ENC1', source_appointment_type_code: 'ROUTINE', source_appointment_type_description: 'Routine visit', normalized_appointment_type_code: null, normalized_appointment_type_description: null, start_datetime: '2023-06-15 09:00:00', end_datetime: '2023-06-15 10:00:00', duration: 60, location_id: 'LOC1', practitioner_id: 'NPI1', source_status: 'booked', normalized_status: null, appointment_specialty: null, reason: null, source_reason_code_type: null, source_reason_code: null, source_reason_description: null, normalized_reason_code_type: null, normalized_reason_code: null, normalized_reason_description: null, cancellation_reason: null, source_cancellation_reason_code_type: null, source_cancellation_reason_code: null, source_cancellation_reason_description: null, normalized_cancellation_reason_code_type: null, normalized_cancellation_reason_code: null, normalized_cancellation_reason_description: null, data_source: 'clinical_src'} + expect: + rows: + - {appointment_id: 'CAP1', person_id: 'P1', source_status: 'booked', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_clinical_appointment_multiple_appointments + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: core__stg_clinical_appointment + description: > + Multiple appointments are all preserved with unique appointment_ids. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + given: + - input: ref('input_layer__appointment') + rows: + - {appointment_id: 'CAP1', person_id: 'P1', patient_id: 'PT1', encounter_id: null, source_appointment_type_code: null, source_appointment_type_description: null, normalized_appointment_type_code: null, normalized_appointment_type_description: null, start_datetime: '2023-06-15 09:00:00', end_datetime: '2023-06-15 10:00:00', duration: 60, location_id: null, practitioner_id: null, source_status: 'booked', normalized_status: null, appointment_specialty: null, reason: null, source_reason_code_type: null, source_reason_code: null, source_reason_description: null, normalized_reason_code_type: null, normalized_reason_code: null, normalized_reason_description: null, cancellation_reason: null, source_cancellation_reason_code_type: null, source_cancellation_reason_code: null, source_cancellation_reason_description: null, normalized_cancellation_reason_code_type: null, normalized_cancellation_reason_code: null, normalized_cancellation_reason_description: null, data_source: 'clinical_src'} + - {appointment_id: 'CAP2', person_id: 'P1', patient_id: 'PT1', encounter_id: null, source_appointment_type_code: null, source_appointment_type_description: null, normalized_appointment_type_code: null, normalized_appointment_type_description: null, start_datetime: '2023-07-15 14:00:00', end_datetime: '2023-07-15 15:00:00', duration: 60, location_id: null, practitioner_id: null, source_status: 'cancelled', normalized_status: null, appointment_specialty: null, reason: null, source_reason_code_type: null, source_reason_code: null, source_reason_description: null, normalized_reason_code_type: null, normalized_reason_code: null, normalized_reason_description: null, cancellation_reason: null, source_cancellation_reason_code_type: null, source_cancellation_reason_code: null, source_cancellation_reason_description: null, normalized_cancellation_reason_code_type: null, normalized_cancellation_reason_code: null, normalized_cancellation_reason_description: null, data_source: 'clinical_src'} + expect: + rows: + - {appointment_id: 'CAP1', source_status: 'booked', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} + - {appointment_id: 'CAP2', source_status: 'cancelled', data_source: 'clinical_src', tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/data_marts/ahrq_measures/_unit_tests.yml b/models/data_marts/ahrq_measures/_unit_tests.yml new file mode 100644 index 000000000..0ebb131f6 --- /dev/null +++ b/models/data_marts/ahrq_measures/_unit_tests.yml @@ -0,0 +1,229 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # AHRQ MEASURES - STAGING: stg_pqi_inpatient_encounter + # ========================================================================= + + - name: test_ahrq_stg_pqi_inpatient_encounter_filters_acute_inpatient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__stg_pqi_inpatient_encounter + description: "Only acute inpatient encounters are selected from core encounters" + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '470', drg_description: 'Hip replacement', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'S72.001A', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 15000, encounter_type: 'acute inpatient'} + - {encounter_id: 'E2', data_source: 'src1', drg_code: null, drg_description: null, admit_source_code: null, encounter_start_date: '2023-06-10', encounter_end_date: '2023-06-10', length_of_stay: 0, primary_diagnosis_code: 'J06.9', person_id: 'P2', facility_npi: 'NPI2', paid_amount: 500, encounter_type: 'emergency department'} + expect: + rows: + - {encounter_id: 'E1', data_source: 'src1', person_id: 'P1', primary_diagnosis_code: 'S72.001A', year_number: 2023} + + # ========================================================================= + # AHRQ MEASURES - INTERMEDIATE: int_pqi_01_num + # ========================================================================= + + - name: test_ahrq_pqi01_num_matches_diabetes_short_term + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_01_num + description: "PQI 01 numerator identifies encounters with diabetes short-term complication diagnosis codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '637', drg_description: 'DM w/MCC', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'E1010', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023} + - {encounter_id: 'E2', data_source: 'src1', drg_code: '470', drg_description: 'Hip', admit_source_code: '1', encounter_start_date: '2023-07-01', encounter_end_date: '2023-07-05', length_of_stay: 4, primary_diagnosis_code: 'S72.001A', person_id: 'P2', facility_npi: 'NPI1', paid_amount: 15000, year_number: 2023} + - input: ref('pqi__value_sets') + rows: + - {code: 'E1010', value_set_name: 'diabetes_with_short-term_complications_diagnosis_codes', pqi_number: '01'} + - input: ref('ahrq_measures__int_pqi_01_denom') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', age: 55, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_01_exclusions') + rows: [] + expect: + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # AHRQ MEASURES - FINAL: pqi_rate + # ========================================================================= + + - name: test_ahrq_pqi_rate_computes_rate_per_100k + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__pqi_rate + description: "PQI rate computes rate per 100,000 as (numerator count / denominator count) * 100,000" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__pqi_num_long') + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + - {data_source: 'src1', person_id: 'P2', year_number: 2023, encounter_id: 'E2', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__pqi_denom_long') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + - {year_number: 2023, person_id: 'P2', data_source: 'src1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + - {year_number: 2023, person_id: 'P3', data_source: 'src1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + - {year_number: 2023, person_id: 'P4', data_source: 'src1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {data_source: 'src1', year_number: 2023, pqi_number: '01', denom_count: 4, num_count: 2, rate_per_100_thousand: 50000.0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # AHRQ MEASURES - FINAL: pqi_summary + # ========================================================================= + + - name: test_ahrq_pqi_summary_joins_encounter_details + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__pqi_summary + description: "PQI summary joins numerator encounters to encounter details and measure names" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__pqi_num_long') + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '637', drg_description: 'DM w/MCC', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'E1010', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023, admit_source_code: '1'} + - input: ref('pqi__measures') + rows: + - {pqi_number: '01', pqi_name: 'Diabetes Short-Term Complications Admission Rate'} + expect: + rows: + - {pqi_number: '01', pqi_name: 'Diabetes Short-Term Complications Admission Rate', encounter_id: 'E1', person_id: 'P1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # AHRQ MEASURES - STAGING: filters non-acute-inpatient types + # ========================================================================= + + - name: test_ahrq_stg_pqi_inpatient_encounter_excludes_ed_and_outpatient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__stg_pqi_inpatient_encounter + description: "Outpatient and office visit encounters are excluded from PQI staging" + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: null, drg_description: null, admit_source_code: null, encounter_start_date: '2023-06-10', encounter_end_date: '2023-06-10', length_of_stay: 0, primary_diagnosis_code: 'J06.9', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 200, encounter_type: 'outpatient'} + - {encounter_id: 'E2', data_source: 'src1', drg_code: null, drg_description: null, admit_source_code: null, encounter_start_date: '2023-06-15', encounter_end_date: '2023-06-15', length_of_stay: 0, primary_diagnosis_code: 'Z00.00', person_id: 'P2', facility_npi: 'NPI2', paid_amount: 100, encounter_type: 'office visit'} + expect: + rows: [] + + # ========================================================================= + # AHRQ MEASURES - PQI 01 NUM: excluded encounters not in numerator + # ========================================================================= + + - name: test_ahrq_pqi01_num_excludes_encounters_with_shared_exclusion + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_01_num + description: "PQI 01 numerator excludes encounters that appear in the shared exclusion list" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '637', drg_description: 'DM', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'E1010', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023} + - input: ref('pqi__value_sets') + rows: + - {code: 'E1010', value_set_name: 'diabetes_with_short-term_complications_diagnosis_codes', pqi_number: '01'} + - input: ref('ahrq_measures__int_pqi_01_denom') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', age: 55, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_01_exclusions') + rows: + - {encounter_id: 'E1', data_source: 'src1', exclusion_reason: 'transfer', exclusion_number: 1, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: [] + + # ========================================================================= + # AHRQ MEASURES - FINAL: pqi_rate zero numerator + # ========================================================================= + + - name: test_ahrq_pqi_rate_zero_numerator + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__pqi_rate + description: "PQI rate returns zero count and zero rate when no numerator encounters exist" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__pqi_num_long') + rows: [] + - input: ref('ahrq_measures__pqi_denom_long') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', pqi_number: '03', tuva_last_run: '2024-01-01 00:00:00'} + - {year_number: 2023, person_id: 'P2', data_source: 'src1', pqi_number: '03', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {data_source: 'src1', year_number: 2023, pqi_number: '03', denom_count: 2, num_count: 0, rate_per_100_thousand: 0.0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # AHRQ MEASURES - FINAL: pqi_rate multiple PQIs + # ========================================================================= + + - name: test_ahrq_pqi_rate_multiple_pqi_numbers + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__pqi_rate + description: "PQI rate produces separate rows for different PQI numbers" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__pqi_num_long') + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + - {data_source: 'src1', person_id: 'P3', year_number: 2023, encounter_id: 'E3', pqi_number: '08', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__pqi_denom_long') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + - {year_number: 2023, person_id: 'P2', data_source: 'src1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + - {year_number: 2023, person_id: 'P3', data_source: 'src1', pqi_number: '08', tuva_last_run: '2024-01-01 00:00:00'} + - {year_number: 2023, person_id: 'P4', data_source: 'src1', pqi_number: '08', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {data_source: 'src1', year_number: 2023, pqi_number: '01', denom_count: 2, num_count: 1, rate_per_100_thousand: 50000.0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_source: 'src1', year_number: 2023, pqi_number: '08', denom_count: 2, num_count: 1, rate_per_100_thousand: 50000.0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # AHRQ MEASURES - FINAL: pqi_summary multiple PQIs + # ========================================================================= + + - name: test_ahrq_pqi_summary_multiple_encounters + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__pqi_summary + description: "PQI summary returns one row per numerator encounter with measure details" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__pqi_num_long') + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + - {data_source: 'src1', person_id: 'P2', year_number: 2023, encounter_id: 'E2', pqi_number: '03', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '637', drg_description: 'DM w/MCC', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'E1010', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023, admit_source_code: '1'} + - {encounter_id: 'E2', data_source: 'src1', drg_code: '637', drg_description: 'DM LT', encounter_start_date: '2023-07-01', encounter_end_date: '2023-07-04', length_of_stay: 3, primary_diagnosis_code: 'E1136', person_id: 'P2', facility_npi: 'NPI2', paid_amount: 8000, year_number: 2023, admit_source_code: '1'} + - input: ref('pqi__measures') + rows: + - {pqi_number: '01', pqi_name: 'Diabetes Short-Term Complications Admission Rate'} + - {pqi_number: '03', pqi_name: 'Diabetes Long-Term Complications Admission Rate'} + expect: + rows: + - {pqi_number: '01', pqi_name: 'Diabetes Short-Term Complications Admission Rate', encounter_id: 'E1', person_id: 'P1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {pqi_number: '03', pqi_name: 'Diabetes Long-Term Complications Admission Rate', encounter_id: 'E2', person_id: 'P2', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/data_marts/ahrq_measures/ahrq_measures_gap_unit_tests.yml b/models/data_marts/ahrq_measures/ahrq_measures_gap_unit_tests.yml new file mode 100644 index 000000000..824a21749 --- /dev/null +++ b/models/data_marts/ahrq_measures/ahrq_measures_gap_unit_tests.yml @@ -0,0 +1,632 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # AHRQ MEASURES - STAGING: stg_pqi_condition + # ========================================================================= + + - name: test_ahrq_stg_pqi_condition_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__stg_pqi_condition + description: "PQI condition staging passes through normalized code fields from core condition" + given: + - input: ref('core__condition') + rows: + - {normalized_code_type: 'icd-10-cm', normalized_code: 'E11.65', encounter_id: 'E1', data_source: 'src1'} + expect: + rows: + - {normalized_code_type: 'icd-10-cm', normalized_code: 'E11.65', encounter_id: 'E1', data_source: 'src1'} + + # ========================================================================= + # AHRQ MEASURES - STAGING: stg_pqi_patient + # ========================================================================= + + - name: test_ahrq_stg_pqi_patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__stg_pqi_patient + description: "PQI patient staging passes through demographics from core patient" + given: + - input: ref('core__patient') + rows: + - {data_source: 'src1', birth_date: '1960-01-01', person_id: 'P1', sex: 'female'} + expect: + rows: + - {data_source: 'src1', birth_date: '1960-01-01', person_id: 'P1', sex: 'female'} + + # ========================================================================= + # AHRQ MEASURES - STAGING: stg_pqi_member_months + # ========================================================================= + + - name: test_ahrq_stg_pqi_member_months_joins_calendar + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__stg_pqi_member_months + description: "PQI member months staging joins core member_months with calendar to get first_day_of_month" + given: + - input: ref('core__member_months') + rows: + - {data_source: 'src1', person_id: 'P1', year_month: '202306'} + - input: ref('reference_data__calendar') + rows: + - {year_month: '2023-06', first_day_of_month: '2023-06-01'} + expect: + rows: + - {data_source: 'src1', person_id: 'P1', first_day_of_month: '2023-06-01', year_month: '202306'} + + # ========================================================================= + # AHRQ MEASURES - STAGING: stg_pqi_procedure + # ========================================================================= + + - name: test_ahrq_stg_pqi_procedure_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__stg_pqi_procedure + description: "PQI procedure staging passes through normalized code fields from core procedure" + given: + - input: ref('core__procedure') + rows: + - {normalized_code_type: 'icd-10-pcs', normalized_code: '0210093', encounter_id: 'E1', data_source: 'src1'} + expect: + rows: + - {normalized_code_type: 'icd-10-pcs', normalized_code: '0210093', encounter_id: 'E1', data_source: 'src1'} + + # ========================================================================= + # AHRQ MEASURES - SHARED EXCLUSION: missing_dates + # ========================================================================= + + - name: test_ahrq_pqi_shared_exclusion_missing_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_shared_exclusion_missing_dates + description: "Missing dates exclusion identifies encounters with null start date" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '470', drg_description: 'Hip', admit_source_code: '1', encounter_start_date: null, encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'S72.001A', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 15000, year_number: 2023} + - {encounter_id: 'E2', data_source: 'src1', drg_code: '470', drg_description: 'Hip', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'S72.001A', person_id: 'P2', facility_npi: 'NPI1', paid_amount: 15000, year_number: 2023} + expect: + rows: + - {encounter_id: 'E1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # AHRQ MEASURES - SHARED EXCLUSION: missing_primary_dx + # ========================================================================= + + - name: test_ahrq_pqi_shared_exclusion_missing_primary_dx + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_shared_exclusion_missing_primary_dx + description: "Missing primary diagnosis exclusion identifies encounters with null primary_diagnosis_code" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '470', drg_description: 'Hip', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: null, person_id: 'P1', facility_npi: 'NPI1', paid_amount: 15000, year_number: 2023} + - {encounter_id: 'E2', data_source: 'src1', drg_code: '470', drg_description: 'Hip', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'S72.001A', person_id: 'P2', facility_npi: 'NPI1', paid_amount: 15000, year_number: 2023} + expect: + rows: + - {encounter_id: 'E1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # AHRQ MEASURES - SHARED EXCLUSION: transfer + # ========================================================================= + + - name: test_ahrq_pqi_shared_exclusion_transfer + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_shared_exclusion_transfer + description: "Transfer exclusion identifies encounters with admit_source_code 4, 5, or 6" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '470', drg_description: 'Hip', admit_source_code: '4', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'S72.001A', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 15000, year_number: 2023} + - {encounter_id: 'E2', data_source: 'src1', drg_code: '470', drg_description: 'Hip', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'S72.001A', person_id: 'P2', facility_npi: 'NPI1', paid_amount: 15000, year_number: 2023} + expect: + rows: + - {encounter_id: 'E1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # AHRQ MEASURES - SHARED EXCLUSION: ungroupable_drg + # ========================================================================= + + - name: test_ahrq_pqi_shared_exclusion_ungroupable_drg + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_shared_exclusion_ungroupable_drg + description: "Ungroupable DRG exclusion identifies encounters with DRG code 999" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '999', drg_description: 'Ungroupable', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'S72.001A', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 15000, year_number: 2023} + - {encounter_id: 'E2', data_source: 'src1', drg_code: '470', drg_description: 'Hip', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'S72.001A', person_id: 'P2', facility_npi: 'NPI1', paid_amount: 15000, year_number: 2023} + expect: + rows: + - {encounter_id: 'E1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # AHRQ MEASURES - SHARED EXCLUSION: union + # ========================================================================= + + - name: test_ahrq_pqi_shared_exclusion_union_combines_reasons + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_shared_exclusion_union + description: "Shared exclusion union combines all exclusion reasons for encounters" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '999', drg_description: 'Ungroupable', admit_source_code: '4', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'S72.001A', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 15000, year_number: 2023} + - input: ref('ahrq_measures__int_pqi_shared_exclusion_missing_age') + rows: [] + - input: ref('ahrq_measures__int_pqi_shared_exclusion_missing_gender') + rows: [] + - input: ref('ahrq_measures__int_pqi_shared_exclusion_missing_dates') + rows: [] + - input: ref('ahrq_measures__int_pqi_shared_exclusion_missing_primary_dx') + rows: [] + - input: ref('ahrq_measures__int_pqi_shared_exclusion_transfer') + rows: + - {encounter_id: 'E1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_shared_exclusion_ungroupable_drg') + rows: + - {encounter_id: 'E1', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', data_source: 'src1', exclusion_reason: 'transfer'} + - {encounter_id: 'E1', data_source: 'src1', exclusion_reason: 'ungroupable DRG'} + + # ========================================================================= + # AHRQ MEASURES - PQI 01 DENOM + # ========================================================================= + + # ========================================================================= + # AHRQ MEASURES - PQI 01 EXCLUSIONS + # ========================================================================= + + - name: test_ahrq_pqi01_exclusions_from_shared + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_01_exclusions + description: "PQI 01 exclusions passes through shared exclusion union with row number" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__int_pqi_shared_exclusion_union') + rows: + - {encounter_id: 'E1', data_source: 'src1', exclusion_reason: 'transfer', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', data_source: 'src1', exclusion_reason: 'transfer', exclusion_number: 1} + + # ========================================================================= + # AHRQ MEASURES - PQI 03 EXCLUSIONS + # ========================================================================= + + - name: test_ahrq_pqi03_exclusions_from_shared + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_03_exclusions + description: "PQI 03 exclusions passes through shared exclusion union with row number" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__int_pqi_shared_exclusion_union') + rows: + - {encounter_id: 'E1', data_source: 'src1', exclusion_reason: 'missing age', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', data_source: 'src1', exclusion_reason: 'missing age', exclusion_number: 1} + + # ========================================================================= + # AHRQ MEASURES - PQI 03 NUM + # ========================================================================= + + - name: test_ahrq_pqi03_num_matches_diabetes_long_term + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_03_num + description: "PQI 03 numerator identifies encounters with diabetes long-term complication diagnosis codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '637', drg_description: 'DM', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'E1136', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023} + - input: ref('pqi__value_sets') + rows: + - {code: 'E1136', value_set_name: 'diabetes_with_long-term_complications_diagnosis_codes', pqi_number: '03'} + - input: ref('ahrq_measures__int_pqi_03_denom') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', age: 55, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_03_exclusions') + rows: [] + expect: + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1'} + + # ========================================================================= + # AHRQ MEASURES - PQI 05 DENOM + # ========================================================================= + + # ========================================================================= + # AHRQ MEASURES - PQI 05 NUM + # ========================================================================= + + - name: test_ahrq_pqi05_num_matches_copd_or_asthma + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_05_num + description: "PQI 05 numerator identifies encounters with COPD or asthma diagnosis codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '190', drg_description: 'COPD', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'J44.1', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023} + - input: ref('pqi__value_sets') + rows: + - {code: 'J44.1', value_set_name: 'chronic_obstructive_pulmonary_disorder', pqi_number: '05'} + - input: ref('ahrq_measures__int_pqi_05_denom') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', age: 55, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_05_exclusions') + rows: [] + expect: + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1'} + + # ========================================================================= + # AHRQ MEASURES - PQI 07 DENOM + # ========================================================================= + + # ========================================================================= + # AHRQ MEASURES - PQI 07 NUM + # ========================================================================= + + - name: test_ahrq_pqi07_num_matches_hypertension + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_07_num + description: "PQI 07 numerator identifies encounters with hypertension diagnosis codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '304', drg_description: 'HTN', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'I10', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023} + - input: ref('pqi__value_sets') + rows: + - {code: 'I10', value_set_name: 'hypertension_diagnosis_codes', pqi_number: '07'} + - input: ref('ahrq_measures__int_pqi_07_denom') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', age: 55, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_07_exclusions') + rows: [] + expect: + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1'} + + # ========================================================================= + # AHRQ MEASURES - PQI 08 DENOM + # ========================================================================= + + # ========================================================================= + # AHRQ MEASURES - PQI 08 NUM + # ========================================================================= + + - name: test_ahrq_pqi08_num_matches_heart_failure + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_08_num + description: "PQI 08 numerator identifies encounters with heart failure diagnosis codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '291', drg_description: 'HF', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'I50.9', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023} + - input: ref('pqi__value_sets') + rows: + - {code: 'I50.9', value_set_name: 'heart_failure_diagnosis_codes', pqi_number: '08'} + - input: ref('ahrq_measures__int_pqi_08_denom') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', age: 55, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_08_exclusions') + rows: [] + expect: + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1'} + + # ========================================================================= + # AHRQ MEASURES - PQI 11 DENOM + # ========================================================================= + + # ========================================================================= + # AHRQ MEASURES - PQI 11 NUM + # ========================================================================= + + - name: test_ahrq_pqi11_num_matches_bacterial_pneumonia + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_11_num + description: "PQI 11 numerator identifies encounters with bacterial pneumonia diagnosis codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '177', drg_description: 'Pneumonia', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'J15.9', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023} + - input: ref('pqi__value_sets') + rows: + - {code: 'J15.9', value_set_name: 'bacterial_pneumonia_diagnosis_codes', pqi_number: '11'} + - input: ref('ahrq_measures__int_pqi_11_denom') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', age: 55, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_11_exclusions') + rows: [] + expect: + rows: [] + + # ========================================================================= + # AHRQ MEASURES - PQI 12 DENOM + # ========================================================================= + + + # ========================================================================= + # AHRQ MEASURES - PQI 12 NUM + # ========================================================================= + + - name: test_ahrq_pqi12_num_matches_urinary_infection + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_12_num + description: "PQI 12 numerator identifies encounters with urinary tract infection diagnosis codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '689', drg_description: 'UTI', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'N39.0', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023} + - input: ref('pqi__value_sets') + rows: + - {code: 'N39.0', value_set_name: 'urinary_tract_infection_diagnosis_codes', pqi_number: '12'} + - input: ref('ahrq_measures__int_pqi_12_denom') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', age: 55, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_12_exclusions') + rows: [] + expect: + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1'} + + # ========================================================================= + # AHRQ MEASURES - PQI 14 DENOM + # ========================================================================= + + # ========================================================================= + # AHRQ MEASURES - PQI 14 EXCLUSIONS + # ========================================================================= + + - name: test_ahrq_pqi14_exclusions_from_shared + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_14_exclusions + description: "PQI 14 exclusions passes through shared exclusion union" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__int_pqi_shared_exclusion_union') + rows: + - {encounter_id: 'E1', data_source: 'src1', exclusion_reason: 'transfer', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', data_source: 'src1', exclusion_reason: 'transfer', exclusion_number: 1} + + # ========================================================================= + # AHRQ MEASURES - PQI 14 NUM + # ========================================================================= + + - name: test_ahrq_pqi14_num_matches_uncontrolled_diabetes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_14_num + description: "PQI 14 numerator identifies encounters with uncontrolled diabetes diagnosis codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '637', drg_description: 'DM', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'E1165', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023} + - input: ref('pqi__value_sets') + rows: + - {code: 'E1165', value_set_name: 'uncontrolled_diabetes_diagnosis_codes', pqi_number: '14'} + - input: ref('ahrq_measures__int_pqi_14_denom') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', age: 55, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_14_exclusions') + rows: [] + expect: + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1'} + + # ========================================================================= + # AHRQ MEASURES - PQI 15 DENOM + # ========================================================================= + + + # ========================================================================= + # AHRQ MEASURES - PQI 15 NUM + # ========================================================================= + + - name: test_ahrq_pqi15_num_matches_asthma_younger + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__int_pqi_15_num + description: "PQI 15 numerator identifies encounters with asthma diagnosis codes for younger adults" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__stg_pqi_inpatient_encounter') + rows: + - {encounter_id: 'E1', data_source: 'src1', drg_code: '202', drg_description: 'Asthma', admit_source_code: '1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, primary_diagnosis_code: 'J45.41', person_id: 'P1', facility_npi: 'NPI1', paid_amount: 10000, year_number: 2023} + - input: ref('pqi__value_sets') + rows: + - {code: 'J45.41', value_set_name: 'asthma_diagnosis_codes', pqi_number: '15'} + - input: ref('ahrq_measures__int_pqi_15_denom') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', age: 30, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_15_exclusions') + rows: [] + expect: + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1'} + + # ========================================================================= + # AHRQ MEASURES - PQI 16 DENOM + # ========================================================================= + + # ========================================================================= + # AHRQ MEASURES - PQI 16 NUM + # ========================================================================= + + # ========================================================================= + # AHRQ MEASURES - FINAL: pqi_denom_long + # ========================================================================= + + - name: test_ahrq_pqi_denom_long_unions_all_denoms + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__pqi_denom_long + description: "PQI denom long unions all PQI denominator models with pqi_number labels" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__int_pqi_01_denom') + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', age: 55, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_03_denom') + rows: [] + - input: ref('ahrq_measures__int_pqi_05_denom') + rows: [] + - input: ref('ahrq_measures__int_pqi_07_denom') + rows: [] + - input: ref('ahrq_measures__int_pqi_08_denom') + rows: [] + - input: ref('ahrq_measures__int_pqi_11_denom') + rows: [] + - input: ref('ahrq_measures__int_pqi_12_denom') + rows: [] + - input: ref('ahrq_measures__int_pqi_14_denom') + rows: [] + - input: ref('ahrq_measures__int_pqi_15_denom') + rows: [] + - input: ref('ahrq_measures__int_pqi_16_denom') + rows: [] + expect: + rows: + - {year_number: 2023, person_id: 'P1', data_source: 'src1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # AHRQ MEASURES - FINAL: pqi_exclusion_long + # ========================================================================= + + - name: test_ahrq_pqi_exclusion_long_unions_all_exclusions + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__pqi_exclusion_long + description: "PQI exclusion long unions all PQI exclusion models with pqi_number labels" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__int_pqi_01_exclusions') + rows: + - {encounter_id: 'E1', data_source: 'src1', exclusion_reason: 'transfer', exclusion_number: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_03_exclusions') + rows: [] + - input: ref('ahrq_measures__int_pqi_05_exclusions') + rows: [] + - input: ref('ahrq_measures__int_pqi_07_exclusions') + rows: [] + - input: ref('ahrq_measures__int_pqi_08_exclusions') + rows: [] + - input: ref('ahrq_measures__int_pqi_11_exclusions') + rows: [] + - input: ref('ahrq_measures__int_pqi_12_exclusions') + rows: [] + - input: ref('ahrq_measures__int_pqi_14_exclusions') + rows: [] + - input: ref('ahrq_measures__int_pqi_15_exclusions') + rows: [] + - input: ref('ahrq_measures__int_pqi_16_exclusions') + rows: [] + expect: + rows: + - {data_source: 'src1', encounter_id: 'E1', exclusion_reason: 'transfer', exclusion_number: 1, pqi_number: 1, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # AHRQ MEASURES - FINAL: pqi_num_long + # ========================================================================= + + - name: test_ahrq_pqi_num_long_unions_all_numerators + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ahrq_measures__pqi_num_long + description: "PQI num long unions all PQI numerator models with pqi_number labels" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__int_pqi_01_num') + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('ahrq_measures__int_pqi_03_num') + rows: [] + - input: ref('ahrq_measures__int_pqi_05_num') + rows: [] + - input: ref('ahrq_measures__int_pqi_07_num') + rows: [] + - input: ref('ahrq_measures__int_pqi_08_num') + rows: [] + - input: ref('ahrq_measures__int_pqi_11_num') + rows: [] + - input: ref('ahrq_measures__int_pqi_12_num') + rows: [] + - input: ref('ahrq_measures__int_pqi_14_num') + rows: [] + - input: ref('ahrq_measures__int_pqi_15_num') + rows: [] + - input: ref('ahrq_measures__int_pqi_16_num') + rows: [] + expect: + rows: + - {data_source: 'src1', person_id: 'P1', year_number: 2023, encounter_id: 'E1', pqi_number: '01', tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/data_marts/benchmarks/_unit_tests.yml b/models/data_marts/benchmarks/_unit_tests.yml new file mode 100644 index 000000000..7abac0fae --- /dev/null +++ b/models/data_marts/benchmarks/_unit_tests.yml @@ -0,0 +1,340 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # BENCHMARKS - STAGING: stg_core__patient + # ========================================================================= + + - name: test_benchmarks_stg_patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_core__patient + description: "Patient staging passes through person_id, sex, birth_date, state, race" + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1960-05-01', state: 'CA', race: 'white'} + - {person_id: 'P2', sex: 'male', birth_date: '1975-11-15', state: 'NY', race: 'black'} + expect: + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1960-05-01', state: 'CA', race: 'white'} + - {person_id: 'P2', sex: 'male', birth_date: '1975-11-15', state: 'NY', race: 'black'} + + # ========================================================================= + # BENCHMARKS - STAGING: stg_core__member_months + # ========================================================================= + + - name: test_benchmarks_stg_member_months_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_core__member_months + description: "Member months staging passes through key columns" + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + + - name: test_benchmarks_stg_member_months_multiple_persons + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_core__member_months + description: "Member months staging handles multiple persons and months" + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', year_month: '202302', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P2', year_month: '202301', payer: 'MCD', plan: 'PlanB', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', year_month: '202302', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P2', year_month: '202301', payer: 'MCD', plan: 'PlanB', data_source: 'src1'} + + # ========================================================================= + # BENCHMARKS - STAGING: stg_core__condition + # ========================================================================= + + - name: test_benchmarks_stg_condition_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_core__condition + description: "Condition staging passes through normalized_code and recorded_date" + given: + - input: ref('core__condition') + rows: + - {person_id: 'P1', normalized_code: 'E11.65', recorded_date: '2023-06-15'} + expect: + rows: + - {person_id: 'P1', normalized_code: 'E11.65', recorded_date: '2023-06-15'} + + - name: test_benchmarks_stg_condition_multiple_conditions + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_core__condition + description: "Condition staging passes through multiple conditions for same person" + given: + - input: ref('core__condition') + rows: + - {person_id: 'P1', normalized_code: 'E11.65', recorded_date: '2023-06-15'} + - {person_id: 'P1', normalized_code: 'I10', recorded_date: '2023-07-01'} + - {person_id: 'P2', normalized_code: 'J44.1', recorded_date: '2023-08-10'} + expect: + rows: + - {person_id: 'P1', normalized_code: 'E11.65', recorded_date: '2023-06-15'} + - {person_id: 'P1', normalized_code: 'I10', recorded_date: '2023-07-01'} + - {person_id: 'P2', normalized_code: 'J44.1', recorded_date: '2023-08-10'} + + # ========================================================================= + # BENCHMARKS - STAGING: stg_core__medical_claim + # ========================================================================= + + - name: test_benchmarks_stg_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_core__medical_claim + description: "Medical claim staging passes through key columns for benchmarks" + given: + - input: ref('core__medical_claim') + rows: + - {person_id: 'P1', encounter_id: 'E1', paid_amount: 500, data_source: 'src1', payer: 'MCR', plan: 'PlanA', claim_end_date: '2023-06-15', encounter_type: 'acute inpatient', encounter_group: 'inpatient', enrollment_flag: 1} + expect: + rows: + - {person_id: 'P1', encounter_id: 'E1', paid_amount: 500, data_source: 'src1', payer: 'MCR', encounter_type: 'acute inpatient', enrollment_flag: 1} + + - name: test_benchmarks_stg_medical_claim_multiple_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_core__medical_claim + description: "Medical claim staging passes through multiple claims with different encounter types" + given: + - input: ref('core__medical_claim') + rows: + - {person_id: 'P1', encounter_id: 'E1', paid_amount: 5000, data_source: 'src1', payer: 'MCR', plan: 'PlanA', claim_end_date: '2023-06-15', encounter_type: 'acute inpatient', encounter_group: 'inpatient', enrollment_flag: 1} + - {person_id: 'P1', encounter_id: 'E2', paid_amount: 200, data_source: 'src1', payer: 'MCR', plan: 'PlanA', claim_end_date: '2023-07-01', encounter_type: 'office visit', encounter_group: 'office based', enrollment_flag: 1} + - {person_id: 'P2', encounter_id: 'E3', paid_amount: 800, data_source: 'src1', payer: 'MCD', plan: 'PlanB', claim_end_date: '2023-08-10', encounter_type: 'emergency department', encounter_group: 'outpatient', enrollment_flag: 0} + expect: + rows: + - {person_id: 'P1', encounter_id: 'E1', paid_amount: 5000, encounter_type: 'acute inpatient', enrollment_flag: 1} + - {person_id: 'P1', encounter_id: 'E2', paid_amount: 200, encounter_type: 'office visit', enrollment_flag: 1} + - {person_id: 'P2', encounter_id: 'E3', paid_amount: 800, encounter_type: 'emergency department', enrollment_flag: 0} + + # ========================================================================= + # BENCHMARKS - STAGING: stg_reference_data__calendar + # ========================================================================= + + - name: test_benchmarks_stg_calendar_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_reference_data__calendar + description: "Calendar staging passes through full_date, year, year_month_int, first_day_of_month" + given: + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-06-15', year: 2023, year_month_int: 202306, first_day_of_month: '2023-06-01'} + expect: + rows: + - {full_date: '2023-06-15', year: 2023, year_month_int: 202306, first_day_of_month: '2023-06-01'} + + # ========================================================================= + # BENCHMARKS - STAGING: stg_core__encounter + # ========================================================================= + + - name: test_benchmarks_stg_encounter_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_core__encounter + description: "Encounter staging passes through encounter columns for benchmarks" + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', data_source: 'src1', encounter_start_date: '2023-06-10', encounter_type: 'acute inpatient', encounter_group: 'inpatient', length_of_stay: 5, discharge_disposition_code: '01', facility_npi: 'FAC1', facility_name: 'Hospital A', drg_code_type: 'ms-drg', drg_code: '470', drg_description: 'Major joint', paid_amount: 25000, primary_diagnosis_code: 'I2510'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', data_source: 'src1', encounter_type: 'acute inpatient', length_of_stay: 5} + + - name: test_benchmarks_stg_encounter_multiple_types + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_core__encounter + description: "Encounter staging handles different encounter types" + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', data_source: 'src1', encounter_start_date: '2023-06-10', encounter_type: 'acute inpatient', encounter_group: 'inpatient', length_of_stay: 5, discharge_disposition_code: '01', facility_npi: 'FAC1', facility_name: 'Hospital A', drg_code_type: 'ms-drg', drg_code: '470', drg_description: 'Major joint', paid_amount: 25000, primary_diagnosis_code: 'I2510'} + - {encounter_id: 'E2', person_id: 'P1', data_source: 'src1', encounter_start_date: '2023-07-01', encounter_type: 'office visit', encounter_group: 'office based', length_of_stay: 0, discharge_disposition_code: null, facility_npi: 'FAC2', facility_name: 'Clinic B', drg_code_type: null, drg_code: null, drg_description: null, paid_amount: 200, primary_diagnosis_code: 'E1165'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', encounter_type: 'acute inpatient', length_of_stay: 5} + - {encounter_id: 'E2', person_id: 'P1', encounter_type: 'office visit', length_of_stay: 0} + + # ========================================================================= + # INTERMEDIATE: pivot_hcc + # ========================================================================= + + - name: test_benchmarks_pivot_hcc_flags_codes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__pivot_hcc + description: "HCC pivot creates binary flags per HCC code per person per year" + given: + - input: ref('benchmarks__stg_cms_hcc__int_disease_factors') + rows: + - {person_id: 'P1', hcc_code: '19', collection_end_date: '2023-12-31'} + - {person_id: 'P1', hcc_code: '85', collection_end_date: '2023-12-31'} + - {person_id: 'P1', hcc_code: '19', collection_end_date: '2023-06-30'} + - input: ref('benchmarks__stg_reference_data__calendar') + rows: + - {full_date: '2023-12-31', year: 2023, year_month_int: 202312, first_day_of_month: '2023-12-01'} + - {full_date: '2023-06-30', year: 2023, year_month_int: 202306, first_day_of_month: '2023-06-01'} + expect: + rows: + - {person_id: 'P1', year_nbr: 2023, hcc_19: 1, hcc_85: 1} + + - name: test_benchmarks_pivot_hcc_no_hcc_codes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__pivot_hcc + description: "HCC pivot returns no rows when all hcc_code values are null" + given: + - input: ref('benchmarks__stg_cms_hcc__int_disease_factors') + rows: + - {person_id: 'P1', hcc_code: null, collection_end_date: '2023-12-31'} + - input: ref('benchmarks__stg_reference_data__calendar') + rows: + - {full_date: '2023-12-31', year: 2023, year_month_int: 202312, first_day_of_month: '2023-12-01'} + expect: + rows: [] + + - name: test_benchmarks_pivot_hcc_multiple_persons + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__pivot_hcc + description: "HCC pivot correctly separates flags by person and year" + given: + - input: ref('benchmarks__stg_cms_hcc__int_disease_factors') + rows: + - {person_id: 'P1', hcc_code: '19', collection_end_date: '2023-12-31'} + - {person_id: 'P2', hcc_code: '85', collection_end_date: '2023-12-31'} + - {person_id: 'P2', hcc_code: '19', collection_end_date: '2022-12-31'} + - input: ref('benchmarks__stg_reference_data__calendar') + rows: + - {full_date: '2023-12-31', year: 2023, year_month_int: 202312, first_day_of_month: '2023-12-01'} + - {full_date: '2022-12-31', year: 2022, year_month_int: 202212, first_day_of_month: '2022-12-01'} + expect: + rows: + - {person_id: 'P1', year_nbr: 2023, hcc_19: 1, hcc_85: 0} + - {person_id: 'P2', year_nbr: 2023, hcc_85: 1, hcc_19: 0} + - {person_id: 'P2', year_nbr: 2022, hcc_19: 1, hcc_85: 0} + + # ========================================================================= + # STAGING: stg_cms_hcc__int_disease_factors + # ========================================================================= + + - name: test_benchmarks_stg_disease_factors_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_cms_hcc__int_disease_factors + description: "Disease factors staging passes through person_id, hcc_code, and collection_end_date" + given: + - input: ref('cms_hcc__int_disease_factors') + rows: + - {person_id: 'P1', hcc_code: '19', collection_end_date: '2023-12-31'} + - {person_id: 'P2', hcc_code: '85', collection_end_date: '2023-12-31'} + expect: + rows: + - {person_id: 'P1', hcc_code: '19', collection_end_date: '2023-12-31'} + - {person_id: 'P2', hcc_code: '85', collection_end_date: '2023-12-31'} + + # ========================================================================= + # POST-PREDICT: unpivot_inpatient + # ========================================================================= + + - name: test_benchmarks_unpivot_inpatient_cross_join + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__unpivot_inpatient + description: "Unpivot inpatient cross joins discharge locations and expected vs actual" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('benchmarks__predict_inpatient') + rows: + - {encounter_id: 'E1', person_id: 'P1', actual_discharge_location: 'home', discharge_pred_proba_snf: 0.1, discharge_pred_proba_home: 0.6, discharge_pred_proba_home_health: 0.1, discharge_pred_proba_expired: 0.05, discharge_pred_proba_transfer_other_facility: 0.05, discharge_pred_proba_ipt_rehab: 0.05, discharge_pred_proba_hospice: 0.02, discharge_pred_proba_other: 0.03} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'snf', eva: 'expected', discharge_location_long: 0.1} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'snf', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home', eva: 'expected', discharge_location_long: 0.6} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home', eva: 'actual', discharge_location_long: 1} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home health', eva: 'expected', discharge_location_long: 0.1} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home health', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'expired', eva: 'expected', discharge_location_long: 0.05} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'expired', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'transfer/other facility', eva: 'expected', discharge_location_long: 0.05} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'transfer/other facility', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'ipt rehab', eva: 'expected', discharge_location_long: 0.05} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'ipt rehab', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'hospice', eva: 'expected', discharge_location_long: 0.02} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'hospice', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'other', eva: 'expected', discharge_location_long: 0.03} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'other', eva: 'actual', discharge_location_long: 0} + + - name: test_benchmarks_unpivot_inpatient_actual_matches_location + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__unpivot_inpatient + description: "Unpivot inpatient sets actual=1 only for the matching discharge location" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('benchmarks__predict_inpatient') + rows: + - {encounter_id: 'E1', person_id: 'P1', actual_discharge_location: 'snf', discharge_pred_proba_snf: 0.8, discharge_pred_proba_home: 0.1, discharge_pred_proba_home_health: 0.02, discharge_pred_proba_expired: 0.02, discharge_pred_proba_transfer_other_facility: 0.02, discharge_pred_proba_ipt_rehab: 0.02, discharge_pred_proba_hospice: 0.01, discharge_pred_proba_other: 0.01} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'snf', eva: 'actual', discharge_location_long: 1} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'snf', eva: 'expected', discharge_location_long: 0.8} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home', eva: 'expected', discharge_location_long: 0.1} + + # ========================================================================= + # POST-PREDICT: unpivot_inpatient_prospective + # ========================================================================= + + - name: test_benchmarks_unpivot_inpatient_prospective_cross_join + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__unpivot_inpatient_prospective + description: "Unpivot inpatient prospective cross joins discharge locations and expected vs actual" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('benchmarks__predict_inpatient_prospective') + rows: + - {encounter_id: 'E1', person_id: 'P1', actual_discharge_location: 'snf', discharge_pred_proba_snf: 0.7, discharge_pred_proba_home: 0.1, discharge_pred_proba_home_health: 0.05, discharge_pred_proba_expired: 0.05, discharge_pred_proba_transfer_other_facility: 0.03, discharge_pred_proba_ipt_rehab: 0.03, discharge_pred_proba_hospice: 0.02, discharge_pred_proba_other: 0.02} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'snf', eva: 'expected', discharge_location_long: 0.7} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'snf', eva: 'actual', discharge_location_long: 1} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home', eva: 'expected', discharge_location_long: 0.1} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home health', eva: 'expected', discharge_location_long: 0.05} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home health', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'expired', eva: 'expected', discharge_location_long: 0.05} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'expired', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'transfer/other facility', eva: 'expected', discharge_location_long: 0.03} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'transfer/other facility', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'ipt rehab', eva: 'expected', discharge_location_long: 0.03} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'ipt rehab', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'hospice', eva: 'expected', discharge_location_long: 0.02} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'hospice', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'other', eva: 'expected', discharge_location_long: 0.02} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'other', eva: 'actual', discharge_location_long: 0} diff --git a/models/data_marts/benchmarks/benchmarks_gap_unit_tests.yml b/models/data_marts/benchmarks/benchmarks_gap_unit_tests.yml new file mode 100644 index 000000000..c753bbf95 --- /dev/null +++ b/models/data_marts/benchmarks/benchmarks_gap_unit_tests.yml @@ -0,0 +1,181 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGING: stg_cms_hcc__int_disease_factors (gap/edge cases) + # ========================================================================= + + - name: test_benchmarks_stg_disease_factors_null_hcc + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_cms_hcc__int_disease_factors + description: "Disease factors staging passes through rows even when hcc_code is null" + given: + - input: ref('cms_hcc__int_disease_factors') + rows: + - {person_id: 'P1', hcc_code: null, collection_end_date: '2023-12-31'} + expect: + rows: + - {person_id: 'P1', hcc_code: null, collection_end_date: '2023-12-31'} + + # ========================================================================= + # STAGING: stg_reference_data__calendar (gap/edge cases) + # ========================================================================= + + - name: test_benchmarks_stg_calendar_multiple_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_reference_data__calendar + description: "Calendar staging handles dates spanning multiple years" + given: + - input: ref('reference_data__calendar') + rows: + - {full_date: '2022-12-31', year: 2022, year_month_int: 202212, first_day_of_month: '2022-12-01'} + - {full_date: '2023-01-01', year: 2023, year_month_int: 202301, first_day_of_month: '2023-01-01'} + - {full_date: '2023-12-31', year: 2023, year_month_int: 202312, first_day_of_month: '2023-12-01'} + expect: + rows: + - {full_date: '2022-12-31', year: 2022, year_month_int: 202212, first_day_of_month: '2022-12-01'} + - {full_date: '2023-01-01', year: 2023, year_month_int: 202301, first_day_of_month: '2023-01-01'} + - {full_date: '2023-12-31', year: 2023, year_month_int: 202312, first_day_of_month: '2023-12-01'} + + # ========================================================================= + # INTERMEDIATE: pivot_hcc (gap/edge cases) + # ========================================================================= + + - name: test_benchmarks_pivot_hcc_deduplicates_same_code + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__pivot_hcc + description: "HCC pivot deduplicates when same HCC code appears multiple times in same year for same person" + given: + - input: ref('benchmarks__stg_cms_hcc__int_disease_factors') + rows: + - {person_id: 'P1', hcc_code: '19', collection_end_date: '2023-03-31'} + - {person_id: 'P1', hcc_code: '19', collection_end_date: '2023-06-30'} + - {person_id: 'P1', hcc_code: '19', collection_end_date: '2023-09-30'} + - input: ref('benchmarks__stg_reference_data__calendar') + rows: + - {full_date: '2023-03-31', year: 2023, year_month_int: 202303, first_day_of_month: '2023-03-01'} + - {full_date: '2023-06-30', year: 2023, year_month_int: 202306, first_day_of_month: '2023-06-01'} + - {full_date: '2023-09-30', year: 2023, year_month_int: 202309, first_day_of_month: '2023-09-01'} + expect: + rows: + - {person_id: 'P1', year_nbr: 2023, hcc_19: 1} + + - name: test_benchmarks_pivot_hcc_different_years_separate + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__pivot_hcc + description: "HCC pivot creates separate rows for different years" + given: + - input: ref('benchmarks__stg_cms_hcc__int_disease_factors') + rows: + - {person_id: 'P1', hcc_code: '19', collection_end_date: '2022-12-31'} + - {person_id: 'P1', hcc_code: '85', collection_end_date: '2023-12-31'} + - input: ref('benchmarks__stg_reference_data__calendar') + rows: + - {full_date: '2022-12-31', year: 2022, year_month_int: 202212, first_day_of_month: '2022-12-01'} + - {full_date: '2023-12-31', year: 2023, year_month_int: 202312, first_day_of_month: '2023-12-01'} + expect: + rows: + - {person_id: 'P1', year_nbr: 2022, hcc_19: 1, hcc_85: 0} + - {person_id: 'P1', year_nbr: 2023, hcc_19: 0, hcc_85: 1} + + # ========================================================================= + # POST-PREDICT: unpivot_inpatient (gap/edge cases) + # ========================================================================= + + - name: test_benchmarks_unpivot_inpatient_expired_location + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__unpivot_inpatient + description: "Unpivot inpatient correctly maps actual discharge to expired" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('benchmarks__predict_inpatient') + rows: + - {encounter_id: 'E1', person_id: 'P1', actual_discharge_location: 'expired', discharge_pred_proba_snf: 0.1, discharge_pred_proba_home: 0.1, discharge_pred_proba_home_health: 0.1, discharge_pred_proba_expired: 0.3, discharge_pred_proba_transfer_other_facility: 0.1, discharge_pred_proba_ipt_rehab: 0.1, discharge_pred_proba_hospice: 0.1, discharge_pred_proba_other: 0.1} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'expired', eva: 'actual', discharge_location_long: 1} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'expired', eva: 'expected', discharge_location_long: 0.3} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home', eva: 'actual', discharge_location_long: 0} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'snf', eva: 'actual', discharge_location_long: 0} + + - name: test_benchmarks_unpivot_inpatient_other_discharge + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__unpivot_inpatient + description: "Unpivot inpatient maps other discharge location correctly" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('benchmarks__predict_inpatient') + rows: + - {encounter_id: 'E1', person_id: 'P1', actual_discharge_location: 'other', discharge_pred_proba_snf: 0.0, discharge_pred_proba_home: 0.2, discharge_pred_proba_home_health: 0.0, discharge_pred_proba_expired: 0.0, discharge_pred_proba_transfer_other_facility: 0.0, discharge_pred_proba_ipt_rehab: 0.0, discharge_pred_proba_hospice: 0.0, discharge_pred_proba_other: 0.8} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'other', eva: 'actual', discharge_location_long: 1} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'other', eva: 'expected', discharge_location_long: 0.8} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home', eva: 'expected', discharge_location_long: 0.2} + + # ========================================================================= + # POST-PREDICT: unpivot_inpatient_prospective (gap/edge cases) + # ========================================================================= + + - name: test_benchmarks_unpivot_inpatient_prospective_transfer_location + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__unpivot_inpatient_prospective + description: "Unpivot inpatient prospective correctly maps actual discharge to transfer/other facility" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('benchmarks__predict_inpatient_prospective') + rows: + - {encounter_id: 'E1', person_id: 'P1', actual_discharge_location: 'transfer/other facility', discharge_pred_proba_snf: 0.1, discharge_pred_proba_home: 0.1, discharge_pred_proba_home_health: 0.05, discharge_pred_proba_expired: 0.05, discharge_pred_proba_transfer_other_facility: 0.5, discharge_pred_proba_ipt_rehab: 0.1, discharge_pred_proba_hospice: 0.05, discharge_pred_proba_other: 0.05} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'transfer/other facility', eva: 'actual', discharge_location_long: 1} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'transfer/other facility', eva: 'expected', discharge_location_long: 0.5} + - {encounter_id: 'E1', person_id: 'P1', discharge_location: 'home', eva: 'actual', discharge_location_long: 0} + + # ========================================================================= + # STAGING: stg_core__patient (gap/edge cases) + # ========================================================================= + + - name: test_benchmarks_stg_patient_null_fields + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_core__patient + description: "Patient staging handles null optional fields" + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', sex: null, birth_date: null, state: null, race: null} + expect: + rows: + - {person_id: 'P1', sex: null, birth_date: null, state: null, race: null} + + # ========================================================================= + # STAGING: stg_core__condition (gap/edge cases) + # ========================================================================= + + - name: test_benchmarks_stg_condition_null_code + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: benchmarks__stg_core__condition + description: "Condition staging passes through rows even with null normalized_code" + given: + - input: ref('core__condition') + rows: + - {person_id: 'P1', normalized_code: null, recorded_date: '2023-06-15'} + expect: + rows: + - {person_id: 'P1', normalized_code: null, recorded_date: '2023-06-15'} diff --git a/models/data_marts/ccsr/_gap_unit_tests.yml b/models/data_marts/ccsr/_gap_unit_tests.yml new file mode 100644 index 000000000..237f813d4 --- /dev/null +++ b/models/data_marts/ccsr/_gap_unit_tests.yml @@ -0,0 +1,150 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # CCSR - STAGING: stg_core__condition (edge cases) + # ========================================================================= + + - name: test_ccsr_stg_condition_dedup_across_multiple_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__stg_core__condition + description: "Same diagnosis code on different claims is preserved as separate rows (dedup is per-claim, not global)" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__condition') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', normalized_code_type: 'icd-10-cm', condition_rank: 1, data_source: 'src1'} + - {encounter_id: 'E2', claim_id: 'C2', person_id: 'P1', normalized_code: 'E11.65', normalized_code_type: 'icd-10-cm', condition_rank: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', condition_rank: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', claim_id: 'C2', person_id: 'P1', normalized_code: 'E11.65', condition_rank: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_ccsr_stg_condition_dedup_mixed_scenario + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__stg_core__condition + description: "Mixed scenario: duplicates within a claim are removed, different codes on same claim preserved, same code on different claims preserved" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__condition') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', normalized_code_type: 'icd-10-cm', condition_rank: 1, data_source: 'src1'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', normalized_code_type: 'icd-10-cm', condition_rank: 1, data_source: 'src1'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'I10', normalized_code_type: 'icd-10-cm', condition_rank: 2, data_source: 'src1'} + - {encounter_id: 'E2', claim_id: 'C2', person_id: 'P2', normalized_code: 'E11.65', normalized_code_type: 'icd-10-cm', condition_rank: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', condition_rank: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'I10', condition_rank: 2, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', claim_id: 'C2', person_id: 'P2', normalized_code: 'E11.65', condition_rank: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_ccsr_stg_condition_null_encounter_id_preserved + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__stg_core__condition + description: "Conditions with null encounter_id are still passed through when code type is ICD-10-CM" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__condition') + rows: + - {encounter_id: null, claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', normalized_code_type: 'icd-10-cm', condition_rank: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: null, claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', condition_rank: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CCSR - FINAL: singular_condition_category + # ========================================================================= + + - name: test_ccsr_singular_condition_picks_default_rank_1 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__singular_condition_category + description: "Singular condition category filters to default IP/OP category with condition_rank=1" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + dxccsr_version: '2023.1' + record_type: 'ip' + given: + - input: ref('ccsr__long_condition_category') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', code_description: 'T2 DM', condition_rank: 1, ccsr_parent_category: 'END', body_system: 'Endocrine', ccsr_category: 'END010', ccsr_category_description: 'DM complication', ccsr_category_rank: 1, is_ip_default_category: 1, is_op_default_category: 1, data_source: 'src1', parent_category_description: 'Endocrine disorders', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', code_description: 'T2 DM', condition_rank: 1, ccsr_parent_category: 'END', body_system: 'Endocrine', ccsr_category: 'END011', ccsr_category_description: 'DM general', ccsr_category_rank: 2, is_ip_default_category: 0, is_op_default_category: 0, data_source: 'src1', parent_category_description: 'Endocrine disorders', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', normalized_code: 'E11.65', ccsr_category: 'END010', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CCSR - FINAL: procedure_summary + # ========================================================================= + + - name: test_ccsr_procedure_summary_aggregates_by_approach + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__procedure_summary + description: "Procedure summary counts occurrences by CCSR category/operation/approach" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ccsr__long_procedure_category') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: '0DBN0ZZ', code_description: 'Excision sigmoid', ccsr_parent_category: 'GIS', ccsr_category: 'GIS004', ccsr_category_description: 'Excision large intestine', clinical_domain: 'GI', procedure_section: 'Medical and Surgical', operation: 'Excision', approach: 'Open', device: 'No Device', qualifier: 'No Qualifier', data_source: 'src1', prccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', claim_id: 'C2', person_id: 'P2', normalized_code: '0DBN4ZZ', code_description: 'Excision sigmoid endo', ccsr_parent_category: 'GIS', ccsr_category: 'GIS004', ccsr_category_description: 'Excision large intestine', clinical_domain: 'GI', procedure_section: 'Medical and Surgical', operation: 'Excision', approach: 'Endoscopic', device: 'No Device', qualifier: 'No Qualifier', data_source: 'src1', prccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {ccsr_category: 'GIS004', operation: 'Excision', approach: 'Open', n_occurrences_with_approach: 1, n_total_occurrences: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {ccsr_category: 'GIS004', operation: 'Excision', approach: 'Endoscopic', n_occurrences_with_approach: 1, n_total_occurrences: 2, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CCSR - FINAL: singular_condition_category (edge cases) + # ========================================================================= + + - name: test_ccsr_singular_condition_op_record_type + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__singular_condition_category + description: "When record_type is OP, singular condition selects the OP default category instead of IP" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + dxccsr_version: '2023.1' + record_type: 'op' + given: + - input: ref('ccsr__long_condition_category') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', code_description: 'T2 DM', condition_rank: 1, ccsr_parent_category: 'END', body_system: 'Endocrine', ccsr_category: 'END010', ccsr_category_description: 'DM complication', ccsr_category_rank: 1, is_ip_default_category: 0, is_op_default_category: 1, data_source: 'src1', parent_category_description: 'Endocrine disorders', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', code_description: 'T2 DM', condition_rank: 1, ccsr_parent_category: 'END', body_system: 'Endocrine', ccsr_category: 'END011', ccsr_category_description: 'DM general', ccsr_category_rank: 2, is_ip_default_category: 1, is_op_default_category: 0, data_source: 'src1', parent_category_description: 'Endocrine disorders', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', normalized_code: 'E11.65', ccsr_category: 'END010', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_ccsr_singular_condition_multiple_encounters + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__singular_condition_category + description: "Multiple encounters each produce their own singular condition category row" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + dxccsr_version: '2023.1' + record_type: 'ip' + given: + - input: ref('ccsr__long_condition_category') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', code_description: 'T2 DM', condition_rank: 1, ccsr_parent_category: 'END', body_system: 'Endocrine', ccsr_category: 'END010', ccsr_category_description: 'DM complication', ccsr_category_rank: 1, is_ip_default_category: 1, is_op_default_category: 1, data_source: 'src1', parent_category_description: 'Endocrine disorders', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', claim_id: 'C2', person_id: 'P2', normalized_code: 'I10', code_description: 'Hypertension', condition_rank: 1, ccsr_parent_category: 'CIR', body_system: 'Circulatory', ccsr_category: 'CIR007', ccsr_category_description: 'Hypertension', ccsr_category_rank: 1, is_ip_default_category: 1, is_op_default_category: 1, data_source: 'src1', parent_category_description: 'Circulatory disorders', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', normalized_code: 'E11.65', ccsr_category: 'END010', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', normalized_code: 'I10', ccsr_category: 'CIR007', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/data_marts/ccsr/_unit_tests.yml b/models/data_marts/ccsr/_unit_tests.yml new file mode 100644 index 000000000..89bd273b3 --- /dev/null +++ b/models/data_marts/ccsr/_unit_tests.yml @@ -0,0 +1,185 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # CCSR - STAGING: stg_core__condition + # ========================================================================= + + - name: test_ccsr_stg_condition_filters_icd10cm + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__stg_core__condition + description: "Only ICD-10-CM condition codes are passed through; other code types are filtered out" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__condition') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', normalized_code_type: 'icd-10-cm', condition_rank: 1, data_source: 'src1'} + - {encounter_id: 'E2', claim_id: 'C2', person_id: 'P2', normalized_code: '250.00', normalized_code_type: 'icd-9-cm', condition_rank: 1, data_source: 'src1'} + - {encounter_id: 'E3', claim_id: 'C3', person_id: 'P3', normalized_code: 'SNOMED1', normalized_code_type: 'snomed-ct', condition_rank: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', condition_rank: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_ccsr_stg_condition_deduplicates_same_dx_across_line_items + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__stg_core__condition + description: "Same diagnosis code on multiple line items of same claim produces only one record after deduplication" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__condition') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', normalized_code_type: 'icd-10-cm', condition_rank: 1, data_source: 'src1'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', normalized_code_type: 'icd-10-cm', condition_rank: 1, data_source: 'src1'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', normalized_code_type: 'icd-10-cm', condition_rank: 1, data_source: 'src1'} + expect: + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', condition_rank: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_ccsr_stg_condition_preserves_different_dx_on_same_claim + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__stg_core__condition + description: "Different diagnosis codes on the same claim are all preserved as separate rows" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__condition') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', normalized_code_type: 'icd-10-cm', condition_rank: 1, data_source: 'src1'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'I10', normalized_code_type: 'icd-10-cm', condition_rank: 2, data_source: 'src1'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'J18.9', normalized_code_type: 'icd-10-cm', condition_rank: 3, data_source: 'src1'} + expect: + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', condition_rank: 1, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'I10', condition_rank: 2, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'J18.9', condition_rank: 3, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CCSR - STAGING: stg_core__procedure + # ========================================================================= + + - name: test_ccsr_stg_procedure_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__stg_core__procedure + description: "Procedure staging passes through all core procedure fields" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__procedure') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: '0DBN0ZZ', data_source: 'src1'} + expect: + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: '0DBN0ZZ', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CCSR - INTERMEDIATE: dx_vertical_pivot + # ========================================================================= + + - name: test_ccsr_dx_vertical_pivot_unpivots_categories + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__dx_vertical_pivot + description: "ICD-10-CM codes are unpivoted from wide category columns (1-6) into long format rows; null categories are excluded" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ccsr__dxccsr_v2023_1_cleaned_map') + rows: + - {icd_10_cm_code: 'E11.65', icd_10_cm_code_description: 'Type 2 DM with hyperglycemia', ccsr_category_1: 'END010', ccsr_category_1_description: 'Diabetes mellitus with complication', ccsr_category_2: null, ccsr_category_2_description: null, ccsr_category_3: null, ccsr_category_3_description: null, ccsr_category_4: null, ccsr_category_4_description: null, ccsr_category_5: null, ccsr_category_5_description: null, ccsr_category_6: null, ccsr_category_6_description: null, default_ccsr_category_ip: 'END010', default_ccsr_category_op: 'END010'} + expect: + rows: + - {code: 'E11.65', code_description: 'Type 2 DM with hyperglycemia', ccsr_parent_category: 'END', ccsr_category: 'END010', ccsr_category_description: 'Diabetes mellitus with complication', ccsr_category_rank: 1, is_ip_default_category: 1, is_op_default_category: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_ccsr_dx_vertical_pivot_ccsr_category_mapping + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__dx_vertical_pivot + description: "Known ICD-10-CM code with multiple CCSR categories produces correct category mappings and ranks" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ccsr__dxccsr_v2023_1_cleaned_map') + rows: + - {icd_10_cm_code: 'I50.9', icd_10_cm_code_description: 'Heart failure unspecified', ccsr_category_1: 'CIR019', ccsr_category_1_description: 'Heart failure', ccsr_category_2: 'CIR020', ccsr_category_2_description: 'Cardiomyopathy', ccsr_category_3: null, ccsr_category_3_description: null, ccsr_category_4: null, ccsr_category_4_description: null, ccsr_category_5: null, ccsr_category_5_description: null, ccsr_category_6: null, ccsr_category_6_description: null, default_ccsr_category_ip: 'CIR019', default_ccsr_category_op: 'CIR019'} + expect: + rows: + - {code: 'I50.9', code_description: 'Heart failure unspecified', ccsr_parent_category: 'CIR', ccsr_category: 'CIR019', ccsr_category_description: 'Heart failure', ccsr_category_rank: 1, is_ip_default_category: 1, is_op_default_category: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {code: 'I50.9', code_description: 'Heart failure unspecified', ccsr_parent_category: 'CIR', ccsr_category: 'CIR020', ccsr_category_description: 'Cardiomyopathy', ccsr_category_rank: 2, is_ip_default_category: 0, is_op_default_category: 0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CCSR - FINAL: singular_condition_category (condition_rank filtering) + # ========================================================================= + + - name: test_ccsr_singular_condition_filters_to_rank_1_only + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__singular_condition_category + description: "Singular condition category only includes conditions with condition_rank=1, excluding secondary diagnoses" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + dxccsr_version: '2023.1' + record_type: 'ip' + given: + - input: ref('ccsr__long_condition_category') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', code_description: 'T2 DM', condition_rank: 1, ccsr_parent_category: 'END', body_system: 'Endocrine', ccsr_category: 'END010', ccsr_category_description: 'DM complication', ccsr_category_rank: 1, is_ip_default_category: 1, is_op_default_category: 1, data_source: 'src1', parent_category_description: 'Endocrine disorders', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'I10', code_description: 'Hypertension', condition_rank: 2, ccsr_parent_category: 'CIR', body_system: 'Circulatory', ccsr_category: 'CIR007', ccsr_category_description: 'Hypertension', ccsr_category_rank: 1, is_ip_default_category: 1, is_op_default_category: 1, data_source: 'src1', parent_category_description: 'Circulatory disorders', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', normalized_code: 'E11.65', ccsr_category: 'END010', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_ccsr_singular_condition_no_duplicates_multi_line_items + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__singular_condition_category + description: "Singular condition category produces exactly one record per encounter when input has no duplicates" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + dxccsr_version: '2023.1' + record_type: 'ip' + given: + - input: ref('ccsr__long_condition_category') + rows: + - {encounter_id: 'E1', claim_id: 'C1', person_id: 'P1', normalized_code: 'E11.65', code_description: 'T2 DM', condition_rank: 1, ccsr_parent_category: 'END', body_system: 'Endocrine', ccsr_category: 'END010', ccsr_category_description: 'DM complication', ccsr_category_rank: 1, is_ip_default_category: 1, is_op_default_category: 1, data_source: 'src1', parent_category_description: 'Endocrine disorders', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', normalized_code: 'E11.65', ccsr_category: 'END010', dxccsr_version: '2023.1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CCSR - INTERMEDIATE: procedure_category_map + # ========================================================================= + + - name: test_ccsr_procedure_category_map_joins_ontology + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ccsr__procedure_category_map + description: "Procedure CCSR map joins to ICD-10-PCS ontology for operation/approach/device/qualifier" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ccsr__prccsr_v2023_1_cleaned_map') + rows: + - {icd_10_pcs: '0DBN0ZZ', icd_10_pcs_description: 'Excision sigmoid colon', prccsr: 'GIS004', prccsr_description: 'Excision of large intestine', clinical_domain: 'Gastrointestinal'} + - input: ref('terminology__icd10_pcs_cms_ontology') + rows: + - {icd10pcs_code: '0DBN0ZZ', section: 'Medical and Surgical', operation: 'Excision', approach: 'Open', device: 'No Device', qualifier: 'No Qualifier'} + expect: + rows: + - {code: '0DBN0ZZ', code_description: 'Excision sigmoid colon', ccsr_category: 'GIS004', ccsr_parent_category: 'GIS', ccsr_category_description: 'Excision of large intestine', clinical_domain: 'Gastrointestinal', procedure_section: 'Medical and Surgical', operation: 'Excision', approach: 'Open', device: 'No Device', qualifier: 'No Qualifier', tuva_last_run: '2024-01-01 00:00:00'} + diff --git a/models/data_marts/chronic_conditions/_gap_unit_tests.yml b/models/data_marts/chronic_conditions/_gap_unit_tests.yml new file mode 100644 index 000000000..fe60fb954 --- /dev/null +++ b/models/data_marts/chronic_conditions/_gap_unit_tests.yml @@ -0,0 +1,23 @@ +version: 2 + +unit_tests: + + - name: test_chronic_conditions__cms_chronic_conditions_long_empty_inputs + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the CMS long format returns empty when all intermediate + models are empty. + model: chronic_conditions__cms_chronic_conditions_long + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('chronic_conditions__cms_chronic_conditions_all') + rows: [] + - input: ref('chronic_conditions__cms_chronic_conditions_hiv_aids') + rows: [] + - input: ref('chronic_conditions__cms_chronic_conditions_oud') + rows: [] + expect: + rows: [] diff --git a/models/data_marts/chronic_conditions/_unit_tests.yml b/models/data_marts/chronic_conditions/_unit_tests.yml new file mode 100644 index 000000000..944f113c1 --- /dev/null +++ b/models/data_marts/chronic_conditions/_unit_tests.yml @@ -0,0 +1,312 @@ +version: 2 + +unit_tests: + + - name: test_tuva_chronic_conditions__stg_core__condition_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the Tuva chronic conditions staging model passes through + person_id, normalized_code, and recorded_date from core condition. + model: tuva_chronic_conditions__stg_core__condition + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__condition') + rows: + - person_id: 'patient_1' + normalized_code: 'E11.65' + recorded_date: '2024-01-15' + - person_id: 'patient_2' + normalized_code: 'I10' + recorded_date: '2024-02-01' + expect: + rows: + - person_id: 'patient_1' + normalized_code: 'E11.65' + recorded_date: '2024-01-15' + - person_id: 'patient_2' + normalized_code: 'I10' + recorded_date: '2024-02-01' + + - name: test_tuva_chronic_conditions__stg_core__patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the Tuva chronic conditions patient staging passes + through person_id from core patient. + model: tuva_chronic_conditions__stg_core__patient + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__patient') + rows: + - person_id: 'patient_1' + - person_id: 'patient_2' + expect: + rows: + - person_id: 'patient_1' + - person_id: 'patient_2' + + - name: test_cms_chronic_conditions__stg_core__condition_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the CMS staging condition model passes through fields + and filters to only claims with a claim_id. + model: cms_chronic_conditions__stg_core__condition + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__condition') + rows: + - claim_id: 'clm_001' + person_id: 'patient_1' + recorded_date: '2024-01-15' + normalized_code_type: 'icd-10-cm' + normalized_code: 'E11.65' + data_source: 'claims_a' + - claim_id: null + person_id: 'patient_2' + recorded_date: '2024-02-01' + normalized_code_type: 'icd-10-cm' + normalized_code: 'I10' + data_source: 'claims_a' + expect: + rows: + - claim_id: 'clm_001' + person_id: 'patient_1' + recorded_date: '2024-01-15' + normalized_code_type: 'icd-10-cm' + normalized_code: 'E11.65' + data_source: 'claims_a' + + - name: test_cms_chronic_conditions__stg_core__medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the CMS staging medical claim model passes through + claim and DRG fields. + model: cms_chronic_conditions__stg_core__medical_claim + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__medical_claim') + rows: + - claim_id: 'clm_010' + person_id: 'patient_1' + claim_start_date: '2024-01-15' + drg_code_type: 'ms-drg' + drg_code: '470' + data_source: 'claims_a' + expect: + rows: + - claim_id: 'clm_010' + person_id: 'patient_1' + claim_start_date: '2024-01-15' + drg_code_type: 'ms-drg' + drg_code: '470' + data_source: 'claims_a' + + - name: test_cms_chronic_conditions__stg_core__patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the CMS staging patient model passes through person_id. + model: cms_chronic_conditions__stg_core__patient + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__patient') + rows: + - person_id: 'patient_1' + - person_id: 'patient_2' + expect: + rows: + - person_id: 'patient_1' + - person_id: 'patient_2' + + - name: test_cms_chronic_conditions__stg_core__pharmacy_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify CMS staging pharmacy claim passes through claim_id, + person_id, paid_date, ndc_code, and data_source. + model: cms_chronic_conditions__stg_core__pharmacy_claim + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__pharmacy_claim') + rows: + - claim_id: 'rx_001' + person_id: 'patient_1' + paid_date: '2024-01-20' + ndc_code: '12345678901' + data_source: 'claims_a' + - claim_id: 'rx_002' + person_id: 'patient_2' + paid_date: '2024-02-15' + ndc_code: '99999999999' + data_source: 'claims_b' + expect: + rows: + - claim_id: 'rx_001' + person_id: 'patient_1' + paid_date: '2024-01-20' + ndc_code: '12345678901' + data_source: 'claims_a' + - claim_id: 'rx_002' + person_id: 'patient_2' + paid_date: '2024-02-15' + ndc_code: '99999999999' + data_source: 'claims_b' + + - name: test_cms_chronic_conditions__stg_core__procedure_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify CMS staging procedure passes through and filters + to only rows with a claim_id. + model: cms_chronic_conditions__stg_core__procedure + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__procedure') + rows: + - claim_id: 'clm_020' + person_id: 'patient_1' + procedure_date: '2024-01-15' + normalized_code_type: 'hcpcs' + normalized_code: 'G0438' + data_source: 'claims_a' + - claim_id: null + person_id: 'patient_2' + procedure_date: '2024-02-01' + normalized_code_type: 'cpt' + normalized_code: '99213' + data_source: 'claims_a' + expect: + rows: + - claim_id: 'clm_020' + person_id: 'patient_1' + procedure_date: '2024-01-15' + normalized_code_type: 'hcpcs' + normalized_code: 'G0438' + data_source: 'claims_a' + + - name: test_chronic_conditions__cms_chronic_conditions_long_union + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the CMS long format unions conditions from the all, + HIV/AIDS, and OUD intermediate models. + model: chronic_conditions__cms_chronic_conditions_long + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('chronic_conditions__cms_chronic_conditions_all') + rows: + - person_id: 'patient_1' + claim_id: 'clm_001' + start_date: '2024-01-15' + chronic_condition_type: 'CMS Type' + condition_category: 'Metabolic' + condition: 'Diabetes' + data_source: 'claims_a' + tuva_last_run: '2024-01-01 00:00:00' + - input: ref('chronic_conditions__cms_chronic_conditions_hiv_aids') + rows: + - person_id: 'patient_2' + claim_id: 'clm_002' + start_date: '2024-02-01' + chronic_condition_type: 'CMS Type' + condition_category: 'Infectious' + condition: 'HIV/AIDS' + data_source: 'claims_a' + tuva_last_run: '2024-01-01 00:00:00' + - input: ref('chronic_conditions__cms_chronic_conditions_oud') + rows: + - person_id: 'patient_3' + claim_id: 'clm_003' + start_date: '2024-03-01' + chronic_condition_type: 'CMS Type' + condition_category: 'Substance Use' + condition: 'Opioid Use Disorder (OUD)' + data_source: 'claims_a' + tuva_last_run: '2024-01-01 00:00:00' + expect: + rows: + - person_id: 'patient_1' + claim_id: 'clm_001' + start_date: '2024-01-15' + chronic_condition_type: 'CMS Type' + condition_category: 'Metabolic' + condition: 'Diabetes' + data_source: 'claims_a' + - person_id: 'patient_2' + claim_id: 'clm_002' + start_date: '2024-02-01' + chronic_condition_type: 'CMS Type' + condition_category: 'Infectious' + condition: 'HIV/AIDS' + data_source: 'claims_a' + - person_id: 'patient_3' + claim_id: 'clm_003' + start_date: '2024-03-01' + chronic_condition_type: 'CMS Type' + condition_category: 'Substance Use' + condition: 'Opioid Use Disorder (OUD)' + data_source: 'claims_a' + + - name: test_chronic_conditions__cms_chronic_conditions_long_deduplication + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the CMS long format deduplicates when the same condition + appears in multiple intermediate models. + model: chronic_conditions__cms_chronic_conditions_long + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('chronic_conditions__cms_chronic_conditions_all') + rows: + - person_id: 'patient_1' + claim_id: 'clm_001' + start_date: '2024-01-15' + chronic_condition_type: 'CMS Type' + condition_category: 'Metabolic' + condition: 'Diabetes' + data_source: 'claims_a' + tuva_last_run: '2024-01-01 00:00:00' + - input: ref('chronic_conditions__cms_chronic_conditions_hiv_aids') + rows: + - person_id: 'patient_1' + claim_id: 'clm_001' + start_date: '2024-01-15' + chronic_condition_type: 'CMS Type' + condition_category: 'Metabolic' + condition: 'Diabetes' + data_source: 'claims_a' + tuva_last_run: '2024-01-01 00:00:00' + - input: ref('chronic_conditions__cms_chronic_conditions_oud') + rows: [] + expect: + rows: + - person_id: 'patient_1' + claim_id: 'clm_001' + start_date: '2024-01-15' + chronic_condition_type: 'CMS Type' + condition_category: 'Metabolic' + condition: 'Diabetes' + data_source: 'claims_a' + + diff --git a/models/data_marts/clinical_concept_library/_unit_tests.yml b/models/data_marts/clinical_concept_library/_unit_tests.yml new file mode 100644 index 000000000..6d6065323 --- /dev/null +++ b/models/data_marts/clinical_concept_library/_unit_tests.yml @@ -0,0 +1,114 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # clinical_concept_library__value_set_member_relevant_fields + # ========================================================================= + + - name: test_ccl_value_set_member_joins_concepts_and_coding_systems + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: clinical_concept_library__value_set_member_relevant_fields + description: > + The value_set_member_relevant_fields model should join clinical_concepts + with value_set_members and coding_systems to produce one row per value + set member with concept name, code, and coding system name. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('clinical_concept_library__clinical_concepts') + rows: + - {concept_id: 'C001', concept_name: 'Diabetes', concept_type: 'condition'} + - {concept_id: 'C002', concept_name: 'Hypertension', concept_type: 'condition'} + - input: ref('clinical_concept_library__value_set_members') + rows: + - {value_set_member_id: 'VSM001', concept_id: 'C001', code: 'E11.65', coding_system_id: 'CS001', include_descendants: 'yes'} + - {value_set_member_id: 'VSM002', concept_id: 'C001', code: '73211009', coding_system_id: 'CS002', include_descendants: 'no'} + - {value_set_member_id: 'VSM003', concept_id: 'C002', code: 'I10', coding_system_id: 'CS001', include_descendants: 'no'} + - input: ref('clinical_concept_library__coding_systems') + rows: + - {coding_system_id: 'CS001', coding_system_name: 'ICD-10-CM'} + - {coding_system_id: 'CS002', coding_system_name: 'SNOMED CT'} + expect: + rows: + - {concept_id: 'C001', concept_name: 'Diabetes', concept_type: 'condition', value_set_member_id: 'VSM001', code: 'E11.65', coding_system_id: 'CS001', include_descendants: 'yes', coding_system_name: 'ICD-10-CM'} + - {concept_id: 'C001', concept_name: 'Diabetes', concept_type: 'condition', value_set_member_id: 'VSM002', code: '73211009', coding_system_id: 'CS002', include_descendants: 'no', coding_system_name: 'SNOMED CT'} + - {concept_id: 'C002', concept_name: 'Hypertension', concept_type: 'condition', value_set_member_id: 'VSM003', code: 'I10', coding_system_id: 'CS001', include_descendants: 'no', coding_system_name: 'ICD-10-CM'} + + - name: test_ccl_value_set_member_handles_concept_without_members + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: clinical_concept_library__value_set_member_relevant_fields + description: > + A concept with no value set members should still produce a row + from the left outer join, with null value_set_member fields. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('clinical_concept_library__clinical_concepts') + rows: + - {concept_id: 'C003', concept_name: 'Orphan concept', concept_type: 'lab'} + - input: ref('clinical_concept_library__value_set_members') + rows: [] + - input: ref('clinical_concept_library__coding_systems') + rows: + - {coding_system_id: 'CS001', coding_system_name: 'ICD-10-CM'} + expect: + rows: + - {concept_id: 'C003', concept_name: 'Orphan concept', concept_type: 'lab', value_set_member_id: null, code: null, coding_system_id: null, include_descendants: null, coding_system_name: null} + + - name: test_ccl_value_set_member_handles_missing_coding_system + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: clinical_concept_library__value_set_member_relevant_fields + description: > + A value set member referencing a coding_system_id not in the + coding_systems table should still appear with null coding_system_name. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('clinical_concept_library__clinical_concepts') + rows: + - {concept_id: 'C001', concept_name: 'Diabetes', concept_type: 'condition'} + - input: ref('clinical_concept_library__value_set_members') + rows: + - {value_set_member_id: 'VSM010', concept_id: 'C001', code: 'XYZ123', coding_system_id: 'CS999', include_descendants: 'no'} + - input: ref('clinical_concept_library__coding_systems') + rows: [] + expect: + rows: + - {concept_id: 'C001', concept_name: 'Diabetes', concept_type: 'condition', value_set_member_id: 'VSM010', code: 'XYZ123', coding_system_id: 'CS999', include_descendants: 'no', coding_system_name: null} + + - name: test_ccl_value_set_member_multiple_codes_per_concept + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: clinical_concept_library__value_set_member_relevant_fields + description: > + A single concept can have multiple value set members across different + coding systems. All should appear as separate rows. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('clinical_concept_library__clinical_concepts') + rows: + - {concept_id: 'C010', concept_name: 'Heart Failure', concept_type: 'condition'} + - input: ref('clinical_concept_library__value_set_members') + rows: + - {value_set_member_id: 'VSM020', concept_id: 'C010', code: 'I50.9', coding_system_id: 'CS001', include_descendants: 'yes'} + - {value_set_member_id: 'VSM021', concept_id: 'C010', code: '84114007', coding_system_id: 'CS002', include_descendants: 'no'} + - {value_set_member_id: 'VSM022', concept_id: 'C010', code: '428.0', coding_system_id: 'CS003', include_descendants: 'no'} + - input: ref('clinical_concept_library__coding_systems') + rows: + - {coding_system_id: 'CS001', coding_system_name: 'ICD-10-CM'} + - {coding_system_id: 'CS002', coding_system_name: 'SNOMED CT'} + - {coding_system_id: 'CS003', coding_system_name: 'ICD-9-CM'} + expect: + rows: + - {concept_id: 'C010', concept_name: 'Heart Failure', concept_type: 'condition', value_set_member_id: 'VSM020', code: 'I50.9', coding_system_id: 'CS001', include_descendants: 'yes', coding_system_name: 'ICD-10-CM'} + - {concept_id: 'C010', concept_name: 'Heart Failure', concept_type: 'condition', value_set_member_id: 'VSM021', code: '84114007', coding_system_id: 'CS002', include_descendants: 'no', coding_system_name: 'SNOMED CT'} + - {concept_id: 'C010', concept_name: 'Heart Failure', concept_type: 'condition', value_set_member_id: 'VSM022', code: '428.0', coding_system_id: 'CS003', include_descendants: 'no', coding_system_name: 'ICD-9-CM'} diff --git a/models/data_marts/cms_hcc/cms_hcc_gap_unit_tests.yml b/models/data_marts/cms_hcc/cms_hcc_gap_unit_tests.yml new file mode 100644 index 000000000..c6e5ec000 --- /dev/null +++ b/models/data_marts/cms_hcc/cms_hcc_gap_unit_tests.yml @@ -0,0 +1,44 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # CMS HCC - INTERMEDIATE: int_eligible_conditions + # ========================================================================= + + # ========================================================================= + # CMS HCC - FINAL: patient_risk_factors_monthly + # ========================================================================= + + - name: test_cms_hcc_patient_risk_factors_monthly_unions_factors + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__patient_risk_factors_monthly + description: "Patient risk factors monthly unions all factor types with risk model defaults" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_demographic_factors') + rows: + - {person_id: 'P1', payer: 'MCR', gender: 'Male', age_group: '65-69', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', risk_model_code: 'CNA', enrollment_status_default: false, medicaid_dual_status_default: false, orec_default: false, institutional_status_default: false, coefficient: 0.35, factor_type: 'demographic', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__int_disease_factors') + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: 'HCC19', hcc_description: 'Diabetes', coefficient: 0.302, factor_type: 'disease', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__int_enrollment_interaction_factors') + rows: [] + - input: ref('cms_hcc__int_disabled_interaction_factors') + rows: [] + - input: ref('cms_hcc__int_disease_interaction_factors') + rows: [] + - input: ref('cms_hcc__int_hcc_count_factors') + rows: [] + expect: + rows: + - {person_id: 'P1', factor_type: 'demographic', coefficient: 0.35, payment_year: 2024, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', factor_type: 'disease', coefficient: 0.302, payment_year: 2024, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # CMS HCC - FINAL: patient_risk_scores_monthly_by_factor_type + # ========================================================================= + diff --git a/models/data_marts/cms_hcc/cms_hcc_unit_tests.yml b/models/data_marts/cms_hcc/cms_hcc_unit_tests.yml new file mode 100644 index 000000000..37cf81965 --- /dev/null +++ b/models/data_marts/cms_hcc/cms_hcc_unit_tests.yml @@ -0,0 +1,515 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGING MODELS + # ========================================================================= + + - name: test_stg_condition_deduplicates_by_rank + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__stg_core__condition + description: "DISTINCT removes duplicates caused by different condition_rank values" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__condition') + rows: + - {claim_id: 'CLM1', person_id: 'P1', payer: 'MCR', recorded_date: '2023-06-15', condition_type: 'discharge', normalized_code_type: 'icd-10-cm', normalized_code: 'E1165', data_source: 'src1', condition_rank: 1} + - {claim_id: 'CLM1', person_id: 'P1', payer: 'MCR', recorded_date: '2023-06-15', condition_type: 'discharge', normalized_code_type: 'icd-10-cm', normalized_code: 'E1165', data_source: 'src1', condition_rank: 2} + expect: + rows: + - {claim_id: 'CLM1', person_id: 'P1', payer: 'MCR', recorded_date: '2023-06-15', condition_type: 'discharge', code_type: 'icd-10-cm', code: 'E1165', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_eligibility_filters_to_medicare + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__stg_core__eligibility + description: "Only records with payer_type='medicare' or null pass through" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__eligibility') + rows: + - {person_id: 'P1', payer: 'MCR', payer_type: 'medicare', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', original_reason_entitlement_code: '0', dual_status_code: null, medicare_status_code: '10', enrollment_status: null, medicaid_indicator: null, long_term_institutional_flag: null, snp_type: null, data_source: 's1'} + - {person_id: 'P2', payer: 'COM', payer_type: 'commercial', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, medicaid_indicator: null, long_term_institutional_flag: null, snp_type: null, data_source: 's1'} + - {person_id: 'P3', payer: 'UNK', payer_type: null, enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, medicaid_indicator: null, long_term_institutional_flag: null, snp_type: null, data_source: 's1'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', original_reason_entitlement_code: '0', dual_status_code: null, medicare_status_code: '10', enrollment_status: null, medicaid_indicator: null, long_term_institutional_flag: null, institutional_snp_flag: 0, snp_flag: 0, data_source: 's1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P3', payer: 'UNK', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, medicaid_indicator: null, long_term_institutional_flag: null, institutional_snp_flag: 0, snp_flag: 0, data_source: 's1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_eligibility_snp_flags + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__stg_core__eligibility + description: "I-SNP sets institutional_snp_flag=1; any SNP sets snp_flag=1" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__eligibility') + rows: + - {person_id: 'P1', payer: 'MCR', payer_type: 'medicare', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', snp_type: 'I-SNP', data_source: 's1'} + - {person_id: 'P2', payer: 'MCR', payer_type: 'medicare', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', snp_type: 'D-SNP', data_source: 's1'} + - {person_id: 'P3', payer: 'MCR', payer_type: 'medicare', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', snp_type: null, data_source: 's1'} + expect: + rows: + - {person_id: 'P1', institutional_snp_flag: 1, snp_flag: 1, payer: 'MCR', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, medicaid_indicator: null, long_term_institutional_flag: null, data_source: 's1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', institutional_snp_flag: 0, snp_flag: 1, payer: 'MCR', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, medicaid_indicator: null, long_term_institutional_flag: null, data_source: 's1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P3', institutional_snp_flag: 0, snp_flag: 0, payer: 'MCR', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', original_reason_entitlement_code: null, dual_status_code: null, medicare_status_code: null, enrollment_status: null, medicaid_indicator: null, long_term_institutional_flag: null, data_source: 's1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__stg_core__medical_claim + description: "Medical claim staging passes through and renames columns correctly" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__medical_claim') + rows: + - {claim_id: 'CLM1', claim_line_number: '1', claim_type: 'professional', person_id: 'P1', payer: 'MCR', claim_start_date: '2023-06-01', claim_end_date: '2023-06-15', bill_type_code: null, hcpcs_code: '99213', rendering_npi: 'NPI1', data_source: 's1'} + expect: + rows: + - {claim_id: 'CLM1', claim_line_number: '1', claim_type: 'professional', person_id: 'P1', payer: 'MCR', claim_start_date: '2023-06-01', claim_end_date: '2023-06-15', bill_type_code: null, hcpcs_code: '99213', rendering_npi: 'NPI1', data_source: 's1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__stg_core__patient + description: "Patient staging passes through columns correctly" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1954-01-01', death_date: null} + expect: + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1954-01-01', death_date: null, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_stg_member_months_deduplicates_plans + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__stg_core__member_months + description: "DISTINCT removes plan-level duplicates from member months" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', payer: 'MCR', year_month: '2023-01', data_source: 's1', plan: 'PlanA'} + - {person_id: 'P1', payer: 'MCR', year_month: '2023-01', data_source: 's1', plan: 'PlanB'} + - {person_id: 'P1', payer: 'MCR', year_month: '2023-02', data_source: 's1', plan: 'PlanA'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', year_month: '2023-01', data_source: 's1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', year_month: '2023-02', data_source: 's1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # MONTHLY COLLECTION DATES + # ========================================================================= + + # ========================================================================= + # HCC MAPPING (includes V28 Heart Patch test - Defect #1) + # ========================================================================= + + - name: test_hcc_mapping_v24_basic + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_hcc_mapping + description: "ICD-10 code maps to V24 HCC when cms_hcc_v24_flag=Yes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_eligible_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', condition_code: 'E1165', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__icd_10_cm_mappings') + rows: + - {payment_year: 2024, diagnosis_code: 'E1165', cms_hcc_v24: '18', cms_hcc_v24_flag: 'Yes', cms_hcc_v28: '37', cms_hcc_v28_flag: 'Yes'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', condition_code: 'E1165', hcc_code: '18', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', condition_code: 'E1165', hcc_code: '37', model_version: 'CMS-HCC-V28', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_mapping_v28_heart_patch_removes_isolated_cc223 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_hcc_mapping + description: "Defect #1: V28 CC223 is removed when no sibling heart CCs (221,222,224,225,226) present" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_eligible_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', condition_code: 'I5020', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__icd_10_cm_mappings') + rows: + - {payment_year: 2024, diagnosis_code: 'I5020', cms_hcc_v24: '85', cms_hcc_v24_flag: 'Yes', cms_hcc_v28: '223', cms_hcc_v28_flag: 'Yes'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', condition_code: 'I5020', hcc_code: '85', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_mapping_v28_heart_patch_keeps_cc223_with_sibling + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_hcc_mapping + description: "V28 CC223 is kept when sibling heart CC (e.g. CC221) is also present" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_eligible_conditions') + rows: + - {person_id: 'P2', payer: 'MCR', condition_code: 'I5020', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - {person_id: 'P2', payer: 'MCR', condition_code: 'I110', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__icd_10_cm_mappings') + rows: + - {payment_year: 2024, diagnosis_code: 'I5020', cms_hcc_v24: null, cms_hcc_v24_flag: 'No', cms_hcc_v28: '223', cms_hcc_v28_flag: 'Yes'} + - {payment_year: 2024, diagnosis_code: 'I110', cms_hcc_v24: null, cms_hcc_v24_flag: 'No', cms_hcc_v28: '221', cms_hcc_v28_flag: 'Yes'} + expect: + rows: + - {person_id: 'P2', payer: 'MCR', condition_code: 'I5020', hcc_code: '223', model_version: 'CMS-HCC-V28', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', payer: 'MCR', condition_code: 'I110', hcc_code: '221', model_version: 'CMS-HCC-V28', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # HCC HIERARCHY + # ========================================================================= + + - name: test_hcc_hierarchy_suppression_and_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_hcc_hierarchy + description: "Parent HCC suppresses child; child survives when parent absent; non-hierarchy HCCs pass through" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_hcc_mapping') + rows: + # P1 has both parent (17) and child (18) -> only 17 survives + - {person_id: 'P1', payer: 'MCR', hcc_code: '17', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - {person_id: 'P1', payer: 'MCR', hcc_code: '18', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + # P2 has only child (18) without parent -> 18 survives + - {person_id: 'P2', payer: 'MCR', hcc_code: '18', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + # P3 has HCC not in hierarchy -> passes through + - {person_id: 'P3', payer: 'MCR', hcc_code: '85', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__disease_hierarchy') + rows: + - {model_version: 'CMS-HCC-V24', hcc_code: '17', description: 'Diabetes with Acute Complications', hccs_to_exclude: '18'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: '17', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', payer: 'MCR', hcc_code: '18', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P3', payer: 'MCR', hcc_code: '85', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # DEMOGRAPHIC FACTORS + # ========================================================================= + + - name: test_demographic_factors_continuing_community_aged + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_demographic_factors + description: "Continuing Non-Dual Aged female gets CNA demographic coefficient" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_members') + rows: + - {person_id: 'P1', payer: 'MCR', enrollment_status: 'Continuing', gender: 'Female', age_group: '70-74', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', originally_disabled_flag: 'No', institutional_snp_flag: 0, enrollment_status_default: false, medicaid_dual_status_default: true, orec_default: false, institutional_status_default: true, payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__demographic_factors') + rows: + - {model_version: 'CMS-HCC-V24', factor_type: 'Demographic', enrollment_status: 'Continuing', gender: 'Female', age_group: '70-74', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', coefficient: 0.421, plan_segment: null} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', enrollment_status: 'Continuing', gender: 'Female', age_group: '70-74', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', originally_disabled_flag: 'No', enrollment_status_default: false, medicaid_dual_status_default: true, orec_default: false, institutional_status_default: true, coefficient: 0.421, factor_type: 'Demographic', risk_model_code: 'CNA', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_demographic_factors_new_enrollee + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_demographic_factors + description: "New Enrollee gets NE demographic coefficient with risk_model_code E" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_members') + rows: + - {person_id: 'P2', payer: 'MCR', enrollment_status: 'New', gender: 'Male', age_group: '35-44', medicaid_status: 'No', dual_status: 'Non', orec: 'Disabled', institutional_status: 'No', originally_disabled_flag: 'No', institutional_snp_flag: 0, enrollment_status_default: false, medicaid_dual_status_default: true, orec_default: false, institutional_status_default: true, payment_year: 2025, collection_start_date: '2024-01-01', collection_end_date: '2024-12-31'} + - input: ref('cms_hcc__demographic_factors') + rows: + - {model_version: 'CMS-HCC-V24', factor_type: 'Demographic', enrollment_status: 'New', gender: 'Male', age_group: '35-44', medicaid_status: 'No', dual_status: null, orec: 'Aged', institutional_status: null, coefficient: 0.555, plan_segment: null} + expect: + rows: + - {person_id: 'P2', payer: 'MCR', enrollment_status: 'New', gender: 'Male', age_group: '35-44', medicaid_status: 'No', dual_status: 'Non', orec: 'Disabled', institutional_status: 'No', originally_disabled_flag: 'No', enrollment_status_default: false, medicaid_dual_status_default: true, orec_default: false, institutional_status_default: true, coefficient: 0.555, factor_type: 'Demographic', risk_model_code: 'E', model_version: 'CMS-HCC-V24', payment_year: 2025, collection_start_date: '2024-01-01', collection_end_date: '2024-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # DISEASE FACTORS (Defect #2: NE exclusion) + # ========================================================================= + + - name: test_disease_factors_continuing_gets_coefficient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_disease_factors + description: "Continuing enrollee with HCC receives disease coefficient" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_demographic_factors') + rows: + - {person_id: 'P1', payer: 'MCR', enrollment_status: 'Continuing', gender: 'Female', age_group: '70-74', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', model_version: 'CMS-HCC-V24', payment_year: 2024, risk_model_code: 'CNA', collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__int_hcc_hierarchy') + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: '19', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__disease_factors') + rows: + - {model_version: 'CMS-HCC-V24', factor_type: 'Disease', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', hcc_code: '19', description: 'Diabetes without Complication', coefficient: 0.105} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: '19', hcc_description: 'Diabetes without Complication', risk_model_code: 'CNA', coefficient: 0.105, factor_type: 'Disease', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_disease_factors_new_enrollee_excluded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_disease_factors + description: "Defect #2: New Enrollee must NOT receive disease HCC coefficients" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_demographic_factors') + rows: + - {person_id: 'P2', payer: 'MCR', enrollment_status: 'New', gender: 'Male', age_group: '35-44', medicaid_status: 'No', dual_status: 'Non', orec: 'Disabled', institutional_status: 'No', model_version: 'CMS-HCC-V24', payment_year: 2024, risk_model_code: 'E', collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__int_hcc_hierarchy') + rows: + - {person_id: 'P2', payer: 'MCR', hcc_code: '19', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__disease_factors') + rows: + - {model_version: 'CMS-HCC-V24', factor_type: 'Disease', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', hcc_code: '19', description: 'Diabetes without Complication', coefficient: 0.105} + expect: + rows: [] + + # ========================================================================= + # DISEASE INTERACTION FACTORS + # ========================================================================= + + - name: test_disease_interaction_both_hccs_present + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_disease_interaction_factors + description: "Interaction factor assigned when patient has both HCCs in the pair" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_demographic_factors') + rows: + - {person_id: 'P1', payer: 'MCR', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__int_hcc_hierarchy') + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: '47', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - {person_id: 'P1', payer: 'MCR', hcc_code: '85', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__disease_interaction_factors') + rows: + - {model_version: 'CMS-HCC-V24', factor_type: 'Disease Interaction', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', short_name: 'HCC47_HCC85', description: 'Immune x Diabetes', hcc_code_1: '47', hcc_code_2: '85', coefficient: 0.121} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code_1: '47', hcc_code_2: '85', description: 'Immune x Diabetes', coefficient: 0.121, factor_type: 'Disease Interaction', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_disease_interaction_missing_one_hcc + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_disease_interaction_factors + description: "No interaction when patient only has one of the two required HCCs" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_demographic_factors') + rows: + - {person_id: 'P1', payer: 'MCR', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__int_hcc_hierarchy') + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: '47', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__disease_interaction_factors') + rows: + - {model_version: 'CMS-HCC-V24', factor_type: 'Disease Interaction', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', short_name: 'HCC47_HCC85', description: 'Immune x Diabetes', hcc_code_1: '47', hcc_code_2: '85', coefficient: 0.121} + expect: + rows: [] + + # ========================================================================= + # DISABLED INTERACTION FACTORS + # ========================================================================= + + - name: test_disabled_interaction_under65_disabled + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_disabled_interaction_factors + description: "Under-65 disabled member with matching HCC gets disabled interaction factor" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_demographic_factors') + rows: + - {person_id: 'P1', payer: 'MCR', enrollment_status: 'Continuing', institutional_status: 'No', orec: 'Disabled', age_group: '55-59', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__int_hcc_hierarchy') + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: '85', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__disabled_interaction_factors') + rows: + - {model_version: 'CMS-HCC-V24', factor_type: 'Disabled Interaction', enrollment_status: 'Continuing', institutional_status: 'No', short_name: 'DISABLED_HCC85', description: 'Disabled x Diabetes', hcc_code: '85', coefficient: 0.103} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', description: 'Disabled x Diabetes', coefficient: 0.103, factor_type: 'Disabled Interaction', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_disabled_interaction_excluded_for_aged_65plus + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_disabled_interaction_factors + description: "Aged 65+ member does NOT get disabled interaction even with matching HCC" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_demographic_factors') + rows: + - {person_id: 'P2', payer: 'MCR', enrollment_status: 'Continuing', institutional_status: 'No', orec: 'Aged', age_group: '70-74', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__int_hcc_hierarchy') + rows: + - {person_id: 'P2', payer: 'MCR', hcc_code: '85', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__disabled_interaction_factors') + rows: + - {model_version: 'CMS-HCC-V24', factor_type: 'Disabled Interaction', enrollment_status: 'Continuing', institutional_status: 'No', short_name: 'DISABLED_HCC85', description: 'Disabled x Diabetes', hcc_code: '85', coefficient: 0.103} + expect: + rows: [] + + # ========================================================================= + # ENROLLMENT INTERACTION FACTORS + # ========================================================================= + + - name: test_enrollment_interaction_originally_disabled + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_enrollment_interaction_factors + description: "Originally disabled non-institutional member gets enrollment interaction" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_demographic_factors') + rows: + - {person_id: 'P1', payer: 'MCR', enrollment_status: 'Continuing', gender: 'Male', age_group: '70-74', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', originally_disabled_flag: 'Yes', institutional_status: 'No', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__enrollment_interaction_factors') + rows: + - {model_version: 'CMS-HCC-V24', factor_type: 'Enrollment Interaction', gender: 'Male', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', institutional_status: 'No', description: 'Originally Disabled Male', coefficient: 0.110} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', description: 'Originally Disabled Male', coefficient: 0.110, factor_type: 'Enrollment Interaction', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # HCC COUNT FACTORS + # ========================================================================= + + - name: test_hcc_count_factors_three_hccs + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__int_hcc_count_factors + description: "Patient with 3 payment HCCs gets the corresponding count factor" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__int_demographic_factors') + rows: + - {person_id: 'P1', payer: 'MCR', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__int_hcc_hierarchy') + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: '17', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - {person_id: 'P1', payer: 'MCR', hcc_code: '85', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - {person_id: 'P1', payer: 'MCR', hcc_code: '111', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31'} + - input: ref('cms_hcc__payment_hcc_count_factors') + rows: + - {model_version: 'CMS-HCC-V24', factor_type: 'HCC Count', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No', payment_hcc_count: '3', description: 'HCC Count 3', coefficient: 0.052} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', description: 'HCC Count 3', coefficient: 0.052, factor_type: 'HCC Count', model_version: 'CMS-HCC-V24', payment_year: 2024, collection_start_date: '2023-01-01', collection_end_date: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # PATIENT RISK SCORES MONTHLY + # ========================================================================= + + - name: test_risk_scores_monthly_aggregates_factor_types + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__patient_risk_scores_monthly + description: "Sums risk scores across factor types for same person/period" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__patient_risk_scores_monthly_by_factor_type') + rows: + - {person_id: 'P1', payer: 'MCR', risk_model_code: 'CNA', enrollment_status: 'Continuing', enrollment_status_default: false, orec_default: false, factor_type: 'Demographic', v24_risk_score: 0.5, v28_risk_score: null, blended_risk_score: 0.5, normalized_risk_score: 0.447, payment_risk_score: 0.421, payment_risk_score_weighted_by_months: 5.052, member_months: 12, payment_year: 2023, collection_start_date: '2022-01-01', collection_end_date: '2022-12-31', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', risk_model_code: 'CNA', enrollment_status: 'Continuing', enrollment_status_default: false, orec_default: false, factor_type: 'Disease', v24_risk_score: 0.3, v28_risk_score: null, blended_risk_score: 0.3, normalized_risk_score: 0.268, payment_risk_score: 0.252, payment_risk_score_weighted_by_months: 3.024, member_months: 12, payment_year: 2023, collection_start_date: '2022-01-01', collection_end_date: '2022-12-31', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', risk_model_code: 'CNA', enrollment_status: 'Continuing', enrollment_status_default: false, orec_default: false, v24_risk_score: 0.8, v28_risk_score: null, blended_risk_score: 0.8, normalized_risk_score: 0.715, payment_risk_score: 0.673, payment_risk_score_weighted_by_months: 8.076, member_months: 12, payment_year: 2023, collection_start_date: '2022-01-01', collection_end_date: '2022-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # PATIENT RISK SCORES (annual - filters to max collection_end_date) + # ========================================================================= + + - name: test_risk_scores_filters_to_max_collection_date + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__patient_risk_scores + description: "Annual risk scores select only the row with max collection_end_date for the payment year" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + cms_hcc_payment_year: 2023 + given: + - input: ref('cms_hcc__patient_risk_scores_monthly') + rows: + - {person_id: 'P1', payer: 'MCR', v24_risk_score: 0.3, v28_risk_score: null, blended_risk_score: 0.3, normalized_risk_score: 0.268, payment_risk_score: 0.252, payment_risk_score_weighted_by_months: 3.024, member_months: 12, payment_year: 2023, collection_start_date: '2022-01-01', collection_end_date: '2022-06-30', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', v24_risk_score: 0.8, v28_risk_score: null, blended_risk_score: 0.8, normalized_risk_score: 0.715, payment_risk_score: 0.673, payment_risk_score_weighted_by_months: 8.076, member_months: 12, payment_year: 2023, collection_start_date: '2022-01-01', collection_end_date: '2022-12-31', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', v24_risk_score: 0.8, v28_risk_score: null, blended_risk_score: 0.8, normalized_risk_score: 0.715, payment_risk_score: 0.673, payment_risk_score_weighted_by_months: 8.076, member_months: 12, payment_year: 2023, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # PATIENT RISK FACTORS (annual - filters to max collection_end_date) + # ========================================================================= + + - name: test_risk_factors_filters_to_max_collection_date + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: cms_hcc__patient_risk_factors + description: "Annual risk factors select only rows with max collection_end_date for the payment year" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + cms_hcc_payment_year: 2023 + given: + - input: ref('cms_hcc__patient_risk_factors_monthly') + rows: + - {person_id: 'P1', payer: 'MCR', enrollment_status: 'Continuing', risk_model_code: 'CNA', enrollment_status_default: false, medicaid_dual_status_default: true, orec_default: false, institutional_status_default: true, factor_type: 'Demographic', risk_factor_description: 'Demo factor', coefficient: 0.421, model_version: 'CMS-HCC-V24', payment_year: 2023, collection_start_date: '2022-01-01', collection_end_date: '2022-06-30', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', enrollment_status: 'Continuing', risk_model_code: 'CNA', enrollment_status_default: false, medicaid_dual_status_default: true, orec_default: false, institutional_status_default: true, factor_type: 'Demographic', risk_factor_description: 'Demo factor', coefficient: 0.421, model_version: 'CMS-HCC-V24', payment_year: 2023, collection_start_date: '2022-01-01', collection_end_date: '2022-12-31', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', enrollment_status_default: false, medicaid_dual_status_default: true, orec_default: false, institutional_status_default: true, factor_type: 'Demographic', risk_factor_description: 'Demo factor', coefficient: 0.421, model_version: 'CMS-HCC-V24', payment_year: 2023, tuva_last_run: '2024-01-01 00:00:00'} + diff --git a/models/data_marts/ed_classification/_gap_unit_tests.yml b/models/data_marts/ed_classification/_gap_unit_tests.yml new file mode 100644 index 000000000..bbf6dfeb5 --- /dev/null +++ b/models/data_marts/ed_classification/_gap_unit_tests.yml @@ -0,0 +1,93 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # ED CLASSIFICATION - STAGING: stg_encounter + # ========================================================================= + + - name: test_ed_classification_stg_encounter_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__stg_encounter + description: "Staging passes through core encounter fields for ED classification" + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'J06.9', primary_diagnosis_description: 'URI', paid_amount: 500, allowed_amount: 400, charge_amount: 600} + expect: + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', primary_diagnosis_code: 'J06.9'} + + - name: test_ed_classification_stg_encounter_multiple_types + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__stg_encounter + description: "Staging passes through all encounter types without filtering" + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'J06.9', primary_diagnosis_description: 'URI', paid_amount: 500, allowed_amount: 400, charge_amount: 600} + - {encounter_id: 'E2', encounter_type: 'inpatient', person_id: 'P2', encounter_end_date: '2023-06-16', facility_npi: 'NPI2', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'I21.0', primary_diagnosis_description: 'MI', paid_amount: 5000, allowed_amount: 4000, charge_amount: 6000} + expect: + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1'} + - {encounter_id: 'E2', encounter_type: 'inpatient', person_id: 'P2'} + + - name: test_ed_classification_stg_encounter_preserves_amounts + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__stg_encounter + description: "Staging preserves paid, allowed, and charge amounts" + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'J06.9', primary_diagnosis_description: 'URI', paid_amount: 500.50, allowed_amount: 400.25, charge_amount: 600.75} + expect: + rows: + - {encounter_id: 'E1', paid_amount: 500.50, allowed_amount: 400.25, charge_amount: 600.75} + + # ========================================================================= + # ED CLASSIFICATION - STAGING: stg_patient + # ========================================================================= + + - name: test_ed_classification_stg_patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__stg_patient + description: "Staging passes through core patient fields for ED classification" + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', sex: 'male', birth_date: '1960-01-01', race: 'white', state: 'NY', zip_code: '10001', latitude: 40.7128, longitude: -74.0060, data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', sex: 'male', birth_date: '1960-01-01', zip_code: '10001', data_source: 'src1'} + + - name: test_ed_classification_stg_patient_null_demographics + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__stg_patient + description: "Staging passes through patient with null demographic fields" + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', sex: null, birth_date: null, race: null, state: null, zip_code: null, latitude: null, longitude: null, data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', sex: null, birth_date: null, race: null, zip_code: null, data_source: 'src1'} + + - name: test_ed_classification_stg_patient_multiple_patients + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__stg_patient + description: "Staging passes through multiple patient records" + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', sex: 'male', birth_date: '1960-01-01', race: 'white', state: 'NY', zip_code: '10001', latitude: 40.7128, longitude: -74.0060, data_source: 'src1'} + - {person_id: 'P2', sex: 'female', birth_date: '1985-05-15', race: 'black', state: 'CA', zip_code: '90210', latitude: 34.0901, longitude: -118.4065, data_source: 'src2'} + expect: + rows: + - {person_id: 'P1', sex: 'male', state: 'NY', data_source: 'src1'} + - {person_id: 'P2', sex: 'female', state: 'CA', data_source: 'src2'} diff --git a/models/data_marts/ed_classification/_unit_tests.yml b/models/data_marts/ed_classification/_unit_tests.yml new file mode 100644 index 000000000..bcad84047 --- /dev/null +++ b/models/data_marts/ed_classification/_unit_tests.yml @@ -0,0 +1,157 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # ED CLASSIFICATION - INTERMEDIATE: int_filter_encounter_with_classification + # ========================================================================= + + - name: test_ed_classification_filter_picks_greatest_probability + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__int_filter_encounter_with_classification + description: "Classification is assigned based on the highest probability column using GREATEST" + given: + - input: ref('ed_classification__int_map_primary_dx') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'J06.9', primary_diagnosis_description: 'URI', paid_amount: 500, allowed_amount: 400, charge_amount: 600, edcnnpa: 0.88, edcnpa: 0.05, epct: 0.02, noner: 0.01, injury: 0.0, psych: 0.0, alcohol: 0.0, drug: 0.0, ed_classification_capture: 1} + - {encounter_id: 'E2', encounter_type: 'emergency department', person_id: 'P2', encounter_end_date: '2023-06-16', facility_npi: 'NPI2', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'S52.0', primary_diagnosis_description: 'Fracture', paid_amount: 700, allowed_amount: 600, charge_amount: 800, edcnnpa: 0.0, edcnpa: 0.0, epct: 0.0, noner: 0.0, injury: 0.95, psych: 0.0, alcohol: 0.0, drug: 0.0, ed_classification_capture: 1} + - {encounter_id: 'E3', encounter_type: 'emergency department', person_id: 'P3', encounter_end_date: '2023-06-17', facility_npi: 'NPI3', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'Z99.9', primary_diagnosis_description: 'Unclassified', paid_amount: 200, allowed_amount: 150, charge_amount: 300, edcnnpa: 0.0, edcnpa: 0.0, epct: 0.0, noner: 0.0, injury: 0.0, psych: 0.0, alcohol: 0.0, drug: 0.0, ed_classification_capture: 0} + expect: + rows: + - {encounter_id: 'E1', classification: 'edcnnpa'} + - {encounter_id: 'E2', classification: 'injury'} + + - name: test_ed_classification_filter_breaks_probability_ties_deterministically + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__int_filter_encounter_with_classification + description: "Ties fall through the CASE order after GREATEST, so edcnnpa wins over later categories" + given: + - input: ref('ed_classification__int_map_primary_dx') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'J06.9', primary_diagnosis_description: 'URI', paid_amount: 500, allowed_amount: 400, charge_amount: 600, edcnnpa: 0.5, edcnpa: 0.0, epct: 0.0, noner: 0.0, injury: 0.5, psych: 0.0, alcohol: 0.0, drug: 0.0, ed_classification_capture: 1} + expect: + rows: + - {encounter_id: 'E1', classification: 'edcnnpa'} + + - name: test_ed_classification_filter_excludes_uncaptured_encounters + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__int_filter_encounter_with_classification + description: "Encounters with ed_classification_capture=0 are excluded from classification results" + given: + - input: ref('ed_classification__int_map_primary_dx') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'Z99.9', primary_diagnosis_description: 'Unknown', paid_amount: 200, allowed_amount: 150, charge_amount: 300, edcnnpa: 0.0, edcnpa: 0.0, epct: 0.0, noner: 0.0, injury: 0.0, psych: 0.0, alcohol: 0.0, drug: 0.0, ed_classification_capture: 0} + expect: + rows: [] + + - name: test_ed_classification_filter_psych_classification + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__int_filter_encounter_with_classification + description: "Encounter with highest psych probability is classified as psych" + given: + - input: ref('ed_classification__int_map_primary_dx') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'F20.0', primary_diagnosis_description: 'Schizophrenia', paid_amount: 1000, allowed_amount: 800, charge_amount: 1200, edcnnpa: 0.0, edcnpa: 0.0, epct: 0.0, noner: 0.0, injury: 0.0, psych: 0.92, alcohol: 0.0, drug: 0.0, ed_classification_capture: 1} + expect: + rows: + - {encounter_id: 'E1', classification: 'psych'} + + - name: test_ed_classification_filter_alcohol_classification + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__int_filter_encounter_with_classification + description: "Encounter with highest alcohol probability is classified as alcohol" + given: + - input: ref('ed_classification__int_map_primary_dx') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'F10.20', primary_diagnosis_description: 'Alcohol dependence', paid_amount: 800, allowed_amount: 600, charge_amount: 900, edcnnpa: 0.0, edcnpa: 0.0, epct: 0.0, noner: 0.0, injury: 0.0, psych: 0.0, alcohol: 0.85, drug: 0.0, ed_classification_capture: 1} + expect: + rows: + - {encounter_id: 'E1', classification: 'alcohol'} + + - name: test_ed_classification_filter_drug_classification + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__int_filter_encounter_with_classification + description: "Encounter with highest drug probability is classified as drug" + given: + - input: ref('ed_classification__int_map_primary_dx') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'F11.20', primary_diagnosis_description: 'Opioid dependence', paid_amount: 800, allowed_amount: 600, charge_amount: 900, edcnnpa: 0.0, edcnpa: 0.0, epct: 0.0, noner: 0.0, injury: 0.0, psych: 0.0, alcohol: 0.0, drug: 0.78, ed_classification_capture: 1} + expect: + rows: + - {encounter_id: 'E1', classification: 'drug'} + + - name: test_ed_classification_filter_epct_classification + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__int_filter_encounter_with_classification + description: "Encounter with highest epct probability is classified as epct" + given: + - input: ref('ed_classification__int_map_primary_dx') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'J02.9', primary_diagnosis_description: 'Pharyngitis', paid_amount: 300, allowed_amount: 250, charge_amount: 400, edcnnpa: 0.10, edcnpa: 0.10, epct: 0.70, noner: 0.05, injury: 0.0, psych: 0.0, alcohol: 0.0, drug: 0.0, ed_classification_capture: 1} + expect: + rows: + - {encounter_id: 'E1', classification: 'epct'} + + - name: test_ed_classification_filter_noner_classification + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__int_filter_encounter_with_classification + description: "Encounter with highest noner probability is classified as noner" + given: + - input: ref('ed_classification__int_map_primary_dx') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'R10.9', primary_diagnosis_description: 'Abdominal pain', paid_amount: 400, allowed_amount: 350, charge_amount: 500, edcnnpa: 0.05, edcnpa: 0.05, epct: 0.05, noner: 0.80, injury: 0.0, psych: 0.0, alcohol: 0.0, drug: 0.0, ed_classification_capture: 1} + expect: + rows: + - {encounter_id: 'E1', classification: 'noner'} + + - name: test_ed_classification_filter_edcnpa_classification + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__int_filter_encounter_with_classification + description: "Encounter with highest edcnpa probability is classified as edcnpa" + given: + - input: ref('ed_classification__int_map_primary_dx') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'I21.0', primary_diagnosis_description: 'MI', paid_amount: 2000, allowed_amount: 1800, charge_amount: 2500, edcnnpa: 0.10, edcnpa: 0.80, epct: 0.02, noner: 0.01, injury: 0.0, psych: 0.0, alcohol: 0.0, drug: 0.0, ed_classification_capture: 1} + expect: + rows: + - {encounter_id: 'E1', classification: 'edcnpa'} + + - name: test_ed_classification_filter_tie_edcnpa_vs_injury + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__int_filter_encounter_with_classification + description: "When edcnpa ties with injury at the greatest value, CASE order gives edcnpa priority" + given: + - input: ref('ed_classification__int_map_primary_dx') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'T14.90', primary_diagnosis_description: 'Injury', paid_amount: 600, allowed_amount: 500, charge_amount: 700, edcnnpa: 0.0, edcnpa: 0.5, epct: 0.0, noner: 0.0, injury: 0.5, psych: 0.0, alcohol: 0.0, drug: 0.0, ed_classification_capture: 1} + expect: + rows: + - {encounter_id: 'E1', classification: 'edcnpa'} + + - name: test_ed_classification_filter_tie_all_equal + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: ed_classification__int_filter_encounter_with_classification + description: "When all probabilities are equal non-zero, CASE order gives edcnnpa priority" + given: + - input: ref('ed_classification__int_map_primary_dx') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', person_id: 'P1', encounter_end_date: '2023-06-15', facility_npi: 'NPI1', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'R69', primary_diagnosis_description: 'Unknown', paid_amount: 200, allowed_amount: 150, charge_amount: 250, edcnnpa: 0.125, edcnpa: 0.125, epct: 0.125, noner: 0.125, injury: 0.125, psych: 0.125, alcohol: 0.125, drug: 0.125, ed_classification_capture: 1} + expect: + rows: + - {encounter_id: 'E1', classification: 'edcnnpa'} + + # ========================================================================= + # ED CLASSIFICATION - FINAL: summary + # ========================================================================= + diff --git a/models/data_marts/fhir_preprocessing/_unit_tests.yml b/models/data_marts/fhir_preprocessing/_unit_tests.yml new file mode 100644 index 000000000..a49e0937a --- /dev/null +++ b/models/data_marts/fhir_preprocessing/_unit_tests.yml @@ -0,0 +1,628 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # FHIR PREPROCESSING - FINAL: patient + # ========================================================================= + + - name: test_fhir_patient_maps_race_unk + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__patient + description: "Patient model maps null race to 'UNK' and passes through other fields" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__patient') + rows: + - {person_id: 'P1', first_name: 'John', last_name: 'Doe', sex: 'male', race: null, birth_date: '1960-01-01', data_source: 'src1'} + - {person_id: 'P2', first_name: 'Jane', last_name: 'Smith', sex: 'female', race: 'white', birth_date: '1975-06-15', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', name_first: 'John', name_last: 'Doe', gender: 'male', race: 'UNK', birth_date: '1960-01-01', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {patient_internal_id: 'P2', name_first: 'Jane', name_last: 'Smith', gender: 'female', race: 'white', birth_date: '1975-06-15', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_fhir_patient_renames_columns + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__patient + description: "Patient model renames person_id to patient_internal_id, first_name to name_first, last_name to name_last, sex to gender" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__patient') + rows: + - {person_id: 'P99', first_name: 'Alice', last_name: 'Brown', sex: 'female', race: 'black', birth_date: '1990-03-20', data_source: 'src2'} + expect: + rows: + - {patient_internal_id: 'P99', name_first: 'Alice', name_last: 'Brown', gender: 'female', race: 'black', birth_date: '1990-03-20', data_source: 'src2', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FHIR PREPROCESSING - FINAL: condition + # ========================================================================= + + - name: test_fhir_condition_maps_code_system_and_adds_dot + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__condition + description: "Condition model maps icd-10-cm to ICD10, inserts dot in codes > 3 chars, and filters claim conditions" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__condition') + rows: + - {person_id: 'P1', condition_id: 'COND1', encounter_id: 'E1', recorded_date: '2023-06-15', onset_date: '2023-06-10', resolved_date: null, status: 'active', normalized_code_type: 'icd-10-cm', normalized_code: 'E1165', claim_id: null, data_source: 'src1', condition_rank: 1} + - {person_id: 'P2', condition_id: 'COND2', encounter_id: 'E2', recorded_date: '2023-07-01', onset_date: null, resolved_date: null, status: 'active', normalized_code_type: 'icd-10-cm', normalized_code: 'I10', claim_id: null, data_source: 'src1', condition_rank: 1} + - {person_id: 'P3', condition_id: 'COND3', encounter_id: 'E3', recorded_date: '2023-08-01', onset_date: null, resolved_date: null, status: 'active', normalized_code_type: 'icd-10-cm', normalized_code: 'J441', claim_id: 'CLM1', data_source: 'src1', condition_rank: 1} + - input: ref('fhir_preprocessing__stg_core__encounter') + rows: + - {encounter_id: 'E1', encounter_group: 'inpatient', encounter_start_date: '2023-06-10', encounter_end_date: '2023-06-15', person_id: 'P1', data_source: 'src1'} + - {encounter_id: 'E2', encounter_group: 'outpatient', encounter_start_date: '2023-07-01', encounter_end_date: '2023-07-01', person_id: 'P2', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'COND1', condition_code: 'E11.65', condition_code_system: 'ICD10', encounter_class_code: 'IMP', tuva_last_run: '2024-01-01 00:00:00'} + - {patient_internal_id: 'P2', resource_internal_id: 'COND2', condition_code: 'I10', condition_code_system: 'ICD10', encounter_class_code: 'AMB', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_fhir_condition_filters_claim_conditions + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__condition + description: "Condition model excludes conditions with a non-null claim_id since those belong in EOB" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__condition') + rows: + - {person_id: 'P1', condition_id: 'COND1', encounter_id: 'E1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', normalized_code_type: 'icd-10-cm', normalized_code: 'I10', claim_id: 'CLM1', data_source: 'src1', condition_rank: 1} + - {person_id: 'P2', condition_id: 'COND2', encounter_id: 'E2', recorded_date: '2023-07-01', onset_date: null, resolved_date: null, status: 'active', normalized_code_type: 'icd-10-cm', normalized_code: 'E119', claim_id: null, data_source: 'src1', condition_rank: 1} + - input: ref('fhir_preprocessing__stg_core__encounter') + rows: + - {encounter_id: 'E2', encounter_group: 'outpatient', encounter_start_date: '2023-07-01', encounter_end_date: '2023-07-01', person_id: 'P2', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P2', resource_internal_id: 'COND2', condition_code: 'E11.9', condition_code_system: 'ICD10', encounter_class_code: 'AMB', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_fhir_condition_filters_null_code_type + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__condition + description: "Condition model filters out conditions where normalized_code_type is null" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__condition') + rows: + - {person_id: 'P1', condition_id: 'COND1', encounter_id: 'E1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', normalized_code_type: null, normalized_code: 'SOME', claim_id: null, data_source: 'src1', condition_rank: 1} + - input: ref('fhir_preprocessing__stg_core__encounter') + rows: + - {encounter_id: 'E1', encounter_group: 'outpatient', encounter_start_date: '2023-06-15', encounter_end_date: '2023-06-15', person_id: 'P1', data_source: 'src1'} + expect: + rows: [] + + - name: test_fhir_condition_maps_icd9_code_system + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__condition + description: "Condition model maps icd-9-cm to ICD9 code system" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__condition') + rows: + - {person_id: 'P1', condition_id: 'COND1', encounter_id: 'E1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', normalized_code_type: 'icd-9-cm', normalized_code: '250.00', claim_id: null, data_source: 'src1', condition_rank: 1} + - input: ref('fhir_preprocessing__stg_core__encounter') + rows: + - {encounter_id: 'E1', encounter_group: 'office based', encounter_start_date: '2023-06-15', encounter_end_date: '2023-06-15', person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'COND1', condition_code: '250.00', condition_code_system: 'ICD9', encounter_class_code: 'AMB', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_fhir_condition_encounter_class_other + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__condition + description: "Condition model maps encounter groups other than inpatient/outpatient/office based to 'other'" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__condition') + rows: + - {person_id: 'P1', condition_id: 'COND1', encounter_id: 'E1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', normalized_code_type: 'icd-10-cm', normalized_code: 'I10', claim_id: null, data_source: 'src1', condition_rank: 1} + - input: ref('fhir_preprocessing__stg_core__encounter') + rows: + - {encounter_id: 'E1', encounter_group: 'snf', encounter_start_date: '2023-06-15', encounter_end_date: '2023-06-15', person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'COND1', condition_code: 'I10', condition_code_system: 'ICD10', encounter_class_code: 'other', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_fhir_condition_onset_defaults_to_recorded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__condition + description: "Condition model defaults onset_date to recorded_date when onset_date is null" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__condition') + rows: + - {person_id: 'P1', condition_id: 'COND1', encounter_id: 'E1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', normalized_code_type: 'icd-10-cm', normalized_code: 'I10', claim_id: null, data_source: 'src1', condition_rank: 1} + - input: ref('fhir_preprocessing__stg_core__encounter') + rows: + - {encounter_id: 'E1', encounter_group: 'outpatient', encounter_start_date: '2023-06-15', encounter_end_date: '2023-06-15', person_id: 'P1', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', condition_onset_datetime: '2023-06-15', condition_recorded_datetime: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FHIR PREPROCESSING - FINAL: procedure + # ========================================================================= + + - name: test_fhir_procedure_maps_code_system + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__procedure + description: "Procedure model maps icd-10-pcs to ICD10 code system and filters out claim procedures" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__procedure') + rows: + - {person_id: 'P1', procedure_id: 'PROC1', normalized_code_type: 'icd-10-pcs', normalized_code: '0DBN0ZZ', normalized_description: 'Excision sigmoid colon', source_code_type: null, source_code: null, source_description: null, procedure_date: '2023-06-15', practitioner_id: 'NPI1', claim_id: null, data_source: 'src1'} + - {person_id: 'P2', procedure_id: 'PROC2', normalized_code_type: 'icd-10-pcs', normalized_code: '0HBT0ZZ', normalized_description: 'Excision breast', source_code_type: null, source_code: null, source_description: null, procedure_date: '2023-07-01', practitioner_id: 'NPI2', claim_id: 'CLM1', data_source: 'src1'} + - {person_id: 'P3', procedure_id: null, normalized_code_type: 'icd-10-pcs', normalized_code: '0DBN0ZZ', normalized_description: null, source_code_type: null, source_code: null, source_description: null, procedure_date: '2023-08-01', practitioner_id: null, claim_id: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'PROC1', procedure_code_system: 'ICD10', procedure_code: '0DBN0ZZ', procedure_status: 'completed', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_fhir_procedure_filters_null_procedure_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__procedure + description: "Procedure model filters out rows with null procedure_id" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__procedure') + rows: + - {person_id: 'P1', procedure_id: null, normalized_code_type: 'icd-10-pcs', normalized_code: '0DBN0ZZ', normalized_description: null, source_code_type: null, source_code: null, source_description: null, procedure_date: '2023-06-15', practitioner_id: null, claim_id: null, data_source: 'src1'} + expect: + rows: [] + + - name: test_fhir_procedure_filters_null_code_type + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__procedure + description: "Procedure model filters out rows where normalized_code_type is null" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__procedure') + rows: + - {person_id: 'P1', procedure_id: 'PROC1', normalized_code_type: null, normalized_code: null, normalized_description: null, source_code_type: null, source_code: null, source_description: null, procedure_date: '2023-06-15', practitioner_id: null, claim_id: null, data_source: 'src1'} + expect: + rows: [] + + - name: test_fhir_procedure_uses_source_code_fallback + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__procedure + description: "Procedure model falls back to source_code_type and source_code when normalized values are null" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__procedure') + rows: + - {person_id: 'P1', procedure_id: 'PROC1', normalized_code_type: null, normalized_code: null, normalized_description: null, source_code_type: 'icd-10-pcs', source_code: 'ABC123', source_description: 'Some proc', procedure_date: '2023-06-15', practitioner_id: 'NPI1', claim_id: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'PROC1', procedure_code_system: 'ICD10', procedure_code: 'ABC123', procedure_display: 'Some proc', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_fhir_procedure_maps_icd9_pcs + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__procedure + description: "Procedure model maps icd-9-pcs to ICD9 code system" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__procedure') + rows: + - {person_id: 'P1', procedure_id: 'PROC1', normalized_code_type: 'icd-9-pcs', normalized_code: '99.04', normalized_description: 'Transfusion', source_code_type: null, source_code: null, source_description: null, procedure_date: '2023-06-15', practitioner_id: 'NPI1', claim_id: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'PROC1', procedure_code_system: 'ICD9', procedure_code: '99.04', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FHIR PREPROCESSING - FINAL: coverage + # ========================================================================= + + - name: test_fhir_coverage_joins_type_list + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__coverage + description: "Coverage model joins intermediate coverage to coverage type list" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__int_coverage') + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'COV1', organization_name: 'Aetna', coverage_plan: 'Gold', coverage_period_start: '2023-01-01', coverage_period_end: '2023-12-31', coverage_relationship: 'self', coverage_status: 'active', coverage_subscriber_id: 'SUB1', data_source: 'src1'} + - input: ref('fhir_preprocessing__int_coverage_type') + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'COV1', coverage_type_list: 'medical'} + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'COV1', organization_name: 'Aetna', coverage_plan: 'Gold', coverage_type_list: 'medical', coverage_status: 'active', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_fhir_coverage_null_type_list + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__coverage + description: "Coverage model handles missing coverage type list gracefully with null via left join" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__int_coverage') + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'COV1', organization_name: 'Aetna', coverage_plan: 'Gold', coverage_period_start: '2023-01-01', coverage_period_end: '2023-12-31', coverage_relationship: 'self', coverage_status: 'active', coverage_subscriber_id: 'SUB1', data_source: 'src1'} + - input: ref('fhir_preprocessing__int_coverage_type') + rows: [] + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'COV1', organization_name: 'Aetna', coverage_plan: 'Gold', coverage_type_list: null, coverage_status: 'active', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FHIR PREPROCESSING - FINAL: medication_dispense + # ========================================================================= + + - name: test_fhir_medication_dispense_maps_ndc + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__medication_dispense + description: "Medication dispense maps NDC codes to NDC code system and sets status to completed" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__medication') + rows: + - {medication_id: 'MED1', person_id: 'P1', source_code_type: 'NDC', ndc_code: '00000000001', ndc_description: 'Aspirin 325mg', rxnorm_code: null, rxnorm_description: null, days_supply: 30, dispensing_date: '2023-06-15', data_source: 'src1'} + - {medication_id: 'MED2', person_id: 'P2', source_code_type: 'RXNORM', ndc_code: null, ndc_description: null, rxnorm_code: '1049502', rxnorm_description: 'Lisinopril 10mg', days_supply: 90, dispensing_date: '2023-07-01', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'MED1', medication_dispense_status: 'completed', medication_code_system: 'NDC', medication_code: '00000000001', medication_code_display: 'Aspirin 325mg', medication_dispense_days_supply_value: 30, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {patient_internal_id: 'P2', resource_internal_id: 'MED2', medication_dispense_status: 'completed', medication_code_system: 'RXNORM', medication_code: '1049502', medication_code_display: 'Lisinopril 10mg', medication_dispense_days_supply_value: 90, data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_fhir_medication_dispense_ndc_over_rxnorm + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__medication_dispense + description: "When both NDC and RXNORM codes present, NDC takes priority" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__medication') + rows: + - {medication_id: 'MED1', person_id: 'P1', source_code_type: 'NDC', ndc_code: '11111111111', ndc_description: 'Aspirin', rxnorm_code: '1049502', rxnorm_description: 'Aspirin RX', days_supply: 30, dispensing_date: '2023-06-15', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'MED1', medication_code_system: 'NDC', medication_code: '11111111111', medication_code_display: 'Aspirin', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_fhir_medication_dispense_source_code_type_fallback + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__medication_dispense + description: "When no NDC or RXNORM code, medication_code_system falls back to source_code_type" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__stg_core__medication') + rows: + - {medication_id: 'MED1', person_id: 'P1', source_code_type: 'CUSTOM', ndc_code: null, ndc_description: null, rxnorm_code: null, rxnorm_description: null, days_supply: 14, dispensing_date: '2023-06-15', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'MED1', medication_code_system: 'CUSTOM', medication_code: null, medication_code_display: null, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FHIR PREPROCESSING - FINAL: observation (union of lab_result + observation) + # ========================================================================= + + - name: test_fhir_observation_unions_lab_and_obs + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__observation + description: "Observation model unions lab results and observations into a single output" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__int_lab_result') + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'LR1', encounter_internal_id: 'E1', observation_status: 'final', observation_category: 'laboratory', observation_code_system: 'LOINC', observation_code: '2345-7', observation_code_text: 'Glucose', observation_datetime: '2023-06-15', observation_value: '120', observation_value_units: 'mg/dL', data_source: 'src1'} + - input: ref('fhir_preprocessing__int_observation') + rows: + - {patient_internal_id: 'P2', resource_internal_id: 'OBS1', encounter_internal_id: 'E2', observation_status: 'final', observation_category: 'vital-signs', observation_code_system: 'LOINC', observation_code: '8480-6', observation_code_text: 'Systolic BP', observation_datetime: '2023-06-15', observation_value: '140', observation_value_units: 'mmHg', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', observation_category: 'laboratory', observation_code: '2345-7', observation_value: '120', tuva_last_run: '2024-01-01 00:00:00'} + - {patient_internal_id: 'P2', observation_category: 'vital-signs', observation_code: '8480-6', observation_value: '140', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FHIR PREPROCESSING - FINAL: explanation_of_benefit (union of medical + pharmacy) + # ========================================================================= + + - name: test_fhir_eob_unions_medical_and_pharmacy + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__explanation_of_benefit + description: "EOB model unions medical and pharmacy claim EOBs" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('fhir_preprocessing__int_medical_claim_eob') + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'MC1', unique_claim_id: 'C1', eob_type_code: 'institutional', eob_subtype_code: 'inpatient', eob_billable_period_start: '2023-06-10', eob_billable_period_end: '2023-06-15', eob_created: '2023-07-01', organization_name: 'Aetna', practitioner_internal_id: 'NPI1', practitioner_name_text: 'Dr Smith', coverage_internal_id: 'COV1', eob_diagnosis_list: null, eob_procedure_list: null, eob_supporting_info_list: null, eob_item_list: null, eob_total_list: null, data_source: 'src1'} + - input: ref('fhir_preprocessing__int_pharmacy_claim_eob') + rows: + - {patient_internal_id: 'P2', resource_internal_id: 'PC1', unique_claim_id: 'C2', eob_type_code: 'pharmacy', eob_subtype_code: null, eob_billable_period_start: null, eob_billable_period_end: null, eob_created: '2023-07-01', organization_name: 'CVS', practitioner_internal_id: 'NPI2', practitioner_name_text: 'Pharmacist', coverage_internal_id: 'COV2', eob_diagnosis_list: null, eob_procedure_list: null, eob_supporting_info_list: null, eob_item_list: null, eob_total_list: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'MC1', eob_type_code: 'institutional', tuva_last_run: '2024-01-01 00:00:00'} + - {patient_internal_id: 'P2', resource_internal_id: 'PC1', eob_type_code: 'pharmacy', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE: int_coverage + # ========================================================================= + + - name: test_fhir_int_coverage_maps_payer_type + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_coverage + description: "Coverage intermediate maps commercial payer_type to PPO product type" + given: + - input: ref('fhir_preprocessing__stg_core__eligibility') + rows: + - {eligibility_id: 'ELG1', person_id: 'P1', member_id: 'M1', payer_type: 'commercial', payer: 'Aetna', plan: 'Gold', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', subscriber_relation: 'self', subscriber_id: 'SUB1', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', organization_name: 'Aetna', coverage_plan: 'Gold', coverage_relationship: 'self', coverage_status: 'active', coverage_subscriber_id: 'SUB1', coverage_type_product: 'PPO', data_source: 'src1'} + + - name: test_fhir_int_coverage_maps_medicare + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_coverage + description: "Coverage intermediate maps medicare payer_type to MCR product type" + given: + - input: ref('fhir_preprocessing__stg_core__eligibility') + rows: + - {eligibility_id: 'ELG1', person_id: 'P1', member_id: 'M1', payer_type: 'medicare', payer: 'CMS', plan: 'PartA', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', subscriber_relation: null, subscriber_id: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', organization_name: 'CMS', coverage_relationship: 'self', coverage_status: 'active', coverage_type_product: 'MCR', data_source: 'src1'} + + - name: test_fhir_int_coverage_maps_medicaid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_coverage + description: "Coverage intermediate maps medicaid payer_type to MCD product type" + given: + - input: ref('fhir_preprocessing__stg_core__eligibility') + rows: + - {eligibility_id: 'ELG1', person_id: 'P1', member_id: 'M1', payer_type: 'medicaid', payer: 'State', plan: 'MCD', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', subscriber_relation: null, subscriber_id: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', organization_name: 'State', coverage_relationship: 'self', coverage_status: 'active', coverage_type_product: 'MCD', data_source: 'src1'} + + - name: test_fhir_int_coverage_defaults_subscriber_relation + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_coverage + description: "Coverage intermediate defaults null subscriber_relation to 'self'" + given: + - input: ref('fhir_preprocessing__stg_core__eligibility') + rows: + - {eligibility_id: 'ELG1', person_id: 'P1', member_id: 'M1', payer_type: 'commercial', payer: 'Blue', plan: 'PPO', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', subscriber_relation: null, subscriber_id: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', coverage_relationship: 'self', data_source: 'src1'} + + - name: test_fhir_int_coverage_subscriber_id_fallback + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_coverage + description: "Coverage intermediate falls back to member_id when subscriber_id is null" + given: + - input: ref('fhir_preprocessing__stg_core__eligibility') + rows: + - {eligibility_id: 'ELG1', person_id: 'P1', member_id: 'M1', payer_type: 'commercial', payer: 'Blue', plan: 'PPO', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', subscriber_relation: 'self', subscriber_id: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', coverage_subscriber_id: 'M1', data_source: 'src1'} + + # ========================================================================= + # INTERMEDIATE: int_lab_result + # ========================================================================= + + - name: test_fhir_int_lab_result_maps_status + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_lab_result + description: "Lab result intermediate maps status values and uppercases code_type" + given: + - input: ref('fhir_preprocessing__stg_core__lab_result') + rows: + - {lab_result_id: 'LR1', person_id: 'P1', encounter_id: 'E1', status: 'F', code_type: 'loinc', code: '2345-7', description: 'Glucose', result_datetime: '2023-06-15 10:00:00', result: '120', units: 'mg/dL', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', observation_status: 'final', observation_category: 'laboratory', observation_code_system: 'LOINC', observation_code: '2345-7', observation_value: '120', data_source: 'src1'} + + - name: test_fhir_int_lab_result_maps_preliminary_status + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_lab_result + description: "Lab result intermediate maps 'P' status to 'preliminary'" + given: + - input: ref('fhir_preprocessing__stg_core__lab_result') + rows: + - {lab_result_id: 'LR1', person_id: 'P1', encounter_id: 'E1', status: 'P', code_type: 'loinc', code: '2345-7', description: 'Glucose', result_datetime: '2023-06-15 10:00:00', result: '100', units: 'mg/dL', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', observation_status: 'preliminary', observation_code: '2345-7', data_source: 'src1'} + + - name: test_fhir_int_lab_result_maps_corrected_status + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_lab_result + description: "Lab result intermediate maps 'C' status to 'corrected'" + given: + - input: ref('fhir_preprocessing__stg_core__lab_result') + rows: + - {lab_result_id: 'LR1', person_id: 'P1', encounter_id: 'E1', status: 'C', code_type: 'loinc', code: '2345-7', description: 'Glucose', result_datetime: '2023-06-15 10:00:00', result: '110', units: 'mg/dL', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', observation_status: 'corrected', observation_code: '2345-7', data_source: 'src1'} + + - name: test_fhir_int_lab_result_maps_cancelled_status + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_lab_result + description: "Lab result intermediate maps 'D' status to 'cancelled'" + given: + - input: ref('fhir_preprocessing__stg_core__lab_result') + rows: + - {lab_result_id: 'LR1', person_id: 'P1', encounter_id: 'E1', status: 'D', code_type: 'loinc', code: '2345-7', description: 'Glucose', result_datetime: '2023-06-15 10:00:00', result: null, units: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', observation_status: 'cancelled', observation_code: '2345-7', data_source: 'src1'} + + # ========================================================================= + # INTERMEDIATE: int_observation + # ========================================================================= + + - name: test_fhir_int_observation_maps_category + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_observation + description: "Observation intermediate maps observation_type to FHIR categories" + given: + - input: ref('fhir_preprocessing__stg_core__observation') + rows: + - {observation_id: 'OBS1', person_id: 'P1', encounter_id: 'E1', observation_type: 'vital-signs', normalized_code_type: 'LOINC', normalized_code: '8480-6', normalized_description: 'Systolic BP', source_code_type: null, source_code: null, source_description: null, observation_date: '2023-06-15', result: '120', normalized_units: 'mmHg', source_units: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', observation_status: 'final', observation_category: 'vital-signs', observation_code_system: 'LOINC', observation_code: '8480-6', observation_value: '120', data_source: 'src1'} + + - name: test_fhir_int_observation_maps_social_history + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_observation + description: "Observation intermediate maps 'social-history' type to social-history category" + given: + - input: ref('fhir_preprocessing__stg_core__observation') + rows: + - {observation_id: 'OBS1', person_id: 'P1', encounter_id: 'E1', observation_type: 'social-history', normalized_code_type: 'LOINC', normalized_code: '72166-2', normalized_description: 'Smoking status', source_code_type: null, source_code: null, source_description: null, observation_date: '2023-06-15', result: 'current', normalized_units: null, source_units: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', observation_category: 'social-history', observation_code: '72166-2', data_source: 'src1'} + + - name: test_fhir_int_observation_maps_unknown_type_to_other + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_observation + description: "Observation intermediate maps unknown observation_type to 'other'" + given: + - input: ref('fhir_preprocessing__stg_core__observation') + rows: + - {observation_id: 'OBS1', person_id: 'P1', encounter_id: 'E1', observation_type: 'unknown_type', normalized_code_type: 'LOINC', normalized_code: '99999-9', normalized_description: 'Unknown', source_code_type: null, source_code: null, source_description: null, observation_date: '2023-06-15', result: '42', normalized_units: null, source_units: null, data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', observation_category: 'other', observation_code: '99999-9', data_source: 'src1'} + + - name: test_fhir_int_observation_uses_source_code_fallback + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_observation + description: "Observation intermediate falls back to source_code when normalized_code is null" + given: + - input: ref('fhir_preprocessing__stg_core__observation') + rows: + - {observation_id: 'OBS1', person_id: 'P1', encounter_id: 'E1', observation_type: 'vital-signs', normalized_code_type: null, normalized_code: null, normalized_description: null, source_code_type: 'CUSTOM', source_code: 'BP_SYS', source_description: 'Systolic BP', observation_date: '2023-06-15', result: '130', normalized_units: null, source_units: 'mmHg', data_source: 'src1'} + expect: + rows: + - {patient_internal_id: 'P1', observation_code_system: 'CUSTOM', observation_code: 'BP_SYS', observation_code_text: 'Systolic BP', observation_value_units: 'mmHg', data_source: 'src1'} + + # ========================================================================= + # INTERMEDIATE: int_medical_claim_eob + # ========================================================================= + + - name: test_fhir_int_medical_claim_eob_maps_subtype + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_medical_claim_eob + description: "Medical claim EOB maps inpatient encounter_group to 'inpatient' subtype, others to 'outpatient'" + given: + - input: ref('fhir_preprocessing__stg_core__eligibility') + rows: + - {eligibility_id: 'ELG1', person_id: 'P1', member_id: 'M1', payer_type: 'commercial', payer: 'MCR', plan: 'PlanA', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', subscriber_relation: 'self', subscriber_id: 'SUB1', data_source: 'src1'} + - input: ref('fhir_preprocessing__stg_core__medical_claim') + rows: + - {medical_claim_id: 'MC1', person_id: 'P1', claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', encounter_group: 'inpatient', claim_start_date: '2023-06-10', claim_end_date: '2023-06-15', claim_line_start_date: '2023-06-10', payer: 'MCR', plan: 'PlanA', billing_npi: 'NPI1', billing_name: 'Dr Smith', rendering_npi: null, rendering_name: null, admission_date: '2023-06-10', discharge_date: '2023-06-15', bill_type_code: '111', revenue_center_code: '0100', revenue_center_description: 'Room', place_of_service_code: '21', place_of_service_description: 'Inpatient', hcpcs_code: '99213', hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null, paid_date: '2023-07-01', paid_amount: 500, in_network_flag: 1, data_source: 'src1'} + - {medical_claim_id: 'MC2', person_id: 'P1', claim_id: 'C2', claim_line_number: 1, claim_type: 'professional', encounter_group: 'outpatient', claim_start_date: '2023-07-01', claim_end_date: '2023-07-01', claim_line_start_date: '2023-07-01', payer: 'MCR', plan: 'PlanA', billing_npi: 'NPI2', billing_name: 'Dr Jones', rendering_npi: null, rendering_name: null, admission_date: null, discharge_date: null, bill_type_code: null, revenue_center_code: null, revenue_center_description: null, place_of_service_code: '11', place_of_service_description: 'Office', hcpcs_code: '99213', hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null, paid_date: '2023-07-15', paid_amount: 150, in_network_flag: 1, data_source: 'src1'} + - input: ref('fhir_preprocessing__int_medical_claim_diagnosis') + rows: [] + - input: ref('fhir_preprocessing__int_medical_claim_procedure') + rows: [] + - input: ref('fhir_preprocessing__int_medical_claim_supporting_info') + rows: [] + - input: ref('fhir_preprocessing__int_medical_claim_item') + rows: [] + - input: ref('fhir_preprocessing__int_medical_claim_total') + rows: [] + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'MC1', unique_claim_id: 'C1', eob_type_code: 'institutional', eob_subtype_code: 'inpatient', data_source: 'src1'} + - {patient_internal_id: 'P1', resource_internal_id: 'MC2', unique_claim_id: 'C2', eob_type_code: 'professional', eob_subtype_code: 'outpatient', data_source: 'src1'} + + - name: test_fhir_int_medical_claim_eob_dummy_practitioner + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_medical_claim_eob + description: "Medical claim EOB defaults to dummy practitioner when both billing and rendering NPI are null" + given: + - input: ref('fhir_preprocessing__stg_core__eligibility') + rows: [] + - input: ref('fhir_preprocessing__stg_core__medical_claim') + rows: + - {medical_claim_id: 'MC1', person_id: 'P1', claim_id: 'C1', claim_line_number: 1, claim_type: 'professional', encounter_group: 'outpatient', claim_start_date: '2023-06-10', claim_end_date: '2023-06-10', claim_line_start_date: '2023-06-10', payer: 'MCR', plan: 'PlanA', billing_npi: null, billing_name: null, rendering_npi: null, rendering_name: null, admission_date: null, discharge_date: null, bill_type_code: null, revenue_center_code: null, revenue_center_description: null, place_of_service_code: null, place_of_service_description: null, hcpcs_code: null, hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null, paid_date: null, paid_amount: 100, in_network_flag: null, data_source: 'src1'} + - input: ref('fhir_preprocessing__int_medical_claim_diagnosis') + rows: [] + - input: ref('fhir_preprocessing__int_medical_claim_procedure') + rows: [] + - input: ref('fhir_preprocessing__int_medical_claim_supporting_info') + rows: [] + - input: ref('fhir_preprocessing__int_medical_claim_item') + rows: [] + - input: ref('fhir_preprocessing__int_medical_claim_total') + rows: [] + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'MC1', practitioner_internal_id: '9999999999', practitioner_name_text: 'Dummy Practitioner', data_source: 'src1'} diff --git a/models/data_marts/fhir_preprocessing/fhir_preprocessing_gap_unit_tests.yml b/models/data_marts/fhir_preprocessing/fhir_preprocessing_gap_unit_tests.yml new file mode 100644 index 000000000..b52b2add6 --- /dev/null +++ b/models/data_marts/fhir_preprocessing/fhir_preprocessing_gap_unit_tests.yml @@ -0,0 +1,317 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGING: stg_core__condition + # ========================================================================= + + - name: test_fhir_stg_condition_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__condition + description: "Condition staging passes through core condition columns" + given: + - input: ref('core__condition') + rows: + - {condition_id: 'COND1', person_id: 'P1', claim_id: null, encounter_id: 'E1', recorded_date: '2023-06-15', onset_date: '2023-06-10', resolved_date: null, status: 'active', normalized_code_type: 'icd-10-cm', normalized_code: 'E1165', normalized_description: 'Type 2 DM', condition_rank: 1, data_source: 'src1'} + expect: + rows: + - {condition_id: 'COND1', person_id: 'P1', encounter_id: 'E1', normalized_code: 'E1165', condition_rank: 1, data_source: 'src1'} + + - name: test_fhir_stg_condition_preserves_claim_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__condition + description: "Condition staging preserves claim_id column for downstream filtering" + given: + - input: ref('core__condition') + rows: + - {condition_id: 'COND1', person_id: 'P1', claim_id: 'CLM1', encounter_id: 'E1', recorded_date: '2023-06-15', onset_date: null, resolved_date: null, status: 'active', normalized_code_type: 'icd-10-cm', normalized_code: 'I10', normalized_description: 'HTN', condition_rank: 1, data_source: 'src1'} + expect: + rows: + - {condition_id: 'COND1', person_id: 'P1', claim_id: 'CLM1', normalized_code: 'I10', data_source: 'src1'} + + # ========================================================================= + # STAGING: stg_core__encounter + # ========================================================================= + + - name: test_fhir_stg_encounter_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__encounter + description: "Encounter staging passes through encounter columns" + given: + - input: ref('core__encounter') + rows: + - {person_id: 'P1', encounter_id: 'E1', encounter_group: 'inpatient', encounter_start_date: '2023-06-10', encounter_end_date: '2023-06-15', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', encounter_id: 'E1', encounter_group: 'inpatient', encounter_start_date: '2023-06-10', encounter_end_date: '2023-06-15', data_source: 'src1'} + + - name: test_fhir_stg_encounter_multiple_groups + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__encounter + description: "Encounter staging passes through multiple encounter groups correctly" + given: + - input: ref('core__encounter') + rows: + - {person_id: 'P1', encounter_id: 'E1', encounter_group: 'inpatient', encounter_start_date: '2023-06-10', encounter_end_date: '2023-06-15', data_source: 'src1'} + - {person_id: 'P2', encounter_id: 'E2', encounter_group: 'outpatient', encounter_start_date: '2023-07-01', encounter_end_date: '2023-07-01', data_source: 'src1'} + - {person_id: 'P3', encounter_id: 'E3', encounter_group: 'office based', encounter_start_date: '2023-08-01', encounter_end_date: '2023-08-01', data_source: 'src2'} + expect: + rows: + - {encounter_id: 'E1', encounter_group: 'inpatient', data_source: 'src1'} + - {encounter_id: 'E2', encounter_group: 'outpatient', data_source: 'src1'} + - {encounter_id: 'E3', encounter_group: 'office based', data_source: 'src2'} + + # ========================================================================= + # STAGING: stg_core__patient + # ========================================================================= + + - name: test_fhir_stg_patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__patient + description: "Patient staging passes through person_id, name, sex, race, birth_date, data_source" + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', first_name: 'John', last_name: 'Doe', sex: 'male', race: 'white', birth_date: '1960-01-01', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', first_name: 'John', last_name: 'Doe', sex: 'male', race: 'white', birth_date: '1960-01-01', data_source: 'src1'} + + - name: test_fhir_stg_patient_null_race + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__patient + description: "Patient staging passes through null race without modification" + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', first_name: 'Jane', last_name: 'Smith', sex: 'female', race: null, birth_date: '1975-06-15', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', first_name: 'Jane', last_name: 'Smith', sex: 'female', race: null, birth_date: '1975-06-15', data_source: 'src1'} + + # ========================================================================= + # STAGING: stg_core__procedure + # ========================================================================= + + - name: test_fhir_stg_procedure_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__procedure + description: "Procedure staging passes through core procedure columns" + given: + - input: ref('core__procedure') + rows: + - {procedure_id: 'PROC1', person_id: 'P1', claim_id: null, encounter_id: 'E1', normalized_code_type: 'icd-10-pcs', normalized_code: '0DBN0ZZ', normalized_description: 'Excision sigmoid', source_code_type: null, source_code: null, source_description: null, procedure_date: '2023-06-15', practitioner_id: 'NPI1', data_source: 'src1'} + expect: + rows: + - {procedure_id: 'PROC1', person_id: 'P1', normalized_code: '0DBN0ZZ', data_source: 'src1'} + + - name: test_fhir_stg_procedure_preserves_claim_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__procedure + description: "Procedure staging preserves claim_id for downstream EOB filtering" + given: + - input: ref('core__procedure') + rows: + - {procedure_id: 'PROC1', person_id: 'P1', claim_id: 'CLM1', encounter_id: 'E1', normalized_code_type: 'icd-10-pcs', normalized_code: '0DBN0ZZ', normalized_description: 'Excision', source_code_type: null, source_code: null, source_description: null, procedure_date: '2023-06-15', practitioner_id: 'NPI1', data_source: 'src1'} + expect: + rows: + - {procedure_id: 'PROC1', person_id: 'P1', claim_id: 'CLM1', data_source: 'src1'} + + # ========================================================================= + # STAGING: stg_core__observation + # ========================================================================= + + - name: test_fhir_stg_observation_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__observation + description: "Observation staging passes through core observation columns" + overrides: + vars: + clinical_enabled: true + claims_enabled: true + given: + - input: ref('core__observation') + rows: + - {observation_id: 'OBS1', person_id: 'P1', encounter_id: 'E1', observation_type: 'vital-signs', normalized_code_type: 'LOINC', normalized_code: '8480-6', normalized_description: 'Systolic BP', source_code_type: null, source_code: null, source_description: null, observation_date: '2023-06-15', result: '120', normalized_units: 'mmHg', source_units: null, data_source: 'src1'} + expect: + rows: + - {observation_id: 'OBS1', person_id: 'P1', normalized_code: '8480-6', data_source: 'src1'} + + # ========================================================================= + # STAGING: stg_core__medication + # ========================================================================= + + - name: test_fhir_stg_medication_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__medication + description: "Medication staging passes through core medication columns" + overrides: + vars: + clinical_enabled: true + claims_enabled: true + given: + - input: ref('core__medication') + rows: + - {medication_id: 'MED1', person_id: 'P1', source_code_type: 'NDC', ndc_code: '00000000001', ndc_description: 'Aspirin', rxnorm_code: null, rxnorm_description: null, days_supply: 30, dispensing_date: '2023-06-15', data_source: 'src1'} + expect: + rows: + - {medication_id: 'MED1', person_id: 'P1', ndc_code: '00000000001', data_source: 'src1'} + + # ========================================================================= + # STAGING: stg_core__eligibility + # ========================================================================= + + - name: test_fhir_stg_eligibility_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__eligibility + description: "Eligibility staging passes through core eligibility columns" + overrides: + vars: + clinical_enabled: true + claims_enabled: true + given: + - input: ref('core__eligibility') + rows: + - {eligibility_id: 'ELG1', person_id: 'P1', member_id: 'M1', payer_type: 'commercial', payer: 'Aetna', plan: 'Gold', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', subscriber_relation: 'self', subscriber_id: 'SUB1', data_source: 'src1'} + expect: + rows: + - {eligibility_id: 'ELG1', person_id: 'P1', payer: 'Aetna', data_source: 'src1'} + + # ========================================================================= + # STAGING: stg_core__pharmacy_claim + # ========================================================================= + + - name: test_fhir_stg_pharmacy_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__pharmacy_claim + description: "Pharmacy claim staging passes through core pharmacy claim columns" + overrides: + vars: + claims_enabled: true + clinical_enabled: true + given: + - input: ref('core__pharmacy_claim') + rows: + - {pharmacy_claim_id: 'PC1', person_id: 'P1', claim_id: 'C1', claim_line_number: 1, payer: 'MCR', plan: 'PlanA', dispensing_provider_id: 'NPI1', dispensing_provider_name: 'Pharmacy A', dispensing_date: '2023-06-15', paid_date: '2023-07-01', days_supply: 30, refills: 2, paid_amount: 50.00, in_network_flag: 1, ndc_code: '00000000001', data_source: 'src1'} + expect: + rows: + - {pharmacy_claim_id: 'PC1', person_id: 'P1', claim_id: 'C1', ndc_code: '00000000001', data_source: 'src1'} + + # ========================================================================= + # STAGING: stg_core__medical_claim + # ========================================================================= + + - name: test_fhir_stg_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__medical_claim + description: "Medical claim staging passes through core medical claim columns" + overrides: + vars: + claims_enabled: true + clinical_enabled: true + given: + - input: ref('core__medical_claim') + rows: + - {medical_claim_id: 'MC1', person_id: 'P1', claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', encounter_group: 'inpatient', claim_start_date: '2023-06-10', claim_end_date: '2023-06-15', claim_line_start_date: '2023-06-10', payer: 'MCR', plan: 'PlanA', billing_npi: 'NPI1', billing_name: 'Dr Smith', rendering_npi: 'NPI2', rendering_name: 'Dr Jones', admission_date: '2023-06-10', discharge_date: '2023-06-15', bill_type_code: '111', revenue_center_code: '0100', revenue_center_description: 'Room', place_of_service_code: '21', place_of_service_description: 'Inpatient', hcpcs_code: '99213', hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null, paid_date: '2023-07-01', paid_amount: 500, in_network_flag: 1, data_source: 'src1'} + expect: + rows: + - {medical_claim_id: 'MC1', person_id: 'P1', claim_id: 'C1', claim_type: 'institutional', data_source: 'src1'} + + # ========================================================================= + # STAGING: stg_core__lab_result + # ========================================================================= + + - name: test_fhir_stg_lab_result_order_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__lab_result + description: "Lab result staging selects order-level data when component code is null" + overrides: + vars: + clinical_enabled: true + claims_enabled: true + given: + - input: ref('core__lab_result') + rows: + - {lab_result_id: 'LR1', person_id: 'P1', encounter_id: 'E1', status: 'F', normalized_order_type: 'loinc', normalized_order_code: '2345-7', normalized_order_description: 'Glucose', source_order_type: null, source_order_code: null, source_order_description: null, normalized_component_type: null, normalized_component_code: null, normalized_component_description: null, source_component_type: null, source_component_code: null, source_component_description: null, result_datetime: '2023-06-15', result: '120', normalized_units: 'mg/dL', source_units: null, data_source: 'src1'} + expect: + rows: + - {lab_result_id: 'LR1', person_id: 'P1', code_type: 'loinc', code: '2345-7', result: '120', data_source: 'src1'} + + - name: test_fhir_stg_lab_result_component_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__stg_core__lab_result + description: "Lab result staging selects component-level data when component code is present" + overrides: + vars: + clinical_enabled: true + claims_enabled: true + given: + - input: ref('core__lab_result') + rows: + - {lab_result_id: 'LR1', person_id: 'P1', encounter_id: 'E1', status: 'F', normalized_order_type: 'loinc', normalized_order_code: '24323-8', normalized_order_description: 'BMP', source_order_type: null, source_order_code: null, source_order_description: null, normalized_component_type: 'loinc', normalized_component_code: '2345-7', normalized_component_description: 'Glucose', source_component_type: null, source_component_code: null, source_component_description: null, result_datetime: '2023-06-15', result: '120', normalized_units: 'mg/dL', source_units: null, data_source: 'src1'} + expect: + rows: + - {lab_result_id: 'LR1', person_id: 'P1', code_type: 'loinc', code: '2345-7', description: 'Glucose', data_source: 'src1'} + + # ========================================================================= + # INTERMEDIATE: int_pharmacy_claim_eob + # ========================================================================= + + - name: test_fhir_int_pharmacy_claim_eob_type_pharmacy + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_pharmacy_claim_eob + description: "Pharmacy claim EOB sets eob_type_code to 'pharmacy' and null subtypes" + given: + - input: ref('fhir_preprocessing__stg_core__eligibility') + rows: + - {eligibility_id: 'ELG1', person_id: 'P1', member_id: 'M1', payer_type: 'commercial', payer: 'MCR', plan: 'PlanA', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', subscriber_relation: 'self', subscriber_id: 'SUB1', data_source: 'src1'} + - input: ref('fhir_preprocessing__stg_core__pharmacy_claim') + rows: + - {pharmacy_claim_id: 'PC1', person_id: 'P1', claim_id: 'C1', claim_line_number: 1, payer: 'MCR', plan: 'PlanA', dispensing_provider_id: 'NPI1', dispensing_provider_name: 'PharmA', dispensing_date: '2023-06-15', paid_date: '2023-06-20', days_supply: 30, refills: 0, paid_amount: 50.00, in_network_flag: 1, ndc_code: '00000000001', data_source: 'src1'} + - input: ref('fhir_preprocessing__int_pharmacy_claim_supporting_info') + rows: [] + - input: ref('fhir_preprocessing__int_pharmacy_claim_item') + rows: [] + - input: ref('fhir_preprocessing__int_pharmacy_claim_total') + rows: [] + expect: + rows: + - {patient_internal_id: 'P1', resource_internal_id: 'PC1', eob_type_code: 'pharmacy', eob_subtype_code: null, eob_billable_period_start: null, eob_billable_period_end: null, data_source: 'src1'} + + - name: test_fhir_int_pharmacy_claim_eob_dummy_practitioner + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: fhir_preprocessing__int_pharmacy_claim_eob + description: "Pharmacy claim EOB defaults to dummy practitioner when dispensing_provider_id is null" + given: + - input: ref('fhir_preprocessing__stg_core__eligibility') + rows: [] + - input: ref('fhir_preprocessing__stg_core__pharmacy_claim') + rows: + - {pharmacy_claim_id: 'PC1', person_id: 'P1', claim_id: 'C1', claim_line_number: 1, payer: 'MCR', plan: 'PlanA', dispensing_provider_id: null, dispensing_provider_name: null, dispensing_date: '2023-06-15', paid_date: '2023-06-20', days_supply: 30, refills: 0, paid_amount: 50.00, in_network_flag: 1, ndc_code: '00000000001', data_source: 'src1'} + - input: ref('fhir_preprocessing__int_pharmacy_claim_supporting_info') + rows: [] + - input: ref('fhir_preprocessing__int_pharmacy_claim_item') + rows: [] + - input: ref('fhir_preprocessing__int_pharmacy_claim_total') + rows: [] + expect: + rows: + - {patient_internal_id: 'P1', practitioner_internal_id: '9999999999', practitioner_name_text: 'Dummy Practitioner', data_source: 'src1'} diff --git a/models/data_marts/financial_pmpm/_gap_unit_tests.yml b/models/data_marts/financial_pmpm/_gap_unit_tests.yml new file mode 100644 index 000000000..69f80f8de --- /dev/null +++ b/models/data_marts/financial_pmpm/_gap_unit_tests.yml @@ -0,0 +1,172 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # FINANCIAL PMPM - STAGING: stg_eligibility + # ========================================================================= + + - name: test_financial_pmpm_stg_eligibility_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__stg_eligibility + description: "Eligibility staging passes through core eligibility fields" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__eligibility') + rows: + - {person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_financial_pmpm_stg_eligibility_multiple_rows + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__stg_eligibility + description: "Eligibility staging handles multiple eligibility records for different payers" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__eligibility') + rows: + - {person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-06-30', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', enrollment_start_date: '2023-07-01', enrollment_end_date: '2023-12-31', payer: 'MCD', plan: 'PlanB', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-06-30', payer: 'MCR', plan: 'PlanA', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', enrollment_start_date: '2023-07-01', enrollment_end_date: '2023-12-31', payer: 'MCD', plan: 'PlanB', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FINANCIAL PMPM - STAGING: stg_medical_claim + # ========================================================================= + + - name: test_financial_pmpm_stg_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__stg_medical_claim + description: "Medical claim staging passes through core medical claim fields" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__medical_claim') + rows: + - {person_id: 'P1', member_id: 'M1', claim_id: 'C1', claim_line_number: 1, claim_start_date: '2023-03-15', claim_end_date: '2023-03-15', service_category_1: 'inpatient', service_category_2: 'acute inpatient', paid_amount: 1000, allowed_amount: 1200, payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', claim_id: 'C1', service_category_1: 'inpatient', paid_amount: 1000, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_financial_pmpm_stg_medical_claim_multiple_lines + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__stg_medical_claim + description: "Medical claim staging passes through multiple claim lines" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__medical_claim') + rows: + - {person_id: 'P1', member_id: 'M1', claim_id: 'C1', claim_line_number: 1, claim_start_date: '2023-03-15', claim_end_date: '2023-03-15', service_category_1: 'inpatient', service_category_2: 'acute inpatient', paid_amount: 1000, allowed_amount: 1200, payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', claim_id: 'C1', claim_line_number: 2, claim_start_date: '2023-03-15', claim_end_date: '2023-03-15', service_category_1: 'inpatient', service_category_2: 'acute inpatient', paid_amount: 500, allowed_amount: 600, payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P2', member_id: 'M2', claim_id: 'C2', claim_line_number: 1, claim_start_date: '2023-04-10', claim_end_date: '2023-04-10', service_category_1: 'outpatient', service_category_2: 'emergency department', paid_amount: 800, allowed_amount: 900, payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, service_category_1: 'inpatient', paid_amount: 1000, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 2, service_category_1: 'inpatient', paid_amount: 500, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', claim_id: 'C2', claim_line_number: 1, service_category_1: 'outpatient', paid_amount: 800, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FINANCIAL PMPM - STAGING: stg_pharmacy_claim + # ========================================================================= + + - name: test_financial_pmpm_stg_pharmacy_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__stg_pharmacy_claim + description: "Pharmacy claim staging passes through core pharmacy claim fields" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__pharmacy_claim') + rows: + - {person_id: 'P1', member_id: 'M1', dispensing_date: '2023-03-15', paid_date: null, paid_amount: 200, allowed_amount: 250, payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', dispensing_date: '2023-03-15', paid_amount: 200, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_financial_pmpm_stg_pharmacy_claim_multiple_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__stg_pharmacy_claim + description: "Pharmacy claim staging passes through multiple pharmacy claims" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__pharmacy_claim') + rows: + - {person_id: 'P1', member_id: 'M1', dispensing_date: '2023-03-15', paid_date: '2023-03-20', paid_amount: 200, allowed_amount: 250, payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', dispensing_date: '2023-04-10', paid_date: '2023-04-15', paid_amount: 75, allowed_amount: 90, payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', dispensing_date: '2023-03-15', paid_amount: 200, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', dispensing_date: '2023-04-10', paid_amount: 75, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FINANCIAL PMPM - FINAL: pmpm_prep (gap/edge case tests) + # ========================================================================= + + - name: test_financial_pmpm_pmpm_prep_multiple_member_months + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__pmpm_prep + description: "PMPM prep correctly handles member with multiple month entries" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null} + - {person_id: 'P1', member_id: 'M1', year_month: '202302', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null} + - input: ref('financial_pmpm__service_category_1_paid_pivot') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', inpatient_paid: 500, outpatient_paid: 0, office_based_paid: 0, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 0} + - input: ref('financial_pmpm__service_category_2_paid_pivot') + rows: [] + - input: ref('financial_pmpm__service_category_1_allowed_pivot') + rows: [] + - input: ref('financial_pmpm__service_category_2_allowed_pivot') + rows: [] + expect: + rows: + - {person_id: 'P1', year_month: '202301', total_paid: 500, medical_paid: 500, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', year_month: '202302', total_paid: 0, medical_paid: 0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FINANCIAL PMPM - FINAL: pmpm_payer (gap/edge case tests) + # ========================================================================= + + - name: test_financial_pmpm_pmpm_payer_multiple_months_same_payer + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__pmpm_payer + description: "PMPM payer aggregates multiple months separately" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('financial_pmpm__pmpm_prep') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', total_paid: 1000, medical_paid: 800, inpatient_paid: 500, outpatient_paid: 200, office_based_paid: 100, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 200, acute_inpatient_paid: 500, ambulance_paid: 0, ambulatory_surgery_center_paid: 0, dialysis_paid: 0, durable_medical_equipment_paid: 0, emergency_department_paid: 0, home_health_paid: 0, inpatient_hospice_paid: 0, inpatient_psychiatric_paid: 0, inpatient_rehabilitation_paid: 0, lab_paid: 0, observation_paid: 0, office_based_other_paid: 0, office_based_pt_ot_st_paid: 0, office_based_radiology_paid: 0, office_based_surgery_paid: 0, office_based_visit_paid: 100, outpatient_hospital_or_clinic_paid: 200, outpatient_pt_ot_st_paid: 0, outpatient_psychiatric_paid: 0, outpatient_radiology_paid: 0, outpatient_rehabilitation_paid: 0, outpatient_surgery_paid: 0, skilled_nursing_paid: 0, telehealth_visit_paid: 0, urgent_care_paid: 0, total_allowed: 1200, medical_allowed: 1000, inpatient_allowed: 600, outpatient_allowed: 250, office_based_allowed: 150, ancillary_allowed: 0, other_allowed: 0, pharmacy_allowed: 200, acute_inpatient_allowed: 600, ambulance_allowed: 0, ambulatory_surgery_center_allowed: 0, dialysis_allowed: 0, durable_medical_equipment_allowed: 0, emergency_department_allowed: 0, home_health_allowed: 0, inpatient_hospice_allowed: 0, inpatient_psychiatric_allowed: 0, inpatient_rehabilitation_allowed: 0, lab_allowed: 0, observation_allowed: 0, office_based_other_allowed: 0, office_based_pt_ot_st_allowed: 0, office_based_radiology_allowed: 0, office_based_surgery_allowed: 0, office_based_visit_allowed: 150, outpatient_hospital_or_clinic_allowed: 250, outpatient_pt_ot_st_allowed: 0, outpatient_psychiatric_allowed: 0, outpatient_radiology_allowed: 0, outpatient_rehabilitation_allowed: 0, outpatient_surgery_allowed: 0, skilled_nursing_allowed: 0, telehealth_visit_allowed: 0, urgent_care_allowed: 0, tuva_last_run: '2024-01-01 00:00:00', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, other_paid_2: 0, pharmacy_paid_2: 0, other_allowed_2: 0, pharmacy_allowed_2: 0, outpatient_hospice_paid: 0, outpatient_hospice_allowed: 0} + - {person_id: 'P1', member_id: 'M1', year_month: '202302', payer: 'MCR', plan: 'PlanA', data_source: 'src1', total_paid: 300, medical_paid: 200, inpatient_paid: 0, outpatient_paid: 100, office_based_paid: 100, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 100, acute_inpatient_paid: 0, ambulance_paid: 0, ambulatory_surgery_center_paid: 0, dialysis_paid: 0, durable_medical_equipment_paid: 0, emergency_department_paid: 0, home_health_paid: 0, inpatient_hospice_paid: 0, inpatient_psychiatric_paid: 0, inpatient_rehabilitation_paid: 0, lab_paid: 0, observation_paid: 0, office_based_other_paid: 0, office_based_pt_ot_st_paid: 0, office_based_radiology_paid: 0, office_based_surgery_paid: 0, office_based_visit_paid: 100, outpatient_hospital_or_clinic_paid: 100, outpatient_pt_ot_st_paid: 0, outpatient_psychiatric_paid: 0, outpatient_radiology_paid: 0, outpatient_rehabilitation_paid: 0, outpatient_surgery_paid: 0, skilled_nursing_paid: 0, telehealth_visit_paid: 0, urgent_care_paid: 0, total_allowed: 400, medical_allowed: 300, inpatient_allowed: 0, outpatient_allowed: 120, office_based_allowed: 130, ancillary_allowed: 0, other_allowed: 50, pharmacy_allowed: 100, acute_inpatient_allowed: 0, ambulance_allowed: 0, ambulatory_surgery_center_allowed: 0, dialysis_allowed: 0, durable_medical_equipment_allowed: 0, emergency_department_allowed: 0, home_health_allowed: 0, inpatient_hospice_allowed: 0, inpatient_psychiatric_allowed: 0, inpatient_rehabilitation_allowed: 0, lab_allowed: 0, observation_allowed: 0, office_based_other_allowed: 0, office_based_pt_ot_st_allowed: 0, office_based_radiology_allowed: 0, office_based_surgery_allowed: 0, office_based_visit_allowed: 130, outpatient_hospital_or_clinic_allowed: 120, outpatient_pt_ot_st_allowed: 0, outpatient_psychiatric_allowed: 0, outpatient_radiology_allowed: 0, outpatient_rehabilitation_allowed: 0, outpatient_surgery_allowed: 0, skilled_nursing_allowed: 0, telehealth_visit_allowed: 0, urgent_care_allowed: 0, tuva_last_run: '2024-01-01 00:00:00', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, other_paid_2: 0, pharmacy_paid_2: 0, other_allowed_2: 0, pharmacy_allowed_2: 0, outpatient_hospice_paid: 0, outpatient_hospice_allowed: 0} + expect: + rows: + - {year_month: '202301', payer: 'MCR', data_source: 'src1', member_months: 1, total_paid: 1000, tuva_last_run: '2024-01-01 00:00:00'} + - {year_month: '202302', payer: 'MCR', data_source: 'src1', member_months: 1, total_paid: 300, tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/data_marts/financial_pmpm/_unit_tests.yml b/models/data_marts/financial_pmpm/_unit_tests.yml new file mode 100644 index 000000000..4819e3f89 --- /dev/null +++ b/models/data_marts/financial_pmpm/_unit_tests.yml @@ -0,0 +1,176 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # FINANCIAL PMPM - FINAL: pmpm_payer + # ========================================================================= + + - name: test_financial_pmpm_pmpm_payer_computes_pmpm + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__pmpm_payer + description: "PMPM payer aggregates by year_month/payer/data_source and divides by member month count" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('financial_pmpm__pmpm_prep') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', total_paid: 1000, medical_paid: 800, inpatient_paid: 500, outpatient_paid: 200, office_based_paid: 100, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 200, acute_inpatient_paid: 500, ambulance_paid: 0, ambulatory_surgery_center_paid: 0, dialysis_paid: 0, durable_medical_equipment_paid: 0, emergency_department_paid: 0, home_health_paid: 0, inpatient_hospice_paid: 0, inpatient_psychiatric_paid: 0, inpatient_rehabilitation_paid: 0, lab_paid: 0, observation_paid: 0, office_based_other_paid: 0, office_based_pt_ot_st_paid: 0, office_based_radiology_paid: 0, office_based_surgery_paid: 0, office_based_visit_paid: 100, outpatient_hospital_or_clinic_paid: 200, outpatient_pt_ot_st_paid: 0, outpatient_psychiatric_paid: 0, outpatient_radiology_paid: 0, outpatient_rehabilitation_paid: 0, outpatient_surgery_paid: 0, skilled_nursing_paid: 0, telehealth_visit_paid: 0, urgent_care_paid: 0, total_allowed: 1200, medical_allowed: 1000, inpatient_allowed: 600, outpatient_allowed: 250, office_based_allowed: 150, ancillary_allowed: 0, other_allowed: 0, pharmacy_allowed: 200, acute_inpatient_allowed: 600, ambulance_allowed: 0, ambulatory_surgery_center_allowed: 0, dialysis_allowed: 0, durable_medical_equipment_allowed: 0, emergency_department_allowed: 0, home_health_allowed: 0, inpatient_hospice_allowed: 0, inpatient_psychiatric_allowed: 0, inpatient_rehabilitation_allowed: 0, lab_allowed: 0, observation_allowed: 0, office_based_other_allowed: 0, office_based_pt_ot_st_allowed: 0, office_based_radiology_allowed: 0, office_based_surgery_allowed: 0, office_based_visit_allowed: 150, outpatient_hospital_or_clinic_allowed: 250, outpatient_pt_ot_st_allowed: 0, outpatient_psychiatric_allowed: 0, outpatient_radiology_allowed: 0, outpatient_rehabilitation_allowed: 0, outpatient_surgery_allowed: 0, skilled_nursing_allowed: 0, telehealth_visit_allowed: 0, urgent_care_allowed: 0, tuva_last_run: '2024-01-01 00:00:00', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, other_paid_2: 0, pharmacy_paid_2: 0, other_allowed_2: 0, pharmacy_allowed_2: 0, outpatient_hospice_paid: 0, outpatient_hospice_allowed: 0} + expect: + rows: + - {year_month: '202301', payer: 'MCR', data_source: 'src1', member_months: 1, total_paid: 1000, inpatient_paid: 500, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_financial_pmpm_pmpm_payer_multiple_members_averages + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__pmpm_payer + description: "PMPM payer with multiple members computes correct average (sum/count)" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('financial_pmpm__pmpm_prep') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', total_paid: 1000, medical_paid: 800, inpatient_paid: 500, outpatient_paid: 200, office_based_paid: 100, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 200, acute_inpatient_paid: 500, ambulance_paid: 0, ambulatory_surgery_center_paid: 0, dialysis_paid: 0, durable_medical_equipment_paid: 0, emergency_department_paid: 0, home_health_paid: 0, inpatient_hospice_paid: 0, inpatient_psychiatric_paid: 0, inpatient_rehabilitation_paid: 0, lab_paid: 0, observation_paid: 0, office_based_other_paid: 0, office_based_pt_ot_st_paid: 0, office_based_radiology_paid: 0, office_based_surgery_paid: 0, office_based_visit_paid: 100, outpatient_hospital_or_clinic_paid: 200, outpatient_pt_ot_st_paid: 0, outpatient_psychiatric_paid: 0, outpatient_radiology_paid: 0, outpatient_rehabilitation_paid: 0, outpatient_surgery_paid: 0, skilled_nursing_paid: 0, telehealth_visit_paid: 0, urgent_care_paid: 0, total_allowed: 1200, medical_allowed: 1000, inpatient_allowed: 600, outpatient_allowed: 250, office_based_allowed: 150, ancillary_allowed: 0, other_allowed: 0, pharmacy_allowed: 200, acute_inpatient_allowed: 600, ambulance_allowed: 0, ambulatory_surgery_center_allowed: 0, dialysis_allowed: 0, durable_medical_equipment_allowed: 0, emergency_department_allowed: 0, home_health_allowed: 0, inpatient_hospice_allowed: 0, inpatient_psychiatric_allowed: 0, inpatient_rehabilitation_allowed: 0, lab_allowed: 0, observation_allowed: 0, office_based_other_allowed: 0, office_based_pt_ot_st_allowed: 0, office_based_radiology_allowed: 0, office_based_surgery_allowed: 0, office_based_visit_allowed: 150, outpatient_hospital_or_clinic_allowed: 250, outpatient_pt_ot_st_allowed: 0, outpatient_psychiatric_allowed: 0, outpatient_radiology_allowed: 0, outpatient_rehabilitation_allowed: 0, outpatient_surgery_allowed: 0, skilled_nursing_allowed: 0, telehealth_visit_allowed: 0, urgent_care_allowed: 0, tuva_last_run: '2024-01-01 00:00:00', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, other_paid_2: 0, pharmacy_paid_2: 0, other_allowed_2: 0, pharmacy_allowed_2: 0, outpatient_hospice_paid: 0, outpatient_hospice_allowed: 0} + - {person_id: 'P2', member_id: 'M2', year_month: '202301', payer: 'MCR', plan: 'PlanB', data_source: 'src1', total_paid: 500, medical_paid: 400, inpatient_paid: 0, outpatient_paid: 200, office_based_paid: 200, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 100, acute_inpatient_paid: 0, ambulance_paid: 0, ambulatory_surgery_center_paid: 0, dialysis_paid: 0, durable_medical_equipment_paid: 0, emergency_department_paid: 0, home_health_paid: 0, inpatient_hospice_paid: 0, inpatient_psychiatric_paid: 0, inpatient_rehabilitation_paid: 0, lab_paid: 0, observation_paid: 0, office_based_other_paid: 0, office_based_pt_ot_st_paid: 0, office_based_radiology_paid: 0, office_based_surgery_paid: 0, office_based_visit_paid: 200, outpatient_hospital_or_clinic_paid: 200, outpatient_pt_ot_st_paid: 0, outpatient_psychiatric_paid: 0, outpatient_radiology_paid: 0, outpatient_rehabilitation_paid: 0, outpatient_surgery_paid: 0, skilled_nursing_paid: 0, telehealth_visit_paid: 0, urgent_care_paid: 0, total_allowed: 600, medical_allowed: 500, inpatient_allowed: 0, outpatient_allowed: 250, office_based_allowed: 250, ancillary_allowed: 0, other_allowed: 0, pharmacy_allowed: 100, acute_inpatient_allowed: 0, ambulance_allowed: 0, ambulatory_surgery_center_allowed: 0, dialysis_allowed: 0, durable_medical_equipment_allowed: 0, emergency_department_allowed: 0, home_health_allowed: 0, inpatient_hospice_allowed: 0, inpatient_psychiatric_allowed: 0, inpatient_rehabilitation_allowed: 0, lab_allowed: 0, observation_allowed: 0, office_based_other_allowed: 0, office_based_pt_ot_st_allowed: 0, office_based_radiology_allowed: 0, office_based_surgery_allowed: 0, office_based_visit_allowed: 250, outpatient_hospital_or_clinic_allowed: 250, outpatient_pt_ot_st_allowed: 0, outpatient_psychiatric_allowed: 0, outpatient_radiology_allowed: 0, outpatient_rehabilitation_allowed: 0, outpatient_surgery_allowed: 0, skilled_nursing_allowed: 0, telehealth_visit_allowed: 0, urgent_care_allowed: 0, tuva_last_run: '2024-01-01 00:00:00', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, other_paid_2: 0, pharmacy_paid_2: 0, other_allowed_2: 0, pharmacy_allowed_2: 0, outpatient_hospice_paid: 0, outpatient_hospice_allowed: 0} + expect: + rows: + - {year_month: '202301', payer: 'MCR', data_source: 'src1', member_months: 2, total_paid: 750, inpatient_paid: 250, pharmacy_paid: 150, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_financial_pmpm_pmpm_payer_separate_payers + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__pmpm_payer + description: "PMPM payer separates results by payer" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('financial_pmpm__pmpm_prep') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', total_paid: 1000, medical_paid: 800, inpatient_paid: 500, outpatient_paid: 200, office_based_paid: 100, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 200, acute_inpatient_paid: 500, ambulance_paid: 0, ambulatory_surgery_center_paid: 0, dialysis_paid: 0, durable_medical_equipment_paid: 0, emergency_department_paid: 0, home_health_paid: 0, inpatient_hospice_paid: 0, inpatient_psychiatric_paid: 0, inpatient_rehabilitation_paid: 0, lab_paid: 0, observation_paid: 0, office_based_other_paid: 0, office_based_pt_ot_st_paid: 0, office_based_radiology_paid: 0, office_based_surgery_paid: 0, office_based_visit_paid: 100, outpatient_hospital_or_clinic_paid: 200, outpatient_pt_ot_st_paid: 0, outpatient_psychiatric_paid: 0, outpatient_radiology_paid: 0, outpatient_rehabilitation_paid: 0, outpatient_surgery_paid: 0, skilled_nursing_paid: 0, telehealth_visit_paid: 0, urgent_care_paid: 0, total_allowed: 1200, medical_allowed: 1000, inpatient_allowed: 600, outpatient_allowed: 250, office_based_allowed: 150, ancillary_allowed: 0, other_allowed: 0, pharmacy_allowed: 200, acute_inpatient_allowed: 600, ambulance_allowed: 0, ambulatory_surgery_center_allowed: 0, dialysis_allowed: 0, durable_medical_equipment_allowed: 0, emergency_department_allowed: 0, home_health_allowed: 0, inpatient_hospice_allowed: 0, inpatient_psychiatric_allowed: 0, inpatient_rehabilitation_allowed: 0, lab_allowed: 0, observation_allowed: 0, office_based_other_allowed: 0, office_based_pt_ot_st_allowed: 0, office_based_radiology_allowed: 0, office_based_surgery_allowed: 0, office_based_visit_allowed: 150, outpatient_hospital_or_clinic_allowed: 250, outpatient_pt_ot_st_allowed: 0, outpatient_psychiatric_allowed: 0, outpatient_radiology_allowed: 0, outpatient_rehabilitation_allowed: 0, outpatient_surgery_allowed: 0, skilled_nursing_allowed: 0, telehealth_visit_allowed: 0, urgent_care_allowed: 0, tuva_last_run: '2024-01-01 00:00:00', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, other_paid_2: 0, pharmacy_paid_2: 0, other_allowed_2: 0, pharmacy_allowed_2: 0, outpatient_hospice_paid: 0, outpatient_hospice_allowed: 0} + - {person_id: 'P2', member_id: 'M2', year_month: '202301', payer: 'MCD', plan: 'PlanB', data_source: 'src1', total_paid: 600, medical_paid: 500, inpatient_paid: 300, outpatient_paid: 100, office_based_paid: 100, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 100, acute_inpatient_paid: 300, ambulance_paid: 0, ambulatory_surgery_center_paid: 0, dialysis_paid: 0, durable_medical_equipment_paid: 0, emergency_department_paid: 0, home_health_paid: 0, inpatient_hospice_paid: 0, inpatient_psychiatric_paid: 0, inpatient_rehabilitation_paid: 0, lab_paid: 0, observation_paid: 0, office_based_other_paid: 0, office_based_pt_ot_st_paid: 0, office_based_radiology_paid: 0, office_based_surgery_paid: 0, office_based_visit_paid: 100, outpatient_hospital_or_clinic_paid: 100, outpatient_pt_ot_st_paid: 0, outpatient_psychiatric_paid: 0, outpatient_radiology_paid: 0, outpatient_rehabilitation_paid: 0, outpatient_surgery_paid: 0, skilled_nursing_paid: 0, telehealth_visit_paid: 0, urgent_care_paid: 0, total_allowed: 700, medical_allowed: 600, inpatient_allowed: 350, outpatient_allowed: 120, office_based_allowed: 130, ancillary_allowed: 0, other_allowed: 0, pharmacy_allowed: 100, acute_inpatient_allowed: 350, ambulance_allowed: 0, ambulatory_surgery_center_allowed: 0, dialysis_allowed: 0, durable_medical_equipment_allowed: 0, emergency_department_allowed: 0, home_health_allowed: 0, inpatient_hospice_allowed: 0, inpatient_psychiatric_allowed: 0, inpatient_rehabilitation_allowed: 0, lab_allowed: 0, observation_allowed: 0, office_based_other_allowed: 0, office_based_pt_ot_st_allowed: 0, office_based_radiology_allowed: 0, office_based_surgery_allowed: 0, office_based_visit_allowed: 130, outpatient_hospital_or_clinic_allowed: 120, outpatient_pt_ot_st_allowed: 0, outpatient_psychiatric_allowed: 0, outpatient_radiology_allowed: 0, outpatient_rehabilitation_allowed: 0, outpatient_surgery_allowed: 0, skilled_nursing_allowed: 0, telehealth_visit_allowed: 0, urgent_care_allowed: 0, tuva_last_run: '2024-01-01 00:00:00', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, other_paid_2: 0, pharmacy_paid_2: 0, other_allowed_2: 0, pharmacy_allowed_2: 0, outpatient_hospice_paid: 0, outpatient_hospice_allowed: 0} + expect: + rows: + - {year_month: '202301', payer: 'MCR', data_source: 'src1', member_months: 1, total_paid: 1000, tuva_last_run: '2024-01-01 00:00:00'} + - {year_month: '202301', payer: 'MCD', data_source: 'src1', member_months: 1, total_paid: 600, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FINANCIAL PMPM - FINAL: pmpm_payer_plan + # ========================================================================= + + - name: test_financial_pmpm_pmpm_payer_plan_aggregates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__pmpm_payer_plan + description: "PMPM payer plan aggregates by year_month/payer/plan/data_source" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('financial_pmpm__pmpm_prep') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', total_paid: 1000, medical_paid: 800, inpatient_paid: 500, outpatient_paid: 200, office_based_paid: 100, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 200, acute_inpatient_paid: 500, ambulance_paid: 0, ambulatory_surgery_center_paid: 0, dialysis_paid: 0, durable_medical_equipment_paid: 0, emergency_department_paid: 0, home_health_paid: 0, inpatient_hospice_paid: 0, inpatient_psychiatric_paid: 0, inpatient_rehabilitation_paid: 0, lab_paid: 0, observation_paid: 0, office_based_other_paid: 0, office_based_pt_ot_st_paid: 0, office_based_radiology_paid: 0, office_based_surgery_paid: 0, office_based_visit_paid: 100, outpatient_hospital_or_clinic_paid: 200, outpatient_pt_ot_st_paid: 0, outpatient_psychiatric_paid: 0, outpatient_radiology_paid: 0, outpatient_rehabilitation_paid: 0, outpatient_surgery_paid: 0, skilled_nursing_paid: 0, telehealth_visit_paid: 0, urgent_care_paid: 0, total_allowed: 1200, medical_allowed: 1000, inpatient_allowed: 600, outpatient_allowed: 250, office_based_allowed: 150, ancillary_allowed: 0, other_allowed: 0, pharmacy_allowed: 200, acute_inpatient_allowed: 600, ambulance_allowed: 0, ambulatory_surgery_center_allowed: 0, dialysis_allowed: 0, durable_medical_equipment_allowed: 0, emergency_department_allowed: 0, home_health_allowed: 0, inpatient_hospice_allowed: 0, inpatient_psychiatric_allowed: 0, inpatient_rehabilitation_allowed: 0, lab_allowed: 0, observation_allowed: 0, office_based_other_allowed: 0, office_based_pt_ot_st_allowed: 0, office_based_radiology_allowed: 0, office_based_surgery_allowed: 0, office_based_visit_allowed: 150, outpatient_hospital_or_clinic_allowed: 250, outpatient_pt_ot_st_allowed: 0, outpatient_psychiatric_allowed: 0, outpatient_radiology_allowed: 0, outpatient_rehabilitation_allowed: 0, outpatient_surgery_allowed: 0, skilled_nursing_allowed: 0, telehealth_visit_allowed: 0, urgent_care_allowed: 0, tuva_last_run: '2024-01-01 00:00:00', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, other_paid_2: 0, pharmacy_paid_2: 0, other_allowed_2: 0, pharmacy_allowed_2: 0, outpatient_hospice_paid: 0, outpatient_hospice_allowed: 0} + expect: + rows: + - {year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', member_months: 1, total_paid: 1000, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_financial_pmpm_pmpm_payer_plan_separates_by_plan + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__pmpm_payer_plan + description: "PMPM payer plan keeps different plans separate within same payer" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('financial_pmpm__pmpm_prep') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', total_paid: 800, medical_paid: 600, inpatient_paid: 400, outpatient_paid: 100, office_based_paid: 100, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 200, acute_inpatient_paid: 400, ambulance_paid: 0, ambulatory_surgery_center_paid: 0, dialysis_paid: 0, durable_medical_equipment_paid: 0, emergency_department_paid: 0, home_health_paid: 0, inpatient_hospice_paid: 0, inpatient_psychiatric_paid: 0, inpatient_rehabilitation_paid: 0, lab_paid: 0, observation_paid: 0, office_based_other_paid: 0, office_based_pt_ot_st_paid: 0, office_based_radiology_paid: 0, office_based_surgery_paid: 0, office_based_visit_paid: 100, outpatient_hospital_or_clinic_paid: 100, outpatient_pt_ot_st_paid: 0, outpatient_psychiatric_paid: 0, outpatient_radiology_paid: 0, outpatient_rehabilitation_paid: 0, outpatient_surgery_paid: 0, skilled_nursing_paid: 0, telehealth_visit_paid: 0, urgent_care_paid: 0, total_allowed: 1000, medical_allowed: 800, inpatient_allowed: 500, outpatient_allowed: 150, office_based_allowed: 150, ancillary_allowed: 0, other_allowed: 0, pharmacy_allowed: 200, acute_inpatient_allowed: 500, ambulance_allowed: 0, ambulatory_surgery_center_allowed: 0, dialysis_allowed: 0, durable_medical_equipment_allowed: 0, emergency_department_allowed: 0, home_health_allowed: 0, inpatient_hospice_allowed: 0, inpatient_psychiatric_allowed: 0, inpatient_rehabilitation_allowed: 0, lab_allowed: 0, observation_allowed: 0, office_based_other_allowed: 0, office_based_pt_ot_st_allowed: 0, office_based_radiology_allowed: 0, office_based_surgery_allowed: 0, office_based_visit_allowed: 150, outpatient_hospital_or_clinic_allowed: 150, outpatient_pt_ot_st_allowed: 0, outpatient_psychiatric_allowed: 0, outpatient_radiology_allowed: 0, outpatient_rehabilitation_allowed: 0, outpatient_surgery_allowed: 0, skilled_nursing_allowed: 0, telehealth_visit_allowed: 0, urgent_care_allowed: 0, tuva_last_run: '2024-01-01 00:00:00', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, other_paid_2: 0, pharmacy_paid_2: 0, other_allowed_2: 0, pharmacy_allowed_2: 0, outpatient_hospice_paid: 0, outpatient_hospice_allowed: 0} + - {person_id: 'P2', member_id: 'M2', year_month: '202301', payer: 'MCR', plan: 'PlanB', data_source: 'src1', total_paid: 400, medical_paid: 300, inpatient_paid: 0, outpatient_paid: 150, office_based_paid: 150, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 100, acute_inpatient_paid: 0, ambulance_paid: 0, ambulatory_surgery_center_paid: 0, dialysis_paid: 0, durable_medical_equipment_paid: 0, emergency_department_paid: 0, home_health_paid: 0, inpatient_hospice_paid: 0, inpatient_psychiatric_paid: 0, inpatient_rehabilitation_paid: 0, lab_paid: 0, observation_paid: 0, office_based_other_paid: 0, office_based_pt_ot_st_paid: 0, office_based_radiology_paid: 0, office_based_surgery_paid: 0, office_based_visit_paid: 150, outpatient_hospital_or_clinic_paid: 150, outpatient_pt_ot_st_paid: 0, outpatient_psychiatric_paid: 0, outpatient_radiology_paid: 0, outpatient_rehabilitation_paid: 0, outpatient_surgery_paid: 0, skilled_nursing_paid: 0, telehealth_visit_paid: 0, urgent_care_paid: 0, total_allowed: 500, medical_allowed: 400, inpatient_allowed: 0, outpatient_allowed: 200, office_based_allowed: 200, ancillary_allowed: 0, other_allowed: 0, pharmacy_allowed: 100, acute_inpatient_allowed: 0, ambulance_allowed: 0, ambulatory_surgery_center_allowed: 0, dialysis_allowed: 0, durable_medical_equipment_allowed: 0, emergency_department_allowed: 0, home_health_allowed: 0, inpatient_hospice_allowed: 0, inpatient_psychiatric_allowed: 0, inpatient_rehabilitation_allowed: 0, lab_allowed: 0, observation_allowed: 0, office_based_other_allowed: 0, office_based_pt_ot_st_allowed: 0, office_based_radiology_allowed: 0, office_based_surgery_allowed: 0, office_based_visit_allowed: 200, outpatient_hospital_or_clinic_allowed: 200, outpatient_pt_ot_st_allowed: 0, outpatient_psychiatric_allowed: 0, outpatient_radiology_allowed: 0, outpatient_rehabilitation_allowed: 0, outpatient_surgery_allowed: 0, skilled_nursing_allowed: 0, telehealth_visit_allowed: 0, urgent_care_allowed: 0, tuva_last_run: '2024-01-01 00:00:00', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null, other_paid_2: 0, pharmacy_paid_2: 0, other_allowed_2: 0, pharmacy_allowed_2: 0, outpatient_hospice_paid: 0, outpatient_hospice_allowed: 0} + expect: + rows: + - {year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', member_months: 1, total_paid: 800, tuva_last_run: '2024-01-01 00:00:00'} + - {year_month: '202301', payer: 'MCR', plan: 'PlanB', data_source: 'src1', member_months: 1, total_paid: 400, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FINANCIAL PMPM - FINAL: pmpm_prep + # ========================================================================= + + - name: test_financial_pmpm_pmpm_prep_joins_pivots + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__pmpm_prep + description: "PMPM prep joins member months to paid/allowed pivots and computes totals" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null} + - input: ref('financial_pmpm__service_category_1_paid_pivot') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', inpatient_paid: 500, outpatient_paid: 0, office_based_paid: 100, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 200} + - input: ref('financial_pmpm__service_category_2_paid_pivot') + rows: [] + - input: ref('financial_pmpm__service_category_1_allowed_pivot') + rows: [] + - input: ref('financial_pmpm__service_category_2_allowed_pivot') + rows: [] + expect: + rows: + - {person_id: 'P1', year_month: '202301', payer: 'MCR', total_paid: 800, medical_paid: 600, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_financial_pmpm_pmpm_prep_no_claims_all_zeros + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__pmpm_prep + description: "Member months with no matching claims get zero for all paid/allowed amounts" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null} + - input: ref('financial_pmpm__service_category_1_paid_pivot') + rows: [] + - input: ref('financial_pmpm__service_category_2_paid_pivot') + rows: [] + - input: ref('financial_pmpm__service_category_1_allowed_pivot') + rows: [] + - input: ref('financial_pmpm__service_category_2_allowed_pivot') + rows: [] + expect: + rows: + - {person_id: 'P1', year_month: '202301', payer: 'MCR', total_paid: 0, medical_paid: 0, total_allowed: 0, medical_allowed: 0, inpatient_paid: 0, pharmacy_paid: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_financial_pmpm_pmpm_prep_total_paid_includes_pharmacy + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: financial_pmpm__pmpm_prep + description: "Total_paid = medical_paid + pharmacy_paid, medical_paid excludes pharmacy" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null} + - input: ref('financial_pmpm__service_category_1_paid_pivot') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', inpatient_paid: 300, outpatient_paid: 200, office_based_paid: 100, ancillary_paid: 50, other_paid: 25, pharmacy_paid: 175} + - input: ref('financial_pmpm__service_category_2_paid_pivot') + rows: [] + - input: ref('financial_pmpm__service_category_1_allowed_pivot') + rows: + - {person_id: 'P1', member_id: 'M1', year_month: '202301', payer: 'MCR', plan: 'PlanA', data_source: 'src1', inpatient_allowed: 400, outpatient_allowed: 250, office_based_allowed: 130, ancillary_allowed: 60, other_allowed: 30, pharmacy_allowed: 200} + - input: ref('financial_pmpm__service_category_2_allowed_pivot') + rows: [] + expect: + rows: + - {person_id: 'P1', year_month: '202301', total_paid: 850, medical_paid: 675, pharmacy_paid: 175, total_allowed: 1070, medical_allowed: 870, pharmacy_allowed: 200, tuva_last_run: '2024-01-01 00:00:00'} + diff --git a/models/data_marts/hcc_recapture/_gap_unit_tests.yml b/models/data_marts/hcc_recapture/_gap_unit_tests.yml new file mode 100644 index 000000000..652c16a96 --- /dev/null +++ b/models/data_marts/hcc_recapture/_gap_unit_tests.yml @@ -0,0 +1,131 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # HCC RECAPTURE - INTERMEDIATE: int_gap_status + # ========================================================================= + + - name: test_hcc_recapture_int_gap_status_closed_when_recaptured + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__int_gap_status + description: "Gap status is closed when an HCC from prior year is recaptured in current year" + given: + - input: ref('hcc_recapture__int_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C1', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - {person_id: 'P1', payer: 'MCR', collection_year: 2022, recorded_date: '2022-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C0', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - input: ref('hcc_recapture__stg_coef_hier') + rows: + - {coefficient: 0.302, model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA'} + - input: ref('hcc_recapture__stg_eligible_benes') + rows: + - {person_id: 'P1', collection_year: 2023, payer: 'MCR'} + - {person_id: 'P1', collection_year: 2022, payer: 'MCR'} + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC19', payment_year: 2023, gap_status: 'new'} + - {person_id: 'P1', hcc_code: 'HCC19', payment_year: 2024, gap_status: 'closed'} + + - name: test_hcc_recapture_int_gap_status_open_when_not_recaptured + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__int_gap_status + description: "Gap status is open when an HCC from prior year is not coded in current year" + given: + - input: ref('hcc_recapture__int_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2022, recorded_date: '2022-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C0', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - input: ref('hcc_recapture__stg_coef_hier') + rows: + - {coefficient: 0.302, model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA'} + - input: ref('hcc_recapture__stg_eligible_benes') + rows: + - {person_id: 'P1', collection_year: 2022, payer: 'MCR'} + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC19', payment_year: 2023, gap_status: 'new'} + + - name: test_hcc_recapture_int_gap_status_new_chronic_hcc + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__int_gap_status + description: "A chronic HCC coded this year but not in prior year gets gap_status 'new'" + given: + - input: ref('hcc_recapture__int_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC85', hcc_description: 'CHF', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C1', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - input: ref('hcc_recapture__stg_coef_hier') + rows: + - {coefficient: 0.450, model_version: 'CMS-HCC-V24', hcc_code: 'HCC85', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA'} + - input: ref('hcc_recapture__stg_eligible_benes') + rows: + - {person_id: 'P1', collection_year: 2023, payer: 'MCR'} + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC85', payment_year: 2024, gap_status: 'new'} + + - name: test_hcc_recapture_int_gap_status_inappropriate_non_chronic + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__int_gap_status + description: "Non-chronic HCCs get gap_status 'inappropriate for recapture'" + given: + - input: ref('hcc_recapture__int_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 0, claim_id: 'C1', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - {person_id: 'P1', payer: 'MCR', collection_year: 2022, recorded_date: '2022-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 0, claim_id: 'C0', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - input: ref('hcc_recapture__stg_coef_hier') + rows: + - {coefficient: 0.302, model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA'} + - input: ref('hcc_recapture__stg_eligible_benes') + rows: + - {person_id: 'P1', collection_year: 2023, payer: 'MCR'} + - {person_id: 'P1', collection_year: 2022, payer: 'MCR'} + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC19', payment_year: 2023, gap_status: 'inappropriate for recapture'} + - {person_id: 'P1', hcc_code: 'HCC19', payment_year: 2024, gap_status: 'inappropriate for recapture'} + + - name: test_hcc_recapture_int_gap_status_higher_hierarchy_closed + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__int_gap_status + description: "When a higher-coefficient HCC in the same hierarchy group is coded, lower one is closed" + given: + - input: ref('hcc_recapture__int_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes High', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C1', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - {person_id: 'P1', payer: 'MCR', collection_year: 2022, recorded_date: '2022-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC18', hcc_description: 'Diabetes Low', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C0', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 2, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - input: ref('hcc_recapture__stg_coef_hier') + rows: + - {coefficient: 0.302, model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA'} + - {coefficient: 0.150, model_version: 'CMS-HCC-V24', hcc_code: 'HCC18', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 2, risk_model_code: 'CNA'} + - input: ref('hcc_recapture__stg_eligible_benes') + rows: + - {person_id: 'P1', collection_year: 2023, payer: 'MCR'} + - {person_id: 'P1', collection_year: 2022, payer: 'MCR'} + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC18', gap_status: 'closed - higher coefficient hcc in hierarchy group'} + - {person_id: 'P1', hcc_code: 'HCC18', gap_status: 'new'} + - {person_id: 'P1', hcc_code: 'HCC19', gap_status: 'closed - higher coefficient hcc in hierarchy group'} + + - name: test_hcc_recapture_int_gap_status_filters_non_eligible_benes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__int_gap_status + description: "Only eligible beneficiaries appear in gap_status results" + given: + - input: ref('hcc_recapture__int_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C1', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - {person_id: 'P1', payer: 'MCR', collection_year: 2022, recorded_date: '2022-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C0', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - input: ref('hcc_recapture__stg_coef_hier') + rows: + - {coefficient: 0.302, model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA'} + - input: ref('hcc_recapture__stg_eligible_benes') + rows: [] + expect: + rows: [] diff --git a/models/data_marts/hcc_recapture/_unit_tests.yml b/models/data_marts/hcc_recapture/_unit_tests.yml new file mode 100644 index 000000000..43b42eb41 --- /dev/null +++ b/models/data_marts/hcc_recapture/_unit_tests.yml @@ -0,0 +1,378 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # HCC RECAPTURE - STAGING: stg_eligible_benes + # ========================================================================= + + - name: test_hcc_recapture_stg_eligible_benes_excludes_esrd + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__stg_eligible_benes + description: "Eligible beneficiaries exclude ESRD enrollment status and flatten to person/year" + given: + - input: ref('cms_hcc__int_members') + rows: + - {person_id: 'P1', collection_end_date: '2023-12-31', payer: 'MCR', enrollment_status: 'Aged'} + - {person_id: 'P1', collection_end_date: '2023-11-30', payer: 'MCR', enrollment_status: 'Aged'} + - {person_id: 'P2', collection_end_date: '2023-12-31', payer: 'MCR', enrollment_status: 'ESRD'} + expect: + rows: + - {person_id: 'P1', collection_year: 2023, payer: 'MCR'} + + - name: test_hcc_recapture_stg_eligible_benes_multiple_years + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__stg_eligible_benes + description: "Beneficiaries with months in different years produce one row per year" + given: + - input: ref('cms_hcc__int_members') + rows: + - {person_id: 'P1', collection_end_date: '2022-12-31', payer: 'MCR', enrollment_status: 'Aged'} + - {person_id: 'P1', collection_end_date: '2023-06-30', payer: 'MCR', enrollment_status: 'Aged'} + expect: + rows: + - {person_id: 'P1', collection_year: 2022, payer: 'MCR'} + - {person_id: 'P1', collection_year: 2023, payer: 'MCR'} + + - name: test_hcc_recapture_stg_eligible_benes_all_esrd_empty + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__stg_eligible_benes + description: "When all beneficiaries are ESRD, result is empty" + given: + - input: ref('cms_hcc__int_members') + rows: + - {person_id: 'P1', collection_end_date: '2023-12-31', payer: 'MCR', enrollment_status: 'ESRD'} + expect: + rows: [] + + # ========================================================================= + # HCC RECAPTURE - STAGING: stg_coef_hier + # ========================================================================= + + - name: test_hcc_recapture_stg_coef_hier_joins_hierarchy + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__stg_coef_hier + description: "Coefficient hierarchy staging joins disease factors to disease hierarchy flat for hierarchy group" + given: + - input: ref('cms_hcc__disease_factors') + rows: + - {coefficient: 0.302, model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No'} + - input: ref('cms_hcc__disease_hierarchy_flat') + rows: + - {model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1} + expect: + rows: + - {coefficient: 0.302, model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_hierarchy_group: 'DM', risk_model_code: 'CNA'} + + - name: test_hcc_recapture_stg_coef_hier_no_hierarchy_defaults + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__stg_coef_hier + description: "HCCs without hierarchy get 'no hierarchy' group and rank 1" + given: + - input: ref('cms_hcc__disease_factors') + rows: + - {coefficient: 0.150, model_version: 'CMS-HCC-V24', hcc_code: 'HCC99', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'No'} + - input: ref('cms_hcc__disease_hierarchy_flat') + rows: [] + expect: + rows: + - {coefficient: 0.150, model_version: 'CMS-HCC-V24', hcc_code: 'HCC99', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA'} + + - name: test_hcc_recapture_stg_coef_hier_institutional_status + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__stg_coef_hier + description: "Institutional enrollees get risk_model_code INS" + given: + - input: ref('cms_hcc__disease_factors') + rows: + - {coefficient: 0.400, model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', enrollment_status: 'Continuing', medicaid_status: 'No', dual_status: 'Non', orec: 'Aged', institutional_status: 'Yes'} + - input: ref('cms_hcc__disease_hierarchy_flat') + rows: + - {model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1} + expect: + rows: + - {model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', risk_model_code: 'INS'} + + - name: test_hcc_recapture_stg_coef_hier_dual_full_aged + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__stg_coef_hier + description: "Full dual aged enrollees get risk_model_code CFA" + given: + - input: ref('cms_hcc__disease_factors') + rows: + - {coefficient: 0.350, model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', enrollment_status: 'Continuing', medicaid_status: 'Yes', dual_status: 'Full', orec: 'Aged', institutional_status: 'No'} + - input: ref('cms_hcc__disease_hierarchy_flat') + rows: + - {model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1} + expect: + rows: + - {model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', risk_model_code: 'CFA'} + + # ========================================================================= + # HCC RECAPTURE - INTERMEDIATE: int_hccs (hierarchy application) + # ========================================================================= + + - name: test_hcc_recapture_int_hccs_applies_hierarchy + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__int_hccs + description: "int_hccs applies hierarchy by keeping only the min rank within each hierarchy group" + given: + - input: ref('hcc_recapture__int_all_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C1', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC18', hcc_description: 'Diabetes w/o complication', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C1', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 2, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC19', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1} + + - name: test_hcc_recapture_int_hccs_filters_non_chronic + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__int_hccs + description: "Non-chronic HCCs are filtered out" + given: + - input: ref('hcc_recapture__int_all_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 0, claim_id: 'C1', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + expect: + rows: [] + + - name: test_hcc_recapture_int_hccs_filters_non_eligible_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__int_hccs + description: "Non-eligible claims are filtered out" + given: + - input: ref('hcc_recapture__int_all_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C1', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 0, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + expect: + rows: [] + + - name: test_hcc_recapture_int_hccs_no_hierarchy_passes_through + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__int_hccs + description: "HCCs without hierarchy group pass through without being filtered" + given: + - input: ref('hcc_recapture__int_all_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC99', hcc_description: 'Standalone HCC', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C1', hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC99', hcc_hierarchy_group: 'no hierarchy'} + + # ========================================================================= + # HCC RECAPTURE - FINAL: gap_status + # ========================================================================= + + - name: test_hcc_recapture_gap_status_filters_hierarchy + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__gap_status + description: "Gap status filters out records suppressed by hierarchy (filtered_out_by_hierarchy = 0)" + given: + - input: ref('hcc_recapture__int_gap_status') + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: 'HCC19', risk_model_code: 'CNA', model_version: 'CMS-HCC-V24', payment_year: 2024, recapture_flag: 1, gap_status: 'closed', suspect_hcc_flag: 0, filtered_out_by_hierarchy: 0, hcc_hierarchy_group: 'G1', hcc_hierarchy_group_rank: 1} + - {person_id: 'P1', payer: 'MCR', hcc_code: 'HCC18', risk_model_code: 'CNA', model_version: 'CMS-HCC-V24', payment_year: 2024, recapture_flag: 1, gap_status: 'open', suspect_hcc_flag: 0, filtered_out_by_hierarchy: 1, hcc_hierarchy_group: 'G1', hcc_hierarchy_group_rank: 2} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: 'HCC19', model_version: 'CMS-HCC-V24', payment_year: 2024, gap_status: 'closed', suspect_hcc_flag: 0} + + - name: test_hcc_recapture_gap_status_multiple_statuses + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__gap_status + description: "Gap status passes through various gap_status values for non-hierarchied records" + given: + - input: ref('hcc_recapture__int_gap_status') + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: 'HCC19', risk_model_code: 'CNA', model_version: 'CMS-HCC-V24', payment_year: 2024, recapture_flag: 1, gap_status: 'closed', suspect_hcc_flag: 0, filtered_out_by_hierarchy: 0, hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1} + - {person_id: 'P2', payer: 'MCR', hcc_code: 'HCC85', risk_model_code: 'CNA', model_version: 'CMS-HCC-V24', payment_year: 2024, recapture_flag: 1, gap_status: 'open', suspect_hcc_flag: 0, filtered_out_by_hierarchy: 0, hcc_hierarchy_group: 'HF', hcc_hierarchy_group_rank: 1} + - {person_id: 'P3', payer: 'MCR', hcc_code: 'HCC99', risk_model_code: 'CNA', model_version: 'CMS-HCC-V24', payment_year: 2024, recapture_flag: 1, gap_status: 'new', suspect_hcc_flag: 0, filtered_out_by_hierarchy: 0, hcc_hierarchy_group: 'no hierarchy', hcc_hierarchy_group_rank: 1} + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC19', gap_status: 'closed', suspect_hcc_flag: 0} + - {person_id: 'P2', hcc_code: 'HCC85', gap_status: 'open', suspect_hcc_flag: 0} + - {person_id: 'P3', hcc_code: 'HCC99', gap_status: 'new', suspect_hcc_flag: 0} + + # ========================================================================= + # HCC RECAPTURE - FINAL: hcc_status + # ========================================================================= + + - name: test_hcc_recapture_hcc_status_joins_gap + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__hcc_status + description: "HCC status joins int_hccs to gap_status for eligible beneficiaries" + given: + - input: ref('hcc_recapture__int_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C1', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - input: ref('hcc_recapture__gap_status') + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: 'HCC19', risk_model_code: 'CNA', model_version: 'CMS-HCC-V24', payment_year: 2024, recapture_flag: 1, gap_status: 'closed', suspect_hcc_flag: 0} + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC19', gap_status: 'closed'} + + - name: test_hcc_recapture_hcc_status_excludes_non_eligible_benes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__hcc_status + description: "Non-eligible beneficiaries are excluded from hcc_status" + given: + - input: ref('hcc_recapture__int_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C1', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 0, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - input: ref('hcc_recapture__gap_status') + rows: [] + expect: + rows: [] + + - name: test_hcc_recapture_hcc_status_no_gap_match + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__hcc_status + description: "When no gap_status match exists, gap_status and recapture_flag are null" + given: + - input: ref('hcc_recapture__int_hccs') + rows: + - {person_id: 'P1', payer: 'MCR', collection_year: 2023, recorded_date: '2023-06-15', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', data_source: 'src1', hcc_chronic_flag: 1, claim_id: 'C1', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, risk_model_code: 'CNA', eligible_bene: 1, eligible_claim_indicator: 1, rendering_npi: 'NPI1', reason: 'Prior coding', condition_type: 'discharge_diagnosis', suspect_hcc_flag: 0} + - input: ref('hcc_recapture__gap_status') + rows: [] + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC19', gap_status: null, recapture_flag: null} + + # ========================================================================= + # HCC RECAPTURE - FINAL: recapture_rates + # ========================================================================= + + - name: test_hcc_recapture_rates_computes_rate + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__recapture_rates + description: "Recapture rates compute closed/open/total HCCs and recapture_rate = closed/total" + given: + - input: ref('hcc_recapture__recapture_rates_monthly') + rows: + - {payer: 'MCR', payment_year: 2024, payment_year_month: '2024-01-01', closed_hccs: 5, open_hccs: 3, total_hccs: 8, recapture_rate: 0.625} + - {payer: 'MCR', payment_year: 2024, payment_year_month: '2024-02-01', closed_hccs: 10, open_hccs: 2, total_hccs: 12, recapture_rate: 0.833} + expect: + rows: + - {payer: 'MCR', payment_year: 2024, closed_hccs: 15, open_hccs: 5, total_hccs: 20} + + - name: test_hcc_recapture_rates_multiple_payers + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__recapture_rates + description: "Recapture rates aggregate separately per payer" + given: + - input: ref('hcc_recapture__recapture_rates_monthly') + rows: + - {payer: 'MCR', payment_year: 2024, payment_year_month: '2024-01-01', closed_hccs: 5, open_hccs: 3, total_hccs: 8, recapture_rate: 0.625} + - {payer: 'BCBS', payment_year: 2024, payment_year_month: '2024-01-01', closed_hccs: 2, open_hccs: 6, total_hccs: 8, recapture_rate: 0.25} + expect: + rows: + - {payer: 'MCR', payment_year: 2024, closed_hccs: 5, open_hccs: 3, total_hccs: 8} + - {payer: 'BCBS', payment_year: 2024, closed_hccs: 2, open_hccs: 6, total_hccs: 8} + + # ========================================================================= + # HCC RECAPTURE - FINAL: recapture_rates_monthly + # ========================================================================= + + - name: test_hcc_recapture_rates_monthly_aggregates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__recapture_rates_monthly + description: "Monthly recapture rates aggregate closed/open HCCs by payer/payment_year/month" + given: + - input: ref('hcc_recapture__hcc_status') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', payment_year: 2024, recorded_date: '2023-06-15', claim_id: 'C1', rendering_npi: 'NPI1', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, suspect_hcc_flag: 0, risk_model_code: 'CNA', eligible_claim_indicator: 1, eligible_bene: 1, reason: 'Prior coding', gap_status: 'closed', recapture_flag: 1} + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', payment_year: 2024, recorded_date: '2023-06-15', claim_id: 'C2', rendering_npi: 'NPI1', model_version: 'CMS-HCC-V24', hcc_code: 'HCC85', hcc_description: 'CHF', hcc_hierarchy_group: 'HF', hcc_hierarchy_group_rank: 1, suspect_hcc_flag: 0, risk_model_code: 'CNA', eligible_claim_indicator: 1, eligible_bene: 1, reason: 'Prior coding', gap_status: 'open', recapture_flag: 1} + expect: + rows: + - {payer: 'MCR', payment_year: 2024, closed_hccs: 1, open_hccs: 1, total_hccs: 2} + + - name: test_hcc_recapture_rates_monthly_excludes_inappropriate + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__recapture_rates_monthly + description: "Records with gap_status 'inappropriate for recapture' or 'new' are excluded" + given: + - input: ref('hcc_recapture__hcc_status') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', payment_year: 2024, recorded_date: '2023-06-15', claim_id: 'C1', rendering_npi: 'NPI1', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, suspect_hcc_flag: 0, risk_model_code: 'CNA', eligible_claim_indicator: 1, eligible_bene: 1, reason: 'Prior coding', gap_status: 'inappropriate for recapture', recapture_flag: 0} + - {person_id: 'P2', payer: 'MCR', data_source: 'src1', payment_year: 2024, recorded_date: '2023-07-01', claim_id: 'C2', rendering_npi: 'NPI2', model_version: 'CMS-HCC-V24', hcc_code: 'HCC85', hcc_description: 'CHF', hcc_hierarchy_group: 'HF', hcc_hierarchy_group_rank: 1, suspect_hcc_flag: 0, risk_model_code: 'CNA', eligible_claim_indicator: 1, eligible_bene: 1, reason: 'Prior coding', gap_status: 'new', recapture_flag: 1} + expect: + rows: [] + + - name: test_hcc_recapture_rates_monthly_excludes_suspect_hccs + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__recapture_rates_monthly + description: "Suspect HCCs (suspect_hcc_flag = 1) are excluded from monthly rates" + given: + - input: ref('hcc_recapture__hcc_status') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', payment_year: 2024, recorded_date: '2023-06-15', claim_id: 'C1', rendering_npi: 'NPI1', model_version: 'CMS-HCC-V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', hcc_hierarchy_group: 'DM', hcc_hierarchy_group_rank: 1, suspect_hcc_flag: 1, risk_model_code: 'CNA', eligible_claim_indicator: 1, eligible_bene: 1, reason: 'Medication suspect', gap_status: 'closed', recapture_flag: 1} + expect: + rows: [] + + # ========================================================================= + # HCC RECAPTURE - FINAL: recapture_rates_monthly_ytd + # ========================================================================= + + - name: test_hcc_recapture_rates_monthly_ytd_running_total + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__recapture_rates_monthly_ytd + description: "Monthly YTD computes running totals of closed/open HCCs" + given: + - input: ref('hcc_recapture__recapture_rates_monthly') + rows: + - {payer: 'MCR', payment_year: 2024, payment_year_month: '2024-01-01', closed_hccs: 5, open_hccs: 3, total_hccs: 8, recapture_rate: 0.625} + - {payer: 'MCR', payment_year: 2024, payment_year_month: '2024-02-01', closed_hccs: 3, open_hccs: 1, total_hccs: 4, recapture_rate: 0.75} + expect: + rows: + - {payer: 'MCR', payment_year: 2024, payment_year_month: '2024-01-01', ytd_closed_hccs: 5, yearly_total_hccs: 12} + - {payer: 'MCR', payment_year: 2024, payment_year_month: '2024-02-01', ytd_closed_hccs: 8, yearly_total_hccs: 12} + + - name: test_hcc_recapture_rates_monthly_ytd_single_month + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__recapture_rates_monthly_ytd + description: "Single month YTD equals the monthly values" + given: + - input: ref('hcc_recapture__recapture_rates_monthly') + rows: + - {payer: 'MCR', payment_year: 2024, payment_year_month: '2024-03-01', closed_hccs: 10, open_hccs: 5, total_hccs: 15, recapture_rate: 0.667} + expect: + rows: + - {payer: 'MCR', payment_year: 2024, payment_year_month: '2024-03-01', monthly_closed_hccs: 10, monthly_open_hccs: 5, ytd_closed_hccs: 10, ytd_open_hccs: 5, yearly_total_hccs: 15} + + - name: test_hcc_recapture_rates_monthly_ytd_multiple_payers + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_recapture__recapture_rates_monthly_ytd + description: "YTD running totals are computed independently per payer" + given: + - input: ref('hcc_recapture__recapture_rates_monthly') + rows: + - {payer: 'MCR', payment_year: 2024, payment_year_month: '2024-01-01', closed_hccs: 5, open_hccs: 3, total_hccs: 8, recapture_rate: 0.625} + - {payer: 'BCBS', payment_year: 2024, payment_year_month: '2024-01-01', closed_hccs: 2, open_hccs: 6, total_hccs: 8, recapture_rate: 0.25} + expect: + rows: + - {payer: 'MCR', payment_year: 2024, payment_year_month: '2024-01-01', ytd_closed_hccs: 5, yearly_total_hccs: 8} + - {payer: 'BCBS', payment_year: 2024, payment_year_month: '2024-01-01', ytd_closed_hccs: 2, yearly_total_hccs: 8} diff --git a/models/data_marts/hcc_suspecting/_gap_unit_tests.yml b/models/data_marts/hcc_suspecting/_gap_unit_tests.yml new file mode 100644 index 000000000..b9ca61545 --- /dev/null +++ b/models/data_marts/hcc_suspecting/_gap_unit_tests.yml @@ -0,0 +1,763 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # HCC SUSPECTING - STAGING: stg_core__condition + # ========================================================================= + + - name: test_hcc_suspecting_stg_condition_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__stg_core__condition + description: "Staging passes through condition fields with distinct and lowered code_type" + given: + - input: ref('core__condition') + rows: + - {claim_id: 'C1', person_id: 'P1', payer: 'MCR', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', normalized_code_type: 'ICD-10-CM', normalized_code: 'E11.65', data_source: 'src1', condition_rank: 1} + expect: + rows: + - {claim_id: 'C1', person_id: 'P1', payer: 'MCR', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'E11.65', data_source: 'src1'} + + - name: test_hcc_suspecting_stg_condition_deduplicates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__stg_core__condition + description: "Duplicate conditions with different condition_rank collapse to one row" + given: + - input: ref('core__condition') + rows: + - {claim_id: 'C1', person_id: 'P1', payer: 'MCR', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', normalized_code_type: 'ICD-10-CM', normalized_code: 'E11.65', data_source: 'src1', condition_rank: 1} + - {claim_id: 'C1', person_id: 'P1', payer: 'MCR', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', normalized_code_type: 'ICD-10-CM', normalized_code: 'E11.65', data_source: 'src1', condition_rank: 2} + expect: + rows: + - {claim_id: 'C1', person_id: 'P1', payer: 'MCR', code_type: 'icd-10-cm', code: 'E11.65', data_source: 'src1'} + + # ========================================================================= + # HCC SUSPECTING - STAGING: stg_core__patient + # ========================================================================= + + - name: test_hcc_suspecting_stg_patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__stg_core__patient + description: "Staging passes through patient demographics" + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', sex: 'male', birth_date: '1960-01-01', death_date: null} + expect: + rows: + - {person_id: 'P1', sex: 'male', birth_date: '1960-01-01', death_date: null} + + - name: test_hcc_suspecting_stg_patient_includes_deceased + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__stg_core__patient + description: "Staging passes through deceased patients without filtering" + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1950-05-20', death_date: '2023-09-01'} + expect: + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1950-05-20', death_date: '2023-09-01'} + + # ========================================================================= + # HCC SUSPECTING - STAGING: stg_core__pharmacy_claim + # ========================================================================= + + - name: test_hcc_suspecting_stg_pharmacy_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__stg_core__pharmacy_claim + description: "Staging passes through pharmacy claim fields" + overrides: + vars: + claims_enabled: true + clinical_enabled: true + given: + - input: ref('core__pharmacy_claim') + rows: + - {person_id: 'P1', payer: 'MCR', dispensing_date: '2023-06-15', ndc_code: 'NDC001', paid_date: '2023-06-20', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', dispensing_date: '2023-06-15', ndc_code: 'NDC001', paid_date: '2023-06-20', data_source: 'src1'} + + # ========================================================================= + # HCC SUSPECTING - INTERMEDIATE: int_prep_conditions + # ========================================================================= + + - name: test_hcc_suspecting_prep_conditions_maps_snomed + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_prep_conditions + description: "SNOMED conditions are mapped to ICD-10-CM via terminology crosswalk; non-SNOMED pass through" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__stg_core__condition') + rows: + - {claim_id: 'C1', person_id: 'P1', payer: 'MCR', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'E11.65', data_source: 'src1'} + - {claim_id: 'C2', person_id: 'P2', payer: 'MCR', recorded_date: '2023-07-01', condition_type: 'discharge_diagnosis', code_type: 'snomed-ct', code: '44054006', data_source: 'src1'} + - input: ref('terminology__snomed_icd_10_map') + rows: + - {referenced_component_id: '44054006', map_target: 'E11.9', map_rule: 'TRUE', map_group: '1'} + expect: + rows: + - {person_id: 'P1', code_type: 'icd-10-cm', code: 'E11.65', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', code_type: 'icd-10-cm', code: 'E11.9', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_prep_conditions_non_snomed_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_prep_conditions + description: "Non-SNOMED conditions pass through with their original code type" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__stg_core__condition') + rows: + - {claim_id: 'C1', person_id: 'P1', payer: 'MCR', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'I50.9', data_source: 'src1'} + - input: ref('terminology__snomed_icd_10_map') + rows: [] + expect: + rows: + - {person_id: 'P1', code_type: 'icd-10-cm', code: 'I50.9', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_prep_conditions_filters_non_default_map_rules + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_prep_conditions + description: "SNOMED map rules that are not TRUE or OTHERWISE TRUE are excluded" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__stg_core__condition') + rows: + - {claim_id: 'C1', person_id: 'P1', payer: 'MCR', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', code_type: 'snomed-ct', code: '12345', data_source: 'src1'} + - input: ref('terminology__snomed_icd_10_map') + rows: + - {referenced_component_id: '12345', map_target: 'Z99.9', map_rule: 'IFA 123456 | Some condition', map_group: '1'} + expect: + rows: [] + + # ========================================================================= + # HCC SUSPECTING - INTERMEDIATE: int_all_conditions + # ========================================================================= + + - name: test_hcc_suspecting_all_conditions_maps_hcc + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_all_conditions + description: "Conditions are joined to HCC mapping seeds to get hcc_code and hcc_description" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', claim_id: 'C1', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'E11.65', data_source: 'src1'} + - input: ref('cms_hcc__icd_10_cm_mappings') + rows: + - {payment_year: 2024, diagnosis_code: 'E11.65', cms_hcc_v28: '37', cms_hcc_v28_flag: 'Yes', cms_hcc_v24: '18', cms_hcc_v24_flag: 'Yes'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '37', hcc_description: 'Diabetes with Chronic Complications'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', hcc_code: '18', model_version: 'CMS-HCC-V24', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', hcc_code: '37', model_version: 'CMS-HCC-V28', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_all_conditions_no_hcc_mapping + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_all_conditions + description: "Conditions without an HCC mapping still produce a row with null hcc_code" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', claim_id: 'C1', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'Z00.00', data_source: 'src1'} + - input: ref('cms_hcc__icd_10_cm_mappings') + rows: [] + - input: ref('hcc_suspecting__hcc_descriptions') + rows: [] + expect: + rows: + - {person_id: 'P1', payer: 'MCR', icd_10_cm_code: 'Z00.00', hcc_code: null, model_version: null, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_all_conditions_filters_non_icd10 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_all_conditions + description: "Non-ICD-10-CM conditions are filtered out in the joined CTE" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', claim_id: 'C1', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', code_type: 'cpt', code: '99213', data_source: 'src1'} + - input: ref('cms_hcc__icd_10_cm_mappings') + rows: [] + - input: ref('hcc_suspecting__hcc_descriptions') + rows: [] + expect: + rows: [] + + # ========================================================================= + # HCC SUSPECTING - INTERMEDIATE: int_all_medications + # ========================================================================= + + - name: test_hcc_suspecting_all_medications_unions_sources + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_all_medications + description: "Medications are unioned from clinical medications (NDC/RXNorm) and pharmacy claims" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__stg_core__medication') + rows: + - {person_id: 'P1', dispensing_date: '2023-03-15', source_code: 'SC1', source_code_type: 'ndc', ndc_code: 'NDC1', rxnorm_code: null, data_source: 'src1'} + - input: ref('hcc_suspecting__stg_core__pharmacy_claim') + rows: + - {person_id: 'P2', payer: 'MCR', dispensing_date: '2023-04-01', ndc_code: 'NDC2', paid_date: null, data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', drug_code: 'NDC1', code_system: 'ndc', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', drug_code: 'SC1', code_system: 'ndc', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', drug_code: 'NDC2', code_system: 'ndc', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_all_medications_rxnorm_source + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_all_medications + description: "RXNorm medications from clinical source are included" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__stg_core__medication') + rows: + - {person_id: 'P1', dispensing_date: '2023-03-15', source_code: 'RX1', source_code_type: 'rxnorm', ndc_code: null, rxnorm_code: 'RXNORM1', data_source: 'src1'} + - input: ref('hcc_suspecting__stg_core__pharmacy_claim') + rows: [] + expect: + rows: + - {person_id: 'P1', drug_code: 'RXNORM1', code_system: 'rxnorm', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', drug_code: 'RX1', code_system: 'rxnorm', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_all_medications_pharmacy_uses_paid_date_fallback + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_all_medications + description: "Pharmacy claims use paid_date when dispensing_date is null" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__stg_core__medication') + rows: [] + - input: ref('hcc_suspecting__stg_core__pharmacy_claim') + rows: + - {person_id: 'P1', payer: 'MCR', dispensing_date: null, ndc_code: 'NDC1', paid_date: '2023-04-01', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', drug_code: 'NDC1', code_system: 'ndc', dispensing_date: '2023-04-01', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # HCC SUSPECTING - INTERMEDIATE: int_patient_hcc_history + # ========================================================================= + + - name: test_hcc_suspecting_patient_hcc_history_tracks_billed + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_patient_hcc_history + description: "Patient HCC history groups conditions by person/payer/hcc and tracks current year billed flag" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_all_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', icd_10_cm_code: 'E11.65', model_version: 'CMS-HCC-V28', hcc_code: '37', hcc_description: 'Diabetes with Chronic Complications'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', model_version: 'CMS-HCC-V28', hcc_code: '37', reason: 'Prior coding history', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_patient_hcc_history_filters_null_hcc + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_patient_hcc_history + description: "Conditions with null hcc_code are excluded from history" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_all_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', icd_10_cm_code: 'Z00.00', model_version: null, hcc_code: null, hcc_description: null} + expect: + rows: [] + + - name: test_hcc_suspecting_patient_hcc_history_multiple_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_patient_hcc_history + description: "History aggregates first and last recorded dates across multiple encounters for same HCC" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_all_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', recorded_date: '2022-01-15', condition_type: 'discharge_diagnosis', icd_10_cm_code: 'E11.65', model_version: 'CMS-HCC-V28', hcc_code: '37', hcc_description: 'Diabetes'} + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', icd_10_cm_code: 'E11.65', model_version: 'CMS-HCC-V28', hcc_code: '37', hcc_description: 'Diabetes'} + expect: + rows: + - {person_id: 'P1', hcc_code: '37', first_recorded: '2022-01-15', last_recorded: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', hcc_code: '37', first_recorded: '2022-01-15', last_recorded: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # HCC SUSPECTING - INTERMEDIATE: int_comorbidity_suspects + # ========================================================================= + + - name: test_hcc_suspecting_comorbidity_suspects_diabetes_ckd + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_comorbidity_suspects + description: "HCC 37 is suspected when diabetes and CKD stage 1/2 co-occur in the same year" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', claim_id: 'C1', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'E11.65', data_source: 'src1'} + - {person_id: 'P1', payer: 'MCR', claim_id: 'C2', recorded_date: '2023-07-01', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'N18.1', data_source: 'src1'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'Diabetes', code: 'E11.65', code_system: 'icd-10-cm'} + - {concept_name: 'Chronic Kidney Disease, Stage 1', code: 'N18.1', code_system: 'icd-10-cm'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '37', hcc_description: 'Diabetes with Chronic Complications'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: + - {person_id: 'P1', hcc_code: '37', reason: 'Comorbidity suspect', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_comorbidity_suspects_different_years_excluded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_comorbidity_suspects + description: "Diabetes and CKD in different years do not create a comorbidity suspect" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', claim_id: 'C1', recorded_date: '2022-06-15', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'E11.65', data_source: 'src1'} + - {person_id: 'P1', payer: 'MCR', claim_id: 'C2', recorded_date: '2023-07-01', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'N18.1', data_source: 'src1'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'Diabetes', code: 'E11.65', code_system: 'icd-10-cm'} + - {concept_name: 'Chronic Kidney Disease, Stage 1', code: 'N18.1', code_system: 'icd-10-cm'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '37', hcc_description: 'Diabetes with Chronic Complications'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: [] + + - name: test_hcc_suspecting_comorbidity_suspects_diabetes_only_no_ckd + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_comorbidity_suspects + description: "Diabetes without CKD does not create a comorbidity suspect" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', claim_id: 'C1', recorded_date: '2023-06-15', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'E11.65', data_source: 'src1'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'Diabetes', code: 'E11.65', code_system: 'icd-10-cm'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '37', hcc_description: 'Diabetes with Chronic Complications'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: [] + + # ========================================================================= + # HCC SUSPECTING - INTERMEDIATE: int_medication_suspects + # ========================================================================= + + - name: test_hcc_suspecting_medication_suspects_antidepressant + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_medication_suspects + description: "HCC 155 is suspected when antidepressant medication is dispensed within past 5 years" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_all_medications') + rows: + - {person_id: 'P1', payer: 'clinical source', dispensing_date: '2023-06-15', drug_code: 'DRUG1', code_system: 'ndc', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'Antidepressant medication', code: 'DRUG1', code_system: 'ndc'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '155', hcc_description: 'Major Depression'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: + - {person_id: 'P1', hcc_code: '155', reason: 'Medication suspect', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_medication_suspects_non_antidepressant_excluded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_medication_suspects + description: "Non-antidepressant medications do not create a medication suspect" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_all_medications') + rows: + - {person_id: 'P1', payer: 'clinical source', dispensing_date: '2023-06-15', drug_code: 'DRUG1', code_system: 'ndc', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'Statin medication', code: 'DRUG1', code_system: 'ndc'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '155', hcc_description: 'Major Depression'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: [] + + - name: test_hcc_suspecting_medication_suspects_already_billed + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_medication_suspects + description: "Medication suspect still generated even if billed (billed flag is informational)" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_all_medications') + rows: + - {person_id: 'P1', payer: 'clinical source', dispensing_date: '2023-06-15', drug_code: 'DRUG1', code_system: 'ndc', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'Antidepressant medication', code: 'DRUG1', code_system: 'ndc'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '155', hcc_description: 'Major Depression'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: + - {person_id: 'P1', payer: 'clinical source', data_source: 'src1', model_version: 'CMS-HCC-V28', hcc_code: '155', current_year_billed: true, reason: 'Prior coding history', contributing_factor: 'F33.1', suspect_date: '2023-01-01', hcc_description: 'Major Depression', recorded_date: '2023-01-01', condition_type: 'discharge_diagnosis', icd_10_cm_code: 'F33.1', first_recorded: '2023-01-01', last_recorded: '2023-01-01', last_billed: '2023-01-01'} + expect: + rows: + - {person_id: 'P1', hcc_code: '155', reason: 'Medication suspect', current_year_billed: true, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # HCC SUSPECTING - INTERMEDIATE: int_lab_suspects + # ========================================================================= + + - name: test_hcc_suspecting_lab_suspects_ckd_stage + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_lab_suspects + description: "CKD stage is assigned based on highest eGFR result from two labs 90+ days apart" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_egfr_labs') + rows: + - {person_id: 'P1', payer: 'clinical source', data_source: 'src1', code_type: 'loinc', code: '33914-3', result_date: '2023-01-15', result: 25, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'clinical source', data_source: 'src1', code_type: 'loinc', code: '33914-3', result_date: '2023-06-15', result: 22, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '327', hcc_description: 'CKD Stage 4'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: + - {person_id: 'P1', hcc_code: '327', reason: 'Lab result suspect', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_lab_suspects_single_lab_excluded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_lab_suspects + description: "A single eGFR lab without a 90-day lookback does not generate a suspect" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_egfr_labs') + rows: + - {person_id: 'P1', payer: 'clinical source', data_source: 'src1', code_type: 'loinc', code: '33914-3', result_date: '2023-06-15', result: 22, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '327', hcc_description: 'CKD Stage 4'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: [] + + - name: test_hcc_suspecting_lab_suspects_ckd_stage_5 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_lab_suspects + description: "eGFR 0-14 maps to HCC 326 (CKD Stage 5)" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_egfr_labs') + rows: + - {person_id: 'P1', payer: 'clinical source', data_source: 'src1', code_type: 'loinc', code: '33914-3', result_date: '2023-01-15', result: 10, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'clinical source', data_source: 'src1', code_type: 'loinc', code: '33914-3', result_date: '2023-06-15', result: 8, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '326', hcc_description: 'CKD Stage 5'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: + - {person_id: 'P1', hcc_code: '326', reason: 'Lab result suspect', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_lab_suspects_ckd_stage_3a + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_lab_suspects + description: "eGFR 45-59 maps to HCC 329 (CKD Stage 3a)" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_egfr_labs') + rows: + - {person_id: 'P1', payer: 'clinical source', data_source: 'src1', code_type: 'loinc', code: '33914-3', result_date: '2023-01-15', result: 50, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'clinical source', data_source: 'src1', code_type: 'loinc', code: '33914-3', result_date: '2023-06-15', result: 48, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '329', hcc_description: 'CKD Stage 3a'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: + - {person_id: 'P1', hcc_code: '329', reason: 'Lab result suspect', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_lab_suspects_normal_egfr_no_suspect + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_lab_suspects + description: "eGFR >= 60 does not map to any CKD HCC and produces no suspect" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_egfr_labs') + rows: + - {person_id: 'P1', payer: 'clinical source', data_source: 'src1', code_type: 'loinc', code: '33914-3', result_date: '2023-01-15', result: 75, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'clinical source', data_source: 'src1', code_type: 'loinc', code: '33914-3', result_date: '2023-06-15', result: 80, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '326', hcc_description: 'CKD Stage 5'} + - {hcc_code: '327', hcc_description: 'CKD Stage 4'} + - {hcc_code: '328', hcc_description: 'CKD Stage 3b'} + - {hcc_code: '329', hcc_description: 'CKD Stage 3a'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: [] + + # ========================================================================= + # HCC SUSPECTING - INTERMEDIATE: int_observation_suspects + # ========================================================================= + + - name: test_hcc_suspecting_observation_suspects_bmi_over_40 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_observation_suspects + description: "HCC 48 is suspected when BMI >= 40 (no comorbidity required)" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: [] + - input: ref('hcc_suspecting__stg_core__observation') + rows: + - {person_id: 'P1', payer: 'clinical source', observation_date: '2023-06-15', result: '42', code_type: 'loinc', code: 'BMI1', data_source: 'src1'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'BMI', code: 'BMI1', code_system: 'loinc'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '48', hcc_description: 'Morbid Obesity'} + - {hcc_code: '155', hcc_description: 'Major Depression'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: + - {person_id: 'P1', hcc_code: '48', reason: 'Observation suspect', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_observation_suspects_bmi_under_30_excluded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_observation_suspects + description: "BMI under 30 does not create any morbid obesity suspect" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: [] + - input: ref('hcc_suspecting__stg_core__observation') + rows: + - {person_id: 'P1', payer: 'clinical source', observation_date: '2023-06-15', result: '25', code_type: 'loinc', code: 'BMI1', data_source: 'src1'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'BMI', code: 'BMI1', code_system: 'loinc'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '48', hcc_description: 'Morbid Obesity'} + - {hcc_code: '155', hcc_description: 'Major Depression'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: [] + + - name: test_hcc_suspecting_observation_suspects_bmi_35_with_diabetes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_observation_suspects + description: "HCC 48 is suspected when BMI >= 35 with diabetes in the same year" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', claim_id: 'C1', recorded_date: '2023-06-01', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'E11.65', data_source: 'src1'} + - input: ref('hcc_suspecting__stg_core__observation') + rows: + - {person_id: 'P1', payer: 'clinical source', observation_date: '2023-06-15', result: '37', code_type: 'loinc', code: 'BMI1', data_source: 'src1'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'BMI', code: 'BMI1', code_system: 'loinc'} + - {concept_name: 'Diabetes', code: 'E11.65', code_system: 'icd-10-cm'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '48', hcc_description: 'Morbid Obesity'} + - {hcc_code: '155', hcc_description: 'Major Depression'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: + - {person_id: 'P1', hcc_code: '48', reason: 'Observation suspect', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_observation_suspects_bmi_30_with_osa + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_observation_suspects + description: "HCC 48 is suspected when BMI >= 30 with obstructive sleep apnea in the same year" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: + - {person_id: 'P1', payer: 'MCR', claim_id: 'C1', recorded_date: '2023-06-01', condition_type: 'discharge_diagnosis', code_type: 'icd-10-cm', code: 'G47.33', data_source: 'src1'} + - input: ref('hcc_suspecting__stg_core__observation') + rows: + - {person_id: 'P1', payer: 'clinical source', observation_date: '2023-06-15', result: '32', code_type: 'loinc', code: 'BMI1', data_source: 'src1'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'BMI', code: 'BMI1', code_system: 'loinc'} + - {concept_name: 'Obstructive Sleep Apnea', code: 'G47.33', code_system: 'icd-10-cm'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '48', hcc_description: 'Morbid Obesity'} + - {hcc_code: '155', hcc_description: 'Major Depression'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: + - {person_id: 'P1', hcc_code: '48', reason: 'Observation suspect', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_observation_suspects_phq9_depression + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_observation_suspects + description: "HCC 155 is suspected when PHQ-9 score >= 15" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: [] + - input: ref('hcc_suspecting__stg_core__observation') + rows: + - {person_id: 'P1', payer: 'clinical source', observation_date: '2023-06-15', result: '18', code_type: 'loinc', code: 'PHQ9', data_source: 'src1'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'Depression Assessment (PHQ-9)', code: 'PHQ9', code_system: 'loinc'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '48', hcc_description: 'Morbid Obesity'} + - {hcc_code: '155', hcc_description: 'Major Depression'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: + - {person_id: 'P1', hcc_code: '155', reason: 'Observation suspect', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_observation_suspects_phq9_below_threshold + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__int_observation_suspects + description: "PHQ-9 score below 15 does not generate a depression suspect" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_prep_conditions') + rows: [] + - input: ref('hcc_suspecting__stg_core__observation') + rows: + - {person_id: 'P1', payer: 'clinical source', observation_date: '2023-06-15', result: '10', code_type: 'loinc', code: 'PHQ9', data_source: 'src1'} + - input: ref('hcc_suspecting__clinical_concepts') + rows: + - {concept_name: 'Depression Assessment (PHQ-9)', code: 'PHQ9', code_system: 'loinc'} + - input: ref('hcc_suspecting__hcc_descriptions') + rows: + - {hcc_code: '48', hcc_description: 'Morbid Obesity'} + - {hcc_code: '155', hcc_description: 'Major Depression'} + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + expect: + rows: [] diff --git a/models/data_marts/hcc_suspecting/_unit_tests.yml b/models/data_marts/hcc_suspecting/_unit_tests.yml new file mode 100644 index 000000000..41d280460 --- /dev/null +++ b/models/data_marts/hcc_suspecting/_unit_tests.yml @@ -0,0 +1,253 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # HCC SUSPECTING - FINAL: list + # ========================================================================= + + - name: test_hcc_suspecting_list_filters_not_billed_current_year + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__list + description: "List model filters to suspects that are NOT billed in the current year (current_year_billed = false or null)" + given: + - input: ref('hcc_suspecting__list_all') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', reason: 'Historical HCC', contributing_factor: 'E11.65', suspect_date: '2023-06-15', current_year_billed: false, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', payer: 'MCR', data_source: 'src1', model_version: 'V24', hcc_code: 'HCC85', hcc_description: 'CHF', reason: 'Comorbidity', contributing_factor: 'I50.9', suspect_date: '2023-07-01', current_year_billed: true, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P3', payer: 'MCR', data_source: 'src1', model_version: 'V24', hcc_code: 'HCC111', hcc_description: 'COPD', reason: 'Lab suspect', contributing_factor: 'Spirometry', suspect_date: '2023-08-01', current_year_billed: null, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC19', reason: 'Historical HCC'} + - {person_id: 'P3', hcc_code: 'HCC111', reason: 'Lab suspect'} + + - name: test_hcc_suspecting_list_excludes_all_billed + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__list + description: "When all suspects are billed in the current year, the list is empty" + given: + - input: ref('hcc_suspecting__list_all') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', reason: 'Historical', contributing_factor: 'E11.65', suspect_date: '2023-06-15', current_year_billed: true, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: [] + + - name: test_hcc_suspecting_list_multiple_suspects_same_patient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__list + description: "A patient can have multiple un-billed suspects from different sources" + given: + - input: ref('hcc_suspecting__list_all') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '37', hcc_description: 'Diabetes with Chronic Complications', reason: 'Prior coding history', contributing_factor: 'E11.65', suspect_date: '2023-06-15', current_year_billed: false, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '155', hcc_description: 'Major Depression', reason: 'Medication suspect', contributing_factor: 'DRUG1', suspect_date: '2023-07-01', current_year_billed: false, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '48', hcc_description: 'Morbid Obesity', reason: 'Observation suspect', contributing_factor: 'BMI 42', suspect_date: '2023-08-01', current_year_billed: null, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', hcc_code: '37', reason: 'Prior coding history'} + - {person_id: 'P1', hcc_code: '155', reason: 'Medication suspect'} + - {person_id: 'P1', hcc_code: '48', reason: 'Observation suspect'} + + # ========================================================================= + # HCC SUSPECTING - FINAL: list_all + # ========================================================================= + + - name: test_hcc_suspecting_list_all_unions_suspect_sources + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__list_all + description: "List all unions history, comorbidity, observation, lab, and medication suspect sources" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', reason: 'Historical', contributing_factor: 'E11.65', suspect_date: '2023-06-15', current_year_billed: false} + - input: ref('hcc_suspecting__int_comorbidity_suspects') + rows: [] + - input: ref('hcc_suspecting__int_observation_suspects') + rows: [] + - input: ref('hcc_suspecting__int_lab_suspects') + rows: + - {person_id: 'P2', payer: 'MCR', data_source: 'src1', model_version: 'V24', hcc_code: 'HCC136', hcc_description: 'CKD Stage 4', reason: 'Lab result', contributing_factor: 'eGFR < 30', suspect_date: '2023-07-01', current_year_billed: false} + - input: ref('hcc_suspecting__int_medication_suspects') + rows: [] + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC19', reason: 'Historical', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', hcc_code: 'HCC136', reason: 'Lab result', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_list_all_unions_all_five_sources + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__list_all + description: "All five suspect sources are unioned correctly with one record each" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '37', hcc_description: 'Diabetes', reason: 'Prior coding history', contributing_factor: 'E11.65', suspect_date: '2023-01-01', current_year_billed: false} + - input: ref('hcc_suspecting__int_comorbidity_suspects') + rows: + - {person_id: 'P2', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '37', hcc_description: 'Diabetes', reason: 'Comorbidity suspect', contributing_factor: 'Diabetes + CKD', suspect_date: '2023-02-01', current_year_billed: false} + - input: ref('hcc_suspecting__int_observation_suspects') + rows: + - {person_id: 'P3', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '48', hcc_description: 'Morbid Obesity', reason: 'Observation suspect', contributing_factor: 'BMI 42', suspect_date: '2023-03-01', current_year_billed: false} + - input: ref('hcc_suspecting__int_lab_suspects') + rows: + - {person_id: 'P4', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '327', hcc_description: 'CKD Stage 4', reason: 'Lab result suspect', contributing_factor: 'eGFR 22', suspect_date: '2023-04-01', current_year_billed: false} + - input: ref('hcc_suspecting__int_medication_suspects') + rows: + - {person_id: 'P5', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '155', hcc_description: 'Major Depression', reason: 'Medication suspect', contributing_factor: 'SSRI', suspect_date: '2023-05-01', current_year_billed: false} + expect: + rows: + - {person_id: 'P1', hcc_code: '37', reason: 'Prior coding history', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', hcc_code: '37', reason: 'Comorbidity suspect', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P3', hcc_code: '48', reason: 'Observation suspect', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P4', hcc_code: '327', reason: 'Lab result suspect', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P5', hcc_code: '155', reason: 'Medication suspect', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_list_all_empty_sources + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__list_all + description: "When all suspect sources are empty, list_all returns no rows" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__int_patient_hcc_history') + rows: [] + - input: ref('hcc_suspecting__int_comorbidity_suspects') + rows: [] + - input: ref('hcc_suspecting__int_observation_suspects') + rows: [] + - input: ref('hcc_suspecting__int_lab_suspects') + rows: [] + - input: ref('hcc_suspecting__int_medication_suspects') + rows: [] + expect: + rows: [] + + # ========================================================================= + # HCC SUSPECTING - FINAL: list_rollup + # ========================================================================= + + - name: test_hcc_suspecting_list_rollup_picks_latest_suspect + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__list_rollup + description: "List rollup deduplicates by person/payer/hcc_code/model_version, keeping the most recent suspect_date" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__list') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', reason: 'Historical', contributing_factor: 'E11.65', suspect_date: '2023-01-15', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', reason: 'Lab suspect', contributing_factor: 'A1C > 9', suspect_date: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', model_version: 'HCC19', hcc_code: 'V24', reason: 'Lab suspect', contributing_factor: 'A1C > 9', latest_suspect_date: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_list_rollup_multiple_hccs + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__list_rollup + description: "List rollup keeps separate rows for different HCC codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__list') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '37', hcc_description: 'Diabetes', reason: 'Historical', contributing_factor: 'E11.65', suspect_date: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '155', hcc_description: 'Depression', reason: 'Medication suspect', contributing_factor: 'SSRI', suspect_date: '2023-07-01', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', model_version: '37', hcc_code: 'V28', latest_suspect_date: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', model_version: '155', hcc_code: 'V28', latest_suspect_date: '2023-07-01', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_list_rollup_single_record + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__list_rollup + description: "A single suspect record passes through without deduplication" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__list') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '48', hcc_description: 'Morbid Obesity', reason: 'Observation suspect', contributing_factor: 'BMI 42', suspect_date: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', model_version: '48', hcc_code: 'V28', reason: 'Observation suspect', latest_suspect_date: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # HCC SUSPECTING - FINAL: summary + # ========================================================================= + + - name: test_hcc_suspecting_summary_counts_gaps + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__summary + description: "Summary joins patients to their suspecting list counts and computes age" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'male', birth_date: '1960-01-01', death_date: null} + - input: ref('hcc_suspecting__list') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V24', hcc_code: 'HCC19', hcc_description: 'Diabetes', reason: 'Historical', contributing_factor: 'E11.65', suspect_date: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V24', hcc_code: 'HCC85', hcc_description: 'CHF', reason: 'Comorbidity', contributing_factor: 'I50.9', suspect_date: '2023-07-01', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', payer: 'MCR', patient_sex: 'male', suspecting_gaps: 2, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_summary_excludes_deceased_patients + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__summary + description: "Deceased patients (death_date not null) are excluded from the summary" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'male', birth_date: '1960-01-01', death_date: '2023-05-01'} + - {person_id: 'P2', sex: 'female', birth_date: '1955-03-15', death_date: null} + - input: ref('hcc_suspecting__list') + rows: + - {person_id: 'P1', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '37', hcc_description: 'Diabetes', reason: 'Historical', contributing_factor: 'E11.65', suspect_date: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', payer: 'MCR', data_source: 'src1', model_version: 'V28', hcc_code: '155', hcc_description: 'Depression', reason: 'Medication suspect', contributing_factor: 'SSRI', suspect_date: '2023-07-01', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P2', payer: 'MCR', patient_sex: 'female', suspecting_gaps: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_hcc_suspecting_summary_no_suspects + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: hcc_suspecting__summary + description: "Patients with no suspects do not appear in summary (inner join)" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'male', birth_date: '1960-01-01', death_date: null} + - input: ref('hcc_suspecting__list') + rows: [] + expect: + rows: [] diff --git a/models/data_marts/normalize/_unit_tests.yml b/models/data_marts/normalize/_unit_tests.yml new file mode 100644 index 000000000..dca63ca22 --- /dev/null +++ b/models/data_marts/normalize/_unit_tests.yml @@ -0,0 +1,3 @@ +version: 2 + +unit_tests: [] diff --git a/models/data_marts/normalize/normalize_gap_unit_tests.yml b/models/data_marts/normalize/normalize_gap_unit_tests.yml new file mode 100644 index 000000000..dca63ca22 --- /dev/null +++ b/models/data_marts/normalize/normalize_gap_unit_tests.yml @@ -0,0 +1,3 @@ +version: 2 + +unit_tests: [] diff --git a/models/data_marts/pharmacy/_gap_unit_tests.yml b/models/data_marts/pharmacy/_gap_unit_tests.yml new file mode 100644 index 000000000..dca63ca22 --- /dev/null +++ b/models/data_marts/pharmacy/_gap_unit_tests.yml @@ -0,0 +1,3 @@ +version: 2 + +unit_tests: [] diff --git a/models/data_marts/pharmacy/_unit_tests.yml b/models/data_marts/pharmacy/_unit_tests.yml new file mode 100644 index 000000000..f6e0da8e9 --- /dev/null +++ b/models/data_marts/pharmacy/_unit_tests.yml @@ -0,0 +1,323 @@ +version: 2 + +unit_tests: + + - name: test_pharmacy__stg_pharmacy_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the staging model passes through pharmacy claim fields + and joins NDC terminology for FDA description. + model: pharmacy__stg_pharmacy_claim + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__pharmacy_claim') + rows: + - ndc_code: '12345678901' + data_source: 'claims_a' + paid_amount: 100.00 + allowed_amount: 120.00 + claim_id: 'rx_001' + claim_line_number: 1 + person_id: 'patient_1' + member_id: 'member_1' + prescribing_provider_id: 'prov_1' + dispensing_provider_id: 'prov_2' + dispensing_date: '2024-01-15' + quantity: 30 + days_supply: 30 + refills: 2 + paid_date: '2024-01-20' + - ndc_code: '99999999999' + data_source: 'claims_a' + paid_amount: 50.00 + allowed_amount: 60.00 + claim_id: 'rx_002' + claim_line_number: 1 + person_id: 'patient_2' + member_id: 'member_2' + prescribing_provider_id: 'prov_3' + dispensing_provider_id: 'prov_4' + dispensing_date: '2024-02-01' + quantity: 60 + days_supply: 60 + refills: 0 + paid_date: '2024-02-05' + - input: ref('terminology__ndc') + rows: + - ndc: '12345678901' + fda_description: 'Brand Drug 10mg Tablet' + rxcui: 'RXCUI_100' + - ndc: '99999999999' + fda_description: 'Generic Drug 20mg Capsule' + rxcui: 'RXCUI_200' + expect: + rows: + - ndc_code: '12345678901' + ndc_description: 'Brand Drug 10mg Tablet' + data_source: 'claims_a' + rxcui: 'RXCUI_100' + paid_amount: 100.00 + allowed_amount: 120.00 + claim_id: 'rx_001' + claim_line_number: 1 + person_id: 'patient_1' + member_id: 'member_1' + prescribing_provider_id: 'prov_1' + dispensing_provider_id: 'prov_2' + dispensing_date: '2024-01-15' + quantity: 30 + days_supply: 30 + refills: 2 + paid_date: '2024-01-20' + - ndc_code: '99999999999' + ndc_description: 'Generic Drug 20mg Capsule' + data_source: 'claims_a' + rxcui: 'RXCUI_200' + paid_amount: 50.00 + allowed_amount: 60.00 + claim_id: 'rx_002' + claim_line_number: 1 + person_id: 'patient_2' + member_id: 'member_2' + prescribing_provider_id: 'prov_3' + dispensing_provider_id: 'prov_4' + dispensing_date: '2024-02-01' + quantity: 60 + days_supply: 60 + refills: 0 + paid_date: '2024-02-05' + + - name: test_pharmacy__stg_pharmacy_claim_ndc_not_found + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify staging handles claims where NDC code has no matching + terminology entry, yielding null description and rxcui. + model: pharmacy__stg_pharmacy_claim + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__pharmacy_claim') + rows: + - ndc_code: '00000000000' + data_source: 'claims_a' + paid_amount: 25.00 + allowed_amount: 30.00 + claim_id: 'rx_003' + claim_line_number: 1 + person_id: 'patient_3' + member_id: 'member_3' + prescribing_provider_id: 'prov_5' + dispensing_provider_id: 'prov_6' + dispensing_date: '2024-03-01' + quantity: 10 + days_supply: 10 + refills: 0 + paid_date: '2024-03-05' + - input: ref('terminology__ndc') + rows: [] + expect: + rows: + - ndc_code: '00000000000' + ndc_description: null + data_source: 'claims_a' + rxcui: null + paid_amount: 25.00 + allowed_amount: 30.00 + claim_id: 'rx_003' + claim_line_number: 1 + person_id: 'patient_3' + member_id: 'member_3' + prescribing_provider_id: 'prov_5' + dispensing_provider_id: 'prov_6' + dispensing_date: '2024-03-01' + quantity: 10 + days_supply: 10 + refills: 0 + paid_date: '2024-03-05' + + - name: test_pharmacy__int_brand_with_generic_available_basic + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the intermediate model correctly identifies brand drugs + that have a generic available based on SCD/GPCK TTY and + marketing date in the past. + model: pharmacy__int_brand_with_generic_available + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy__rxnorm_generic_available') + rows: + - product_rxcui: 'RXCUI_100' + ndc: '55555555555' + ndc_product_tty: 'SCD' + product_startmarketingdate: '2020-01-01' + - product_rxcui: 'RXCUI_200' + ndc: '66666666666' + ndc_product_tty: 'GPCK' + product_startmarketingdate: '2023-06-01' + - product_rxcui: 'RXCUI_300' + ndc: '77777777777' + ndc_product_tty: 'SBD' + product_startmarketingdate: '2020-01-01' + expect: + rows: + - brand_with_generic_available: 'RXCUI_100' + - brand_with_generic_available: 'RXCUI_200' + + - name: test_pharmacy__int_brand_with_generic_available_future_date + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify that generics with a future marketing date are excluded. + model: pharmacy__int_brand_with_generic_available + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy__rxnorm_generic_available') + rows: + - product_rxcui: 'RXCUI_400' + ndc: '88888888888' + ndc_product_tty: 'SCD' + product_startmarketingdate: '2099-01-01' + expect: + rows: [] + + - name: test_pharmacy__int_generic_cost_by_ndc_basic + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the generic cost by NDC model correctly joins generic + available data with claims current cost for generic drugs. + model: pharmacy__int_generic_cost_by_ndc + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy__rxnorm_generic_available') + rows: + - product_rxcui: 'RXCUI_100' + ndc: '55555555555' + - input: ref('pharmacy__int_claims_current_cost') + rows: + - ndc_code: '55555555555' + ndc_description: 'Generic Drug 10mg' + data_source: 'claims_a' + rxcui: 'RXCUI_GEN' + brand_vs_generic: 'generic' + generic_available: null + paid_amount: 300.00 + claim_count: 3 + cost_per_claim: 100.00 + total_units: 90 + cost_per_unit: 3.33 + tuva_last_run: '2024-01-01 00:00:00' + expect: + rows: + - brand_rxcui: 'RXCUI_100' + data_source: 'claims_a' + generic_ndc_code: '55555555555' + paid_amount: 300.00 + claim_count: 3 + total_units: 90 + cost_per_unit: 3.33 + prescribed_atleast_one_generic_history: 1 + + - name: test_pharmacy__int_generic_cost_by_ndc_no_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify that a generic NDC with zero claims gets + prescribed_atleast_one_generic_history = 0. + model: pharmacy__int_generic_cost_by_ndc + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy__rxnorm_generic_available') + rows: + - product_rxcui: 'RXCUI_200' + ndc: '66666666666' + - input: ref('pharmacy__int_claims_current_cost') + rows: + - ndc_code: '66666666666' + ndc_description: 'Generic Drug 20mg' + data_source: 'claims_a' + rxcui: 'RXCUI_GEN2' + brand_vs_generic: 'generic' + generic_available: null + paid_amount: 0.00 + claim_count: 0 + cost_per_claim: 0.00 + total_units: 0 + cost_per_unit: null + tuva_last_run: '2024-01-01 00:00:00' + expect: + rows: + - brand_rxcui: 'RXCUI_200' + data_source: 'claims_a' + generic_ndc_code: '66666666666' + paid_amount: 0.00 + claim_count: 0 + total_units: 0 + cost_per_unit: null + prescribed_atleast_one_generic_history: 0 + + - name: test_pharmacy__int_generic_cost_aggregation + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: > + Verify the generic cost model aggregates across multiple NDCs + for the same brand rxcui and computes weighted average cost. + model: pharmacy__int_generic_cost + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy__rxnorm_generic_available') + rows: + - product_rxcui: 'RXCUI_100' + ndc: '55555555555' + - product_rxcui: 'RXCUI_100' + ndc: '66666666666' + - input: ref('pharmacy__int_claims_current_cost') + rows: + - ndc_code: '55555555555' + ndc_description: 'Generic A' + data_source: 'claims_a' + rxcui: 'RXCUI_GEN_A' + brand_vs_generic: 'generic' + generic_available: null + paid_amount: 200.00 + claim_count: 2 + cost_per_claim: 100.00 + total_units: 100 + cost_per_unit: 2.00 + tuva_last_run: '2024-01-01 00:00:00' + - ndc_code: '66666666666' + ndc_description: 'Generic B' + data_source: 'claims_a' + rxcui: 'RXCUI_GEN_B' + brand_vs_generic: 'generic' + generic_available: null + paid_amount: 300.00 + claim_count: 3 + cost_per_claim: 100.00 + total_units: 100 + cost_per_unit: 3.00 + tuva_last_run: '2024-01-01 00:00:00' + expect: + rows: + - brand_rxcui: 'RXCUI_100' + data_source: 'claims_a' + prescribed_atleast_one_generic_history: 1 + generic_average_cost_per_unit: 2.50 + + diff --git a/models/data_marts/provider_attribution/_gap_unit_tests.yml b/models/data_marts/provider_attribution/_gap_unit_tests.yml new file mode 100644 index 000000000..e39d3e602 --- /dev/null +++ b/models/data_marts/provider_attribution/_gap_unit_tests.yml @@ -0,0 +1,449 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # PROVIDER ATTRIBUTION - STAGING: stg_core__medical_claim + # ========================================================================= + + - name: test_provider_attribution_stg_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__stg_core__medical_claim + description: "Medical claim staging passes through fields from core medical claim" + given: + - input: ref('core__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', allowed_amount: 500, paid_amount: 400, rendering_npi: 'NPI1', hcpcs_code: '99213', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', claim_id: 'C1', rendering_npi: 'NPI1', hcpcs_code: '99213'} + + - name: test_provider_attribution_stg_medical_claim_multiple_lines + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__stg_core__medical_claim + description: > + Multiple claim lines for the same claim should each produce a separate + output row preserving all claim-line-level fields. + given: + - input: ref('core__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', allowed_amount: 500, paid_amount: 400, rendering_npi: 'NPI1', hcpcs_code: '99213', data_source: 'src1'} + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 2, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', allowed_amount: 200, paid_amount: 150, rendering_npi: 'NPI1', hcpcs_code: '99214', data_source: 'src1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, hcpcs_code: '99213', allowed_amount: 500} + - {claim_id: 'C1', claim_line_number: 2, hcpcs_code: '99214', allowed_amount: 200} + + # ========================================================================= + # PROVIDER ATTRIBUTION - STAGING: stg_core__claims_medical_claim + # ========================================================================= + + - name: test_provider_attribution_stg_claims_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__stg_core__claims_medical_claim + description: "Claims medical claim staging passes through claim_id, claim_line_number, data_source, and encounter_id" + given: + - input: ref('core__stg_claims_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', encounter_id: 'E1'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', encounter_id: 'E1'} + + - name: test_provider_attribution_stg_claims_medical_claim_multiple_rows + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__stg_core__claims_medical_claim + description: > + Multiple claim lines from different claims are all passed through + without filtering. + given: + - input: ref('core__stg_claims_medical_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', encounter_id: 'E1'} + - {claim_id: 'C2', claim_line_number: 1, data_source: 'src1', encounter_id: 'E2'} + - {claim_id: 'C3', claim_line_number: 1, data_source: 'src2', encounter_id: 'E3'} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, data_source: 'src1', encounter_id: 'E1'} + - {claim_id: 'C2', claim_line_number: 1, data_source: 'src1', encounter_id: 'E2'} + - {claim_id: 'C3', claim_line_number: 1, data_source: 'src2', encounter_id: 'E3'} + + # ========================================================================= + # PROVIDER ATTRIBUTION - STAGING: stg_core__member_months + # ========================================================================= + + - name: test_provider_attribution_stg_member_months_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__stg_core__member_months + description: "Member months staging passes through fields" + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', year_month: '202301'} + expect: + rows: + - {person_id: 'P1', year_month: '202301'} + + - name: test_provider_attribution_stg_member_months_multiple_people + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__stg_core__member_months + description: > + Member months for multiple people across different months should + all pass through correctly. + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', year_month: '202301'} + - {person_id: 'P1', year_month: '202302'} + - {person_id: 'P2', year_month: '202301'} + expect: + rows: + - {person_id: 'P1', year_month: '202301'} + - {person_id: 'P1', year_month: '202302'} + - {person_id: 'P2', year_month: '202301'} + + # ========================================================================= + # PROVIDER ATTRIBUTION - STAGING: stg_terminology__provider + # ========================================================================= + + - name: test_provider_attribution_stg_provider_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__stg_terminology__provider + description: "Provider staging passes through NPI and taxonomy fields" + given: + - input: ref('terminology__provider') + rows: + - {npi: 'NPI1', primary_taxonomy_code: 'TAX1', primary_specialty_description: 'Internal Medicine', entity_type_description: 'Individual', provider_organization_name: 'Clinic A', practice_state: 'NY', practice_city: 'NYC', practice_zip_code: '10001'} + expect: + rows: + - {npi: 'NPI1', primary_taxonomy_code: 'TAX1', primary_specialty_description: 'Internal Medicine', entity_type_description: 'Individual'} + + - name: test_provider_attribution_stg_provider_selects_only_needed_columns + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__stg_terminology__provider + description: > + The staging model should only select npi, primary_taxonomy_code, + primary_specialty_description, and entity_type_description, dropping + other columns from the terminology table. + given: + - input: ref('terminology__provider') + rows: + - {npi: 'NPI2', primary_taxonomy_code: 'TAX2', primary_specialty_description: 'Cardiology', entity_type_description: 'Individual', provider_organization_name: 'Heart Center', practice_state: 'CA', practice_city: 'LA', practice_zip_code: '90001'} + - {npi: 'NPI3', primary_taxonomy_code: 'TAX3', primary_specialty_description: 'General Surgery', entity_type_description: 'Organization', provider_organization_name: 'Surgery Group', practice_state: 'TX', practice_city: 'Houston', practice_zip_code: '77001'} + expect: + rows: + - {npi: 'NPI2', primary_taxonomy_code: 'TAX2', primary_specialty_description: 'Cardiology', entity_type_description: 'Individual'} + - {npi: 'NPI3', primary_taxonomy_code: 'TAX3', primary_specialty_description: 'General Surgery', entity_type_description: 'Organization'} + + # ========================================================================= + # PROVIDER ATTRIBUTION - STAGING: stg_reference_data__calendar + # ========================================================================= + + - name: test_provider_attribution_stg_calendar_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__stg_reference_data__calendar + description: "Calendar staging passes through date fields" + given: + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-01-01', year: 2023, month: 1, year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31'} + expect: + rows: + - {full_date: '2023-01-01', year: 2023, month: 1, year_month_int: 202301} + + - name: test_provider_attribution_stg_calendar_multiple_months + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__stg_reference_data__calendar + description: > + Calendar staging passes through multiple month records correctly + including the year_month field. + given: + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-01-01', year: 2023, month: 1, year_month: '2023-01', year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31'} + - {full_date: '2023-02-01', year: 2023, month: 2, year_month: '2023-02', year_month_int: 202302, first_day_of_month: '2023-02-01', last_day_of_month: '2023-02-28'} + - {full_date: '2023-12-01', year: 2023, month: 12, year_month: '2023-12', year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31'} + expect: + rows: + - {full_date: '2023-01-01', year: 2023, month: 1, year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31'} + - {full_date: '2023-02-01', year: 2023, month: 2, year_month_int: 202302, first_day_of_month: '2023-02-01', last_day_of_month: '2023-02-28'} + - {full_date: '2023-12-01', year: 2023, month: 12, year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31'} + + # ========================================================================= + # PROVIDER ATTRIBUTION - INTERMEDIATE: int_primary_care_claims + # ========================================================================= + + - name: test_provider_attribution_primary_care_claims_excludes_organizations_gap + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__int_primary_care_claims + description: > + Claims rendered by an organization NPI (not individual) should be + excluded from primary care claims because the inner join on + entity_type_description='individual' filters them out. + given: + - input: ref('provider_attribution__stg_core__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', allowed_amount: 500, paid_amount: 400, rendering_npi: 'NPI_ORG', hcpcs_code: '99213', data_source: 'src1'} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {full_date: '2023-06-01', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202306'} + - input: ref('cms_provider_attribution__primary_care_hcpcs_codes') + rows: + - {hcpcs_code: '99213'} + - input: ref('provider_attribution__provider_classification') + rows: [] + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI_ORG', primary_taxonomy_code: 'TAX_ORG', primary_specialty_description: 'Hospital', entity_type_description: 'Organization'} + expect: + rows: [] + + - name: test_provider_attribution_primary_care_claims_multiple_providers + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__int_primary_care_claims + description: > + Claims rendered by different providers for the same person should each + appear in the output with their respective provider buckets. + given: + - input: ref('provider_attribution__stg_core__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', allowed_amount: 500, paid_amount: 400, rendering_npi: 'NPI1', hcpcs_code: '99213', data_source: 'src1'} + - {person_id: 'P1', claim_id: 'C2', claim_line_number: 1, encounter_id: 'E2', claim_start_date: '2023-06-15', claim_end_date: '2023-06-15', allowed_amount: 300, paid_amount: 250, rendering_npi: 'NPI2', hcpcs_code: '99214', data_source: 'src1'} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {full_date: '2023-06-01', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - {full_date: '2023-06-15', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202306'} + - input: ref('cms_provider_attribution__primary_care_hcpcs_codes') + rows: + - {hcpcs_code: '99213'} + - {hcpcs_code: '99214'} + - input: ref('provider_attribution__provider_classification') + rows: + - {provider_id: 'NPI1', prov_specialty: 'Internal Medicine', provider_bucket: 'pcp'} + - {provider_id: 'NPI2', prov_specialty: 'Cardiology', provider_bucket: 'specialist'} + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI1', primary_taxonomy_code: 'TAX1', primary_specialty_description: 'Internal Medicine', entity_type_description: 'Individual'} + - {npi: 'NPI2', primary_taxonomy_code: 'TAX2', primary_specialty_description: 'Cardiology', entity_type_description: 'Individual'} + expect: + rows: + - {person_id: 'P1', provider_id: 'NPI1', provider_bucket: 'pcp', hcpcs_code: '99213'} + - {person_id: 'P1', provider_id: 'NPI2', provider_bucket: 'specialist', hcpcs_code: '99214'} + + # ========================================================================= + # PROVIDER ATTRIBUTION - FINAL: assigned_beneficiaries_current (gap tests) + # ========================================================================= + + - name: test_provider_attribution_current_ignores_yearly_scope + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__assigned_beneficiaries_current + description: > + Current assignment should only use scope='current' records from + provider_ranking, ignoring scope='yearly' entirely. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + provider_attribution_as_of_date: '2023-12-31' + given: + - input: ref('provider_attribution__int_primary_care_claims') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', claim_year: 2023, claim_month: 6, claim_year_month: '202306', claim_year_month_int: 202306, allowed_amount: 500, provider_id: 'NPI1', hcpcs_code: '99213', provider_bucket: 'pcp', prov_specialty: 'Internal Medicine'} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {full_date: '2023-01-01', year: 2023, month: 1, year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31'} + - {full_date: '2023-06-01', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - {full_date: '2023-12-31', year: 2023, month: 12, year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202306'} + - input: ref('provider_attribution__provider_ranking') + rows: + - {person_id: 'P1', performance_year: 2023, as_of_date: null, provider_id: 'NPI1', provider_bucket: 'pcp', prov_specialty: 'Internal Med', step: 1, step_description: '12-month PCP/NPP primary-care HCPCS', allowed_amount: 500, visits: 3, scope: 'yearly', lookback_start_date: '2023-01-01', lookback_end_date: '2023-12-31', ranking: 1, attribution_key: 'yearly|2023|P1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', provider_id: '9999999999', provider_bucket: 'no_eligible_history', assigned_step: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_provider_attribution_current_multiple_beneficiaries + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__assigned_beneficiaries_current + description: > + Multiple beneficiaries should each receive their own assignment: one from + ranking, others receiving fallback if not ranked. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + provider_attribution_as_of_date: '2023-12-31' + given: + - input: ref('provider_attribution__int_primary_care_claims') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', claim_year: 2023, claim_month: 6, claim_year_month: '202306', claim_year_month_int: 202306, allowed_amount: 500, provider_id: 'NPI1', hcpcs_code: '99213', provider_bucket: 'pcp', prov_specialty: 'Internal Medicine'} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {full_date: '2023-01-01', year: 2023, month: 1, year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31'} + - {full_date: '2023-06-01', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - {full_date: '2023-12-31', year: 2023, month: 12, year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202306'} + - {person_id: 'P2', year_month: '202306'} + - {person_id: 'P3', year_month: '202306'} + - input: ref('provider_attribution__provider_ranking') + rows: + - {person_id: 'P1', performance_year: null, as_of_date: '2023-12-31', provider_id: 'NPI1', provider_bucket: 'pcp', prov_specialty: 'Internal Med', step: 1, step_description: '12-month PCP/NPP primary-care HCPCS', allowed_amount: 500, visits: 3, scope: 'current', lookback_start_date: '2023-01-01', lookback_end_date: '2023-12-31', ranking: 1, attribution_key: 'current|20231231|P1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', provider_id: 'NPI1', provider_bucket: 'pcp', assigned_step: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', provider_id: '9999999999', provider_bucket: 'no_eligible_history', assigned_step: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P3', provider_id: '9999999999', provider_bucket: 'no_eligible_history', assigned_step: 0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # PROVIDER ATTRIBUTION - FINAL: assigned_beneficiaries_yearly (gap tests) + # ========================================================================= + + - name: test_provider_attribution_yearly_fallback_all_missing + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__assigned_beneficiaries_yearly + description: > + When all beneficiaries in a given year have no provider ranking records, + every one should receive the fallback provider assignment. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('provider_attribution__int_person_years') + rows: + - {person_id: 'P1', performance_year: 2023} + - {person_id: 'P2', performance_year: 2023} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31', full_date: '2023-01-01'} + - {year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31', full_date: '2023-12-01'} + - input: ref('provider_attribution__provider_ranking') + rows: [] + expect: + rows: + - {person_id: 'P1', performance_year: 2023, provider_id: '9999999999', provider_bucket: 'no_eligible_history', assigned_step: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', performance_year: 2023, provider_id: '9999999999', provider_bucket: 'no_eligible_history', assigned_step: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_provider_attribution_yearly_skips_rank_2 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__assigned_beneficiaries_yearly + description: > + Yearly assignment should only select ranking=1, so a provider with + ranking=2 should not appear in the assigned output. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('provider_attribution__int_person_years') + rows: + - {person_id: 'P1', performance_year: 2023} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31', full_date: '2023-01-01'} + - {year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31', full_date: '2023-12-01'} + - input: ref('provider_attribution__provider_ranking') + rows: + - {person_id: 'P1', performance_year: 2023, as_of_date: null, provider_id: 'NPI1', provider_bucket: 'pcp', prov_specialty: 'Internal Med', step: 1, step_description: '12-month PCP/NPP primary-care HCPCS', allowed_amount: 500, visits: 3, scope: 'yearly', lookback_start_date: '2023-01-01', lookback_end_date: '2023-12-31', ranking: 1, attribution_key: 'yearly|2023|P1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', performance_year: 2023, as_of_date: null, provider_id: 'NPI2', provider_bucket: 'specialist', prov_specialty: 'Cardiology', step: 2, step_description: '12-month specialist primary-care HCPCS', allowed_amount: 200, visits: 1, scope: 'yearly', lookback_start_date: '2023-01-01', lookback_end_date: '2023-12-31', ranking: 2, attribution_key: 'yearly|2023|P1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', performance_year: 2023, provider_id: 'NPI1', provider_bucket: 'pcp', assigned_step: 1, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # PROVIDER ATTRIBUTION - FINAL: provider_ranking (gap tests) + # ========================================================================= + + - name: test_provider_attribution_ranking_current_scope_eligible_only + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__provider_ranking + description: > + Provider ranking for current scope should only include beneficiaries + who have member months within the 12-month eligibility window. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + provider_attribution_as_of_date: '2023-12-31' + given: + - input: ref('provider_attribution__int_person_years') + rows: [] + - input: ref('provider_attribution__int_primary_care_claims') + rows: + - {person_id: 'P1', provider_id: 'NPI1', provider_bucket: 'pcp', prov_specialty: 'Internal Medicine', encounter_id: 'E1', claim_id: 'C1', claim_year: 2023, claim_year_month_int: 202306, claim_end_date: '2023-06-15', allowed_amount: 400} + - {person_id: 'P2', provider_id: 'NPI2', provider_bucket: 'pcp', prov_specialty: 'Family Med', encounter_id: 'E2', claim_id: 'C2', claim_year: 2023, claim_year_month_int: 202306, claim_end_date: '2023-06-15', allowed_amount: 300} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31', full_date: '2023-01-01'} + - {year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30', full_date: '2023-06-01'} + - {year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31', full_date: '2023-12-01'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202306'} + - input: ref('provider_attribution__stg_core__medical_claim') + rows: [] + - input: ref('provider_attribution__provider_classification') + rows: [] + - input: ref('provider_attribution__stg_terminology__provider') + rows: [] + expect: + rows: + - {person_id: 'P1', provider_id: 'NPI1', step: 1, scope: 'current', ranking: 1} + + - name: test_provider_attribution_ranking_yearly_scope_multiple_steps + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__provider_ranking + description: > + In yearly scope, a provider qualifying at both step 1 (PCP) and step 4 + (any classification) should only appear once with the earliest step. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + provider_attribution_as_of_date: '2023-12-31' + given: + - input: ref('provider_attribution__int_person_years') + rows: + - {person_id: 'P1', performance_year: 2023} + - input: ref('provider_attribution__int_primary_care_claims') + rows: + - {person_id: 'P1', provider_id: 'NPI1', provider_bucket: 'pcp', prov_specialty: 'Family Medicine', encounter_id: 'E1', claim_id: 'C1', claim_year: 2023, claim_year_month_int: 202306, claim_end_date: '2023-06-15', allowed_amount: 400} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {year_month_int: 202201, first_day_of_month: '2022-01-01', last_day_of_month: '2022-01-31', full_date: '2022-01-01'} + - {year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31', full_date: '2023-01-01'} + - {year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30', full_date: '2023-06-01'} + - {year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31', full_date: '2023-12-01'} + - input: ref('provider_attribution__stg_core__member_months') + rows: [] + - input: ref('provider_attribution__stg_core__medical_claim') + rows: [] + - input: ref('provider_attribution__provider_classification') + rows: [] + - input: ref('provider_attribution__stg_terminology__provider') + rows: [] + expect: + rows: + - {person_id: 'P1', performance_year: 2023, provider_id: 'NPI1', provider_bucket: 'pcp', step: 1, scope: 'yearly', ranking: 1} diff --git a/models/data_marts/provider_attribution/_unit_tests.yml b/models/data_marts/provider_attribution/_unit_tests.yml new file mode 100644 index 000000000..c020b4cb9 --- /dev/null +++ b/models/data_marts/provider_attribution/_unit_tests.yml @@ -0,0 +1,509 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # PROVIDER ATTRIBUTION - INTERMEDIATE: int_person_years + # ========================================================================= + + - name: test_provider_attribution_person_years_extracts_year + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__int_person_years + description: "Person years are derived from member months by extracting the 4-digit year from year_month" + given: + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202301'} + - {person_id: 'P1', year_month: '202302'} + - {person_id: 'P1', year_month: '202401'} + - {person_id: 'P2', year_month: '202301'} + expect: + rows: + - {person_id: 'P1', performance_year: 2023} + - {person_id: 'P1', performance_year: 2024} + - {person_id: 'P2', performance_year: 2023} + + - name: test_provider_attribution_person_years_deduplicates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__int_person_years + description: > + Multiple member months in the same year for the same person should + produce only one person-year row. + given: + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202301'} + - {person_id: 'P1', year_month: '202302'} + - {person_id: 'P1', year_month: '202303'} + - {person_id: 'P1', year_month: '202304'} + - {person_id: 'P1', year_month: '202305'} + - {person_id: 'P1', year_month: '202306'} + expect: + rows: + - {person_id: 'P1', performance_year: 2023} + + - name: test_provider_attribution_person_years_multiple_people_years + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__int_person_years + description: > + Each unique person/year combination from member months should produce + exactly one person-year row, supporting multiple people and years. + given: + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202201'} + - {person_id: 'P1', year_month: '202301'} + - {person_id: 'P2', year_month: '202201'} + - {person_id: 'P2', year_month: '202301'} + - {person_id: 'P3', year_month: '202301'} + expect: + rows: + - {person_id: 'P1', performance_year: 2022} + - {person_id: 'P1', performance_year: 2023} + - {person_id: 'P2', performance_year: 2022} + - {person_id: 'P2', performance_year: 2023} + - {person_id: 'P3', performance_year: 2023} + + # ========================================================================= + # PROVIDER ATTRIBUTION - INTERMEDIATE: provider_classification + # ========================================================================= + + - name: test_provider_attribution_classification_assigns_bucket + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__provider_classification + description: "Provider classification maps NPI to pcp/specialist/npp bucket via taxonomy crosswalk with priority ranking" + given: + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI1', primary_taxonomy_code: 'TAX1', primary_specialty_description: 'Internal Medicine', entity_type_description: 'Individual'} + - input: ref('terminology__medicare_provider_and_supplier_taxonomy_crosswalk') + rows: + - {provider_taxonomy_code: 'TAX1', medicare_specialty_code: '11'} + - input: ref('cms_provider_attribution__provider_specialty_assignment_codes') + rows: + - {specialty_code: '11', primary_care_physician_step1: 'yes', specialist_physician_step_2: 'no', physician: 1} + expect: + rows: + - {provider_id: 'NPI1', prov_specialty: 'Internal Medicine', provider_bucket: 'pcp'} + + - name: test_provider_attribution_classification_specialist_bucket + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__provider_classification + description: > + A physician whose specialty code is not flagged as PCP step-1 but is + flagged as specialist step-2 should be classified as specialist. + given: + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI2', primary_taxonomy_code: 'TAX2', primary_specialty_description: 'Cardiology', entity_type_description: 'Individual'} + - input: ref('terminology__medicare_provider_and_supplier_taxonomy_crosswalk') + rows: + - {provider_taxonomy_code: 'TAX2', medicare_specialty_code: '06'} + - input: ref('cms_provider_attribution__provider_specialty_assignment_codes') + rows: + - {specialty_code: '06', primary_care_physician_step1: 'no', specialist_physician_step_2: 'yes', physician: 1} + expect: + rows: + - {provider_id: 'NPI2', prov_specialty: 'Cardiology', provider_bucket: 'specialist'} + + - name: test_provider_attribution_classification_npp_bucket + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__provider_classification + description: > + A non-physician provider (physician=0) should be classified as npp + regardless of step-1 or step-2 flags. + given: + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI3', primary_taxonomy_code: 'TAX3', primary_specialty_description: 'Nurse Practitioner', entity_type_description: 'Individual'} + - input: ref('terminology__medicare_provider_and_supplier_taxonomy_crosswalk') + rows: + - {provider_taxonomy_code: 'TAX3', medicare_specialty_code: '50'} + - input: ref('cms_provider_attribution__provider_specialty_assignment_codes') + rows: + - {specialty_code: '50', primary_care_physician_step1: 'no', specialist_physician_step_2: 'no', physician: 0} + expect: + rows: + - {provider_id: 'NPI3', prov_specialty: 'Nurse Practitioner', provider_bucket: 'npp'} + + - name: test_provider_attribution_classification_excludes_organizations + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__provider_classification + description: > + Organization entity types should be excluded from provider classification + since only individuals are eligible for attribution. + given: + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI4', primary_taxonomy_code: 'TAX4', primary_specialty_description: 'Hospital', entity_type_description: 'Organization'} + - input: ref('terminology__medicare_provider_and_supplier_taxonomy_crosswalk') + rows: + - {provider_taxonomy_code: 'TAX4', medicare_specialty_code: '11'} + - input: ref('cms_provider_attribution__provider_specialty_assignment_codes') + rows: + - {specialty_code: '11', primary_care_physician_step1: 'yes', specialist_physician_step_2: 'no', physician: 1} + expect: + rows: [] + + - name: test_provider_attribution_classification_priority_pcp_over_specialist + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__provider_classification + description: > + When a provider maps to both PCP and specialist via multiple taxonomy + crosswalk entries, the PCP bucket should win due to priority ranking. + given: + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI5', primary_taxonomy_code: 'TAX5', primary_specialty_description: 'Family Medicine', entity_type_description: 'Individual'} + - input: ref('terminology__medicare_provider_and_supplier_taxonomy_crosswalk') + rows: + - {provider_taxonomy_code: 'TAX5', medicare_specialty_code: '08'} + - {provider_taxonomy_code: 'TAX5', medicare_specialty_code: '38'} + - input: ref('cms_provider_attribution__provider_specialty_assignment_codes') + rows: + - {specialty_code: '08', primary_care_physician_step1: 'yes', specialist_physician_step_2: 'no', physician: 1} + - {specialty_code: '38', primary_care_physician_step1: 'no', specialist_physician_step_2: 'yes', physician: 1} + expect: + rows: + - {provider_id: 'NPI5', prov_specialty: 'Family Medicine', provider_bucket: 'pcp'} + + # ========================================================================= + # PROVIDER ATTRIBUTION - INTERMEDIATE: int_primary_care_claims + # ========================================================================= + + - name: test_provider_attribution_primary_care_claims_filters_hcpcs + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__int_primary_care_claims + description: "Primary care claims filters to eligible HCPCS codes and joins provider bucket" + given: + - input: ref('provider_attribution__stg_core__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', allowed_amount: 500, paid_amount: 400, rendering_npi: 'NPI1', hcpcs_code: '99213', data_source: 'src1'} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {full_date: '2023-06-01', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202306'} + - input: ref('cms_provider_attribution__primary_care_hcpcs_codes') + rows: + - {hcpcs_code: '99213'} + - input: ref('provider_attribution__provider_classification') + rows: + - {provider_id: 'NPI1', prov_specialty: 'Internal Medicine', provider_bucket: 'pcp'} + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI1', primary_taxonomy_code: 'TAX1', primary_specialty_description: 'Internal Medicine', entity_type_description: 'Individual'} + expect: + rows: + - {person_id: 'P1', provider_id: 'NPI1', provider_bucket: 'pcp', hcpcs_code: '99213'} + + - name: test_provider_attribution_primary_care_claims_excludes_non_primary_hcpcs + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__int_primary_care_claims + description: > + Claims with HCPCS codes not in the primary care list should be excluded + from the primary care claims result. + given: + - input: ref('provider_attribution__stg_core__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', allowed_amount: 500, paid_amount: 400, rendering_npi: 'NPI1', hcpcs_code: '99999', data_source: 'src1'} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {full_date: '2023-06-01', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202306'} + - input: ref('cms_provider_attribution__primary_care_hcpcs_codes') + rows: + - {hcpcs_code: '99213'} + - input: ref('provider_attribution__provider_classification') + rows: + - {provider_id: 'NPI1', prov_specialty: 'Internal Medicine', provider_bucket: 'pcp'} + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI1', primary_taxonomy_code: 'TAX1', primary_specialty_description: 'Internal Medicine', entity_type_description: 'Individual'} + expect: + rows: [] + + - name: test_provider_attribution_primary_care_claims_excludes_unenrolled + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__int_primary_care_claims + description: > + Claims in a month where the person has no member month record should + be excluded, ensuring only enrolled claims are considered. + given: + - input: ref('provider_attribution__stg_core__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', allowed_amount: 500, paid_amount: 400, rendering_npi: 'NPI1', hcpcs_code: '99213', data_source: 'src1'} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {full_date: '2023-06-01', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202301'} + - input: ref('cms_provider_attribution__primary_care_hcpcs_codes') + rows: + - {hcpcs_code: '99213'} + - input: ref('provider_attribution__provider_classification') + rows: + - {provider_id: 'NPI1', prov_specialty: 'Internal Medicine', provider_bucket: 'pcp'} + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI1', primary_taxonomy_code: 'TAX1', primary_specialty_description: 'Internal Medicine', entity_type_description: 'Individual'} + expect: + rows: [] + + - name: test_provider_attribution_primary_care_claims_fallback_to_paid_amount + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__int_primary_care_claims + description: > + When allowed_amount is zero, the model should fall back to paid_amount + via the coalesce(nullif(allowed_amount, 0), paid_amount, 0) expression. + given: + - input: ref('provider_attribution__stg_core__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', allowed_amount: 0, paid_amount: 350, rendering_npi: 'NPI1', hcpcs_code: '99213', data_source: 'src1'} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {full_date: '2023-06-01', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202306'} + - input: ref('cms_provider_attribution__primary_care_hcpcs_codes') + rows: + - {hcpcs_code: '99213'} + - input: ref('provider_attribution__provider_classification') + rows: + - {provider_id: 'NPI1', prov_specialty: 'Internal Medicine', provider_bucket: 'pcp'} + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI1', primary_taxonomy_code: 'TAX1', primary_specialty_description: 'Internal Medicine', entity_type_description: 'Individual'} + expect: + rows: + - {person_id: 'P1', provider_id: 'NPI1', allowed_amount: 350, hcpcs_code: '99213'} + + - name: test_provider_attribution_primary_care_claims_unclassified_provider + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__int_primary_care_claims + description: > + When a provider is not in the classification table, the bucket should + default to other_individual and specialty falls back to the provider table. + given: + - input: ref('provider_attribution__stg_core__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', allowed_amount: 200, paid_amount: 150, rendering_npi: 'NPI9', hcpcs_code: '99213', data_source: 'src1'} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {full_date: '2023-06-01', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202306'} + - input: ref('cms_provider_attribution__primary_care_hcpcs_codes') + rows: + - {hcpcs_code: '99213'} + - input: ref('provider_attribution__provider_classification') + rows: [] + - input: ref('provider_attribution__stg_terminology__provider') + rows: + - {npi: 'NPI9', primary_taxonomy_code: 'TAX9', primary_specialty_description: 'General Practice', entity_type_description: 'Individual'} + expect: + rows: + - {person_id: 'P1', provider_id: 'NPI9', provider_bucket: 'other_individual', prov_specialty: 'General Practice', hcpcs_code: '99213'} + + # ========================================================================= + # PROVIDER ATTRIBUTION - FINAL: assigned_beneficiaries_yearly + # ========================================================================= + + - name: test_provider_attribution_yearly_picks_rank_1 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__assigned_beneficiaries_yearly + description: "Yearly assignment picks ranking=1 from provider_ranking for scope='yearly'; missing beneficiaries get fallback" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('provider_attribution__int_person_years') + rows: + - {person_id: 'P1', performance_year: 2023} + - {person_id: 'P2', performance_year: 2023} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31', full_date: '2023-01-01'} + - {year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31', full_date: '2023-12-01'} + - input: ref('provider_attribution__provider_ranking') + rows: + - {person_id: 'P1', performance_year: 2023, as_of_date: null, provider_id: 'NPI1', provider_bucket: 'pcp', prov_specialty: 'Internal Med', step: 1, step_description: '12-month PCP/NPP primary-care HCPCS', allowed_amount: 500, visits: 3, scope: 'yearly', lookback_start_date: '2023-01-01', lookback_end_date: '2023-12-31', ranking: 1, attribution_key: 'yearly|2023|P1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', performance_year: 2023, as_of_date: null, provider_id: 'NPI2', provider_bucket: 'specialist', prov_specialty: 'Cardiology', step: 2, step_description: '12-month specialist primary-care HCPCS', allowed_amount: 200, visits: 1, scope: 'yearly', lookback_start_date: '2023-01-01', lookback_end_date: '2023-12-31', ranking: 2, attribution_key: 'yearly|2023|P1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', performance_year: 2023, provider_id: 'NPI1', provider_bucket: 'pcp', assigned_step: 1, attribution_key: 'yearly|2023|P1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', performance_year: 2023, provider_id: '9999999999', provider_bucket: 'no_eligible_history', assigned_step: 0, attribution_key: 'yearly|2023|P2', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_provider_attribution_yearly_ignores_current_scope + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__assigned_beneficiaries_yearly + description: > + Yearly assignment should only use records with scope='yearly' from + provider_ranking, ignoring scope='current' records entirely. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('provider_attribution__int_person_years') + rows: + - {person_id: 'P1', performance_year: 2023} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31', full_date: '2023-01-01'} + - {year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31', full_date: '2023-12-01'} + - input: ref('provider_attribution__provider_ranking') + rows: + - {person_id: 'P1', performance_year: null, as_of_date: '2023-12-31', provider_id: 'NPI1', provider_bucket: 'pcp', prov_specialty: 'Internal Med', step: 1, step_description: '12-month PCP/NPP primary-care HCPCS', allowed_amount: 500, visits: 3, scope: 'current', lookback_start_date: '2023-01-01', lookback_end_date: '2023-12-31', ranking: 1, attribution_key: 'current|20231231|P1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', performance_year: 2023, provider_id: '9999999999', provider_bucket: 'no_eligible_history', assigned_step: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_provider_attribution_yearly_multiple_years + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__assigned_beneficiaries_yearly + description: > + A person with enrollment in multiple years should get independent + yearly assignments; each year should have its own assigned provider or fallback. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('provider_attribution__int_person_years') + rows: + - {person_id: 'P1', performance_year: 2022} + - {person_id: 'P1', performance_year: 2023} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {year_month_int: 202201, first_day_of_month: '2022-01-01', last_day_of_month: '2022-01-31', full_date: '2022-01-01'} + - {year_month_int: 202212, first_day_of_month: '2022-12-01', last_day_of_month: '2022-12-31', full_date: '2022-12-01'} + - {year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31', full_date: '2023-01-01'} + - {year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31', full_date: '2023-12-01'} + - input: ref('provider_attribution__provider_ranking') + rows: + - {person_id: 'P1', performance_year: 2022, as_of_date: null, provider_id: 'NPI1', provider_bucket: 'pcp', prov_specialty: 'Family Med', step: 1, step_description: '12-month PCP/NPP primary-care HCPCS', allowed_amount: 300, visits: 2, scope: 'yearly', lookback_start_date: '2022-01-01', lookback_end_date: '2022-12-31', ranking: 1, attribution_key: 'yearly|2022|P1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', performance_year: 2023, as_of_date: null, provider_id: 'NPI2', provider_bucket: 'specialist', prov_specialty: 'Cardiology', step: 2, step_description: '12-month specialist primary-care HCPCS', allowed_amount: 600, visits: 4, scope: 'yearly', lookback_start_date: '2023-01-01', lookback_end_date: '2023-12-31', ranking: 1, attribution_key: 'yearly|2023|P1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', performance_year: 2022, provider_id: 'NPI1', provider_bucket: 'pcp', assigned_step: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', performance_year: 2023, provider_id: 'NPI2', provider_bucket: 'specialist', assigned_step: 2, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # PROVIDER ATTRIBUTION - FINAL: assigned_beneficiaries_current + # ========================================================================= + + - name: test_provider_attribution_current_picks_rank_1 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__assigned_beneficiaries_current + description: "Current assignment picks ranking=1 from provider_ranking for scope='current'" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + provider_attribution_as_of_date: '2023-12-31' + given: + - input: ref('provider_attribution__int_primary_care_claims') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', claim_year: 2023, claim_month: 6, claim_year_month: '202306', claim_year_month_int: 202306, allowed_amount: 500, provider_id: 'NPI1', hcpcs_code: '99213', provider_bucket: 'pcp', prov_specialty: 'Internal Medicine'} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {full_date: '2023-06-01', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - {full_date: '2023-12-31', year: 2023, month: 12, year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202306'} + - input: ref('provider_attribution__provider_ranking') + rows: + - {person_id: 'P1', performance_year: null, as_of_date: '2023-12-31', provider_id: 'NPI1', provider_bucket: 'pcp', prov_specialty: 'Internal Med', step: 1, step_description: '12-month PCP/NPP primary-care HCPCS', allowed_amount: 500, visits: 3, scope: 'current', lookback_start_date: '2023-01-01', lookback_end_date: '2023-12-31', ranking: 1, attribution_key: 'current|20231231|P1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', provider_id: 'NPI1', provider_bucket: 'pcp', assigned_step: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_provider_attribution_current_fallback_no_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__assigned_beneficiaries_current + description: > + An eligible beneficiary with no matching provider ranking records + should receive the fallback provider assignment with step 0. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + provider_attribution_as_of_date: '2023-12-31' + given: + - input: ref('provider_attribution__int_primary_care_claims') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_line_number: 1, encounter_id: 'E1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', claim_year: 2023, claim_month: 6, claim_year_month: '202306', claim_year_month_int: 202306, allowed_amount: 500, provider_id: 'NPI1', hcpcs_code: '99213', provider_bucket: 'pcp', prov_specialty: 'Internal Medicine'} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {full_date: '2023-01-01', year: 2023, month: 1, year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31'} + - {full_date: '2023-06-01', year: 2023, month: 6, year_month_int: 202306, first_day_of_month: '2023-06-01', last_day_of_month: '2023-06-30'} + - {full_date: '2023-12-31', year: 2023, month: 12, year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P2', year_month: '202306'} + - input: ref('provider_attribution__provider_ranking') + rows: [] + expect: + rows: + - {person_id: 'P2', provider_id: '9999999999', provider_bucket: 'no_eligible_history', assigned_step: 0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # PROVIDER ATTRIBUTION - FINAL: provider_ranking + # ========================================================================= + + - name: test_provider_attribution_provider_ranking_collapses_to_earliest_step + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: provider_attribution__provider_ranking + description: "Provider ranking collapses multiple qualifying steps for the same person/provider down to the earliest step" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + provider_attribution_as_of_date: '2023-12-31' + given: + - input: ref('provider_attribution__int_person_years') + rows: + - {person_id: 'P1', performance_year: 2023} + - input: ref('provider_attribution__int_primary_care_claims') + rows: + - {person_id: 'P1', provider_id: 'NPI1', provider_bucket: 'pcp', prov_specialty: 'Internal Medicine', encounter_id: 'E1', claim_id: 'C1', claim_year: 2023, claim_year_month_int: 202306, claim_end_date: '2023-06-15', allowed_amount: 400} + - {person_id: 'P1', provider_id: 'NPI1', provider_bucket: 'specialist', prov_specialty: 'Internal Medicine', encounter_id: 'E2', claim_id: 'C2', claim_year: 2023, claim_year_month_int: 202303, claim_end_date: '2023-03-15', allowed_amount: 150} + - input: ref('provider_attribution__stg_reference_data__calendar') + rows: + - {year_month_int: 202301, first_day_of_month: '2023-01-01', last_day_of_month: '2023-01-31', full_date: '2023-01-01'} + - {year_month_int: 202312, first_day_of_month: '2023-12-01', last_day_of_month: '2023-12-31', full_date: '2023-12-01'} + - input: ref('provider_attribution__stg_core__member_months') + rows: + - {person_id: 'P1', year_month: '202306'} + - input: ref('provider_attribution__stg_core__medical_claim') + rows: [] + - input: ref('provider_attribution__stg_terminology__provider') + rows: [] + - input: ref('provider_attribution__provider_classification') + rows: [] + expect: + rows: + - {person_id: 'P1', performance_year: 2023, as_of_date: null, provider_id: 'NPI1', provider_bucket: 'pcp', prov_specialty: 'Internal Medicine', step: 1, step_description: '12-month PCP/NPP primary-care HCPCS', allowed_amount: 400, visits: 1, scope: 'yearly', lookback_start_date: '2023-01-01', lookback_end_date: '2023-12-31', ranking: 1, attribution_key: 'yearly|2023|P1', tuva_last_run: '2024-01-01 00:00:00'} + diff --git a/models/data_marts/quality_measures/_unit_tests.yml b/models/data_marts/quality_measures/_unit_tests.yml new file mode 100644 index 000000000..73e541996 --- /dev/null +++ b/models/data_marts/quality_measures/_unit_tests.yml @@ -0,0 +1,171 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # QUALITY MEASURES - FINAL: summary_counts + # ========================================================================= + + - name: test_quality_measures_summary_counts_aggregates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__summary_counts + description: "Summary counts aggregates denominator, numerator, exclusion sums and computes performance rate per measure" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__summary_long') + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 1, exclusion_flag: 0, performance_flag: 1, evidence_date: '2023-06-15', evidence_value: null, exclusion_date: null, exclusion_reason: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', denominator_flag: 1, numerator_flag: 0, exclusion_flag: 0, performance_flag: 0, evidence_date: null, evidence_value: null, exclusion_date: null, exclusion_reason: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P3', denominator_flag: 1, numerator_flag: 0, exclusion_flag: 1, performance_flag: null, evidence_date: null, evidence_value: null, exclusion_date: '2023-03-01', exclusion_reason: 'Hospice', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', denominator_sum: 3, numerator_sum: 1, exclusion_sum: 1, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - FINAL: summary_wide + # ========================================================================= + + - name: test_quality_measures_summary_wide_pivots_measures + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__summary_wide + description: "Summary wide pivots each measure_id into a column per patient" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__summary_long') + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 1, exclusion_flag: 0, performance_flag: 1, evidence_date: null, evidence_value: null, exclusion_date: null, exclusion_reason: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 0, exclusion_flag: 0, performance_flag: 0, evidence_date: null, evidence_value: null, exclusion_date: null, exclusion_reason: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM130', measure_name: 'Documentation of Current Medications', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', cqm_438: 1, cqm_130: 0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - STAGING: stg_core__patient + # ========================================================================= + + - name: test_quality_measures_stg_patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__stg_core__patient + description: "Patient staging passes through key demographics" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1960-01-01', death_date: null} + expect: + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1960-01-01', death_date: null, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - FINAL: summary_counts - multiple measures + # ========================================================================= + + - name: test_quality_measures_summary_counts_multiple_measures + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__summary_counts + description: "Summary counts produces separate rows for different measures" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__summary_long') + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 1, exclusion_flag: 0, performance_flag: 1, evidence_date: '2023-06-15', evidence_value: null, exclusion_date: null, exclusion_reason: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', denominator_flag: 1, numerator_flag: 1, exclusion_flag: 0, performance_flag: 1, evidence_date: '2023-07-01', evidence_value: null, exclusion_date: null, exclusion_reason: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM130', measure_name: 'Documentation of Current Medications', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {measure_id: 'CQM130', measure_name: 'Documentation of Current Medications', denominator_sum: 1, numerator_sum: 1, exclusion_sum: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', denominator_sum: 1, numerator_sum: 1, exclusion_sum: 0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - FINAL: summary_counts - null measure_id filtered + # ========================================================================= + + - name: test_quality_measures_summary_counts_filters_null_measure_id + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__summary_counts + description: "Summary counts filters out rows where measure_id is null" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__summary_long') + rows: + - {person_id: 'P1', denominator_flag: null, numerator_flag: null, exclusion_flag: null, performance_flag: null, evidence_date: null, evidence_value: null, exclusion_date: null, exclusion_reason: null, performance_period_begin: null, performance_period_end: null, measure_id: null, measure_name: null, measure_version: null, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', denominator_flag: 1, numerator_flag: 1, exclusion_flag: 0, performance_flag: 1, evidence_date: '2023-06-15', evidence_value: null, exclusion_date: null, exclusion_reason: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'NQF0420', measure_name: 'Pain Assessment', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {measure_id: 'NQF0420', measure_name: 'Pain Assessment', denominator_sum: 1, numerator_sum: 1, exclusion_sum: 0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - FINAL: summary_wide - exclusion nulls performance + # ========================================================================= + + - name: test_quality_measures_summary_wide_exclusion_nullifies_performance + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__summary_wide + description: "Summary wide shows null performance_flag for excluded patients" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__summary_long') + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 0, exclusion_flag: 1, performance_flag: null, evidence_date: null, evidence_value: null, exclusion_date: '2023-03-01', exclusion_reason: 'Hospice', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'ADH-Diabetes', measure_name: 'Medication Adherence Diabetes', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', adh_diabetes: null, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - FINAL: summary_wide - multiple patients + # ========================================================================= + + - name: test_quality_measures_summary_wide_multiple_patients + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__summary_wide + description: "Summary wide produces one row per patient with all measure columns" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__summary_long') + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 1, exclusion_flag: 0, performance_flag: 1, evidence_date: null, evidence_value: null, exclusion_date: null, exclusion_reason: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'SUPD', measure_name: 'Statin Use in Persons with Diabetes', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', denominator_flag: 1, numerator_flag: 0, exclusion_flag: 0, performance_flag: 0, evidence_date: null, evidence_value: null, exclusion_date: null, exclusion_reason: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'SUPD', measure_name: 'Statin Use in Persons with Diabetes', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', supd: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', supd: 0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - STAGING: stg_core__patient - deceased patient + # ========================================================================= + + - name: test_quality_measures_stg_patient_with_death_date + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__stg_core__patient + description: "Patient staging passes through death_date for deceased patients" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', sex: 'male', birth_date: '1950-03-15', death_date: '2023-09-01'} + expect: + rows: + - {person_id: 'P1', sex: 'male', birth_date: '1950-03-15', death_date: '2023-09-01', tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/data_marts/quality_measures/quality_measures_gap_unit_tests.yml b/models/data_marts/quality_measures/quality_measures_gap_unit_tests.yml new file mode 100644 index 000000000..e012691fa --- /dev/null +++ b/models/data_marts/quality_measures/quality_measures_gap_unit_tests.yml @@ -0,0 +1,1322 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # QUALITY MEASURES - STAGING: stg_core__condition + # ========================================================================= + + - name: test_quality_measures_stg_condition_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__stg_core__condition + description: "Condition staging passes through key fields from core condition" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__condition') + rows: + - {person_id: 'P1', claim_id: 'C1', encounter_id: 'E1', recorded_date: '2023-06-01', source_code_type: 'icd-10-cm', source_code: 'E11.65', normalized_code_type: 'icd-10-cm', normalized_code: 'E11.65'} + expect: + rows: + - {person_id: 'P1', claim_id: 'C1', encounter_id: 'E1', recorded_date: '2023-06-01', source_code_type: 'icd-10-cm', source_code: 'E11.65', normalized_code_type: 'icd-10-cm', normalized_code: 'E11.65', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - STAGING: stg_core__encounter + # ========================================================================= + + - name: test_quality_measures_stg_encounter_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__stg_core__encounter + description: "Encounter staging passes through key fields from core encounter" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + claims_enabled: true + given: + - input: ref('core__encounter') + rows: + - {person_id: 'P1', encounter_id: 'E1', encounter_type: 'office visit', encounter_group: 'office based', length_of_stay: 0, encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-01'} + expect: + rows: + - {person_id: 'P1', encounter_id: 'E1', encounter_type: 'office visit', encounter_group: 'office based', length_of_stay: 0, encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-01', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - STAGING: stg_core__lab_result + # ========================================================================= + + - name: test_quality_measures_stg_lab_result_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__stg_core__lab_result + description: "Lab result staging passes through key fields from core lab_result" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + claims_enabled: true + given: + - input: ref('core__lab_result') + rows: + - {person_id: 'P1', result: '200', result_datetime: '2023-06-01', collection_datetime: '2023-06-01', normalized_order_type: 'loinc', normalized_order_code: '13457-7', source_order_type: null, source_order_code: null, normalized_component_type: null, normalized_component_code: null, source_component_type: null, source_component_code: null} + expect: + rows: + - {person_id: 'P1', result: '200', result_date: '2023-06-01', collection_date: '2023-06-01', code_type: 'loinc', code: '13457-7'} + + # ========================================================================= + # QUALITY MEASURES - STAGING: stg_core__medication + # ========================================================================= + + - name: test_quality_measures_stg_medication_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__stg_core__medication + description: "Medication staging passes through key fields from core medication" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + claims_enabled: true + given: + - input: ref('core__medication') + rows: + - {person_id: 'P1', encounter_id: 'E1', prescribing_date: '2023-06-01', dispensing_date: '2023-06-02', source_code_type: 'rxnorm', source_code: '314076', ndc_code: '00378123401', rxnorm_code: '314076'} + expect: + rows: + - {person_id: 'P1', encounter_id: 'E1', prescribing_date: '2023-06-01', dispensing_date: '2023-06-02', source_code_type: 'rxnorm', source_code: '314076', ndc_code: '00378123401', rxnorm_code: '314076', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - STAGING: stg_core__observation + # ========================================================================= + + - name: test_quality_measures_stg_observation_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__stg_core__observation + description: "Observation staging passes through key fields from core observation" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + claims_enabled: true + given: + - input: ref('core__observation') + rows: + - {person_id: 'P1', encounter_id: 'E1', observation_date: '2023-06-01', result: 'positive', source_code_type: 'snomed-ct', source_code: '12345', normalized_code_type: 'snomed-ct', normalized_code: '12345', normalized_description: 'Test observation'} + expect: + rows: + - {person_id: 'P1', encounter_id: 'E1', observation_date: '2023-06-01', result: 'positive', source_code_type: 'snomed-ct', source_code: '12345', normalized_code_type: 'snomed-ct', normalized_code: '12345', normalized_description: 'Test observation', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - STAGING: stg_core__procedure + # ========================================================================= + + - name: test_quality_measures_stg_procedure_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__stg_core__procedure + description: "Procedure staging passes through key fields from core procedure" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__procedure') + rows: + - {person_id: 'P1', encounter_id: 'E1', procedure_date: '2023-06-01', source_code_type: 'hcpcs', source_code: '99213', normalized_code_type: 'hcpcs', normalized_code: '99213', modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null} + expect: + rows: + - {person_id: 'P1', encounter_id: 'E1', procedure_date: '2023-06-01', source_code_type: 'hcpcs', source_code: '99213', normalized_code_type: 'hcpcs', normalized_code: '99213', modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - STAGING: stg_medical_claim + # ========================================================================= + + - name: test_quality_measures_stg_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__stg_medical_claim + description: "Medical claim staging passes through key fields from core medical claim" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + claims_enabled: true + given: + - input: ref('core__medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', place_of_service_code: '11', hcpcs_code: '99213', hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null} + expect: + rows: + - {person_id: 'P1', claim_id: 'C1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-01', place_of_service_code: '11', hcpcs_code: '99213', hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - STAGING: stg_pharmacy_claim + # ========================================================================= + + - name: test_quality_measures_stg_pharmacy_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__stg_pharmacy_claim + description: "Pharmacy claim staging passes through key fields from core pharmacy claim" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + clinical_enabled: true + claims_enabled: true + given: + - input: ref('core__pharmacy_claim') + rows: + - {person_id: 'P1', dispensing_date: '2023-06-01', ndc_code: '00378123401', days_supply: 30, paid_date: '2023-06-15'} + expect: + rows: + - {person_id: 'P1', dispensing_date: '2023-06-01', ndc_code: '00378123401', days_supply: 30, paid_date: '2023-06-15', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # QUALITY MEASURES - SHARED EXCLUSIONS: hospice_palliative + # ========================================================================= + + - name: test_quality_measures_shared_exclusions_hospice_palliative + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_shared_exclusions_hospice_palliative + description: "Hospice palliative exclusion identifies patients with hospice condition codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__value_sets') + rows: + - {code: 'Z51.5', code_system: 'ICD10CM', concept_name: 'hospice encounter'} + - input: ref('quality_measures__stg_core__condition') + rows: + - {person_id: 'P1', claim_id: 'C1', recorded_date: '2023-06-01', source_code_type: null, source_code: null, normalized_code_type: 'icd-10-cm', normalized_code: 'Z51.5', encounter_id: 'E1'} + - input: ref('quality_measures__stg_medical_claim') + rows: [] + - input: ref('quality_measures__stg_core__observation') + rows: [] + - input: ref('quality_measures__stg_core__procedure') + rows: [] + expect: + rows: + - {person_id: 'P1', exclusion_date: '2023-06-01', exclusion_reason: 'hospice encounter', exclusion_type: 'hospice_palliative'} + + # ========================================================================= + # QUALITY MEASURES - SHARED EXCLUSIONS: frailty + # ========================================================================= + + - name: test_quality_measures_shared_exclusions_frailty + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_shared_exclusions_frailty + description: "Frailty exclusion identifies patients with frailty condition codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1940-01-01', death_date: null} + - input: ref('quality_measures__value_sets') + rows: + - {code: 'M62.81', code_system: 'ICD10CM', concept_name: 'frailty diagnosis'} + - input: ref('quality_measures__stg_core__condition') + rows: + - {person_id: 'P1', claim_id: 'C1', recorded_date: '2023-06-01', source_code_type: null, source_code: null, normalized_code_type: 'icd-10-cm', normalized_code: 'M62.81', encounter_id: 'E1'} + - input: ref('quality_measures__stg_medical_claim') + rows: [] + - input: ref('quality_measures__stg_core__observation') + rows: [] + - input: ref('quality_measures__stg_core__procedure') + rows: [] + expect: + rows: [] + + # ========================================================================= + # QUALITY MEASURES - SHARED EXCLUSIONS: institutional_snp + # ========================================================================= + + - name: test_quality_measures_shared_exclusions_institutional_snp + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_shared_exclusions_institutional_snp + description: "Institutional SNP exclusion identifies patients with 90+ day stays at institutional POS codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1940-01-01', death_date: null} + - input: ref('quality_measures__stg_medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_start_date: '2023-01-01', claim_end_date: '2023-06-01', place_of_service_code: '32', hcpcs_code: null, hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null} + expect: + rows: + - {person_id: 'P1', exclusion_date: '2023-01-01', exclusion_reason: 'institutional or long term care', exclusion_type: 'institutional_snp'} + + # ========================================================================= + # QUALITY MEASURES - SHARED EXCLUSIONS: dementia + # ========================================================================= + + - name: test_quality_measures_shared_exclusions_dementia + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_shared_exclusions_dementia + description: "Dementia exclusion identifies frail patients with dementia medication dispensing" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__int_shared_exclusions_frailty') + rows: + - {person_id: 'P1', exclusion_date: '2023-06-01', exclusion_reason: 'frailty diagnosis'} + - input: ref('quality_measures__value_sets') + rows: + - {code: '00078012345', code_system: 'ndc', concept_name: 'dementia medications'} + - input: ref('quality_measures__stg_core__medication') + rows: [] + - input: ref('quality_measures__stg_pharmacy_claim') + rows: + - {person_id: 'P1', dispensing_date: '2023-07-01', ndc_code: '00078012345', days_supply: 30, paid_date: '2023-07-15'} + expect: + rows: + - {person_id: 'P1', exclusion_type: 'dementia'} + + # ========================================================================= + # QUALITY MEASURES - SHARED EXCLUSIONS: advanced_illness + # ========================================================================= + + - name: test_quality_measures_shared_exclusions_advanced_illness + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_shared_exclusions_advanced_illness + description: "Advanced illness exclusion identifies frail patients with advanced illness on acute inpatient claims" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__int_shared_exclusions_frailty') + rows: + - {person_id: 'P1', exclusion_date: '2023-06-01', exclusion_reason: 'frailty diagnosis'} + - input: ref('quality_measures__value_sets') + rows: + - {code: 'G30.9', code_system: 'ICD10CM', concept_name: 'advanced illness'} + - {code: '99221', code_system: 'CPT', concept_name: 'acute inpatient'} + - input: ref('quality_measures__stg_core__condition') + rows: + - {person_id: 'P1', claim_id: 'C1', recorded_date: '2023-06-01', source_code_type: null, source_code: null, normalized_code_type: 'icd-10-cm', normalized_code: 'G30.9', encounter_id: 'E1'} + - input: ref('quality_measures__stg_medical_claim') + rows: + - {person_id: 'P1', claim_id: 'C1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-05', hcpcs_code: '99221', place_of_service_code: '21', hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null} + - input: ref('quality_measures__stg_core__procedure') + rows: [] + expect: + rows: [] + + # ========================================================================= + # CQM438 - PERFORMANCE PERIOD + # ========================================================================= + + - name: test_quality_measures_cqm438_performance_period + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm438__performance_period + description: "CQM438 performance period returns measure metadata and computed date range" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__measures') + rows: + - {id: 'CQM438', name: 'Statin Therapy CVD', version: '2023'} + expect: + rows: + - {measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + + # ========================================================================= + # CQM438 - DENOMINATOR CRITERIA 1 (ASCVD) + # ========================================================================= + + - name: test_quality_measures_cqm438_denom_criteria1_ascvd + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm438_denominator_criteria1 + description: "CQM438 criteria1 identifies patients with ASCVD conditions" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__value_sets') + rows: + - {code: 'I25.10', code_system: 'ICD10CM', concept_name: 'ischemic heart disease or related diagnoses'} + - input: ref('quality_measures__stg_core__condition') + rows: + - {person_id: 'P1', claim_id: 'C1', encounter_id: 'E1', recorded_date: '2023-03-01', source_code_type: null, source_code: null, normalized_code_type: 'icd-10-cm', normalized_code: 'I25.10'} + - input: ref('quality_measures__stg_core__procedure') + rows: [] + - input: ref('quality_measures__int_cqm438__performance_period') + rows: + - {measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + expect: + rows: [] + + # ========================================================================= + # CQM438 - DENOMINATOR CRITERIA 2 (Cholesterol) + # ========================================================================= + + - name: test_quality_measures_cqm438_denom_criteria2_cholesterol + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm438_denominator_criteria2 + description: "CQM438 criteria2 identifies patients with familial hypercholesterolemia condition" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__value_sets') + rows: + - {code: 'E78.01', code_system: 'ICD10CM', concept_name: 'familial hypercholesterolemia'} + - input: ref('quality_measures__stg_core__condition') + rows: + - {person_id: 'P1', claim_id: 'C1', encounter_id: 'E1', recorded_date: '2023-03-01', source_code_type: null, source_code: null, normalized_code_type: 'icd-10-cm', normalized_code: 'E78.01'} + - input: ref('quality_measures__stg_core__procedure') + rows: [] + - input: ref('quality_measures__stg_core__lab_result') + rows: [] + - input: ref('quality_measures__int_cqm438__performance_period') + rows: + - {measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + expect: + rows: [] + + # ========================================================================= + # CQM438 - DENOMINATOR CRITERIA 3 (Diabetes) + # ========================================================================= + + - name: test_quality_measures_cqm438_denom_criteria3_diabetes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm438_denominator_criteria3 + description: "CQM438 criteria3 identifies patients with diabetes condition" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__value_sets') + rows: + - {code: 'E11.65', code_system: 'ICD10CM', concept_name: 'diabetes'} + - input: ref('quality_measures__stg_core__condition') + rows: + - {person_id: 'P1', claim_id: 'C1', encounter_id: 'E1', recorded_date: '2023-03-01', source_code_type: null, source_code: null, normalized_code_type: 'icd-10-cm', normalized_code: 'E11.65'} + - input: ref('quality_measures__int_cqm438__performance_period') + rows: + - {measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + expect: + rows: [] + + # ========================================================================= + # CQM438 - DENOMINATOR + # ========================================================================= + + - name: test_quality_measures_cqm438_denominator_unions_criteria + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm438_denominator + description: "CQM438 denominator unions criteria and filters by age with qualifying encounters" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_cqm438_denominator_criteria1') + rows: + - {person_id: 'P1', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023'} + - input: ref('quality_measures__int_cqm438_denominator_criteria2') + rows: [] + - input: ref('quality_measures__int_cqm438_denominator_criteria3') + rows: [] + - input: ref('quality_measures__value_sets') + rows: + - {code: '99213', code_system: 'CPT', concept_name: 'office visit'} + - input: ref('quality_measures__stg_core__encounter') + rows: + - {person_id: 'P1', encounter_id: 'E1', encounter_type: 'office visit', encounter_group: 'office based', length_of_stay: 0, encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-01', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_core__procedure') + rows: [] + - input: ref('quality_measures__stg_medical_claim') + rows: [] + - input: ref('quality_measures__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1960-01-01', death_date: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_cqm438__performance_period') + rows: + - {measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, measure_id: 'CQM438'} + + # ========================================================================= + # CQM438 - EXCLUSIONS + # ========================================================================= + + - name: test_quality_measures_cqm438_exclusions_condition_match + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm438_exclusions + description: "CQM438 exclusions identifies denominator patients with qualifying exclusion conditions" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_cqm438__performance_period') + rows: + - {measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + - input: ref('quality_measures__value_sets') + rows: + - {code: 'M62.82', code_system: 'ICD10CM', concept_name: 'rhabdomyolysis'} + - input: ref('quality_measures__stg_core__condition') + rows: + - {person_id: 'P1', claim_id: 'C1', recorded_date: '2023-06-01', source_code_type: null, source_code: null, normalized_code_type: 'icd-10-cm', normalized_code: 'M62.82', encounter_id: 'E1'} + - input: ref('quality_measures__stg_medical_claim') + rows: [] + - input: ref('quality_measures__stg_core__observation') + rows: [] + - input: ref('quality_measures__stg_core__procedure') + rows: [] + - input: ref('quality_measures__stg_core__medication') + rows: [] + - input: ref('quality_measures__stg_pharmacy_claim') + rows: [] + - input: ref('quality_measures__int_shared_exclusions_hospice_palliative') + rows: [] + - input: ref('quality_measures__int_cqm438_denominator') + rows: + - {person_id: 'P1', age: 65, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {person_id: 'P1', exclusion_date: '2023-06-01', exclusion_reason: 'rhabdomyolysis', exclusion_flag: 1} + + # ========================================================================= + # CQM438 - NUMERATOR + # ========================================================================= + + - name: test_quality_measures_cqm438_numerator_statin_procedure + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm438_numerator + description: "CQM438 numerator identifies denominator patients with statin therapy procedure" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_cqm438_denominator') + rows: + - {person_id: 'P1', age: 65, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__value_sets') + rows: + - {code: '36567', code_system: 'rxnorm', concept_name: 'statin therapy'} + - input: ref('quality_measures__stg_core__procedure') + rows: + - {person_id: 'P1', encounter_id: 'E1', procedure_date: '2023-06-15', source_code_type: 'rxnorm', source_code: '36567', normalized_code_type: null, normalized_code: null, modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_pharmacy_claim') + rows: [] + - input: ref('quality_measures__stg_core__medication') + rows: [] + expect: + rows: + - {person_id: 'P1', evidence_date: '2023-06-15', numerator_flag: 1} + + # ========================================================================= + # CQM438 - LONG + # ========================================================================= + + - name: test_quality_measures_cqm438_long_combines_flags + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm438_long + description: "CQM438 long combines denominator, numerator, and exclusion flags per patient" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__int_cqm438_denominator') + rows: + - {person_id: 'P1', age: 65, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_cqm438_numerator') + rows: + - {person_id: 'P1', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM438', measure_name: 'Statin Therapy CVD', measure_version: '2023', evidence_date: '2023-06-15', evidence_value: null, numerator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_cqm438_exclusions') + rows: [] + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 1, exclusion_flag: 0, measure_id: 'CQM438'} + + # ========================================================================= + # CQM130 - PERFORMANCE PERIOD + # ========================================================================= + + - name: test_quality_measures_cqm130_performance_period + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm130__performance_period + description: "CQM130 performance period returns measure metadata and computed date range" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__measures') + rows: + - {id: 'CQM130', name: 'Documentation of Current Medications', version: '2023'} + expect: + rows: + - {measure_id: 'CQM130', measure_name: 'Documentation of Current Medications', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + + # ========================================================================= + # CQM130 - DENOMINATOR + # ========================================================================= + + - name: test_quality_measures_cqm130_denominator_qualifying_patient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm130_denominator + description: "CQM130 denominator identifies patients 18+ with qualifying encounters in the performance period" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__value_sets') + rows: + - {code: '99213', code_system: 'CPT', concept_name: 'encounter to document medications'} + - input: ref('quality_measures__stg_core__encounter') + rows: + - {person_id: 'P1', encounter_id: 'E1', encounter_type: 'office visit', encounter_group: 'office based', length_of_stay: 0, encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-01', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_core__procedure') + rows: [] + - input: ref('quality_measures__stg_medical_claim') + rows: [] + - input: ref('quality_measures__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1960-01-01', death_date: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_cqm130__performance_period') + rows: + - {measure_id: 'CQM130', measure_name: 'Documentation of Current Medications', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, measure_id: 'CQM130'} + + # ========================================================================= + # CQM130 - EXCLUSIONS + # ========================================================================= + + - name: test_quality_measures_cqm130_exclusions_medical_reason + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm130_exclusions + description: "CQM130 exclusions identifies denominator patients with medical reason exclusion codes" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_cqm130__performance_period') + rows: + - {measure_id: 'CQM130', measure_name: 'Documentation of Current Medications', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + - input: ref('quality_measures__value_sets') + rows: + - {code: 'G9692', code_system: 'CPT', concept_name: 'medical reason'} + - input: ref('quality_measures__stg_core__condition') + rows: [] + - input: ref('quality_measures__stg_core__procedure') + rows: + - {person_id: 'P1', encounter_id: 'E1', procedure_date: '2023-06-01', source_code_type: null, source_code: null, normalized_code_type: 'hcpcs', normalized_code: 'G9692', modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_medical_claim') + rows: [] + - input: ref('quality_measures__int_cqm130_denominator') + rows: + - {person_id: 'P1', age: 65, procedure_encounter_date: '2023-06-01', claims_encounter_date: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM130', measure_name: 'Documentation of Current Medications', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: [] + + # ========================================================================= + # CQM130 - NUMERATOR + # ========================================================================= + + - name: test_quality_measures_cqm130_numerator_documenting_meds + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm130_numerator + description: "CQM130 numerator identifies denominator patients with medication documentation procedures" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_cqm130_denominator') + rows: + - {person_id: 'P1', age: 65, procedure_encounter_date: '2023-06-01', claims_encounter_date: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM130', measure_name: 'Documentation of Current Medications', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__value_sets') + rows: + - {code: 'G8427', code_system: 'CPT', concept_name: 'eligible clinician attests to documenting current medications'} + - input: ref('quality_measures__stg_core__procedure') + rows: + - {person_id: 'P1', encounter_id: 'E1', procedure_date: '2023-06-01', source_code_type: null, source_code: null, normalized_code_type: 'hcpcs', normalized_code: 'G8427', modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_medical_claim') + rows: [] + expect: + rows: [] + + # ========================================================================= + # CQM130 - LONG + # ========================================================================= + + - name: test_quality_measures_cqm130_long_combines_flags + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_cqm130_long + description: "CQM130 long combines denominator, numerator, and exclusion flags per patient" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__int_cqm130_denominator') + rows: + - {person_id: 'P1', age: 65, procedure_encounter_date: '2023-06-01', claims_encounter_date: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM130', measure_name: 'Documentation of Current Medications', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_cqm130_numerator') + rows: + - {person_id: 'P1', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'CQM130', measure_name: 'Documentation of Current Medications', measure_version: '2023', evidence_date: '2023-06-01', evidence_value: null, numerator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_cqm130_exclusions') + rows: [] + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 1, exclusion_flag: 0, measure_id: 'CQM130'} + + # ========================================================================= + # NQF0420 - PERFORMANCE PERIOD + # ========================================================================= + + - name: test_quality_measures_nqf0420_performance_period + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_nqf0420__performance_period + description: "NQF0420 performance period returns measure metadata and computed date range" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__measures') + rows: + - {id: 'NQF0420', name: 'Pain Assessment and Follow-Up', version: '2023'} + expect: + rows: + - {measure_id: 'NQF0420', measure_name: 'Pain Assessment and Follow-Up', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + + # ========================================================================= + # NQF0420 - DENOMINATOR + # ========================================================================= + + - name: test_quality_measures_nqf0420_denominator_qualifying_patient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_nqf0420_denominator + description: "NQF0420 denominator identifies patients 18+ with qualifying encounters" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__value_sets') + rows: + - {code: '99213', code_system: 'CPT', concept_name: 'office visit'} + - input: ref('quality_measures__stg_core__encounter') + rows: + - {person_id: 'P1', encounter_id: 'E1', encounter_type: 'office visit', encounter_group: 'office based', length_of_stay: 0, encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-01', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_core__procedure') + rows: [] + - input: ref('quality_measures__stg_medical_claim') + rows: [] + - input: ref('quality_measures__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1960-01-01', death_date: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_nqf0420__performance_period') + rows: + - {measure_id: 'NQF0420', measure_name: 'Pain Assessment and Follow-Up', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, measure_id: 'NQF0420'} + + # ========================================================================= + # NQF0420 - EXCLUSIONS + # ========================================================================= + + - name: test_quality_measures_nqf0420_exclusions + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_nqf0420_exclusions + description: "NQF0420 exclusions identifies patients not eligible for pain assessment" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_nqf0420__performance_period') + rows: + - {measure_id: 'NQF0420', measure_name: 'Pain Assessment and Follow-Up', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + - input: ref('quality_measures__int_nqf0420_denominator') + rows: + - {person_id: 'P1', age: 65, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'NQF0420', measure_name: 'Pain Assessment and Follow-Up', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__value_sets') + rows: + - {code: 'G8731', code_system: 'CPT', concept_name: 'patient is not eligible for a pain assessment'} + - input: ref('quality_measures__stg_core__procedure') + rows: + - {person_id: 'P1', encounter_id: 'E1', procedure_date: '2023-06-01', source_code_type: null, source_code: null, normalized_code_type: 'hcpcs', normalized_code: 'G8731', modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_medical_claim') + rows: [] + expect: + rows: [] + + # ========================================================================= + # NQF0420 - NUMERATOR + # ========================================================================= + + - name: test_quality_measures_nqf0420_numerator_pain_assessment + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_nqf0420_numerator + description: "NQF0420 numerator identifies patients with documented pain assessment" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_nqf0420_denominator') + rows: + - {person_id: 'P1', age: 65, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'NQF0420', measure_name: 'Pain Assessment and Follow-Up', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__value_sets') + rows: + - {code: 'G8730', code_system: 'CPT', concept_name: 'pain assessment documented'} + - input: ref('quality_measures__stg_core__procedure') + rows: + - {person_id: 'P1', encounter_id: 'E1', procedure_date: '2023-06-15', source_code_type: null, source_code: null, normalized_code_type: 'hcpcs', normalized_code: 'G8730', modifier_1: null, modifier_2: null, modifier_3: null, modifier_4: null, modifier_5: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_medical_claim') + rows: [] + expect: + rows: [] + + # ========================================================================= + # NQF0420 - LONG + # ========================================================================= + + - name: test_quality_measures_nqf0420_long_combines_flags + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_nqf0420_long + description: "NQF0420 long combines denominator, numerator, and exclusion flags per patient" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__int_nqf0420_denominator') + rows: + - {person_id: 'P1', age: 65, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'NQF0420', measure_name: 'Pain Assessment and Follow-Up', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_nqf0420_numerator') + rows: + - {person_id: 'P1', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'NQF0420', measure_name: 'Pain Assessment and Follow-Up', measure_version: '2023', evidence_date: '2023-06-15', evidence_value: null, numerator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_nqf0420_exclusions') + rows: [] + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 1, exclusion_flag: 0, measure_id: 'NQF0420'} + + # ========================================================================= + # ADH-Diabetes - PERFORMANCE PERIOD + # ========================================================================= + + - name: test_quality_measures_adh_diabetes_performance_period + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adh_diabetes__performance_period + description: "ADH-Diabetes performance period returns measure metadata and computed date range" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__measures') + rows: + - {id: 'ADH-Diabetes', name: 'Medication Adherence for Diabetes Medications', version: '2023'} + expect: + rows: + - {measure_id: 'ADH-Diabetes', measure_name: 'Medication Adherence for Diabetes Medications', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + + # ========================================================================= + # ADH-Diabetes - DENOMINATOR + # ========================================================================= + + - name: test_quality_measures_adh_diabetes_denominator_qualifying_patient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adh_diabetes_denominator + description: "ADH-Diabetes denominator identifies patients 18+ with 2+ diabetes medication fills and first fill 91+ days before period end" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__value_sets') + rows: + - {code: '00378123401', code_system: 'ndc', concept_name: 'pqa diabetes medications'} + - input: ref('quality_measures__stg_pharmacy_claim') + rows: + - {person_id: 'P1', dispensing_date: '2023-03-01', ndc_code: '00378123401', days_supply: 30, paid_date: '2023-03-15', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', dispensing_date: '2023-04-01', ndc_code: '00378123401', days_supply: 30, paid_date: '2023-04-15', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1960-01-01', death_date: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_adh_diabetes__performance_period') + rows: + - {measure_id: 'ADH-Diabetes', measure_name: 'Medication Adherence for Diabetes Medications', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, ndc_code: '00378123401'} + - {person_id: 'P1', denominator_flag: 1, ndc_code: '00378123401'} + + # ========================================================================= + # ADH-Diabetes - EXCLUSIONS + # ========================================================================= + + - name: test_quality_measures_adh_diabetes_exclusions_esrd + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adh_diabetes_exclusions + description: "ADH-Diabetes exclusions identifies denominator patients with ESRD or insulin" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_adh_diabetes__performance_period') + rows: + - {measure_id: 'ADH-Diabetes', measure_name: 'Medication Adherence for Diabetes Medications', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + - input: ref('quality_measures__int_adh_diabetes_denominator') + rows: + - {person_id: 'P1', age: 65, dispensing_date: '2023-03-01', ndc_code: '00378123401', days_supply: 30, days_in_treatment_period: 306, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'ADH-Diabetes', measure_name: 'Medication Adherence for Diabetes Medications', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__value_sets') + rows: + - {code: 'N18.6', code_system: 'ICD10CM', concept_name: 'pqa esrd'} + - input: ref('quality_measures__int_shared_exclusions_hospice_palliative') + rows: [] + - input: ref('quality_measures__stg_core__condition') + rows: + - {person_id: 'P1', claim_id: 'C1', recorded_date: '2023-06-01', source_code_type: null, source_code: null, normalized_code_type: 'icd-10-cm', normalized_code: 'N18.6', encounter_id: 'E1'} + - input: ref('quality_measures__stg_pharmacy_claim') + rows: [] + expect: + rows: [] + + # ========================================================================= + # ADH-Diabetes - NUMERATOR + # ========================================================================= + + - name: test_quality_measures_adh_diabetes_numerator_adherent + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adh_diabetes_numerator + description: "ADH-Diabetes numerator identifies patients with 80%+ medication adherence" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_adh_diabetes_denominator') + rows: + - {person_id: 'P1', age: 65, dispensing_date: '2023-03-01', ndc_code: 'NDC1', days_supply: 306, days_in_treatment_period: 306, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'ADH-Diabetes', measure_name: 'Medication Adherence for Diabetes Medications', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_adh_diabetes__performance_period') + rows: + - {measure_id: 'ADH-Diabetes', measure_name: 'Medication Adherence for Diabetes Medications', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + expect: + rows: + - {person_id: 'P1', numerator_flag: 1} + + # ========================================================================= + # ADH-Diabetes - LONG + # ========================================================================= + + - name: test_quality_measures_adh_diabetes_long_combines_flags + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adh_diabetes_long + description: "ADH-Diabetes long combines denominator, numerator, and exclusion flags per patient" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__int_adh_diabetes_denominator') + rows: + - {person_id: 'P1', age: 65, dispensing_date: '2023-03-01', ndc_code: 'NDC1', days_supply: 30, days_in_treatment_period: 306, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'ADH-Diabetes', measure_name: 'Medication Adherence for Diabetes Medications', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_adh_diabetes_numerator') + rows: + - {person_id: 'P1', evidence_date: '2023-03-01', evidence_value: '30', adherence: 100.0, numerator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_adh_diabetes_exclusions') + rows: [] + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 1, exclusion_flag: 0, measure_id: 'ADH-Diabetes'} + + # ========================================================================= + # ADH-RAS - PERFORMANCE PERIOD + # ========================================================================= + + - name: test_quality_measures_adhras_performance_period + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adhras__performance_period + description: "ADH-RAS performance period returns measure metadata and computed date range" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__measures') + rows: + - {id: 'ADH-RAS', name: 'Medication Adherence for Hypertension (RAS Antagonists)', version: '2023'} + expect: + rows: + - {measure_id: 'ADH-RAS', measure_name: 'Medication Adherence for Hypertension (RAS Antagonists)', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + + # ========================================================================= + # ADH-RAS - DENOMINATOR + # ========================================================================= + + - name: test_quality_measures_adhras_denominator_placeholder + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adhras_denominator + description: "ADH-RAS denominator identifies patients with qualifying RAS antagonist fills" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__value_sets') + rows: + - {code: '00378999901', code_system: 'ndc', concept_name: 'pqa ras antagonist medications'} + - input: ref('quality_measures__stg_pharmacy_claim') + rows: + - {person_id: 'P1', dispensing_date: '2023-03-01', ndc_code: '00378999901', days_supply: 30, paid_date: '2023-03-15', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', dispensing_date: '2023-04-01', ndc_code: '00378999901', days_supply: 30, paid_date: '2023-04-15', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1960-01-01', death_date: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_adhras__performance_period') + rows: + - {measure_id: 'ADH-RAS', measure_name: 'Medication Adherence for Hypertension (RAS Antagonists)', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + expect: + rows: [] + + # ========================================================================= + # ADH-RAS - EXCLUSIONS + # ========================================================================= + + - name: test_quality_measures_adhras_exclusions_hospice + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adhras_exclusions + description: "ADH-RAS exclusions identifies denominator patients with hospice or sacubitril/valsartan" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_adhras__performance_period') + rows: + - {measure_id: 'ADH-RAS', measure_name: 'Medication Adherence for Hypertension (RAS Antagonists)', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + - input: ref('quality_measures__int_adhras_denominator') + rows: + - {person_id: 'P1', dispensing_date: '2023-03-01', ndc_code: '00378999901', days_supply: 30, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'ADH-RAS', measure_name: 'Medication Adherence for Hypertension (RAS Antagonists)', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__value_sets') + rows: + - {code: 'Z51.5', code_system: 'ICD10CM', concept_name: 'pqa sacubitril valsartan medications'} + - input: ref('quality_measures__int_shared_exclusions_hospice_palliative') + rows: [] + - input: ref('quality_measures__stg_pharmacy_claim') + rows: [] + - input: ref('quality_measures__stg_core__condition') + rows: [] + expect: + rows: [] + + # ========================================================================= + # ADH-RAS - LONG + # ========================================================================= + + - name: test_quality_measures_adhras_long_combines_flags + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adhras_long + description: "ADH-RAS long combines denominator, numerator, and exclusion flags per patient" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__int_adhras_denominator') + rows: + - {person_id: 'P1', dispensing_date: '2023-03-01', ndc_code: 'NDC1', days_supply: 30, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'ADH-RAS', measure_name: 'Medication Adherence for Hypertension (RAS Antagonists)', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_adhras_numerator') + rows: [] + - input: ref('quality_measures__int_adhras_exclusions') + rows: [] + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 0, exclusion_flag: 0, measure_id: 'ADH-RAS'} + + # ========================================================================= + # ADH-Statins - PERFORMANCE PERIOD + # ========================================================================= + + - name: test_quality_measures_adh_statins_performance_period + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adh_statins__performance_period + description: "ADH-Statins performance period returns measure metadata and computed date range" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__measures') + rows: + - {id: 'ADH-Statins', name: 'Medication Adherence for Cholesterol (Statins)', version: '2023'} + expect: + rows: + - {measure_id: 'ADH-Statins', measure_name: 'Medication Adherence for Cholesterol (Statins)', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + + # ========================================================================= + # ADH-Statins - DENOMINATOR + # ========================================================================= + + - name: test_quality_measures_adh_statins_denominator_placeholder + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adh_statins_denominator + description: "ADH-Statins denominator identifies patients with qualifying statin fills" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__value_sets') + rows: + - {code: '00378888801', code_system: 'ndc', concept_name: 'pqa statin medications'} + - input: ref('quality_measures__stg_pharmacy_claim') + rows: + - {person_id: 'P1', dispensing_date: '2023-03-01', ndc_code: '00378888801', days_supply: 30, paid_date: '2023-03-15', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', dispensing_date: '2023-04-01', ndc_code: '00378888801', days_supply: 30, paid_date: '2023-04-15', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1960-01-01', death_date: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_adh_statins__performance_period') + rows: + - {measure_id: 'ADH-Statins', measure_name: 'Medication Adherence for Cholesterol (Statins)', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + expect: + rows: + - {person_id: 'P1', denominator_flag: 1} + - {person_id: 'P1', denominator_flag: 1} + + # ========================================================================= + # ADH-Statins - EXCLUSIONS + # ========================================================================= + + - name: test_quality_measures_adh_statins_exclusions_empty + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adh_statins_exclusions + description: "ADH-Statins exclusions returns empty when no exclusion conditions present" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_adh_statins__performance_period') + rows: + - {measure_id: 'ADH-Statins', measure_name: 'Medication Adherence for Cholesterol (Statins)', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + - input: ref('quality_measures__int_adh_statins_denominator') + rows: + - {person_id: 'P1', dispensing_date: '2023-03-01', ndc_code: '00378888801', days_supply: 30, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'ADH-Statins', measure_name: 'Medication Adherence for Cholesterol (Statins)', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__value_sets') + rows: [] + - input: ref('quality_measures__int_shared_exclusions_hospice_palliative') + rows: [] + - input: ref('quality_measures__stg_core__condition') + rows: [] + expect: + rows: [] + + # ========================================================================= + # ADH-Statins - LONG + # ========================================================================= + + - name: test_quality_measures_adh_statins_long_combines_flags + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_adh_statins_long + description: "ADH-Statins long combines denominator, numerator, and exclusion flags per patient" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__int_adh_statins_denominator') + rows: + - {person_id: 'P1', dispensing_date: '2023-03-01', ndc_code: 'NDC1', days_supply: 30, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'ADH-Statins', measure_name: 'Medication Adherence for Cholesterol (Statins)', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_adh_statins_numerator') + rows: [] + - input: ref('quality_measures__int_adh_statins_exclusions') + rows: [] + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 0, exclusion_flag: 0, measure_id: 'ADH-Statins'} + + # ========================================================================= + # SUPD - PERFORMANCE PERIOD + # ========================================================================= + + - name: test_quality_measures_supd_performance_period + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_supd__performance_period + description: "SUPD performance period returns measure metadata and computed date range" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__measures') + rows: + - {id: 'SUPD', name: 'Statin Use in Persons with Diabetes', version: '2023'} + expect: + rows: + - {measure_id: 'SUPD', measure_name: 'Statin Use in Persons with Diabetes', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + + # ========================================================================= + # SUPD - DENOMINATOR + # ========================================================================= + + - name: test_quality_measures_supd_denominator_placeholder + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_supd_denominator + description: "SUPD denominator identifies patients 40-75 with diabetes and qualifying fills" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__value_sets') + rows: + - {code: '00378777701', code_system: 'ndc', concept_name: 'pqa diabetes medications'} + - input: ref('quality_measures__stg_pharmacy_claim') + rows: + - {person_id: 'P1', dispensing_date: '2023-03-01', ndc_code: '00378777701', days_supply: 30, paid_date: '2023-03-15', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', dispensing_date: '2023-04-01', ndc_code: '00378777701', days_supply: 30, paid_date: '2023-04-15', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__stg_core__patient') + rows: + - {person_id: 'P1', sex: 'female', birth_date: '1960-01-01', death_date: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_supd__performance_period') + rows: + - {measure_id: 'SUPD', measure_name: 'Statin Use in Persons with Diabetes', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + expect: + rows: [] + + # ========================================================================= + # SUPD - EXCLUSIONS + # ========================================================================= + + - name: test_quality_measures_supd_exclusions_empty + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_supd_exclusions + description: "SUPD exclusions returns empty when no exclusion conditions present" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_supd__performance_period') + rows: + - {measure_id: 'SUPD', measure_name: 'Statin Use in Persons with Diabetes', measure_version: '2023', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31'} + - input: ref('quality_measures__int_supd_denominator') + rows: + - {person_id: 'P1', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'SUPD', measure_name: 'Statin Use in Persons with Diabetes', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__value_sets') + rows: [] + - input: ref('quality_measures__int_shared_exclusions_hospice_palliative') + rows: [] + - input: ref('quality_measures__stg_core__condition') + rows: [] + - input: ref('quality_measures__stg_pharmacy_claim') + rows: [] + expect: + rows: [] + + # ========================================================================= + # SUPD - NUMERATOR + # ========================================================================= + + - name: test_quality_measures_supd_numerator_statin_fill + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_supd_numerator + description: "SUPD numerator identifies denominator patients with statin pharmacy fill" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + quality_measures_period_end: '2023-12-31' + given: + - input: ref('quality_measures__int_supd_denominator') + rows: + - {person_id: 'P1', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'SUPD', measure_name: 'Statin Use in Persons with Diabetes', measure_version: '2023', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__value_sets') + rows: + - {code: '00378555501', code_system: 'ndc', concept_name: 'statin therapy'} + - input: ref('quality_measures__stg_pharmacy_claim') + rows: + - {person_id: 'P1', dispensing_date: '2023-06-15', ndc_code: '00378555501', days_supply: 30, paid_date: '2023-06-20', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: [] + + # ========================================================================= + # SUPD - LONG + # ========================================================================= + + - name: test_quality_measures_supd_long_combines_flags + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: quality_measures__int_supd_long + description: "SUPD long combines denominator, numerator, and exclusion flags per patient" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__int_supd_denominator') + rows: + - {person_id: 'P1', performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'SUPD', measure_name: 'Statin Use in Persons with Diabetes', measure_version: '2023', denominator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_supd_numerator') + rows: + - {person_id: 'P1', evidence_date: '2023-06-15', evidence_value: null, numerator_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('quality_measures__int_supd_exclusions') + rows: [] + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 1, exclusion_flag: 0, measure_id: 'SUPD'} diff --git a/models/data_marts/readmissions/_gap_unit_tests.yml b/models/data_marts/readmissions/_gap_unit_tests.yml new file mode 100644 index 000000000..82bf83b0d --- /dev/null +++ b/models/data_marts/readmissions/_gap_unit_tests.yml @@ -0,0 +1,167 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # READMISSIONS - STAGING: stg_core__encounter + # ========================================================================= + + - name: test_readmissions_stg_encounter_filters_acute_inpatient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__stg_core__encounter + description: "Staging filters to acute inpatient encounters only" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', encounter_type: 'acute inpatient', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1'} + - {encounter_id: 'E2', person_id: 'P2', encounter_type: 'emergency department', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-01', discharge_disposition_code: '01', facility_npi: 'NPI2', drg_code_type: null, drg_code: null, paid_amount: 500, primary_diagnosis_code: 'J06.9', encounter_source_type: 'claims', data_source: 'src1'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_stg_encounter_filters_all_non_inpatient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__stg_core__encounter + description: "All non-acute-inpatient encounter types are filtered out" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', encounter_type: 'emergency department', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-01', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: null, drg_code: null, paid_amount: 500, primary_diagnosis_code: 'J06.9', encounter_source_type: 'claims', data_source: 'src1'} + - {encounter_id: 'E2', person_id: 'P2', encounter_type: 'outpatient', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-01', discharge_disposition_code: '01', facility_npi: 'NPI2', drg_code_type: null, drg_code: null, paid_amount: 200, primary_diagnosis_code: 'Z00.00', encounter_source_type: 'claims', data_source: 'src1'} + - {encounter_id: 'E3', person_id: 'P3', encounter_type: 'skilled nursing facility', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-10', discharge_disposition_code: '01', facility_npi: 'NPI3', drg_code_type: null, drg_code: null, paid_amount: 8000, primary_diagnosis_code: 'I50.9', encounter_source_type: 'claims', data_source: 'src1'} + expect: + rows: [] + + - name: test_readmissions_stg_encounter_preserves_fields + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__stg_core__encounter + description: "Staging preserves all relevant encounter fields including DRG and paid amount" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', encounter_type: 'acute inpatient', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000.50, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # READMISSIONS - STAGING: stg_core__procedure + # ========================================================================= + + - name: test_readmissions_stg_procedure_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__stg_core__procedure + description: "Staging passes through procedure fields" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__procedure') + rows: + - {encounter_id: 'E1', normalized_code: '0DBN0ZZ', normalized_code_type: 'icd-10-pcs'} + expect: + rows: + - {encounter_id: 'E1', normalized_code: '0DBN0ZZ', normalized_code_type: 'icd-10-pcs', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_stg_procedure_multiple_codes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__stg_core__procedure + description: "Staging passes through multiple procedure records for the same encounter" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__procedure') + rows: + - {encounter_id: 'E1', normalized_code: '0DBN0ZZ', normalized_code_type: 'icd-10-pcs'} + - {encounter_id: 'E1', normalized_code: '0SRA0JZ', normalized_code_type: 'icd-10-pcs'} + - {encounter_id: 'E2', normalized_code: '99213', normalized_code_type: 'hcpcs'} + expect: + rows: + - {encounter_id: 'E1', normalized_code: '0DBN0ZZ', normalized_code_type: 'icd-10-pcs', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E1', normalized_code: '0SRA0JZ', normalized_code_type: 'icd-10-pcs', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', normalized_code: '99213', normalized_code_type: 'hcpcs', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_crude_excludes_overlapping_not_best + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__readmission_crude + description: "Encounters that are not the best in their overlap group are excluded from crude readmission" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P1', admit_date: '2023-06-02', discharge_date: '2023-06-04', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 8000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__encounter_overlap') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', actual_length_of_stay: 4, source_type_priority: 1, completeness_score: 5, overlap_group_id: 'E1', has_overlaps: 1, encounter_rank_in_group: 1, is_best_encounter: 1, selection_reason: 'Selected as best among overlapping encounters'} + - {encounter_id: 'E2', person_id: 'P1', admit_date: '2023-06-02', discharge_date: '2023-06-04', actual_length_of_stay: 2, source_type_priority: 1, completeness_score: 5, overlap_group_id: 'E1', has_overlaps: 1, encounter_rank_in_group: 2, is_best_encounter: 0, selection_reason: 'Not selected - better encounter exists'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', had_readmission_flag: 0, readmit_30_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: encounter_data_quality (APR-DRG) + # ========================================================================= + + - name: test_readmissions_data_quality_valid_apr_drg + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_data_quality + description: "Encounter with valid APR-DRG code does not get invalid_drg_flag" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'apr-drg', drg_code: '302', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__encounter_overlap') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', actual_length_of_stay: 4, source_type_priority: 1, completeness_score: 5, overlap_group_id: 'E1', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1, selection_reason: 'No overlapping encounters'} + - input: ref('terminology__discharge_disposition') + rows: + - {discharge_disposition_code: '01'} + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: + - {apr_drg_code: '302'} + expect: + rows: + - {encounter_id: 'E1', disqualified_encounter_flag: 0, invalid_drg_flag: 0, missing_drg_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_summary_multi_person_no_cross_link + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__readmission_summary + description: "Readmission sequences do not cross patients" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_augmented') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, length_of_stay: 4, index_admission_flag: 1, planned_flag: 0, specialty_cohort: 'Medicine', died_flag: 0, diagnosis_ccs: '226', disqualified_encounter_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-06-10', discharge_date: '2023-06-12', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 8000, length_of_stay: 2, index_admission_flag: 1, planned_flag: 0, specialty_cohort: 'Medicine', died_flag: 0, diagnosis_ccs: '108', disqualified_encounter_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', had_readmission_flag: 0, readmit_30_flag: 0, unplanned_readmit_30_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', had_readmission_flag: 0, readmit_30_flag: 0, unplanned_readmit_30_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/data_marts/readmissions/_unit_tests.yml b/models/data_marts/readmissions/_unit_tests.yml new file mode 100644 index 000000000..c4bd5d020 --- /dev/null +++ b/models/data_marts/readmissions/_unit_tests.yml @@ -0,0 +1,1039 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: encounter_with_ccs + # ========================================================================= + + - name: test_readmissions_encounter_with_ccs_maps_diagnosis + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_with_ccs + description: "Encounter with CCS maps primary diagnosis to CCS category and validates code" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'S72.001A'} + - input: ref('readmissions__icd_10_cm_to_ccs') + rows: + - {icd_10_cm: 'S72.001A', ccs_diagnosis_category: '226'} + expect: + rows: + - {encounter_id: 'E1', primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_encounter_with_ccs_invalid_diagnosis + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_with_ccs + description: "Encounter with unrecognized ICD-10-CM code gets valid_primary_diagnosis_code_flag=0 and null CCS" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'INVALID', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'S72.001A'} + - input: ref('readmissions__icd_10_cm_to_ccs') + rows: + - {icd_10_cm: 'S72.001A', ccs_diagnosis_category: '226'} + expect: + rows: + - {encounter_id: 'E1', primary_diagnosis_code: 'INVALID', valid_primary_diagnosis_code_flag: 0, ccs_diagnosis_category: null, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_encounter_with_ccs_null_diagnosis + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_with_ccs + description: "Encounter with null primary diagnosis code gets valid flag=0 and null CCS" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: null, encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__icd_10_cm') + rows: [] + - input: ref('readmissions__icd_10_cm_to_ccs') + rows: [] + expect: + rows: + - {encounter_id: 'E1', primary_diagnosis_code: null, valid_primary_diagnosis_code_flag: 0, ccs_diagnosis_category: null, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: index_discharge_requirement + # ========================================================================= + + - name: test_readmissions_index_discharge_excludes_invalid_codes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__index_discharge_requirement + description: "Encounters with discharge_disposition_code 02 (transfer), 07 (AMA), or 20 (died) are excluded from index admissions" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-06-01', discharge_date: '2023-06-03', discharge_disposition_code: '02', facility_npi: 'NPI2', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 10000, primary_diagnosis_code: 'I21.0', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E3', person_id: 'P3', admit_date: '2023-06-01', discharge_date: '2023-06-02', discharge_disposition_code: '07', facility_npi: 'NPI3', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 5000, primary_diagnosis_code: 'J18.9', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E4', person_id: 'P4', admit_date: '2023-06-01', discharge_date: '2023-06-10', discharge_disposition_code: '20', facility_npi: 'NPI4', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 25000, primary_diagnosis_code: 'I50.9', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_index_discharge_allows_other_codes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__index_discharge_requirement + description: "Encounters with valid discharge disposition codes other than 02, 07, 20 pass through" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-06-01', discharge_date: '2023-06-03', discharge_disposition_code: '06', facility_npi: 'NPI2', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 10000, primary_diagnosis_code: 'I21.0', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E3', person_id: 'P3', admit_date: '2023-06-01', discharge_date: '2023-06-02', discharge_disposition_code: null, facility_npi: 'NPI3', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 5000, primary_diagnosis_code: 'J18.9', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E3', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: index_time_requirement + # ========================================================================= + + - name: test_readmissions_index_time_requirement_30_day_buffer + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__index_time_requirement + description: "Encounters discharged within 30 days of the max discharge date are excluded" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-12-15', discharge_date: '2023-12-20', discharge_disposition_code: '01', facility_npi: 'NPI2', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 10000, primary_diagnosis_code: 'I21.0', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_index_time_requirement_exactly_30_days + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__index_time_requirement + description: "Encounter discharged exactly 30 days before max qualifies for index time requirement" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-11-01', discharge_date: '2023-11-20', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-12-01', discharge_date: '2023-12-20', discharge_disposition_code: '01', facility_npi: 'NPI2', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 10000, primary_diagnosis_code: 'I21.0', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_index_time_requirement_29_days_excluded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__index_time_requirement + description: "Encounter discharged only 29 days before the max is excluded from time requirement" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-11-01', discharge_date: '2023-11-22', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-12-01', discharge_date: '2023-12-21', discharge_disposition_code: '01', facility_npi: 'NPI2', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 10000, primary_diagnosis_code: 'I21.0', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: [] + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: index_admission + # ========================================================================= + + - name: test_readmissions_index_admission_requires_all_criteria + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__index_admission + description: "Index admissions require passing time, discharge, and not having an exclusion" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-06-01', discharge_date: '2023-06-03', discharge_disposition_code: '01', facility_npi: 'NPI2', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 10000, primary_diagnosis_code: 'I21.0', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__index_time_requirement') + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__index_discharge_requirement') + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__exclusion') + rows: [] + expect: + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_index_admission_excluded_by_exclusion + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__index_admission + description: "Encounter meeting time and discharge requirements is excluded when in exclusion list" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'C50.9', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__index_time_requirement') + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__index_discharge_requirement') + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__exclusion') + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: [] + + - name: test_readmissions_index_admission_fails_time_requirement + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__index_admission + description: "Encounter meeting discharge but not time requirement is excluded from index admissions" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__index_time_requirement') + rows: [] + - input: ref('readmissions__index_discharge_requirement') + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__exclusion') + rows: [] + expect: + rows: [] + + - name: test_readmissions_index_admission_fails_discharge_requirement + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__index_admission + description: "Encounter meeting time but not discharge requirement is excluded from index admissions" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '02', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__index_time_requirement') + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__index_discharge_requirement') + rows: [] + - input: ref('readmissions__exclusion') + rows: [] + expect: + rows: [] + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: exclusion + # ========================================================================= + + - name: test_readmissions_exclusion_filters_excluded_ccs + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__exclusion + description: "Encounters with excluded CCS diagnosis categories are identified" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI2', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 10000, primary_diagnosis_code: 'C50.9', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '11', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__exclusion_ccs_diagnosis_category') + rows: + - {ccs_diagnosis_category: '11'} + expect: + rows: + - {encounter_id: 'E2', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_exclusion_null_ccs_not_excluded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__exclusion + description: "Encounters with null CCS diagnosis category are not excluded" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'INVALID', valid_primary_diagnosis_code_flag: 0, ccs_diagnosis_category: null, tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__exclusion_ccs_diagnosis_category') + rows: + - {ccs_diagnosis_category: '11'} + expect: + rows: [] + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: encounter_overlap + # ========================================================================= + + - name: test_readmissions_encounter_overlap_identifies_best + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_overlap + description: "Overlap model identifies best encounter among overlapping encounters for same person" + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-07-01', discharge_date: '2023-07-03', discharge_disposition_code: '01', facility_npi: 'NPI2', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 5000, primary_diagnosis_code: 'J18.9', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', has_overlaps: 0, is_best_encounter: 1} + - {encounter_id: 'E2', person_id: 'P2', has_overlaps: 0, is_best_encounter: 1} + + - name: test_readmissions_encounter_overlap_collapses_three_way_overlap_without_fanout + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_overlap + description: "Three encounters that all overlap stay in one overlap group and do not fan out" + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P1', admit_date: '2023-06-02', discharge_date: '2023-06-06', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 12000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E3', person_id: 'P1', admit_date: '2023-06-03', discharge_date: '2023-06-07', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 9000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', overlap_group_id: 'E1', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1} + - {encounter_id: 'E2', person_id: 'P1', overlap_group_id: 'E2', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1} + - {encounter_id: 'E3', person_id: 'P1', overlap_group_id: 'E3', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1} + + - name: test_readmissions_encounter_overlap_multi_person_isolation + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_overlap + description: "Overlap groups do not cross patients; overlapping encounters for different persons are independent" + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P1', admit_date: '2023-06-03', discharge_date: '2023-06-07', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 12000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E3', person_id: 'P2', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'I21.0', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E4', person_id: 'P2', admit_date: '2023-06-03', discharge_date: '2023-06-07', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 10000, primary_diagnosis_code: 'I21.0', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', has_overlaps: 0, is_best_encounter: 1} + - {encounter_id: 'E2', person_id: 'P1', has_overlaps: 0, is_best_encounter: 1} + - {encounter_id: 'E3', person_id: 'P2', has_overlaps: 0, is_best_encounter: 1} + - {encounter_id: 'E4', person_id: 'P2', has_overlaps: 0, is_best_encounter: 1} + + - name: test_readmissions_encounter_overlap_claims_preferred_over_non_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_overlap + description: "Among overlapping encounters, claim source type is preferred over non-claim" + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-03', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'other', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-03', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claim', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', has_overlaps: 1, is_best_encounter: 0} + - {encounter_id: 'E2', person_id: 'P1', has_overlaps: 1, is_best_encounter: 1} + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: procedure_ccs + # ========================================================================= + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: encounter_specialty_cohort + # ========================================================================= + + - name: test_readmissions_specialty_cohort_defaults_medicine + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_specialty_cohort + description: "Encounters without procedure/diagnosis specialty assignments default to Medicine" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__procedure_ccs') + rows: [] + - input: ref('readmissions__surgery_gynecology_cohort') + rows: [] + - input: ref('readmissions__specialty_cohort') + rows: [] + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', specialty_cohort: 'Medicine', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_specialty_cohort_surgery_via_procedure + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_specialty_cohort + description: "Encounter with Surgery/Gynecology procedure code gets Surgery/Gynecology cohort" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__procedure_ccs') + rows: + - {encounter_id: 'E1', procedure_code: '0SRA0JZ', valid_icd_10_pcs_flag: 1, ccs_procedure_category: '152', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__surgery_gynecology_cohort') + rows: + - {icd_10_pcs: '0SRA0JZ'} + - input: ref('readmissions__specialty_cohort') + rows: [] + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', specialty_cohort: 'Surgery/Gynecology', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_specialty_cohort_diagnosis_based + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_specialty_cohort + description: "Encounter with a diagnosis CCS mapped to a specialty cohort gets that cohort" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'I21.0', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__procedure_ccs') + rows: [] + - input: ref('readmissions__surgery_gynecology_cohort') + rows: [] + - input: ref('readmissions__specialty_cohort') + rows: + - {ccs: '100', specialty_cohort: 'Cardiorespiratory', procedure_or_diagnosis: 'Diagnosis'} + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'I21.0', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '100', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', specialty_cohort: 'Cardiorespiratory', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: planned_encounter + # ========================================================================= + + - name: test_readmissions_planned_encounter_always_planned + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__planned_encounter + description: "Encounters with always-planned CCS procedure categories are flagged as planned" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__procedure_ccs') + rows: + - {encounter_id: 'E1', procedure_code: '0DBN0ZZ', valid_icd_10_pcs_flag: 1, ccs_procedure_category: '90', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__always_planned_ccs_procedure_category') + rows: + - {ccs_procedure_category: '90'} + - input: ref('readmissions__always_planned_ccs_diagnosis_category') + rows: [] + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__potentially_planned_ccs_procedure_category') + rows: [] + - input: ref('readmissions__potentially_planned_icd_10_pcs') + rows: [] + - input: ref('readmissions__acute_diagnosis_icd_10_cm') + rows: [] + - input: ref('readmissions__acute_diagnosis_ccs') + rows: [] + expect: + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_planned_encounter_always_planned_dx + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__planned_encounter + description: "Encounters with always-planned CCS diagnosis categories are flagged as planned" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__procedure_ccs') + rows: [] + - input: ref('readmissions__always_planned_ccs_procedure_category') + rows: [] + - input: ref('readmissions__always_planned_ccs_diagnosis_category') + rows: + - {ccs_diagnosis_category: '254'} + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'Z51.11', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '254', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__potentially_planned_ccs_procedure_category') + rows: [] + - input: ref('readmissions__potentially_planned_icd_10_pcs') + rows: [] + - input: ref('readmissions__acute_diagnosis_icd_10_cm') + rows: [] + - input: ref('readmissions__acute_diagnosis_ccs') + rows: [] + expect: + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_planned_encounter_potentially_planned_non_acute + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__planned_encounter + description: "Potentially planned encounter that is NOT acute is confirmed as planned" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__procedure_ccs') + rows: + - {encounter_id: 'E1', procedure_code: '0SRA0JZ', valid_icd_10_pcs_flag: 1, ccs_procedure_category: '152', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__always_planned_ccs_procedure_category') + rows: [] + - input: ref('readmissions__always_planned_ccs_diagnosis_category') + rows: [] + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'M16.11', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '203', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__potentially_planned_ccs_procedure_category') + rows: + - {ccs_procedure_category: '152'} + - input: ref('readmissions__potentially_planned_icd_10_pcs') + rows: [] + - input: ref('readmissions__acute_diagnosis_icd_10_cm') + rows: [] + - input: ref('readmissions__acute_diagnosis_ccs') + rows: [] + expect: + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_planned_encounter_potentially_planned_but_acute + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__planned_encounter + description: "Potentially planned encounter that IS acute is NOT flagged as planned" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__procedure_ccs') + rows: + - {encounter_id: 'E1', procedure_code: '0SRA0JZ', valid_icd_10_pcs_flag: 1, ccs_procedure_category: '152', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__always_planned_ccs_procedure_category') + rows: [] + - input: ref('readmissions__always_planned_ccs_diagnosis_category') + rows: [] + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'I21.0', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '100', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__potentially_planned_ccs_procedure_category') + rows: + - {ccs_procedure_category: '152'} + - input: ref('readmissions__potentially_planned_icd_10_pcs') + rows: [] + - input: ref('readmissions__acute_diagnosis_icd_10_cm') + rows: + - {icd_10_cm: 'I21.0'} + - input: ref('readmissions__acute_diagnosis_ccs') + rows: [] + expect: + rows: [] + + - name: test_readmissions_planned_encounter_not_planned + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__planned_encounter + description: "Encounter with no planned procedure or diagnosis categories is not planned" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__procedure_ccs') + rows: + - {encounter_id: 'E1', procedure_code: '0DBN0ZZ', valid_icd_10_pcs_flag: 1, ccs_procedure_category: '90', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__always_planned_ccs_procedure_category') + rows: [] + - input: ref('readmissions__always_planned_ccs_diagnosis_category') + rows: [] + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__potentially_planned_ccs_procedure_category') + rows: [] + - input: ref('readmissions__potentially_planned_icd_10_pcs') + rows: [] + - input: ref('readmissions__acute_diagnosis_icd_10_cm') + rows: [] + - input: ref('readmissions__acute_diagnosis_ccs') + rows: [] + expect: + rows: [] + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: encounter_data_quality + # ========================================================================= + + - name: test_readmissions_data_quality_flags_missing_admit + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_data_quality + description: "Data quality flags missing admit date and sets disqualified flag" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: null, discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__encounter_overlap') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: null, discharge_date: '2023-06-05', actual_length_of_stay: 1, source_type_priority: 1, completeness_score: 4, overlap_group_id: 'E1', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1, selection_reason: 'No overlapping encounters'} + - input: ref('terminology__discharge_disposition') + rows: + - {discharge_disposition_code: '01'} + - input: ref('terminology__ms_drg') + rows: + - {ms_drg_code: '470'} + - input: ref('terminology__apr_drg') + rows: [] + expect: + rows: + - {encounter_id: 'E1', disqualified_encounter_flag: 1, missing_admit_date_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_data_quality_flags_admit_after_discharge + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_data_quality + description: "Data quality flags admit date after discharge date" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-10', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__encounter_overlap') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-10', discharge_date: '2023-06-05', actual_length_of_stay: 1, source_type_priority: 1, completeness_score: 5, overlap_group_id: 'E1', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1, selection_reason: 'No overlapping encounters'} + - input: ref('terminology__discharge_disposition') + rows: + - {discharge_disposition_code: '01'} + - input: ref('terminology__ms_drg') + rows: + - {ms_drg_code: '470'} + - input: ref('terminology__apr_drg') + rows: [] + expect: + rows: + - {encounter_id: 'E1', disqualified_encounter_flag: 1, admit_after_discharge_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_data_quality_flags_invalid_discharge_disposition + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_data_quality + description: "Data quality flags an invalid discharge disposition code" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: 'XX', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__encounter_overlap') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', actual_length_of_stay: 4, source_type_priority: 1, completeness_score: 5, overlap_group_id: 'E1', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1, selection_reason: 'No overlapping encounters'} + - input: ref('terminology__discharge_disposition') + rows: + - {discharge_disposition_code: '01'} + - input: ref('terminology__ms_drg') + rows: + - {ms_drg_code: '470'} + - input: ref('terminology__apr_drg') + rows: [] + expect: + rows: + - {encounter_id: 'E1', disqualified_encounter_flag: 1, invalid_discharge_disposition_code_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_data_quality_flags_missing_drg + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_data_quality + description: "Data quality flags missing DRG code" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: null, paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__encounter_overlap') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', actual_length_of_stay: 4, source_type_priority: 1, completeness_score: 4, overlap_group_id: 'E1', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1, selection_reason: 'No overlapping encounters'} + - input: ref('terminology__discharge_disposition') + rows: + - {discharge_disposition_code: '01'} + - input: ref('terminology__ms_drg') + rows: [] + - input: ref('terminology__apr_drg') + rows: [] + expect: + rows: + - {encounter_id: 'E1', disqualified_encounter_flag: 1, missing_drg_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_data_quality_clean_encounter + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_data_quality + description: "Clean encounter with all valid fields gets disqualified_encounter_flag=0" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__encounter_overlap') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', actual_length_of_stay: 4, source_type_priority: 1, completeness_score: 5, overlap_group_id: 'E1', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1, selection_reason: 'No overlapping encounters'} + - input: ref('terminology__discharge_disposition') + rows: + - {discharge_disposition_code: '01'} + - input: ref('terminology__ms_drg') + rows: + - {ms_drg_code: '470'} + - input: ref('terminology__apr_drg') + rows: [] + expect: + rows: + - {encounter_id: 'E1', disqualified_encounter_flag: 0, missing_admit_date_flag: 0, missing_discharge_date_flag: 0, admit_after_discharge_flag: 0, missing_discharge_disposition_code_flag: 0, invalid_discharge_disposition_code_flag: 0, missing_primary_diagnosis_flag: 0, invalid_primary_diagnosis_code_flag: 0, no_diagnosis_ccs_flag: 0, overlaps_with_another_encounter_flag: 0, missing_drg_flag: 0, invalid_drg_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_data_quality_flags_overlap + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_data_quality + description: "Encounter that is not best in its overlap group gets overlap flag" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_with_ccs') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', valid_primary_diagnosis_code_flag: 1, ccs_diagnosis_category: '226', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__encounter_overlap') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', actual_length_of_stay: 4, source_type_priority: 1, completeness_score: 5, overlap_group_id: 'E0', has_overlaps: 1, encounter_rank_in_group: 2, is_best_encounter: 0, selection_reason: 'Not selected - better encounter exists'} + - input: ref('terminology__discharge_disposition') + rows: + - {discharge_disposition_code: '01'} + - input: ref('terminology__ms_drg') + rows: + - {ms_drg_code: '470'} + - input: ref('terminology__apr_drg') + rows: [] + expect: + rows: + - {encounter_id: 'E1', disqualified_encounter_flag: 1, overlaps_with_another_encounter_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # READMISSIONS - INTERMEDIATE: readmission_crude + # ========================================================================= + + - name: test_readmissions_crude_flags_30_day_readmit + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__readmission_crude + description: "Crude readmission flags encounters with a subsequent admission within 30 days" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P1', admit_date: '2023-06-20', discharge_date: '2023-06-22', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 8000, primary_diagnosis_code: 'I50.9', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__encounter_overlap') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', actual_length_of_stay: 4, source_type_priority: 1, completeness_score: 5, overlap_group_id: 'E1', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1, selection_reason: 'No overlapping encounters'} + - {encounter_id: 'E2', person_id: 'P1', admit_date: '2023-06-20', discharge_date: '2023-06-22', actual_length_of_stay: 2, source_type_priority: 1, completeness_score: 5, overlap_group_id: 'E2', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1, selection_reason: 'No overlapping encounters'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', had_readmission_flag: 1, readmit_30_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P1', had_readmission_flag: 0, readmit_30_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_crude_different_persons_not_linked + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__readmission_crude + description: "Encounters for different patients are not linked as readmissions" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-06-10', discharge_date: '2023-06-12', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 8000, primary_diagnosis_code: 'I50.9', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__encounter_overlap') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', actual_length_of_stay: 4, source_type_priority: 1, completeness_score: 5, overlap_group_id: 'E1', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1, selection_reason: 'No overlapping encounters'} + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-06-10', discharge_date: '2023-06-12', actual_length_of_stay: 2, source_type_priority: 1, completeness_score: 5, overlap_group_id: 'E2', has_overlaps: 0, encounter_rank_in_group: 1, is_best_encounter: 1, selection_reason: 'No overlapping encounters'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', had_readmission_flag: 0, readmit_30_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P2', had_readmission_flag: 0, readmit_30_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # READMISSIONS - FINAL: encounter_augmented + # ========================================================================= + + - name: test_readmissions_encounter_augmented_flags + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_augmented + description: "Encounter augmented model joins index admission, planned, specialty cohort and data quality flags" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__index_admission') + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__planned_encounter') + rows: [] + - input: ref('readmissions__encounter_specialty_cohort') + rows: + - {encounter_id: 'E1', specialty_cohort: 'Surgical/Gynecology'} + - input: ref('readmissions__encounter_data_quality') + rows: + - {encounter_id: 'E1', diagnosis_ccs: '226', disqualified_encounter_flag: 0, missing_admit_date_flag: 0, missing_discharge_date_flag: 0, admit_after_discharge_flag: 0, missing_discharge_disposition_code_flag: 0, invalid_discharge_disposition_code_flag: 0, missing_primary_diagnosis_flag: 0, invalid_primary_diagnosis_code_flag: 0, no_diagnosis_ccs_flag: 0, overlaps_with_another_encounter_flag: 0, missing_drg_flag: 0, invalid_drg_flag: 0} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', index_admission_flag: 1, planned_flag: 0, specialty_cohort: 'Surgical/Gynecology', died_flag: 0, disqualified_encounter_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_encounter_augmented_minimum_los_is_one + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_augmented + description: "Same-day admit and discharge still produce a minimum length_of_stay of 1" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E2', person_id: 'P2', admit_date: '2023-06-01', discharge_date: '2023-06-01', discharge_disposition_code: '01', facility_npi: 'NPI2', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 8000, primary_diagnosis_code: 'I50.9', encounter_source_type: 'claims', data_source: 'src1'} + - input: ref('readmissions__index_admission') + rows: [] + - input: ref('readmissions__planned_encounter') + rows: [] + - input: ref('readmissions__encounter_specialty_cohort') + rows: [] + - input: ref('readmissions__encounter_data_quality') + rows: [] + expect: + rows: + - {encounter_id: 'E2', person_id: 'P2', length_of_stay: 1, index_admission_flag: 0, planned_flag: 0, died_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_encounter_augmented_died_flag + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_augmented + description: "Encounter with discharge_disposition_code 20 gets died_flag=1" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-10', discharge_disposition_code: '20', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 25000, primary_diagnosis_code: 'I50.9', encounter_source_type: 'claims', data_source: 'src1'} + - input: ref('readmissions__index_admission') + rows: [] + - input: ref('readmissions__planned_encounter') + rows: [] + - input: ref('readmissions__encounter_specialty_cohort') + rows: [] + - input: ref('readmissions__encounter_data_quality') + rows: [] + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', died_flag: 1, index_admission_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_encounter_augmented_planned_flag + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_augmented + description: "Encounter listed in planned_encounter table gets planned_flag=1" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'M16.11', encounter_source_type: 'claims', data_source: 'src1'} + - input: ref('readmissions__index_admission') + rows: [] + - input: ref('readmissions__planned_encounter') + rows: + - {encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('readmissions__encounter_specialty_cohort') + rows: + - {encounter_id: 'E1', specialty_cohort: 'Surgery/Gynecology'} + - input: ref('readmissions__encounter_data_quality') + rows: + - {encounter_id: 'E1', diagnosis_ccs: '203', disqualified_encounter_flag: 0, missing_admit_date_flag: 0, missing_discharge_date_flag: 0, admit_after_discharge_flag: 0, missing_discharge_disposition_code_flag: 0, invalid_discharge_disposition_code_flag: 0, missing_primary_diagnosis_flag: 0, invalid_primary_diagnosis_code_flag: 0, no_diagnosis_ccs_flag: 0, overlaps_with_another_encounter_flag: 0, missing_drg_flag: 0, invalid_drg_flag: 0} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', planned_flag: 1, index_admission_flag: 0, specialty_cohort: 'Surgery/Gynecology', died_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_encounter_augmented_multi_day_los + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__encounter_augmented + description: "Multi-day encounter correctly computes length_of_stay as datediff" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-10', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, primary_diagnosis_code: 'S72.001A', encounter_source_type: 'claims', data_source: 'src1'} + - input: ref('readmissions__index_admission') + rows: [] + - input: ref('readmissions__planned_encounter') + rows: [] + - input: ref('readmissions__encounter_specialty_cohort') + rows: [] + - input: ref('readmissions__encounter_data_quality') + rows: [] + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', length_of_stay: 9, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # READMISSIONS - FINAL: readmission_summary + # ========================================================================= + + - name: test_readmissions_summary_computes_readmission_flags + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__readmission_summary + description: "Readmission summary sequences non-disqualified encounters and computes readmission flags" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_augmented') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, length_of_stay: 4, index_admission_flag: 1, planned_flag: 0, specialty_cohort: 'Medicine', died_flag: 0, diagnosis_ccs: '226', disqualified_encounter_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', had_readmission_flag: 0, readmit_30_flag: 0, unplanned_readmit_30_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_summary_unplanned_readmit_30 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__readmission_summary + description: "Readmission summary flags unplanned 30-day readmission when next encounter is within 30 days and unplanned" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_augmented') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, length_of_stay: 4, index_admission_flag: 1, planned_flag: 0, specialty_cohort: 'Medicine', died_flag: 0, diagnosis_ccs: '226', disqualified_encounter_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P1', admit_date: '2023-06-20', discharge_date: '2023-06-22', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 8000, length_of_stay: 2, index_admission_flag: 0, planned_flag: 0, specialty_cohort: 'Medicine', died_flag: 0, diagnosis_ccs: '108', disqualified_encounter_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', had_readmission_flag: 1, readmit_30_flag: 1, unplanned_readmit_30_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P1', had_readmission_flag: 0, readmit_30_flag: 0, unplanned_readmit_30_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_summary_planned_readmit_30 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__readmission_summary + description: "Planned 30-day readmission gets readmit_30_flag=1 but unplanned_readmit_30_flag=0" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_augmented') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, length_of_stay: 4, index_admission_flag: 1, planned_flag: 0, specialty_cohort: 'Medicine', died_flag: 0, diagnosis_ccs: '226', disqualified_encounter_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P1', admit_date: '2023-06-20', discharge_date: '2023-06-22', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 8000, length_of_stay: 2, index_admission_flag: 0, planned_flag: 1, specialty_cohort: 'Surgery/Gynecology', died_flag: 0, diagnosis_ccs: '203', disqualified_encounter_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', had_readmission_flag: 1, readmit_30_flag: 1, unplanned_readmit_30_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E2', person_id: 'P1', had_readmission_flag: 0, readmit_30_flag: 0, unplanned_readmit_30_flag: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_summary_disqualified_excluded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: readmissions__readmission_summary + description: "Disqualified encounters are excluded from readmission summary" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__encounter_augmented') + rows: + - {encounter_id: 'E1', person_id: 'P1', admit_date: '2023-06-01', discharge_date: '2023-06-05', discharge_disposition_code: '01', facility_npi: 'NPI1', drg_code_type: 'ms-drg', drg_code: '470', paid_amount: 15000, length_of_stay: 4, index_admission_flag: 1, planned_flag: 0, specialty_cohort: 'Medicine', died_flag: 0, diagnosis_ccs: '226', disqualified_encounter_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: [] diff --git a/models/data_marts/semantic_layer/_unit_tests.yml b/models/data_marts/semantic_layer/_unit_tests.yml new file mode 100644 index 000000000..34151d6b9 --- /dev/null +++ b/models/data_marts/semantic_layer/_unit_tests.yml @@ -0,0 +1,92 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # SEMANTIC LAYER - DIMENSION: dim_encounter_group + # ========================================================================= + + - name: test_semantic_layer_dim_encounter_group_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__dim_encounter_group + description: "Encounter group dimension passes through data from seed with tuva_last_run appended" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounter_group_sk') + rows: + - {encounter_group_sk: 'sk1', encounter_group: 'inpatient'} + - {encounter_group_sk: 'sk2', encounter_group: 'outpatient'} + expect: + rows: + - {encounter_group_sk: 'sk1', encounter_group: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_group_sk: 'sk2', encounter_group: 'outpatient', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # SEMANTIC LAYER - DIMENSION: dim_encounter_type + # ========================================================================= + + - name: test_semantic_layer_dim_encounter_type_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__dim_encounter_type + description: "Encounter type dimension passes through seed data with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounter_type_sk') + rows: + - {encounter_type_sk: 'sk1', encounter_type: 'acute inpatient'} + expect: + rows: + - {encounter_type_sk: 'sk1', encounter_type: 'acute inpatient', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # SEMANTIC LAYER - DIMENSION: dim_service_category + # ========================================================================= + + - name: test_semantic_layer_dim_service_category_distinct + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__dim_service_category + description: "Service category dimension produces distinct service category combinations with surrogate key" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('service_category__service_categories') + rows: + - {service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: null} + - {service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: null} + - {service_category_1: 'outpatient', service_category_2: 'emergency department', service_category_3: null} + expect: + rows: + - {service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: null, tuva_last_run: '2024-01-01 00:00:00'} + - {service_category_1: 'outpatient', service_category_2: 'emergency department', service_category_3: null, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # SEMANTIC LAYER - FACT: fact_encounter_service_bridge + # ========================================================================= + + - name: test_semantic_layer_fact_encounter_service_bridge_distinct + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__fact_encounter_service_bridge + description: "Encounter service bridge selects distinct encounter_id and service_category_sk from fact_claims" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('semantic_layer__fact_claims') + rows: + - {encounter_id: 'E1', service_category_sk: 'sk1', medical_claim_id: 'MC1'} + - {encounter_id: 'E1', service_category_sk: 'sk1', medical_claim_id: 'MC2'} + - {encounter_id: 'E1', service_category_sk: 'sk2', medical_claim_id: 'MC3'} + expect: + rows: + - {encounter_id: 'E1', service_category_sk: 'sk1', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_id: 'E1', service_category_sk: 'sk2', tuva_last_run: '2024-01-01 00:00:00'} + diff --git a/models/data_marts/semantic_layer/semantic_layer_gap_unit_tests.yml b/models/data_marts/semantic_layer/semantic_layer_gap_unit_tests.yml new file mode 100644 index 000000000..84ff9c10e --- /dev/null +++ b/models/data_marts/semantic_layer/semantic_layer_gap_unit_tests.yml @@ -0,0 +1,423 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGING: stg_ahrq_measures__pqi_summary + # ========================================================================= + + - name: test_semantic_layer_stg_ahrq_pqi_summary_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_ahrq_measures__pqi_summary + description: "PQI summary staging passes through pqi_number, pqi_name, encounter_id and appends tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ahrq_measures__pqi_summary') + rows: + - {pqi_number: 'PQI01', pqi_name: 'Diabetes Short-Term Complications', encounter_id: 'E1'} + expect: + rows: + - {pqi_number: 'PQI01', pqi_name: 'Diabetes Short-Term Complications', encounter_id: 'E1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_chronic_conditions__tuva_chronic_conditions_long + # ========================================================================= + + - name: test_semantic_layer_stg_chronic_conditions_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_chronic_conditions__tuva_chronic_conditions_long + description: "Chronic conditions staging passes through person_id and condition with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('chronic_conditions__tuva_chronic_conditions_long') + rows: + - {person_id: 'P1', condition: 'Diabetes Mellitus'} + expect: + rows: + - {person_id: 'P1', condition: 'Diabetes Mellitus', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_semantic_layer_stg_chronic_conditions_multiple + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_chronic_conditions__tuva_chronic_conditions_long + description: "Chronic conditions staging handles multiple conditions per patient" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('chronic_conditions__tuva_chronic_conditions_long') + rows: + - {person_id: 'P1', condition: 'Diabetes Mellitus'} + - {person_id: 'P1', condition: 'Hypertension'} + - {person_id: 'P2', condition: 'COPD'} + expect: + rows: + - {person_id: 'P1', condition: 'Diabetes Mellitus', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', condition: 'Hypertension', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', condition: 'COPD', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_cms_hcc__patient_risk_factors + # ========================================================================= + + - name: test_semantic_layer_stg_risk_factors_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_cms_hcc__patient_risk_factors + description: "Risk factors staging passes through all columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__patient_risk_factors') + rows: + - {person_id: 'P1', factor_type: 'disease', risk_factor_description: 'HCC19', coefficient: 0.302, model_version: 'V24', payment_year: 2024} + expect: + rows: + - {person_id: 'P1', factor_type: 'disease', risk_factor_description: 'HCC19', coefficient: 0.302, model_version: 'V24', payment_year: 2024, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_cms_hcc__patient_risk_scores + # ========================================================================= + + - name: test_semantic_layer_stg_risk_scores_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_cms_hcc__patient_risk_scores + description: "Risk scores staging passes through all columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__patient_risk_scores') + rows: + - {person_id: 'P1', v24_risk_score: 1.5, v28_risk_score: 1.3, blended_risk_score: 1.4, normalized_risk_score: 1.4, payment_risk_score: 1.4, payment_risk_score_weighted_by_months: 14.0, member_months: 10, payment_year: 2024} + expect: + rows: + - {person_id: 'P1', v24_risk_score: 1.5, v28_risk_score: 1.3, blended_risk_score: 1.4, normalized_risk_score: 1.4, payment_risk_score: 1.4, payment_risk_score_weighted_by_months: 14.0, member_months: 10, payment_year: 2024, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_cms_hcc__patient_risk_scores_monthly + # ========================================================================= + + - name: test_semantic_layer_stg_risk_scores_monthly_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_cms_hcc__patient_risk_scores_monthly + description: "Monthly risk scores staging passes through columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__patient_risk_scores_monthly') + rows: + - {collection_end_date: '2024-03-31', person_id: 'P1', normalized_risk_score: 1.25} + expect: + rows: + - {collection_end_date: '2024-03-31', person_id: 'P1', normalized_risk_score: 1.25, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_core__eligibility + # ========================================================================= + + - name: test_semantic_layer_stg_eligibility_distinct_data_source + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_core__eligibility + description: "Eligibility staging selects distinct data_source values" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__eligibility') + rows: + - {data_source: 'src1', person_id: 'P1'} + - {data_source: 'src1', person_id: 'P2'} + - {data_source: 'src2', person_id: 'P3'} + expect: + rows: + - {data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {data_source: 'src2', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_core__member_months + # ========================================================================= + + - name: test_semantic_layer_stg_member_months_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_core__member_months + description: "Member months staging passes through key columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', data_source: 'src1', year_month: '202301', payer: 'MCR', plan: 'PlanA', payer_attributed_provider: null, payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: null, custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null} + expect: + rows: + - {person_id: 'P1', data_source: 'src1', year_month: '202301', payer: 'MCR', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_core__patient + # ========================================================================= + + - name: test_semantic_layer_stg_patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_core__patient + description: "Patient staging passes through all core patient columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', name_suffix: null, first_name: 'John', middle_name: null, last_name: 'Doe', sex: 'male', race: 'white', birth_date: '1960-01-01', death_date: null, death_flag: 0, address: '123 Main', city: 'Town', state: 'CA', zip_code: '90210', county: 'LA', latitude: 34.0, longitude: -118.0, phone: '5551234567', email: null, ethnicity: null, data_source: 'src1', age: 64, age_group: '60-69'} + expect: + rows: + - {person_id: 'P1', first_name: 'John', last_name: 'Doe', sex: 'male', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_core__pharmacy_claim + # ========================================================================= + + - name: test_semantic_layer_stg_pharmacy_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_core__pharmacy_claim + description: "Pharmacy claim staging passes through key columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__pharmacy_claim') + rows: + - {claim_id: 'C1', claim_line_number: 1, person_id: 'P1', data_source: 'src1', ndc_code: '00000000001', paid_amount: 50.00, allowed_amount: 60.00, prescribing_provider_id: 'NPI1', prescribing_provider_name: 'Dr Smith', dispensing_provider_id: 'NPI2', dispensing_provider_name: 'Pharmacy A', paid_date: '2023-06-15', dispensing_date: '2023-06-14', days_supply: 30, quantity: 30} + expect: + rows: + - {claim_id: 'C1', claim_line_number: 1, person_id: 'P1', ndc_code: '00000000001', paid_amount: 50.00, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_core__practitioner + # ========================================================================= + + - name: test_semantic_layer_stg_practitioner_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_core__practitioner + description: "Practitioner staging passes through npi, specialty, practitioner_id with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__practitioner') + rows: + - {npi: '1234567890', specialty: 'Internal Medicine', practitioner_id: 'PRAC1'} + expect: + rows: + - {npi: '1234567890', specialty: 'Internal Medicine', practitioner_id: 'PRAC1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_ed_classification__summary + # ========================================================================= + + - name: test_semantic_layer_stg_ed_classification_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_ed_classification__summary + description: "ED classification staging passes through encounter_id, person_id, ed classification columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ed_classification__summary') + rows: + - {encounter_id: 'E1', person_id: 'P1', ed_classification_order: 1, ed_classification_description: 'Non-Emergent'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', ed_classification_order: 1, ed_classification_description: 'Non-Emergent', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_financial_pmpm__pmpm_prep + # ========================================================================= + + - name: test_semantic_layer_stg_pmpm_prep_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_financial_pmpm__pmpm_prep + description: "PMPM prep staging passes through cost columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('financial_pmpm__pmpm_prep') + rows: + - {person_id: 'P1', year_month: '202301', data_source: 'src1', inpatient_paid: 1000, outpatient_paid: 500, office_based_paid: 200, ancillary_paid: 0, other_paid: 0, pharmacy_paid: 100, acute_inpatient_paid: 1000, ambulance_paid: 0, ambulatory_surgery_center_paid: 0, dialysis_paid: 0, durable_medical_equipment_paid: 0, emergency_department_paid: 0, home_health_paid: 0, inpatient_hospice_paid: 0, inpatient_psychiatric_paid: 0, inpatient_rehabilitation_paid: 0, lab_paid: 0, observation_paid: 0, office_based_other_paid: 0, office_based_pt_ot_st_paid: 0, office_based_radiology_paid: 0, office_based_surgery_paid: 0, office_based_visit_paid: 200, outpatient_hospice_paid: 0, outpatient_hospital_or_clinic_paid: 0, outpatient_pt_ot_st_paid: 0, outpatient_psychiatric_paid: 0, outpatient_radiology_paid: 0, outpatient_rehabilitation_paid: 0, outpatient_surgery_paid: 0, skilled_nursing_paid: 0, telehealth_visit_paid: 0, urgent_care_paid: 0, inpatient_allowed: 1200, outpatient_allowed: 600, office_based_allowed: 250, ancillary_allowed: 0, other_allowed: 0, pharmacy_allowed: 120, acute_inpatient_allowed: 1200, ambulance_allowed: 0, ambulatory_surgery_center_allowed: 0, dialysis_allowed: 0, durable_medical_equipment_allowed: 0, emergency_department_allowed: 0, home_health_allowed: 0, inpatient_hospice_allowed: 0, inpatient_psychiatric_allowed: 0, inpatient_rehabilitation_allowed: 0, lab_allowed: 0, observation_allowed: 0, office_based_other_allowed: 0, office_based_pt_ot_st_allowed: 0, office_based_radiology_allowed: 0, office_based_surgery_allowed: 0, office_based_visit_allowed: 250, outpatient_hospice_allowed: 0, outpatient_hospital_or_clinic_allowed: 0, outpatient_pt_ot_st_allowed: 0, outpatient_psychiatric_allowed: 0, outpatient_radiology_allowed: 0, outpatient_rehabilitation_allowed: 0, outpatient_surgery_allowed: 0, skilled_nursing_allowed: 0, telehealth_visit_allowed: 0, urgent_care_allowed: 0, total_paid: 1800, medical_paid: 1700, total_allowed: 2170, medical_allowed: 2050} + expect: + rows: + - {person_id: 'P1', year_month: '202301', data_source: 'src1', inpatient_paid: 1000, total_paid: 1800, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_hcc_suspecting__list_rollup + # ========================================================================= + + - name: test_semantic_layer_stg_hcc_suspecting_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_hcc_suspecting__list_rollup + description: "HCC suspecting staging passes through all columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('hcc_suspecting__list_rollup') + rows: + - {person_id: 'P1', hcc_code: 'HCC19', hcc_description: 'Diabetes', reason: 'Historical', contributing_factor: 'E11.65', latest_suspect_date: '2023-12-01'} + expect: + rows: + - {person_id: 'P1', hcc_code: 'HCC19', hcc_description: 'Diabetes', reason: 'Historical', contributing_factor: 'E11.65', latest_suspect_date: '2023-12-01', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_pharmacy__pharmacy_claim_expanded + # ========================================================================= + + - name: test_semantic_layer_stg_pharmacy_expanded_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_pharmacy__pharmacy_claim_expanded + description: "Pharmacy claim expanded staging passes through columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy__pharmacy_claim_expanded') + rows: + - {data_source: 'src1', claim_id: 'C1', claim_line_number: 1, generic_available_total_opportunity: 100.00, generic_average_cost_per_unit: 1.50, brand_cost_per_unit: 5.00, generic_available: 'yes', generic_available_sk: 'sk1'} + expect: + rows: + - {data_source: 'src1', claim_id: 'C1', claim_line_number: 1, generic_available: 'yes', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_quality_measures__summary_long + # ========================================================================= + + - name: test_semantic_layer_stg_quality_measures_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_quality_measures__summary_long + description: "Quality measures staging passes through all columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__summary_long') + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 0, exclusion_flag: 0, performance_flag: 0, evidence_date: '2023-06-15', evidence_value: null, exclusion_date: null, exclusion_reason: null, performance_period_begin: '2023-01-01', performance_period_end: '2023-12-31', measure_id: 'NQF0059', measure_name: 'Diabetes HbA1c', measure_version: '2023'} + expect: + rows: + - {person_id: 'P1', denominator_flag: 1, numerator_flag: 0, measure_id: 'NQF0059', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_readmissions__readmission_summary + # ========================================================================= + + - name: test_semantic_layer_stg_readmission_summary_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_readmissions__readmission_summary + description: "Readmission summary staging passes through all columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__readmission_summary') + rows: + - {encounter_id: 'E1', index_admission_flag: 1, had_readmission_flag: 1, planned_flag: 0, readmit_30_flag: 1, unplanned_readmit_30_flag: 1, readmission_encounter_id: 'E2', days_to_readmit: 14, readmission_admit_date: '2023-07-01', readmission_discharge_date: '2023-07-05', readmission_discharge_disposition_code: '01', readmission_facility: 'Hospital A', readmission_drg_code_type: 'ms-drg', readmission_drg: '470', readmission_length_of_stay: 4, readmission_index_admission_flag: 0, readmission_planned_flag: 0, readmission_specialty_cohort: 'medicine', readmission_died_flag: 0, readmission_diagnosis_ccs: '108'} + expect: + rows: + - {encounter_id: 'E1', index_admission_flag: 1, had_readmission_flag: 1, readmit_30_flag: 1, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_readmissions__encounter_augmented + # ========================================================================= + + - name: test_semantic_layer_stg_encounter_augmented_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_readmissions__encounter_augmented + description: "Encounter augmented staging passes through encounter data from readmissions" + given: + - input: ref('readmissions__encounter_augmented') + rows: + - {encounter_id: 'E1', person_id: 'P1'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1'} + + # ========================================================================= + # STAGING: stg_reference_data__calendar + # ========================================================================= + + - name: test_semantic_layer_stg_calendar_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_reference_data__calendar + description: "Calendar staging passes through all columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-03-15', year: 2023, month: 3, day: 15, month_name: 'March', day_of_week_number: 4, day_of_week_name: 'Wednesday', week_of_year: 11, day_of_year: 74, year_month: '2023-03', first_day_of_month: '2023-03-01', last_day_of_month: '2023-03-31', year_month_int: 202303} + expect: + rows: + - {full_date: '2023-03-15', year: 2023, month: 3, day: 15, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_core__encounter + # ========================================================================= + + - name: test_semantic_layer_stg_encounter_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_core__encounter + description: "Encounter staging passes through all core encounter columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', person_id: 'P1', encounter_type: 'acute inpatient', encounter_group: 'inpatient', encounter_start_date: '2023-06-10', encounter_end_date: '2023-06-15', length_of_stay: 5, admit_source_code: '1', admit_source_description: 'Physician Referral', admit_type_code: '1', admit_type_description: 'Emergency', discharge_disposition_code: '01', discharge_disposition_description: 'Home', attending_provider_id: 'NPI1', attending_provider_name: 'Dr Smith', facility_npi: 'FAC1', facility_name: 'Hospital A', facility_type: 'acute care hospital', observation_flag: 0, lab_flag: 0, dme_flag: 0, ambulance_flag: 0, pharmacy_flag: 0, ed_flag: 0, delivery_flag: 0, delivery_type: null, newborn_flag: 0, nicu_flag: 0, snf_part_b_flag: 0, primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'I2510', primary_diagnosis_description: 'ASCVD', drg_code_type: 'ms-drg', drg_code: '470', drg_description: 'Major joint replacement', paid_amount: 25000, allowed_amount: 30000, charge_amount: 50000, claim_count: 2, inst_claim_count: 1, prof_claim_count: 1, source_model: 'tuva', data_source: 'src1', encounter_source_type: 'claims'} + expect: + rows: + - {encounter_id: 'E1', person_id: 'P1', encounter_type: 'acute inpatient', encounter_group: 'inpatient', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # STAGING: stg_core__medical_claim + # ========================================================================= + + - name: test_semantic_layer_stg_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: semantic_layer__stg_core__medical_claim + description: "Medical claim staging passes through all columns with tuva_last_run" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__medical_claim') + rows: + - {medical_claim_id: 'MC1', encounter_id: 'E1', person_id: 'P1', claim_id: 'C1', claim_line_number: 1, claim_type: 'institutional', payer: 'MCR', plan: 'PlanA', claim_start_date: '2023-06-10', claim_end_date: '2023-06-15', claim_line_start_date: '2023-06-10', claim_line_end_date: '2023-06-15', admission_date: '2023-06-10', discharge_date: '2023-06-15', admit_source_code: '1', admit_source_description: null, admit_type_code: '1', admit_type_description: null, discharge_disposition_code: '01', discharge_disposition_description: null, place_of_service_code: '21', place_of_service_description: null, bill_type_code: '111', bill_type_description: null, drg_code_type: null, drg_code: null, drg_description: null, revenue_center_code: '0100', revenue_center_description: null, service_unit_quantity: 1, hcpcs_code: '99213', hcpcs_modifier_1: null, hcpcs_modifier_2: null, hcpcs_modifier_3: null, hcpcs_modifier_4: null, hcpcs_modifier_5: null, rendering_npi: 'NPI1', rendering_tin: null, rendering_name: null, billing_npi: 'NPI2', billing_tin: null, billing_name: null, facility_npi: 'FAC1', facility_name: null, paid_date: '2023-07-01', paid_amount: 500, allowed_amount: 600, charge_amount: 1000, coinsurance_amount: 0, copayment_amount: 0, deductible_amount: 0, total_cost_amount: 500, in_network_flag: 1, data_source: 'src1', service_category_1: 'inpatient', service_category_2: 'acute inpatient', service_category_3: null, enrollment_flag: 1} + expect: + rows: + - {medical_claim_id: 'MC1', person_id: 'P1', claim_id: 'C1', claim_start_date: '2023-06-10', tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/data_quality/data_quality_gap_unit_tests.yml b/models/data_quality/data_quality_gap_unit_tests.yml new file mode 100644 index 000000000..0b6f1242d --- /dev/null +++ b/models/data_quality/data_quality_gap_unit_tests.yml @@ -0,0 +1,727 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGE MODELS + # ========================================================================= + + - name: test_eligibility_dq_stage_expands_spans_to_months + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_dq_stage + description: > + Expands eligibility enrollment spans into monthly rows by + joining to a calendar table. A span covering Jan-Mar 2023 + produces three monthly rows. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-03-31', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - input: ref('reference_data__calendar') + rows: + - {year_month_int: 202301, full_date: '2023-01-01'} + - {year_month_int: 202301, full_date: '2023-01-31'} + - {year_month_int: 202302, full_date: '2023-02-01'} + - {year_month_int: 202302, full_date: '2023-02-28'} + - {year_month_int: 202303, full_date: '2023-03-01'} + - {year_month_int: 202303, full_date: '2023-03-31'} + expect: + rows: + - {person_id: 'P1', year_month: 202301, month_start_date: '2023-01-01', month_end_date: '2023-01-31', payer: 'MCR', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', year_month: 202302, month_start_date: '2023-02-01', month_end_date: '2023-02-28', payer: 'MCR', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', year_month: 202303, month_start_date: '2023-03-01', month_end_date: '2023-03-31', payer: 'MCR', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS + # ========================================================================= + + - name: test_eligibility_missing_person_id_detects_nulls_and_blanks + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_missing_person_id + description: > + Counts eligibility spans where person_id is null or blank. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('input_layer__eligibility') + rows: + - {member_id: 'M1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA', person_id: 'P1'} + - {member_id: 'M2', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA', person_id: null} + - {member_id: 'M3', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA', person_id: ''} + expect: + rows: + - {data_quality_check: 'Missing person_id', result_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_eligibility_missing_payer_detects_missing + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_missing_payer + description: > + Detects eligibility spans with missing payer_type, missing + payer name, and invalid payer_type values. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('input_layer__eligibility') + rows: + - {member_id: 'M1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA', payer_type: 'commercial'} + - {member_id: 'M2', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: null, plan: 'PlanB', payer_type: null} + - {member_id: 'M3', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'Aetna', plan: 'PlanC', payer_type: 'INVALID_TYPE'} + - input: ref('terminology__payer_type') + rows: + - {payer_type: 'commercial'} + expect: + rows: + - {data_quality_check: 'Missing payer type', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'Missing payer name', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'Payer type does not join to terminology table', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_medical_claim_person_id_missing_and_orphaned + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__medical_claim_person_id + description: > + Detects medical claims with missing person_id, multiple + person_ids per claim, and orphaned claims without matching + eligibility. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1', person_id: 'P1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-15'} + - {claim_id: 'MC2', person_id: null, claim_start_date: '2023-06-01', claim_end_date: '2023-06-15'} + - {claim_id: 'MC3', person_id: 'P99', claim_start_date: '2023-06-01', claim_end_date: '2023-06-15'} + - input: ref('data_quality__eligibility_dq_stage') + rows: + - {person_id: 'P1', month_start_date: '2023-06-01', month_end_date: '2023-06-30'} + expect: + rows: + - {data_quality_check: 'multiple medical_claim person_ids', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing medical_claim person_id', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'orphaned medical_claim claims', result_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_medical_claim_inst_header_fields_missing_and_invalid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__medical_claim_inst_header_fields + description: > + Detects missing and invalid bill_type_code, drg_code, and + discharge_disposition_code on institutional claims. DRG checks + only apply to inpatient claims (joined to inpatient_dq_stage). + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1', claim_type: 'institutional', bill_type_code: '111', discharge_disposition_code: '01', drg_code: '470', drg_code_type: 'ms-drg'} + - {claim_id: 'MC2', claim_type: 'institutional', bill_type_code: null, discharge_disposition_code: null, drg_code: null, drg_code_type: null} + - {claim_id: 'MC3', claim_type: 'institutional', bill_type_code: 'INVALID', discharge_disposition_code: 'INVALID', drg_code: 'INVALID', drg_code_type: 'ms-drg'} + - input: ref('data_quality__inpatient_dq_stage') + rows: + - {claim_id: 'MC1', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'MC3', tuva_last_run: '2024-01-01 00:00:00'} + - input: ref('terminology__bill_type') + rows: + - {bill_type_code: '111'} + - input: ref('terminology__ms_drg') + rows: + - {ms_drg_code: '470', ms_drg_description: 'Major Joint'} + - input: ref('terminology__apr_drg') + rows: [] + - input: ref('terminology__discharge_disposition') + rows: + - {discharge_disposition_code: '01'} + expect: + rows: + - {data_quality_check: 'invalid bill_type_code', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'invalid drg_code', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'invalid discharge_disposition_code', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing bill_type_code', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing drg_code', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing discharge_disposition_code', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'bill_type_code multiple', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'drg_code multiple', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'discharge_disposition_code multiple', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_chronic_conditions_none_percent + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__chronic_conditions_none + description: > + Calculates the percentage of patients who do not have any + chronic conditions in the CMS chronic conditions model. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1'} + - {person_id: 'P2'} + - {person_id: 'P3'} + - {person_id: 'P4'} + - input: ref('chronic_conditions__cms_chronic_conditions_long') + rows: + - {person_id: 'P1'} + - {person_id: 'P2'} + - input: ref('data_quality__reference_mart_analytics') + rows: + - {analytics_measure: 'Percent of patients without chronic conditions', analytics_value: 25.0} + expect: + rows: + - {data_quality_check: 'Percent of patients without chronic conditions', result_count: 50, medicare_lds_reference: 25.0, normally_zero: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_cms_hcc_reference_avg_risk_score + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__cms_hcc_reference + description: > + Computes the average normalized risk score from CMS-HCC + patient risk scores and joins to reference data. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('cms_hcc__patient_risk_scores') + rows: + - {person_id: 'P1', normalized_risk_score: 1.0} + - {person_id: 'P2', normalized_risk_score: 2.0} + - {person_id: 'P3', normalized_risk_score: 3.0} + - input: ref('data_quality__reference_mart_analytics') + rows: + - {analytics_concept: 'cms-hcc', analytics_measure: 'normalized risk score', analytics_value: 1.5} + - {analytics_concept: 'readmissions', analytics_measure: 'readmission rate', analytics_value: 0.1} + expect: + rows: + - {analytics_concept: 'cms-hcc', analytics_measure: 'normalized risk score', data_source_value: 2.0, analytics_value: 1.5, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_quality_measures_reference_joins_performance_rate + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__quality_measures_reference + description: > + Joins quality measure performance rates to reference data + for comparison. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('quality_measures__summary_counts') + rows: + - {measure_name: 'Breast Cancer Screening', performance_rate: 0.75} + - {measure_name: 'Colorectal Cancer Screening', performance_rate: 0.60} + - input: ref('data_quality__reference_mart_analytics') + rows: + - {analytics_concept: 'quality measures', analytics_measure: 'Breast Cancer Screening', analytics_value: 0.80} + - {analytics_concept: 'quality measures', analytics_measure: 'Controlling Blood Pressure', analytics_value: 0.65} + expect: + rows: + - {analytics_concept: 'quality measures', analytics_measure: 'Breast Cancer Screening', data_source_value: 0.75, analytics_value: 0.80, tuva_last_run: '2024-01-01 00:00:00'} + - {analytics_concept: 'quality measures', analytics_measure: 'Controlling Blood Pressure', data_source_value: null, analytics_value: 0.65, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_readmissions_reference_calculates_readmit_rate + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__readmissions_reference + description: > + Calculates the readmission rate from index admissions and + joins to reference data. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('readmissions__readmission_summary') + rows: + - {encounter_id: 'E1', index_admission_flag: 1, unplanned_readmit_30_flag: 1} + - {encounter_id: 'E2', index_admission_flag: 1, unplanned_readmit_30_flag: 0} + - {encounter_id: 'E3', index_admission_flag: 1, unplanned_readmit_30_flag: 0} + - {encounter_id: 'E4', index_admission_flag: 1, unplanned_readmit_30_flag: 1} + - {encounter_id: 'E5', index_admission_flag: 0, unplanned_readmit_30_flag: 0} + - input: ref('data_quality__reference_mart_analytics') + rows: + - {analytics_concept: 'readmissions', analytics_measure: 'readmission rate', analytics_value: 0.15} + expect: + rows: + - {analytics_concept: 'readmissions', analytics_measure: 'readmission rate', data_source_value: 0.5, analytics_value: 0.15, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_acute_inpatient_reference_los_and_mortality + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__acute_inpatient_reference + description: > + Calculates average length of stay and mortality rate for + acute inpatient encounters and joins to reference data. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', encounter_type: 'acute inpatient', length_of_stay: 4, discharge_disposition_code: '01'} + - {encounter_id: 'E2', encounter_type: 'acute inpatient', length_of_stay: 6, discharge_disposition_code: '20'} + - {encounter_id: 'E3', encounter_type: 'emergency department', length_of_stay: 0, discharge_disposition_code: '01'} + - input: ref('data_quality__reference_mart_analytics') + rows: + - {analytics_concept: 'acute inpatient', analytics_measure: 'length of stay', analytics_value: 4.5} + - {analytics_concept: 'acute inpatient', analytics_measure: 'mortality rate', analytics_value: 0.02} + expect: + rows: + - {analytics_concept: 'acute inpatient', analytics_measure: 'length of stay', data_source_value: 5.0, analytics_value: 4.5, tuva_last_run: '2024-01-01 00:00:00'} + - {analytics_concept: 'acute inpatient', analytics_measure: 'mortality rate', data_source_value: 0.5, analytics_value: 0.02, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_encounters_cost_and_utilization_pkpy + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__encounters_cost_and_utilization + description: > + Calculates PKPY (per-thousand-per-year) and paid-per-encounter + metrics by encounter type, using member months as the + denominator. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', year_month: '202301'} + - {person_id: 'P2', year_month: '202301'} + - {person_id: 'P1', year_month: '202302'} + - {person_id: 'P2', year_month: '202302'} + - {person_id: 'P1', year_month: '202303'} + - {person_id: 'P2', year_month: '202303'} + - {person_id: 'P1', year_month: '202304'} + - {person_id: 'P2', year_month: '202304'} + - {person_id: 'P1', year_month: '202305'} + - {person_id: 'P2', year_month: '202305'} + - {person_id: 'P1', year_month: '202306'} + - {person_id: 'P2', year_month: '202306'} + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', encounter_group: 'inpatient', encounter_type: 'acute inpatient', paid_amount: 10000.00} + - {encounter_id: 'E2', encounter_group: 'inpatient', encounter_type: 'acute inpatient', paid_amount: 20000.00} + - input: ref('data_quality__reference_mart_analytics') + rows: + - {analytics_concept: 'encounters cost and utilization PKPY', analytics_measure: 'acute inpatient', analytics_value: 100.0} + - {analytics_concept: 'encounters cost and utilization paid per', analytics_measure: 'acute inpatient', analytics_value: 12000.0} + expect: + rows: + - {analytics_concept: 'encounters cost and utilization PKPY', encounter_group: 'inpatient', analytics_measure: 'acute inpatient', data_source_value: 2000.0, analytics_value: 100.0, tuva_last_run: '2024-01-01 00:00:00'} + - {analytics_concept: 'encounters cost and utilization paid per', encounter_group: 'inpatient', analytics_measure: 'acute inpatient', data_source_value: 15000.0, analytics_value: 12000.0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_financial_pmpm_calculates_annual_pmpm + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__financial_pmpm + description: > + Calculates member months and total PMPM by year from + the financial_pmpm prep table. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('financial_pmpm__pmpm_prep') + rows: + - {person_id: 'P1', year_month: '202301', total_paid: 500.00} + - {person_id: 'P1', year_month: '202302', total_paid: 300.00} + - {person_id: 'P2', year_month: '202301', total_paid: 200.00} + - input: ref('reference_data__calendar') + rows: + - {year_month_int: 202301, year: 2023} + - {year_month_int: 202302, year: 2023} + expect: + rows: + - {member_months: 3, year_number: 2023} + + - name: test_service_categories_pmpm_calculation + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__service_categories_pmpm + description: > + Calculates PMPM by service category using total paid and + overall member months, joined to reference data. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('core__medical_claim') + rows: + - {claim_id: 'MC1', service_category_2: 'Inpatient', paid_amount: 1000.00} + - {claim_id: 'MC2', service_category_2: 'Inpatient', paid_amount: 500.00} + - {claim_id: 'MC3', service_category_2: 'Office Visit', paid_amount: 200.00} + - input: ref('core__member_months') + rows: + - {person_id: 'P1'} + - {person_id: 'P2'} + - {person_id: 'P3'} + - input: ref('data_quality__reference_mart_analytics') + rows: + - {analytics_concept: 'service categories pmpm', analytics_measure: 'Inpatient', analytics_value: 400.0} + - {analytics_concept: 'service categories pmpm', analytics_measure: 'Office Visit', analytics_value: 50.0} + expect: + rows: + - {analytics_concept: 'service categories pmpm', analytics_measure: 'Inpatient', data_source_value: 500.0, analytics_value: 400.0, tuva_last_run: '2024-01-01 00:00:00'} + - {analytics_concept: 'service categories pmpm', analytics_measure: 'Office Visit', data_source_value: 66.66666666666667, analytics_value: 50.0, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FINAL MODELS + # ========================================================================= + + - name: test_analytics_populated_counts_tables + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__analytics_populated + description: > + Counts records in each analytics table (chronic conditions, + CMS-HCC, service categories, financial PMPM, readmissions, + quality measures, acute inpatient, and ED visits). + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('chronic_conditions__tuva_chronic_conditions_long') + rows: + - {person_id: 'P1', condition: 'Diabetes'} + - {person_id: 'P2', condition: 'Asthma'} + - input: ref('cms_hcc__patient_risk_factors') + rows: + - {person_id: 'P1', factor_type: 'Demographic'} + - input: ref('service_category__service_category_grouper') + rows: + - {claim_id: 'MC1'} + - {claim_id: 'MC2'} + - {claim_id: 'MC3'} + - input: ref('financial_pmpm__pmpm_payer') + rows: + - {year_month: '202301'} + - input: ref('readmissions__readmission_summary') + rows: + - {encounter_id: 'E1'} + - {encounter_id: 'E2'} + - input: ref('quality_measures__summary_long') + rows: + - {measure_id: 'M1'} + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', encounter_type: 'acute inpatient'} + - {encounter_id: 'E2', encounter_type: 'emergency department'} + - {encounter_id: 'E3', encounter_type: 'emergency department'} + expect: + rows: + - {table_name: 'tuva_chronic_condition_long', record_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'cms_hcc__patient_risk_factors', record_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'service_category__service_category_grouper', record_count: 3, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'financial_pmpm__pmpm_payer', record_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'readmissions__readmission_summary', record_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'quality_measures__summary_long', record_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'acute_inpatient_visits', record_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'ed_visits', record_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_encounters_cost_and_utilization_trend + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__encounters_cost_and_utilization_trend + description: > + Calculates PKPY and paid-per-encounter trends by year_month. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', year_month: '202301'} + - {person_id: 'P2', year_month: '202301'} + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', encounter_group: 'inpatient', encounter_type: 'acute inpatient', paid_amount: 10000.00, encounter_start_date: '2023-01-15'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-01-15', year_month_int: 202301} + expect: + rows: + - {year_month: '202301', encounter_group: 'inpatient', encounter_type: 'acute inpatient', pkpy: 6000.0, paid_per: 10000.0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_service_category_pmpm_trend + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__service_category_pmpm_trend + description: > + Calculates service category PMPM trends by year_month, using + member months as the denominator. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', year_month: '202301'} + - {person_id: 'P2', year_month: '202301'} + - input: ref('core__medical_claim') + rows: + - {claim_id: 'MC1', service_category_1: 'Inpatient', service_category_2: 'Acute Inpatient', paid_amount: 1000.00, claim_start_date: '2023-01-15'} + - {claim_id: 'MC2', service_category_1: 'Inpatient', service_category_2: 'Acute Inpatient', paid_amount: 500.00, claim_start_date: '2023-01-20'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-01-15', year_month_int: 202301} + - {full_date: '2023-01-20', year_month_int: 202301} + expect: + rows: + - {year_month: '202301', service_category_1: 'Inpatient', service_category_2: 'Acute Inpatient', total_paid: 1500.0, pmpm: 750.0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_data_loss_compares_input_to_core + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__data_loss + description: > + Compares record counts, patient counts, and dollar amounts + between input layer and core layer for medical, pharmacy, + and eligibility tables. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1', person_id: 'P1', paid_amount: 100.00, allowed_amount: 120.00, member_id: 'M1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA'} + - {claim_id: 'MC2', person_id: 'P2', paid_amount: 200.00, allowed_amount: 250.00, member_id: 'M2', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA'} + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', person_id: 'P1', paid_amount: 50.00, allowed_amount: 60.00} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA'} + - {person_id: 'P2', member_id: 'M2', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA'} + - input: ref('data_quality__eligibility_dq_stage') + rows: + - {person_id: 'P1'} + - {person_id: 'P2'} + - input: ref('core__medical_claim') + rows: + - {claim_id: 'MC1', person_id: 'P1', paid_amount: 100.00, allowed_amount: 120.00} + - input: ref('core__pharmacy_claim') + rows: + - {claim_id: 'RX1', person_id: 'P1', paid_amount: 50.00, allowed_amount: 60.00} + - input: ref('core__eligibility') + rows: + - {person_id: 'P1'} + - {person_id: 'P2'} + - input: ref('core__member_months') + rows: + - {person_id: 'P1'} + - {person_id: 'P2'} + expect: + rows: + - {table_name: 'medical_claim', metric: 'Total Unique Patients', input_layer_value: 2, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'medical_claim', metric: 'Total Unique Claims', input_layer_value: 2, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'medical_claim', metric: 'Total Records', input_layer_value: 2, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'medical_claim', metric: 'Total Paid Amount', input_layer_value: 300.0, core_value: 100.0, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'medical_claim', metric: 'Total Allowed Amount', input_layer_value: 370.0, core_value: 120.0, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'pharmacy_claim', metric: 'Total Unique Patients', input_layer_value: 1, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'pharmacy_claim', metric: 'Total Unique Claims', input_layer_value: 1, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'pharmacy_claim', metric: 'Total Records', input_layer_value: 1, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'pharmacy_claim', metric: 'Total Paid Amount', input_layer_value: 50.0, core_value: 50.0, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'pharmacy_claim', metric: 'Total Allowed Amount', input_layer_value: 60.0, core_value: 60.0, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'eligibility', metric: 'Total Unique Patients', input_layer_value: 2, core_value: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'eligibility', metric: 'Total Unique Eligibility Spans', input_layer_value: 2, core_value: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'eligibility', metric: 'Total Member Months', input_layer_value: 2, core_value: 2, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_data_loss_ignores_duplicate_rows_in_distinct_counts + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__data_loss + description: > + Duplicate input rows should not inflate distinct patient or + span counts, but they should still increase raw record counts. + This catches fanout regressions in the count logic. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1', person_id: 'P1', paid_amount: 100.00, allowed_amount: 110.00} + - {claim_id: 'MC1', person_id: 'P1', paid_amount: 100.00, allowed_amount: 110.00} + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', person_id: 'P2', paid_amount: 50.00, allowed_amount: 55.00} + - {claim_id: 'RX1', person_id: 'P2', paid_amount: 50.00, allowed_amount: 55.00} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA'} + - {person_id: 'P1', member_id: 'M1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA'} + - input: ref('data_quality__eligibility_dq_stage') + rows: + - {person_id: 'P1'} + - input: ref('core__medical_claim') + rows: + - {claim_id: 'MC1', person_id: 'P1', paid_amount: 100.00, allowed_amount: 110.00} + - input: ref('core__pharmacy_claim') + rows: + - {claim_id: 'RX1', person_id: 'P2', paid_amount: 50.00, allowed_amount: 55.00} + - input: ref('core__eligibility') + rows: + - {person_id: 'P1'} + - input: ref('core__member_months') + rows: + - {person_id: 'P1'} + expect: + rows: + - {table_name: 'medical_claim', metric: 'Total Unique Patients', input_layer_value: 1, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'medical_claim', metric: 'Total Unique Claims', input_layer_value: 1, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'medical_claim', metric: 'Total Records', input_layer_value: 2, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'medical_claim', metric: 'Total Paid Amount', input_layer_value: 200.0, core_value: 100.0, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'medical_claim', metric: 'Total Allowed Amount', input_layer_value: 220.0, core_value: 110.0, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'pharmacy_claim', metric: 'Total Unique Patients', input_layer_value: 1, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'pharmacy_claim', metric: 'Total Unique Claims', input_layer_value: 1, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'pharmacy_claim', metric: 'Total Records', input_layer_value: 2, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'pharmacy_claim', metric: 'Total Paid Amount', input_layer_value: 100.0, core_value: 50.0, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'pharmacy_claim', metric: 'Total Allowed Amount', input_layer_value: 110.0, core_value: 55.0, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'eligibility', metric: 'Total Unique Patients', input_layer_value: 1, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'eligibility', metric: 'Total Unique Eligibility Spans', input_layer_value: 1, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'eligibility', metric: 'Total Member Months', input_layer_value: 1, core_value: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_analytics_checks_summary_coalesces_null_results + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__analytics_checks_summary + description: > + Coalesces null result_count and normally_zero values to stable + defaults while preserving non-null analytics checks. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('data_quality__readmissions') + rows: + - {data_quality_check: 'readmissions rate', result_count: null, normally_zero: null} + - input: ref('data_quality__quality_measures') + rows: + - {data_quality_check: 'quality measure numerator zero', result_count: 2, normally_zero: 0} + - input: ref('data_quality__ed_classification') + rows: + - {data_quality_check: 'ed classification missing pc_treatable', result_count: 1, normally_zero: null} + expect: + rows: + - {data_quality_check: 'readmissions rate', result_count: 0, normally_zero: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'quality measure numerator zero', result_count: 2, normally_zero: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'ed classification missing pc_treatable', result_count: 1, normally_zero: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_analytics_reference_summary_unions_reference_rows + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__analytics_reference_summary + description: > + Preserves analytics reference rows from multiple source models + without altering the measured values. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + enable_legacy_data_quality: true + claims_enabled: true + given: + - input: ref('data_quality__readmissions_reference') + rows: + - {analytics_concept: 'readmissions', analytics_measure: 'readmission rate', data_source_value: 0.25, analytics_value: 0.15, value_rank: 1} + - input: ref('data_quality__quality_measures_reference') + rows: + - {analytics_concept: 'quality measures', analytics_measure: 'Breast Cancer Screening', data_source_value: 0.75, analytics_value: 0.80, value_rank: 2} + expect: + rows: + - {analytics_concept: 'readmissions', analytics_measure: 'readmission rate', data_source_value: 0.25, analytics_value: 0.15, value_rank: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {analytics_concept: 'quality measures', analytics_measure: 'Breast Cancer Screening', data_source_value: 0.75, analytics_value: 0.8, value_rank: 2, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_data_quality_detail_unions_claims_and_clinical + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__data_quality_detail + description: > + When both claims and clinical are enabled, the detail model unions + both sources, stamping clinical rows with claim_type='CLINICAL'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: true + given: + - input: ref('data_quality__data_quality_claims_detail') + rows: + - {data_source: 'src1', source_date: '2023-01-01', table_name: 'eligibility', drill_down_key: 'member_id', drill_down_value: 'M1', claim_type: 'ELIGIBILITY', field_name: 'birth_date', bucket_name: 'valid', invalid_reason: null, field_value: '1960-01-01', summary_sk: 'SK1'} + - input: ref('data_quality__data_quality_clinical_detail') + rows: + - {data_source: 'src2', source_date: '2023-02-01', table_name: 'lab_result', drill_down_key: 'lab_result_id', drill_down_value: 'LR1', field_name: 'result', bucket_name: 'valid', invalid_reason: null, field_value: '200', summary_sk: 'SK200'} + expect: + rows: + - {data_source: 'src1', table_name: 'eligibility', claim_type: 'ELIGIBILITY', field_name: 'birth_date', bucket_name: 'valid', drill_down_value: 'M1', tuva_last_run: '2024-01-01 00:00:00'} + - {data_source: 'src2', table_name: 'lab_result', claim_type: 'CLINICAL', field_name: 'result', bucket_name: 'valid', drill_down_value: 'LR1', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # DATA QUALITY FOR PBI — Claims-only path + # ========================================================================= + + - name: test_data_quality_for_pbi_claims_only + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__data_quality_for_pbi + description: > + In claims-only mode, the PBI model passes through claims PBI data + with the original claim_type intact. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: false + given: + - input: ref('data_quality__data_quality_claims_for_pbi') + rows: + - {summary_sk: 1, data_source: 'src1', table_name: 'medical_claim', claim_type: 'INSTITUTIONAL', field_name: 'bill_type_code', bucket_name: 'valid', invalid_reason: null, drill_down_key: 'claim_id', drill_down_value: 'MC1', field_value: '111', frequency: 5} + expect: + rows: + - {summary_sk: 1, data_source: 'src1', table_name: 'medical_claim', claim_type: 'INSTITUTIONAL', field_name: 'bill_type_code', bucket_name: 'valid', frequency: 5, tuva_last_run: '2024-01-01 00:00:00'} + diff --git a/models/data_quality/data_quality_unit_tests.yml b/models/data_quality/data_quality_unit_tests.yml new file mode 100644 index 000000000..93d0f7abc --- /dev/null +++ b/models/data_quality/data_quality_unit_tests.yml @@ -0,0 +1,660 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGE MODELS + # ========================================================================= + + - name: test_inpatient_dq_stage_identifies_inpatient_by_bill_type + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__inpatient_dq_stage + description: > + Claims with institutional claim_type and bill_type_code starting with + '11' or '12' are identified as inpatient claims. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'CLM1', claim_type: 'institutional', bill_type_code: '111', drg_code: null, drg_code_type: null} + - {claim_id: 'CLM2', claim_type: 'institutional', bill_type_code: '121', drg_code: null, drg_code_type: null} + - {claim_id: 'CLM3', claim_type: 'institutional', bill_type_code: '131', drg_code: null, drg_code_type: null} + - {claim_id: 'CLM4', claim_type: 'professional', bill_type_code: null, drg_code: null, drg_code_type: null} + - input: ref('terminology__ms_drg') + rows: [] + expect: + rows: + - {claim_id: 'CLM1', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'CLM2', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_inpatient_dq_stage_identifies_inpatient_by_drg + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__inpatient_dq_stage + description: > + Claims with a valid ms_drg code are identified as inpatient claims + even without a matching bill_type_code. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'CLM5', claim_type: 'institutional', bill_type_code: '999', drg_code: '470', drg_code_type: 'ms-drg'} + - {claim_id: 'CLM6', claim_type: 'institutional', bill_type_code: '999', drg_code: 'INVALID', drg_code_type: 'ms-drg'} + - input: ref('terminology__ms_drg') + rows: + - {ms_drg_code: '470', ms_drg_description: 'Major Joint Replacement'} + expect: + rows: + - {claim_id: 'CLM5', tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # INTERMEDIATE MODELS + # ========================================================================= + + - name: test_primary_key_check_detects_pharmacy_pk_errors + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__primary_key_check + description: > + Detects primary key violations in pharmacy_claim when the same + claim_id + claim_line_number + data_source appears more than once. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', claim_line_number: '1', data_source: 'src1'} + - {claim_id: 'RX1', claim_line_number: '1', data_source: 'src1'} + - {claim_id: 'RX2', claim_line_number: '1', data_source: 'src1'} + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1', claim_line_number: '1', data_source: 'src1'} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', plan: 'Plan1', data_source: 'src1'} + expect: + rows: + - {data_quality_check: 'pk errors pharmacy claim', result_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'pk errors medical claim', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'pk errors eligibility', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_primary_key_check_detects_medical_pk_errors + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__primary_key_check + description: > + Detects primary key violations in medical_claim when the same + claim_id + claim_line_number + data_source appears more than once. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', claim_line_number: '1', data_source: 'src1'} + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1', claim_line_number: '1', data_source: 'src1'} + - {claim_id: 'MC1', claim_line_number: '1', data_source: 'src1'} + - {claim_id: 'MC1', claim_line_number: '1', data_source: 'src1'} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', plan: 'Plan1', data_source: 'src1'} + expect: + rows: + - {data_quality_check: 'pk errors pharmacy claim', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'pk errors medical claim', result_count: 3, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'pk errors eligibility', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_primary_key_check_no_violations + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__primary_key_check + description: > + When all tables have unique primary keys, all result_counts should be 0. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', claim_line_number: '1', data_source: 'src1'} + - {claim_id: 'RX2', claim_line_number: '1', data_source: 'src1'} + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1', claim_line_number: '1', data_source: 'src1'} + - {claim_id: 'MC2', claim_line_number: '1', data_source: 'src1'} + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', plan: 'Plan1', data_source: 'src1'} + - {person_id: 'P2', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', plan: 'Plan1', data_source: 'src1'} + expect: + rows: + - {data_quality_check: 'pk errors pharmacy claim', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'pk errors medical claim', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'pk errors eligibility', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_pharmacy_claim_date_checks_missing_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_claim_date_checks + description: > + Detects claims with missing paid_date and missing dispensing_date. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', paid_date: null, dispensing_date: '2023-06-01'} + - {claim_id: 'RX2', paid_date: '2023-06-15', dispensing_date: null} + - {claim_id: 'RX3', paid_date: null, dispensing_date: null} + - {claim_id: 'RX4', paid_date: '2023-07-01', dispensing_date: '2023-07-01'} + expect: + rows: + - {data_quality_check: 'missing pharmacy_claim paid_date', result_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing dispensing_date', result_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_pharmacy_claim_date_checks_no_missing + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_claim_date_checks + description: > + When all pharmacy claims have both paid_date and dispensing_date, + result_counts should be 0. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', paid_date: '2023-06-15', dispensing_date: '2023-06-01'} + - {claim_id: 'RX2', paid_date: '2023-07-01', dispensing_date: '2023-07-01'} + expect: + rows: + - {data_quality_check: 'missing pharmacy_claim paid_date', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing dispensing_date', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_pharmacy_claim_ndc_missing_and_invalid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_claim_ndc + description: > + Detects claims with missing NDC codes and claims with NDC codes + that do not join to the terminology table. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', ndc_code: null} + - {claim_id: 'RX2', ndc_code: '12345678901'} + - {claim_id: 'RX3', ndc_code: 'INVALID_NDC'} + - {claim_id: 'RX4', ndc_code: '99999999999'} + - input: ref('terminology__ndc') + rows: + - {ndc: '12345678901'} + expect: + rows: + - {data_quality_check: 'missing ndc', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'invalid ndc', result_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_pharmacy_claim_prescription_details_missing + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_claim_prescription_details + description: > + Detects claims with missing quantity, days_supply, and refills. + Zero values for quantity and days_supply count as missing. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', quantity: null, days_supply: 30, refills: 1} + - {claim_id: 'RX2', quantity: 0, days_supply: 0, refills: null} + - {claim_id: 'RX3', quantity: 90, days_supply: 90, refills: 0} + expect: + rows: + - {data_quality_check: 'missing quantity', result_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing days supply', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing refills', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_pharmacy_claim_npi_missing_and_invalid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_claim_npi + description: > + Detects missing and invalid prescribing/dispensing NPIs. Also + detects wrong entity type (organization prescribing, individual dispensing). + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', prescribing_provider_npi: null, dispensing_provider_npi: 'NPI_D1'} + - {claim_id: 'RX2', prescribing_provider_npi: 'NPI_P1', dispensing_provider_npi: null} + - {claim_id: 'RX3', prescribing_provider_npi: 'INVALID', dispensing_provider_npi: 'INVALID'} + - input: ref('terminology__provider') + rows: + - {npi: 'NPI_P1', entity_type_code: '1'} + - {npi: 'NPI_D1', entity_type_code: '2'} + expect: + rows: + - {data_quality_check: 'invalid prescribing_npi', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing prescribing_npi', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'wrong entity type prescribing_npi', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'invalid dispensing_npi', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing dispensing_npi', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'wrong entity type dispensing_npi', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_pharmacy_claim_person_id_missing_and_orphaned + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_claim_person_id + description: > + Detects pharmacy claims with missing person_id, multiple person_ids + per claim, and orphaned claims without matching eligibility. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', person_id: 'P1', paid_date: '2023-06-15', dispensing_date: '2023-06-01'} + - {claim_id: 'RX2', person_id: null, paid_date: '2023-06-15', dispensing_date: '2023-06-01'} + - {claim_id: 'RX3', person_id: 'P99', paid_date: '2023-06-15', dispensing_date: '2023-06-01'} + - input: ref('data_quality__eligibility_dq_stage') + rows: + - {person_id: 'P1', month_start_date: '2023-06-01', month_end_date: '2023-06-30'} + expect: + rows: + - {data_quality_check: 'multiple pharmacy_claim person_ids', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing pharmacy_claim person_id', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'orphaned pharmacy_claim claims', result_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_medical_claim_date_checks_missing_dates + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__medical_claim_date_checks + description: > + Detects medical claims with missing claim_start_date and claim_end_date. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {claim_id: 'MC1', claim_start_date: null, claim_end_date: '2023-06-30', claim_line_start_date: '2023-06-01', claim_line_end_date: '2023-06-30', admission_date: null, discharge_date: null, paid_date: '2023-07-01'} + - {claim_id: 'MC2', claim_start_date: '2023-07-01', claim_end_date: null, claim_line_start_date: null, claim_line_end_date: null, admission_date: null, discharge_date: null, paid_date: null} + - {claim_id: 'MC3', claim_start_date: '2023-08-01', claim_end_date: '2023-08-15', claim_line_start_date: '2023-08-01', claim_line_end_date: '2023-08-15', admission_date: null, discharge_date: null, paid_date: '2023-09-01'} + - input: ref('data_quality__inpatient_dq_stage') + rows: [] + expect: + rows: + - {data_quality_check: 'missing claim_start_date', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing claim_end_date', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing claim_line_start_date', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing claim_line_end_date', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing admission_date', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing discharge_date', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing medical_claim paid_date', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'claim start multiple', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'claim end multiple', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'admission date multiple', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'discharge date multiple', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_medical_claim_date_checks_inpatient_missing_admission + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__medical_claim_date_checks + description: > + Detects inpatient claims with missing admission_date and + discharge_date. Only inpatient claims (joined to inpatient_dq_stage) + are checked for admission/discharge dates. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {claim_id: 'MC1', claim_start_date: '2023-06-01', claim_end_date: '2023-06-15', claim_line_start_date: '2023-06-01', claim_line_end_date: '2023-06-15', admission_date: null, discharge_date: null, paid_date: '2023-07-01'} + - {claim_id: 'MC2', claim_start_date: '2023-07-01', claim_end_date: '2023-07-10', claim_line_start_date: '2023-07-01', claim_line_end_date: '2023-07-10', admission_date: '2023-07-01', discharge_date: '2023-07-10', paid_date: '2023-08-01'} + - input: ref('data_quality__inpatient_dq_stage') + rows: + - {claim_id: 'MC1', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'MC2', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {data_quality_check: 'missing claim_start_date', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing claim_end_date', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing claim_line_start_date', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing claim_line_end_date', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing admission_date', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing discharge_date', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing medical_claim paid_date', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'claim start multiple', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'claim end multiple', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'admission date multiple', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'discharge date multiple', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_medical_claim_claim_line_fields_missing_and_invalid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__medical_claim_claim_line_fields + description: > + Detects missing and invalid HCPCS, place_of_service, and + revenue_center codes. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1', claim_type: 'professional', hcpcs_code: '99213', place_of_service_code: '11', revenue_center_code: null} + - {claim_id: 'MC2', claim_type: 'professional', hcpcs_code: null, place_of_service_code: null, revenue_center_code: null} + - {claim_id: 'MC3', claim_type: 'institutional', hcpcs_code: 'BADCODE', place_of_service_code: null, revenue_center_code: null} + - input: ref('terminology__hcpcs_level_2') + rows: + - {hcpcs: '99213'} + - input: ref('terminology__place_of_service') + rows: + - {place_of_service_code: '11'} + - input: ref('terminology__revenue_center') + rows: + - {revenue_center_code: '0100'} + expect: + rows: + - {data_quality_check: 'invalid hcpcs_code', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'invalid place_of_service_code', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'invalid revenue_center_code', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing hcpcs_code', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing place_of_service_code', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing revenue_center_code', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_medical_claim_provider_npi_missing_and_invalid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__medical_claim_provider_npi + description: > + Detects missing, invalid, and wrong entity type NPI values for + rendering, billing, and facility NPIs. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1', rendering_npi: 'NPI1', billing_npi: 'NPI2', facility_npi: 'NPI3'} + - {claim_id: 'MC2', rendering_npi: null, billing_npi: null, facility_npi: null} + - {claim_id: 'MC3', rendering_npi: 'BAD1', billing_npi: 'BAD2', facility_npi: 'BAD3'} + - input: ref('terminology__provider') + rows: + - {npi: 'NPI1', entity_type_code: '1'} + - {npi: 'NPI2', entity_type_code: '1'} + - {npi: 'NPI3', entity_type_code: '2'} + expect: + rows: + - {data_quality_check: 'invalid rendering_npi', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'invalid billing_npi', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'invalid facility_npi', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing rendering_npi', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing billing_npi', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing facility_npi', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'wrong entity type rendering_npi', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'wrong entity type facility_npi', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'multiple rendering_npi values', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'multiple billing_npi values', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'multiple facility_npi values', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_encounters_missing_groups_detects_missing + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__encounters_missing_groups + description: > + Detects encounter groups that are expected but not present in the + core encounter table. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__encounter') + rows: + - {encounter_group: 'inpatient'} + - {encounter_group: 'outpatient'} + expect: + rows: + - {encounter_group: 'inpatient', missing_encounter_group: 'populated', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_group: 'outpatient', missing_encounter_group: 'populated', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_group: null, missing_encounter_group: 'missing', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_group: null, missing_encounter_group: 'missing', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_encounters_missing_groups_union_counts + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__encounters_missing_groups_union + description: > + Counts the number of rows in encounters_missing_groups (which + includes both present and missing groups). + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('data_quality__encounters_missing_groups') + rows: + - {encounter_group: 'inpatient', missing_encounter_group: 'populated', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_group: null, missing_encounter_group: 'missing', tuva_last_run: '2024-01-01 00:00:00'} + - {encounter_group: null, missing_encounter_group: 'missing', tuva_last_run: '2024-01-01 00:00:00'} + expect: + rows: + - {data_quality_check: 'number of missing encounter groups', result_count: 3, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_cms_hcc_missing_factors + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__cms_hcc + description: > + Detects when CMS-HCC patient risk factors are missing demographic + or disease factor types. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__patient_risk_factors') + rows: + - {factor_type: 'Demographic', coefficient: 0.5} + - {factor_type: 'Disease', coefficient: 0.3} + expect: + rows: + - {data_quality_check: 'missing cms-hcc demographic factor', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing cms-hcc disease factor', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_cms_hcc_missing_disease_factor + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__cms_hcc + description: > + When no disease factors exist, the check flags result_count = 1. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__patient_risk_factors') + rows: + - {factor_type: 'Demographic', coefficient: 0.5} + expect: + rows: + - {data_quality_check: 'missing cms-hcc demographic factor', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'missing cms-hcc disease factor', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_ed_classification_detects_missing_categories + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__ed_classification + description: > + Detects when ED classification categories are missing from the + ed_classification summary table. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('ed_classification__summary') + rows: + - {ed_classification_description: 'Emergent, ED Care Needed, Preventable/Avoidable'} + - {ed_classification_description: 'Emergent, Primary Care Treatable'} + expect: + rows: + - {data_quality_check: 'ed classification missing ed_care_needed_preventable', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'ed classification missing pc_treatable', result_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'ed classification missing ed_care_needed_not_preventable', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'ed classification missing non_emergent', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_quality_measures_zero_counts + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__quality_measures + description: > + Detects quality measures with zero numerator and denominator counts. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__summary_counts') + rows: + - {measure_name: 'Measure A', numerator_sum: 10, denominator_sum: 100, performance_rate: 0.1} + - {measure_name: 'Measure B', numerator_sum: 0, denominator_sum: 50, performance_rate: 0.0} + - {measure_name: 'Measure C', numerator_sum: 5, denominator_sum: 0, performance_rate: null} + expect: + rows: + - {data_quality_check: 'quality measure numerator zero', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {data_quality_check: 'quality measure denominator zero', result_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_acute_inpatient_missing_prof_claim + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__acute_inpatient + description: > + Counts acute inpatient encounters missing professional claims. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__encounter') + rows: + - {encounter_type: 'acute inpatient', prof_claim_count: 0} + - {encounter_type: 'acute inpatient', prof_claim_count: 3} + - {encounter_type: 'acute inpatient', prof_claim_count: 0} + - {encounter_type: 'emergency department', prof_claim_count: 0} + expect: + rows: + - {data_quality_check: 'inpatient encounter missing professional claim', result_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # FINAL MODELS + # ========================================================================= + + - name: test_core_populated_counts_records + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__core_populated + description: > + Counts records in each core table and unions them together. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__medical_claim') + rows: + - {claim_id: 'MC1'} + - {claim_id: 'MC2'} + - input: ref('core__pharmacy_claim') + rows: + - {claim_id: 'RX1'} + - input: ref('core__eligibility') + rows: + - {person_id: 'P1'} + - {person_id: 'P2'} + - {person_id: 'P3'} + - input: ref('core__member_months') + rows: + - {person_id: 'P1'} + - input: ref('core__patient') + rows: + - {person_id: 'P1'} + - {person_id: 'P2'} + - input: ref('core__encounter') + rows: [] + - input: ref('core__condition') + rows: + - {condition_id: 'C1'} + - input: ref('core__procedure') + rows: [] + expect: + rows: + - {table_name: 'medical_claim', record_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'pharmacy_claim', record_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'eligibility', record_count: 3, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'member_months', record_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'patient', record_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'encounter', record_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'condition', record_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {table_name: 'procedure', record_count: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_pharmacy_claim_volume_and_dollars + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_claim_volume_and_dollars + description: > + Aggregates pharmacy claim volume and paid amounts by year_month, + using paid_date with dispensing_date as fallback. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1', paid_date: '2023-06-15', dispensing_date: '2023-06-01', paid_amount: 100.00} + - {claim_id: 'RX2', paid_date: '2023-06-20', dispensing_date: '2023-06-10', paid_amount: 200.00} + - {claim_id: 'RX3', paid_date: null, dispensing_date: '2023-07-01', paid_amount: 50.00} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-06-15', year_month_int: 202306} + - {full_date: '2023-06-20', year_month_int: 202306} + - {full_date: '2023-07-01', year_month_int: 202307} + expect: + rows: + - {year_month: 202306, claim_volume: 2, paid_amount: 300.00, tuva_last_run: '2024-01-01 00:00:00'} + - {year_month: 202307, claim_volume: 1, paid_amount: 50.00, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_claim_percent_calculates_proportions + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_percent + description: > + Calculates paid amount as a percentage of total for each claim type, + including pharmacy. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__medical_claim') + rows: + - {paid_amount: 600.00, claim_type: 'institutional'} + - {paid_amount: 400.00, claim_type: 'professional'} + - input: ref('input_layer__pharmacy_claim') + rows: + - {paid_amount: 1000.00} + expect: + rows: + - {claim_type: 'institutional', percent_of_total_paid: 0.3} + - {claim_type: 'professional', percent_of_total_paid: 0.2} + - {claim_type: 'pharmacy', percent_of_total_paid: 0.5} diff --git a/models/data_quality/dqi/dqi_gap_unit_tests.yml b/models/data_quality/dqi/dqi_gap_unit_tests.yml new file mode 100644 index 000000000..2dbe311df --- /dev/null +++ b/models/data_quality/dqi/dqi_gap_unit_tests.yml @@ -0,0 +1,348 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGE MODELS + # ========================================================================= + + - name: test_stg_immunization_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__stg_immunization + description: > + Passes through all rows from the immunization source without + any filtering. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('immunization') + rows: + - {person_id: 'P1', occurrence_date: '2023-01-15', normalized_code: 'CVX001'} + - {person_id: 'P2', occurrence_date: '2023-06-01', normalized_code: 'CVX002'} + expect: + rows: + - {person_id: 'P1', occurrence_date: '2023-01-15', normalized_code: 'CVX001'} + - {person_id: 'P2', occurrence_date: '2023-06-01', normalized_code: 'CVX002'} + + # ========================================================================= + # MART REVIEW FINAL MODELS + # ========================================================================= + + - name: test_number_of_conditions_counts_per_patient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__number_of_conditions + description: > + Counts the number of chronic conditions per patient by joining + core patient to tuva chronic conditions. Patients without + conditions get a count of 0. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', data_source: 'src1'} + - {person_id: 'P2', data_source: 'src1'} + - {person_id: 'P3', data_source: 'src1'} + - input: ref('chronic_conditions__tuva_chronic_conditions_long') + rows: + - {person_id: 'P1', condition: 'Diabetes'} + - {person_id: 'P1', condition: 'Hypertension'} + - {person_id: 'P2', condition: 'Asthma'} + expect: + rows: + - {person_id: 'P1', data_source: 'src1', numofconditions: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', data_source: 'src1', numofconditions: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P3', data_source: 'src1', numofconditions: 0, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_patient_adds_data_source_key + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__patient + description: > + Passes through all patient records and adds a + patient_data_source_key by concatenating person_id and + data_source. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__patient') + rows: + - {person_id: 'P1', data_source: 'src1'} + - {person_id: 'P2', data_source: 'src2'} + expect: + rows: + - {person_id: 'P1', data_source: 'src1', patient_data_source_key: 'P1|src1'} + - {person_id: 'P2', data_source: 'src2', patient_data_source_key: 'P2|src2'} + + - name: test_tuva_chronic_conditions_with_and_without_conditions + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__tuva_chronic_conditions + description: > + Patients with chronic conditions get a row per condition. + Patients without any chronic conditions get a single row + with 'No Chronic Conditions'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('chronic_conditions__tuva_chronic_conditions_long') + rows: + - {person_id: 'P1', condition: 'Diabetes'} + - {person_id: 'P1', condition: 'Hypertension'} + - input: ref('core__patient') + rows: + - {person_id: 'P1', data_source: 'src1'} + - {person_id: 'P2', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', data_source: 'src1', condition: 'Diabetes', patient_source_key: 'P1|src1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P1', data_source: 'src1', condition: 'Hypertension', patient_source_key: 'P1|src1', tuva_last_run: '2024-01-01 00:00:00'} + - {person_id: 'P2', data_source: 'src1', condition: 'No Chronic Conditions', patient_source_key: 'P2|src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_pmpm_calculates_absolute_amounts + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__pmpm + description: > + Multiplies per-member-per-month rates by member_months to + produce absolute paid amounts. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('financial_pmpm__pmpm_payer') + rows: + - {data_source: 'src1', year_month: '202301', payer: 'MCR', member_months: 100, total_paid: 5.0, medical_paid: 4.0, pharmacy_paid: 1.0, inpatient_paid: 2.0, outpatient_paid: 1.0, office_based_paid: 0.5, ancillary_paid: 0.3, other_paid: 0.2} + expect: + rows: + - {data_source: 'src1', year_month: '202301', member_months: 100, total_paid: 5.0, medical_paid: 4.0, pharmacy_paid: 1.0, total_paid_absolute: 500.0, medical_paid_absolute: 400.0, pharmacy_paid_absolute: 100.0, inpatient_paid_absolute: 200.0, outpatient_paid_absolute: 100.0, office_based_paid_absolute: 50.0, ancillary_paid_absolute: 30.0, other_paid_absolute: 20.0, data_source_month_key: 'src1|202301'} + + - name: test_ed_classification_classifies_ed_encounters + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__ed_classification + description: > + Filters core encounters to emergency department type and + joins to ED classification for avoidable categorization. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__encounter') + rows: + - {encounter_id: 'E1', encounter_type: 'emergency department', paid_amount: 500.00, primary_diagnosis_code: 'R10.9', primary_diagnosis_description: 'Abdominal pain', facility_npi: 'NPI1', allowed_amount: 600.00, charge_amount: 800.00, data_source: 'src1', length_of_stay: 0, discharge_disposition_code: '01', discharge_disposition_description: 'Home', person_id: 'P1', facility_name: 'Hospital A', encounter_start_date: '2023-06-01'} + - {encounter_id: 'E2', encounter_type: 'acute inpatient', paid_amount: 1000.00, primary_diagnosis_code: 'J18.9', primary_diagnosis_description: 'Pneumonia', facility_npi: 'NPI2', allowed_amount: 1200.00, charge_amount: 1500.00, data_source: 'src1', length_of_stay: 3, discharge_disposition_code: '01', discharge_disposition_description: 'Home', person_id: 'P2', facility_name: 'Hospital B', encounter_start_date: '2023-07-01'} + - input: ref('ed_classification__summary') + rows: + - {encounter_id: 'E1', ed_classification_description: 'Emergent, Primary Care Treatable', ed_classification_order: '4'} + - input: ref('core__location') + rows: + - {location_id: 'NPI1', npi: 'NPI1', name: 'Hospital A'} + - input: ref('ccsr__dx_vertical_pivot') + rows: + - {code: 'R10.9', ccsr_parent_category: 'SYM001', ccsr_category: 'SYM001A', ccsr_category_description: 'Abdominal pain', ccsr_category_rank: 1} + - input: ref('ccsr__dxccsr_v2023_1_body_systems') + rows: + - {ccsr_parent_category: 'SYM001', body_system: 'Symptoms'} + expect: + rows: + - {encounter_id: 'E1', ed_classification_description: 'Emergent, Primary Care Treatable', avoidable_category: 'Non-Avoidable', paid_amount: 500.00, primary_diagnosis_code: 'R10.9', data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_pharmacy_joins_ndc_and_calculates_cost + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__pharmacy + description: > + Joins pharmacy claims to NDC terminology and calculates + cost_per_day and thirty_day_equivalent_cost from paid_amount + and days_supply. days_supply of 0 produces null cost. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__pharmacy_claim') + rows: + - {claim_id: 'RX1', claim_line_number: '1', person_id: 'P1', data_source: 'src1', ndc_code: '12345678901', paid_amount: 300.00, allowed_amount: 350.00, prescribing_provider_id: 'PR1', prescribing_provider_name: 'Dr. Smith', dispensing_provider_id: 'D1', dispensing_provider_name: 'Pharmacy A', paid_date: '2023-06-15', dispensing_date: '2023-06-01', days_supply: 30, quantity: 90} + - {claim_id: 'RX2', claim_line_number: '1', person_id: 'P2', data_source: 'src1', ndc_code: '99999999999', paid_amount: 100.00, allowed_amount: 120.00, prescribing_provider_id: null, prescribing_provider_name: null, dispensing_provider_id: null, dispensing_provider_name: null, paid_date: '2023-07-01', dispensing_date: '2023-07-01', days_supply: 0, quantity: 10} + - input: ref('terminology__ndc') + rows: + - {ndc: '12345678901', fda_description: 'Drug A', rxnorm_description: 'DrugA RxNorm', rxcui: 'RX001'} + - input: ref('terminology__rxnorm_brand_generic') + rows: + - {product_rxcui: 'RX001', brand_name: 'BrandA', brand_vs_generic: 'brand', ingredient_name: 'IngredientA'} + - input: ref('terminology__rxnorm_to_atc') + rows: + - {rxcui: 'RX001', atc_1_name: 'ATC1', atc_2_name: 'ATC2', atc_3_name: 'ATC3', atc_4_name: 'ATC4'} + - input: ref('core__practitioner') + rows: + - {practitioner_id: 'PR1', specialty: 'Internal Medicine'} + - input: ref('pharmacy__pharmacy_claim_expanded') + rows: + - {data_source: 'src1', claim_id: 'RX1', claim_line_number: '1', generic_available_total_opportunity: 50.00, generic_average_cost_per_unit: 1.00, brand_cost_per_unit: 3.33, generic_available: 'Y', generic_available_sk: 1} + expect: + rows: + - {claim_id: 'RX1', person_id: 'P1', ndc_code: '12345678901', ndc_description: 'Drug A', paid_amount: 300.00, cost_per_day: 10.0, thirty_day_equivalent_cost: 300.0, specialty_tier: 0, brand_name: 'BrandA', brand_vs_generic: 'brand', generic_available: 'Y', tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'RX2', person_id: 'P2', ndc_code: '99999999999', ndc_description: null, paid_amount: 100.00, cost_per_day: null, thirty_day_equivalent_cost: null, specialty_tier: 0, brand_name: null, brand_vs_generic: null, generic_available: null, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_crosswalk_field_to_mart_sk_deduplicates_duplicate_rows + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__crosswalk_field_to_mart_sk + description: > + Duplicate detail and crosswalk rows for the same field should + collapse to a single dense_rank key per field/table/claim type + combination. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + given: + - input: ref('data_quality__data_quality_detail') + rows: + - {table_name: 'medical_claim', claim_type: 'institutional', field_name: 'bill_type_code'} + - {table_name: 'medical_claim', claim_type: 'institutional', field_name: 'bill_type_code'} + - input: ref('data_quality__crosswalk_field_to_mart') + rows: + - {input_layer_table_name: 'medical_claim', claim_type: 'institutional', field_name: 'bill_type_code', mart_name: 'encounters'} + - {input_layer_table_name: 'medical_claim', claim_type: 'institutional', field_name: 'bill_type_code', mart_name: 'encounters'} + expect: + rows: + - {input_layer_table_name: 'medical_claim', claim_type: 'institutional', field_name: 'bill_type_code', mart_name: null, table_claim_type_field_sk: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {input_layer_table_name: 'medical_claim', claim_type: 'institutional', field_name: 'bill_type_code', mart_name: 'encounters', table_claim_type_field_sk: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_data_quality_for_pbi_unions_claims_and_clinical_rows + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__data_quality_for_pbi + description: > + When both claims and clinical testing outputs are enabled, the + final PBI model should union both sources and stamp clinical + rows with claim_type='CLINICAL'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + clinical_enabled: true + given: + - input: ref('data_quality__data_quality_claims_for_pbi') + rows: + - {summary_sk: 1, data_source: 'src1', table_name: 'medical_claim', claim_type: 'INSTITUTIONAL', field_name: 'bill_type_code', bucket_name: 'invalid', invalid_reason: 'bad value', drill_down_key: 'claim_id', drill_down_value: 'MC1', field_value: '999', frequency: 1} + - input: ref('data_quality__data_quality_clinical_for_pbi') + rows: + - {summary_sk: 100001, data_source: 'src2', table_name: 'appointment', field_name: 'appointment_start_datetime', bucket_name: 'valid', invalid_reason: null, drill_down_key: 'appointment_id', drill_down_value: 'A1', field_value: '2023-06-01', frequency: 1} + expect: + rows: + - {summary_sk: 1, data_source: 'src1', table_name: 'medical_claim', claim_type: 'INSTITUTIONAL', field_name: 'bill_type_code', bucket_name: 'invalid', field_value: '999', drill_down_key: 'claim_id', drill_down_value: 'MC1', invalid_reason: 'bad value', frequency: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {summary_sk: 100001, data_source: 'src2', table_name: 'appointment', claim_type: 'CLINICAL', field_name: 'appointment_start_datetime', bucket_name: 'valid', field_value: '2023-06-01', drill_down_key: 'appointment_id', drill_down_value: 'A1', invalid_reason: null, frequency: 1, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # DQI STAGE — Institutional inpatient bill type 12 filter + # ========================================================================= + + - name: test_stg_institutional_inpatient_filters_bill_type_12 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__stg_institutional_inpatient + description: > + Claims with institutional claim_type and bill_type_code starting with + '12' are also identified as inpatient claims. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1', claim_type: 'institutional', bill_type_code: '121', claim_line_number: '1'} + - {claim_id: 'MC2', claim_type: 'institutional', bill_type_code: '129', claim_line_number: '1'} + - {claim_id: 'MC3', claim_type: 'professional', bill_type_code: '121', claim_line_number: '1'} + expect: + rows: [] + + # ========================================================================= + # DQI ATOMIC CHECKS — Clinical condition source_code pattern + # ========================================================================= + + - name: test_clinical_condition_source_code_valid_and_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__condition_source_code + description: > + The clinical atomic check for condition source_code classifies + non-null values as 'valid' and null values as 'null'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('condition') + rows: + - {data_source: 'src1', condition_id: 'COND1', source_code: 'J06.9', recorded_date: '2023-06-15'} + - {data_source: 'src1', condition_id: 'COND2', source_code: null, recorded_date: '2023-07-01'} + expect: + rows: + - {data_source: 'src1', table_name: 'CONDITION', field_name: 'SOURCE_CODE', drill_down_value: 'COND1', bucket_name: 'valid', field_value: 'J06.9', tuva_last_run: '2024-01-01 00:00:00'} + - {data_source: 'src1', table_name: 'CONDITION', field_name: 'SOURCE_CODE', drill_down_value: 'COND2', bucket_name: 'null', field_value: null, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # DQI ATOMIC CHECKS — Claims eligibility gender validation + # ========================================================================= + + - name: test_eligibility_gender_valid_invalid_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_gender + description: > + The claims atomic check for eligibility gender validates values + against the terminology__gender table, producing 'valid', 'invalid', + or 'null' buckets. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', member_id: 'M1', enrollment_start_date: '2023-01-01', gender: 'female'} + - {data_source: 'src1', member_id: 'M2', enrollment_start_date: '2023-01-01', gender: 'UNKNOWN_VALUE'} + - {data_source: 'src1', member_id: 'M3', enrollment_start_date: '2023-01-01', gender: null} + - input: ref('terminology__gender') + rows: + - {gender: 'female'} + - {gender: 'male'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'GENDER', drill_down_value: 'M1', bucket_name: 'valid', field_value: 'female', tuva_last_run: '2024-01-01 00:00:00'} + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'GENDER', drill_down_value: 'M2', bucket_name: 'invalid', field_value: 'UNKNOWN_VALUE', tuva_last_run: '2024-01-01 00:00:00'} + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'GENDER', drill_down_value: 'M3', bucket_name: 'null', field_value: null, tuva_last_run: '2024-01-01 00:00:00'} + + # ========================================================================= + # DQI FINAL — Crosswalk field to mart SK with multiple fields + # ========================================================================= + + - name: test_crosswalk_field_to_mart_sk_multiple_fields_ranked + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__crosswalk_field_to_mart_sk + description: > + Multiple fields from different tables each get their own + dense_rank SK value, ordered by table/claim_type/field. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('data_quality__data_quality_detail') + rows: + - {table_name: 'eligibility', claim_type: 'ELIGIBILITY', field_name: 'birth_date'} + - {table_name: 'eligibility', claim_type: 'ELIGIBILITY', field_name: 'gender'} + - {table_name: 'medical_claim', claim_type: 'INSTITUTIONAL', field_name: 'bill_type_code'} + - input: ref('data_quality__crosswalk_field_to_mart') + rows: [] + expect: + rows: + - {input_layer_table_name: 'eligibility', claim_type: 'ELIGIBILITY', field_name: 'birth_date', mart_name: null, table_claim_type_field_sk: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {input_layer_table_name: 'eligibility', claim_type: 'ELIGIBILITY', field_name: 'gender', mart_name: null, table_claim_type_field_sk: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {input_layer_table_name: 'medical_claim', claim_type: 'INSTITUTIONAL', field_name: 'bill_type_code', mart_name: null, table_claim_type_field_sk: 3, tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/data_quality/dqi/dqi_unit_tests.yml b/models/data_quality/dqi/dqi_unit_tests.yml new file mode 100644 index 000000000..a0af205eb --- /dev/null +++ b/models/data_quality/dqi/dqi_unit_tests.yml @@ -0,0 +1,155 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGE MODELS + # ========================================================================= + + - name: test_stg_institutional_inpatient_filters_bill_type_11 + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__stg_institutional_inpatient + description: > + Filters medical claims to only institutional claims with + bill_type_code starting with '11'. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1', claim_type: 'institutional', bill_type_code: '111', claim_line_number: '1'} + - {claim_id: 'MC2', claim_type: 'institutional', bill_type_code: '121', claim_line_number: '1'} + - {claim_id: 'MC3', claim_type: 'institutional', bill_type_code: '131', claim_line_number: '1'} + - {claim_id: 'MC4', claim_type: 'professional', bill_type_code: null, claim_line_number: '1'} + expect: + rows: + - {claim_id: 'MC1', claim_type: 'institutional', bill_type_code: '111', claim_line_number: '1'} + + - name: test_stg_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__stg_medical_claim + description: > + Passes through all rows from the medical_claim source without + any filtering. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {claim_id: 'MC1', claim_type: 'institutional'} + - {claim_id: 'MC2', claim_type: 'professional'} + expect: + rows: + - {claim_id: 'MC1', claim_type: 'institutional'} + - {claim_id: 'MC2', claim_type: 'professional'} + + - name: test_stg_pharmacy_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__stg_pharmacy_claim + description: > + Passes through all rows from the pharmacy_claim source without + any filtering. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {claim_id: 'RX1', ndc_code: '12345678901'} + - {claim_id: 'RX2', ndc_code: '99999999999'} + expect: + rows: + - {claim_id: 'RX1', ndc_code: '12345678901'} + - {claim_id: 'RX2', ndc_code: '99999999999'} + + - name: test_stg_eligibility_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__stg_eligibility + description: > + Passes through all rows from the eligibility source without + any filtering. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31'} + - {person_id: 'P2', enrollment_start_date: '2023-06-01', enrollment_end_date: '2023-12-31'} + expect: + rows: + - {person_id: 'P1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31'} + - {person_id: 'P2', enrollment_start_date: '2023-06-01', enrollment_end_date: '2023-12-31'} + + # ========================================================================= + # FINAL MODELS + # ========================================================================= + + - name: test_raw_summary_counts_input_layer_tables + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__raw_summary + description: > + Counts rows and unique identifiers per input layer table and + pairs them with raw_data placeholders. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P1'} + - {person_id: 'P2'} + - {person_id: 'P1'} + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'MC1'} + - {claim_id: 'MC1'} + - {claim_id: 'MC2'} + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX1'} + expect: + rows: + - {source: 'input_layer', table_name: 'eligibility', row_count: 3, unique_check: 2, unique_check_desc: 'Unique Patient Count', table_order: 2, tuva_last_run: '2024-01-01 00:00:00'} + - {source: 'raw_data', table_name: 'eligibility', row_count: null, unique_check: null, unique_check_desc: 'Unique Patient Count', table_order: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {source: 'raw_data', table_name: 'eligibility', row_count: null, unique_check: null, unique_check_desc: 'Unique Patient Count', table_order: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {source: 'raw_data', table_name: 'eligibility', row_count: null, unique_check: null, unique_check_desc: 'Unique Patient Count', table_order: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {source: 'input_layer', table_name: 'medical_claim', row_count: 3, unique_check: 2, unique_check_desc: 'Unique Claim Count', table_order: 4, tuva_last_run: '2024-01-01 00:00:00'} + - {source: 'raw_data', table_name: 'medical_claim', row_count: null, unique_check: null, unique_check_desc: 'Unique Claim Count', table_order: 3, tuva_last_run: '2024-01-01 00:00:00'} + - {source: 'raw_data', table_name: 'medical_claim', row_count: null, unique_check: null, unique_check_desc: 'Unique Claim Count', table_order: 3, tuva_last_run: '2024-01-01 00:00:00'} + - {source: 'raw_data', table_name: 'medical_claim', row_count: null, unique_check: null, unique_check_desc: 'Unique Claim Count', table_order: 3, tuva_last_run: '2024-01-01 00:00:00'} + - {source: 'input_layer', table_name: 'pharmacy_claim', row_count: 1, unique_check: 1, unique_check_desc: 'Unique Claim Count', table_order: 6, tuva_last_run: '2024-01-01 00:00:00'} + - {source: 'raw_data', table_name: 'pharmacy_claim', row_count: null, unique_check: null, unique_check_desc: 'Unique Claim Count', table_order: 5, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_crosswalk_field_to_mart_sk_assigns_dense_rank + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__crosswalk_field_to_mart_sk + description: > + Assigns dense_rank surrogate keys (table_claim_type_field_sk) based on + table_name + claim_type + field_name combinations, merging results from + both the detail table and the crosswalk table. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('data_quality__data_quality_detail') + rows: + - {table_name: 'medical_claim', claim_type: 'institutional', field_name: 'bill_type_code', data_source: 'src1', source_date: '2023-01-01', drill_down_key: 'claim_id', drill_down_value: 'MC1', bucket_name: 'valid', invalid_reason: null, field_value: '111', summary_sk: 'SK1'} + - {table_name: 'medical_claim', claim_type: 'professional', field_name: 'hcpcs_code', data_source: 'src1', source_date: '2023-01-01', drill_down_key: 'claim_id', drill_down_value: 'MC2', bucket_name: 'valid', invalid_reason: null, field_value: '99213', summary_sk: 'SK2'} + - input: ref('data_quality__crosswalk_field_to_mart') + rows: + - {input_layer_table_name: 'medical_claim', claim_type: 'institutional', field_name: 'bill_type_code', mart_name: 'encounters'} + expect: + rows: + - {input_layer_table_name: 'medical_claim', claim_type: 'institutional', field_name: 'bill_type_code', mart_name: null, table_claim_type_field_sk: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {input_layer_table_name: 'medical_claim', claim_type: 'institutional', field_name: 'bill_type_code', mart_name: 'encounters', table_claim_type_field_sk: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {input_layer_table_name: 'medical_claim', claim_type: 'professional', field_name: 'hcpcs_code', mart_name: null, table_claim_type_field_sk: 2, tuva_last_run: '2024-01-01 00:00:00'} + diff --git a/models/data_quality/dqi/intermediate/atomic_checks/claims/claims_atomic_unit_tests.yml b/models/data_quality/dqi/intermediate/atomic_checks/claims/claims_atomic_unit_tests.yml new file mode 100644 index 000000000..ee5d5928b --- /dev/null +++ b/models/data_quality/dqi/intermediate/atomic_checks/claims/claims_atomic_unit_tests.yml @@ -0,0 +1,1698 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # ELIGIBILITY ATOMIC CHECKS (27 models) + # ========================================================================= + + - name: test_eligibility_address_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_address + description: > + Address is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', address: '123 Main St'} + expect: + rows: + - {data_source: 'src1', table_name: 'eligibility', field_name: 'ADDRESS', bucket_name: 'valid'} + + - name: test_eligibility_birth_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_birth_date + description: > + Birth date is a valid past date so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', birth_date: '1980-06-15'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'BIRTH_DATE', bucket_name: 'valid'} + + - name: test_eligibility_city_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_city + description: > + City is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', city: 'Boston'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'CITY', bucket_name: 'valid'} + + - name: test_eligibility_data_source_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_data_source + description: > + Data source is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'DATA_SOURCE', bucket_name: 'valid'} + + - name: test_eligibility_death_date_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_death_date + description: > + Death date is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', birth_date: '1980-01-01', death_date: null} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'DEATH_DATE', bucket_name: 'null'} + + - name: test_eligibility_death_flag_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_death_flag + description: > + Death flag is 0 so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', death_flag: 0} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'DEATH_FLAG', bucket_name: 'valid'} + + - name: test_eligibility_dual_status_code_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_dual_status_code + description: > + Dual status code joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', dual_status_code: '01'} + - input: ref('terminology__medicare_dual_eligibility') + rows: + - {dual_status_code: '01', dual_status_description: 'Qualified Medicare Beneficiary'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'DUAL_STATUS_CODE', bucket_name: 'valid'} + + - name: test_eligibility_email_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_email + description: > + Email is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', email: null} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'EMAIL', bucket_name: 'null'} + + - name: test_eligibility_end_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_end_date + description: > + End date is after start date so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', enrollment_end_date: '2023-12-31'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'ENROLLMENT_END_DATE', bucket_name: 'valid'} + + - name: test_eligibility_ethnicity_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_ethnicity + description: > + Ethnicity is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', ethnicity: null} + - input: ref('terminology__ethnicity') + rows: + - {code: 'hispanic'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'ETHNICITY', bucket_name: 'null'} + + - name: test_eligibility_first_name_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_first_name + description: > + First name is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', first_name: 'John'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'FIRST_NAME', bucket_name: 'valid'} + + - name: test_eligibility_gender_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_gender + description: > + Gender joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', gender: 'male'} + - input: ref('terminology__gender') + rows: + - {gender: 'male'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'GENDER', bucket_name: 'valid'} + + - name: test_eligibility_last_name_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_last_name + description: > + Last name is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', last_name: 'Doe'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'LAST_NAME', bucket_name: 'valid'} + + - name: test_eligibility_medicare_status_code_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_medicare_status_code + description: > + Medicare status code joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', medicare_status_code: '10'} + - input: ref('terminology__medicare_status') + rows: + - {medicare_status_code: '10', medicare_status_description: 'Aged without ESRD'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'MEDICARE_STATUS_CODE', bucket_name: 'valid'} + + - name: test_eligibility_member_id_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_member_id + description: > + Member ID is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'MEMBER_ID', bucket_name: 'valid'} + + - name: test_eligibility_middle_name_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_middle_name + description: > + Middle name is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', middle_name: null} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'MIDDLE_NAME', bucket_name: 'null'} + + - name: test_eligibility_name_suffix_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_name_suffix + description: > + Name suffix is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', name_suffix: null} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'NAME_SUFFIX', bucket_name: 'null'} + + - name: test_eligibility_original_reason_entitlement_code_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_original_reason_entitlement_code + description: > + OREC joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', original_reason_entitlement_code: '0'} + - input: ref('terminology__medicare_orec') + rows: + - {original_reason_entitlement_code: '0', original_reason_entitlement_description: 'Old Age'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'ORIGINAL_REASON_ENTITLEMENT_CODE', bucket_name: 'valid'} + + - name: test_eligibility_payer_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_payer + description: > + Payer is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', payer: 'Medicare'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'PAYER', bucket_name: 'valid'} + + - name: test_eligibility_payer_type_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_payer_type + description: > + Payer type joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', payer_type: 'medicare'} + - input: ref('terminology__payer_type') + rows: + - {payer_type: 'medicare'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'PAYER_TYPE', bucket_name: 'valid'} + + - name: test_eligibility_person_id_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_person_id + description: > + Person ID is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', person_id: 'P1'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'PERSON_ID', bucket_name: 'valid'} + + - name: test_eligibility_phone_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_phone + description: > + Phone is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', phone: null} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'PHONE', bucket_name: 'null'} + + - name: test_eligibility_plan_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_plan + description: > + Plan is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', plan: 'Plan A'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'PLAN', bucket_name: 'valid'} + + - name: test_eligibility_race_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_race + description: > + Race joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', race: 'white'} + - input: ref('terminology__race') + rows: + - {description: 'white'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'RACE', bucket_name: 'valid'} + + - name: test_eligibility_start_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_start_date + description: > + Start date is valid past date so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'ENROLLMENT_START_DATE', bucket_name: 'valid'} + + - name: test_eligibility_state_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_state + description: > + State joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', state: 'Massachusetts'} + - input: ref('reference_data__ssa_fips_state') + rows: + - {ssa_fips_state_name: 'Massachusetts'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'STATE', bucket_name: 'valid'} + + - name: test_eligibility_zip_code_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__eligibility_zip_code + description: > + Zip code is 5 digits so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {data_source: 'src1', enrollment_start_date: '2023-01-01', member_id: 'M1', zip_code: '02101'} + expect: + rows: + - {data_source: 'src1', table_name: 'ELIGIBILITY', field_name: 'ZIP_CODE', bucket_name: 'valid'} + + # ========================================================================= + # MEDICAL CLAIM (shared/general) ATOMIC CHECKS (21 models) + # ========================================================================= + + - name: test_claim_allowed_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_allowed_amount + description: > + Allowed amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', allowed_amount: 100.00} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'ALLOWED_AMOUNT', bucket_name: 'valid'} + + - name: test_claim_charge_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_charge_amount + description: > + Charge amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', charge_amount: 200.00} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'CHARGE_AMOUNT', bucket_name: 'valid'} + + - name: test_claim_claim_id_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_claim_id + description: > + Claim ID is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'CLAIM_ID', bucket_name: 'valid'} + + - name: test_claim_claim_line_end_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_claim_line_end_date + description: > + Claim line end date is valid so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', claim_line_end_date: '2023-01-15', claim_end_date: '2023-01-15'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'CLAIM_LINE_END_DATE', bucket_name: 'valid'} + + - name: test_claim_claim_line_number_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_claim_line_number + description: > + Claim line number is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', claim_line_number: 1} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'CLAIM_LINE_NUMBER', bucket_name: 'valid'} + + - name: test_claim_claim_line_start_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_claim_line_start_date + description: > + Claim line start date is valid so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', claim_line_start_date: '2023-01-01'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'CLAIM_LINE_START_DATE', bucket_name: 'valid'} + + - name: test_claim_claim_type_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_claim_type + description: > + Claim type joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional'} + - input: ref('terminology__claim_type') + rows: + - {claim_type: 'institutional'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'CLAIM_TYPE', bucket_name: 'valid'} + + - name: test_claim_coinsurance_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_coinsurance_amount + description: > + Coinsurance amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', coinsurance_amount: 50.00} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'COINSURANCE_AMOUNT', bucket_name: 'valid'} + + - name: test_claim_copayment_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_copayment_amount + description: > + Copayment amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', copayment_amount: 25.00} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'COPAYMENT_AMOUNT', bucket_name: 'valid'} + + - name: test_claim_data_source_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_data_source + description: > + Data source is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DATA_SOURCE', bucket_name: 'valid'} + + - name: test_claim_deductible_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_deductible_amount + description: > + Deductible amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', deductible_amount: 500.00} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DEDUCTIBLE_AMOUNT', bucket_name: 'valid'} + + - name: test_claim_diagnosis_code_type_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_diagnosis_code_type + description: > + Diagnosis code type joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', diagnosis_code_type: 'icd-10-cm'} + - input: ref('reference_data__code_type') + rows: + - {code_type: 'icd-10-cm'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DIAGNOSIS_CODE_TYPE', bucket_name: 'valid'} + + - name: test_claim_drg_code_type_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_drg_code_type + description: > + DRG code type joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', drg_code_type: 'ms-drg'} + - input: ref('reference_data__code_type') + rows: + - {code_type: 'ms-drg'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DRG_CODE_TYPE', bucket_name: 'valid'} + + - name: test_claim_hcpcs_code_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_hcpcs_code + description: > + HCPCS code joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'professional', hcpcs_code: '99213'} + - input: ref('terminology__hcpcs_level_2') + rows: + - {hcpcs: '99213', short_description: 'Office visit'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'HCPCS_CODE', bucket_name: 'valid'} + + - name: test_claim_member_id_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_member_id + description: > + Member ID is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', member_id: 'M1'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'MEMBER_ID', bucket_name: 'valid'} + + - name: test_claim_paid_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_paid_amount + description: > + Paid amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', paid_amount: 75.00} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'PAID_AMOUNT', bucket_name: 'valid'} + + - name: test_claim_paid_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_paid_date + description: > + Paid date is valid so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', paid_date: '2023-02-01'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'PAID_DATE', bucket_name: 'valid'} + + - name: test_claim_payer_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_payer + description: > + Payer is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', payer: 'Medicare'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'PAYER', bucket_name: 'valid'} + + - name: test_claim_person_id_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_person_id + description: > + Person ID is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', person_id: 'P1'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'PERSON_ID', bucket_name: 'valid'} + + - name: test_claim_plan_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_plan + description: > + Plan is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', plan: 'Plan A'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'PLAN', bucket_name: 'valid'} + + - name: test_claim_total_cost_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__claim_total_cost_amount + description: > + Total cost amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', total_cost_amount: 1000.00} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'TOTAL_COST_AMOUNT', bucket_name: 'valid'} + + # ========================================================================= + # INSTITUTIONAL ATOMIC CHECKS (26 models) + # ========================================================================= + + - name: test_institutional_bill_type_code_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_bill_type_code + description: > + Bill type code joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', bill_type_code: '111'} + - input: ref('terminology__bill_type') + rows: + - {bill_type_code: '111', bill_type_description: 'Hospital Inpatient'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'BILL_TYPE_CODE', bucket_name: 'valid'} + + - name: test_institutional_billing_npi_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_billing_npi + description: > + Billing NPI joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', billing_npi: '1234567890'} + - input: ref('terminology__provider') + rows: + - {npi: '1234567890'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'BILLING_NPI', bucket_name: 'valid'} + + - name: test_institutional_claim_end_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_claim_end_date + description: > + Claim end date is valid so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', claim_end_date: '2023-01-15'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'CLAIM_END_DATE', bucket_name: 'valid'} + + - name: test_institutional_claim_start_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_claim_start_date + description: > + Claim start date is valid so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'CLAIM_START_DATE', bucket_name: 'valid'} + + - name: test_institutional_diagnosis_code_1_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_diagnosis_code_1 + description: > + Diagnosis code 1 is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', diagnosis_code_1: null} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'E1165', short_description: 'Type 2 diabetes'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DIAGNOSIS_CODE_1', bucket_name: 'null'} + + - name: test_institutional_diagnosis_code_2_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_diagnosis_code_2 + description: > + Diagnosis code 2 is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', diagnosis_code_2: null} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'E1165', short_description: 'Type 2 diabetes'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DIAGNOSIS_CODE_2', bucket_name: 'null'} + + - name: test_institutional_diagnosis_code_3_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_diagnosis_code_3 + description: > + Diagnosis code 3 is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', diagnosis_code_3: null} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'E1165', short_description: 'Type 2 diabetes'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DIAGNOSIS_CODE_3', bucket_name: 'null'} + + - name: test_institutional_diagnosis_code_uniqueness_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_diagnosis_code_uniqueness + description: > + No duplicate diagnosis codes so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', diagnosis_code_1: 'E11', diagnosis_code_2: 'I10', diagnosis_code_3: null, diagnosis_code_4: null, diagnosis_code_5: null, diagnosis_code_6: null, diagnosis_code_7: null, diagnosis_code_8: null, diagnosis_code_9: null, diagnosis_code_10: null, diagnosis_code_11: null, diagnosis_code_12: null, diagnosis_code_13: null, diagnosis_code_14: null, diagnosis_code_15: null, diagnosis_code_16: null, diagnosis_code_17: null, diagnosis_code_18: null, diagnosis_code_19: null, diagnosis_code_20: null, diagnosis_code_21: null, diagnosis_code_22: null, diagnosis_code_23: null, diagnosis_code_24: null, diagnosis_code_25: null} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DIAGNOSIS_CODE_UNIQUENESS', bucket_name: 'valid'} + + - name: test_institutional_discharge_disposition_code_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_discharge_disposition_code + description: > + Discharge disposition code is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', discharge_disposition_code: null} + - input: ref('terminology__discharge_disposition') + rows: + - {discharge_disposition_code: '01', discharge_disposition_description: 'Discharged to home'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DISCHARGE_DISPOSITION_CODE', bucket_name: 'null'} + + - name: test_institutional_facility_npi_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_facility_npi + description: > + Facility NPI is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', facility_npi: null} + - input: ref('terminology__provider') + rows: + - {npi: '1234567890'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'FACILITY_NPI', bucket_name: 'null'} + + - name: test_institutional_present_on_admission_1_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_present_on_admission_1 + description: > + POA 1 is 'y' so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', diagnosis_poa_1: 'y'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DIAGNOSIS_POA_1', bucket_name: 'valid'} + + - name: test_institutional_present_on_admission_2_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_present_on_admission_2 + description: > + POA 2 is 'n' so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', diagnosis_poa_2: 'n'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DIAGNOSIS_POA_2', bucket_name: 'valid'} + + - name: test_institutional_present_on_admission_3_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_present_on_admission_3 + description: > + POA 3 is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', diagnosis_poa_3: null} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DIAGNOSIS_POA_3', bucket_name: 'null'} + + - name: test_institutional_rendering_npi_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_rendering_npi + description: > + Rendering NPI is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'institutional', rendering_npi: null} + - input: ref('terminology__provider') + rows: + - {npi: '1234567890'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'RENDERING_NPI', bucket_name: 'null'} + + - name: test_institutional_revenue_center_code_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_revenue_center_code + description: > + Revenue center code joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', revenue_center_code: '0120'} + - input: ref('terminology__revenue_center') + rows: + - {revenue_center_code: '0120', revenue_center_description: 'Room and Board'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'REVENUE_CENTER_CODE', bucket_name: 'valid'} + + - name: test_institutional_service_unit_quantity_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__institutional_service_unit_quantity + description: > + Service unit quantity is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'institutional', service_unit_quantity: 5} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'service_unit_quantity', bucket_name: 'valid'} + + # ========================================================================= + # PROFESSIONAL ATOMIC CHECKS (9 models) + # ========================================================================= + + - name: test_professional_billing_npi_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__professional_billing_npi + description: > + Billing NPI joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'professional', billing_npi: '1234567890'} + - input: ref('terminology__provider') + rows: + - {npi: '1234567890'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'BILLING_NPI', bucket_name: 'valid'} + + - name: test_professional_claim_end_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__professional_claim_end_date + description: > + Professional claim end date is valid so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'professional', claim_end_date: '2023-01-15'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'CLAIM_END_DATE', bucket_name: 'valid'} + + - name: test_professional_claim_start_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__professional_claim_start_date + description: > + Professional claim start date is valid so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_type: 'professional'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'CLAIM_START_DATE', bucket_name: 'valid'} + + - name: test_professional_diagnosis_code_1_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__professional_diagnosis_code_1 + description: > + Professional diagnosis code 1 is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'professional', diagnosis_code_1: null} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'E1165', short_description: 'Type 2 diabetes'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DIAGNOSIS_CODE_1', bucket_name: 'null'} + + - name: test_professional_diagnosis_code_2_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__professional_diagnosis_code_2 + description: > + Professional diagnosis code 2 is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'professional', diagnosis_code_2: null} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'E1165', short_description: 'Type 2 diabetes'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DIAGNOSIS_CODE_2', bucket_name: 'null'} + + - name: test_professional_diagnosis_code_3_null + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__professional_diagnosis_code_3 + description: > + Professional diagnosis code 3 is null so bucket should be null. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'professional', diagnosis_code_3: null} + - input: ref('terminology__icd_10_cm') + rows: + - {icd_10_cm: 'E1165', short_description: 'Type 2 diabetes'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'DIAGNOSIS_CODE_3', bucket_name: 'null'} + + - name: test_professional_facility_npi_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__professional_facility_npi + description: > + Facility NPI joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'professional', facility_npi: '1234567890'} + - input: ref('terminology__provider') + rows: + - {npi: '1234567890'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'FACILITY_NPI', bucket_name: 'valid'} + + - name: test_professional_place_of_service_code_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__professional_place_of_service_code + description: > + Place of service code joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'professional', place_of_service_code: '11'} + - input: ref('terminology__place_of_service') + rows: + - {place_of_service_code: '11', place_of_service_description: 'Office'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'PLACE_OF_SERVICE_CODE', bucket_name: 'valid'} + + - name: test_professional_rendering_npi_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__professional_rendering_npi + description: > + Rendering NPI joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {data_source: 'src1', claim_start_date: '2023-01-01', claim_id: 'MC1', claim_line_number: 1, claim_type: 'professional', rendering_npi: '1234567890'} + - input: ref('terminology__provider') + rows: + - {npi: '1234567890'} + expect: + rows: + - {data_source: 'src1', table_name: 'MEDICAL_CLAIM', field_name: 'RENDERING_NPI', bucket_name: 'valid'} + + # ========================================================================= + # PHARMACY ATOMIC CHECKS (21 models) + # ========================================================================= + + - name: test_pharmacy_allowed_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_allowed_amount + description: > + Allowed amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, allowed_amount: 100.00} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'ALLOWED_AMOUNT', bucket_name: 'valid'} + + - name: test_pharmacy_claim_id_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_claim_id + description: > + Pharmacy claim ID is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'CLAIM_ID', bucket_name: 'valid'} + + - name: test_pharmacy_claim_line_number_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_claim_line_number + description: > + Pharmacy claim line number is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'CLAIM_LINE_NUMBER', bucket_name: 'valid'} + + - name: test_pharmacy_coinsurance_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_coinsurance_amount + description: > + Coinsurance amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, coinsurance_amount: 10.00} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'COINSURANCE_AMOUNT', bucket_name: 'valid'} + + - name: test_pharmacy_copayment_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_copayment_amount + description: > + Copayment amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, copayment_amount: 15.00} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'COPAYMENT_AMOUNT', bucket_name: 'valid'} + + - name: test_pharmacy_data_source_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_data_source + description: > + Pharmacy data source is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'DATA_SOURCE', bucket_name: 'valid'} + + - name: test_pharmacy_days_supply_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_days_supply + description: > + Days supply is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, days_supply: 30} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'DAYS_SUPPLY', bucket_name: 'valid'} + + - name: test_pharmacy_deductible_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_deductible_amount + description: > + Deductible amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, deductible_amount: 50.00} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'DEDUCTIBLE_AMOUNT', bucket_name: 'valid'} + + - name: test_pharmacy_dispensing_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_dispensing_date + description: > + Dispensing date is valid so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, dispensing_date: '2023-01-10'} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'DISPENSING_DATE', bucket_name: 'valid'} + + - name: test_pharmacy_dispensing_provider_npi_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_dispensing_provider_npi + description: > + Dispensing provider NPI joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, dispensing_provider_npi: '1234567890'} + - input: ref('terminology__provider') + rows: + - {npi: '1234567890'} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'DISPENSING_PROVIDER_NPI', bucket_name: 'valid'} + + - name: test_pharmacy_member_id_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_member_id + description: > + Pharmacy member ID is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, member_id: 'M1'} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'MEMBER_ID', bucket_name: 'valid'} + + - name: test_pharmacy_ndc_code_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_ndc_code + description: > + NDC code joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, ndc_code: '12345678901'} + - input: ref('terminology__ndc') + rows: + - {ndc: '12345678901', rxnorm_description: 'Metformin 500mg', fda_description: null} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'NDC_CODE', bucket_name: 'valid'} + + - name: test_pharmacy_paid_amount_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_paid_amount + description: > + Paid amount is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, paid_amount: 75.00} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'PAID_AMOUNT', bucket_name: 'valid'} + + - name: test_pharmacy_paid_date_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_paid_date + description: > + Paid date is valid so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'PAID_DATE', bucket_name: 'valid'} + + - name: test_pharmacy_payer_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_payer + description: > + Payer is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, payer: 'Medicare'} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'PAYER', bucket_name: 'valid'} + + - name: test_pharmacy_person_id_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_person_id + description: > + Pharmacy person ID is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, person_id: 'P1'} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'PERSON_ID', bucket_name: 'valid'} + + - name: test_pharmacy_plan_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_plan + description: > + Plan is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, plan: 'Plan A'} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'PLAN', bucket_name: 'valid'} + + - name: test_pharmacy_prescribing_provider_npi_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_prescribing_provider_npi + description: > + Prescribing provider NPI joins to terminology so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, prescribing_provider_npi: '1234567890'} + - input: ref('terminology__provider') + rows: + - {npi: '1234567890'} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'PRESCRIBING_PROVIDER_NPI', bucket_name: 'valid'} + + - name: test_pharmacy_quantity_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_quantity + description: > + Quantity is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, quantity: 60} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'QUANTITY', bucket_name: 'valid'} + + - name: test_pharmacy_refills_valid + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: data_quality__pharmacy_refills + description: > + Refills is non-null so bucket should be valid. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {data_source: 'src1', paid_date: '2023-01-15', claim_id: 'RX1', claim_line_number: 1, refills: 3} + expect: + rows: + - {data_source: 'src1', table_name: 'PHARMACY_CLAIM', field_name: 'REFILLS', bucket_name: 'valid'} + diff --git a/models/data_quality/dqi/mart_review/mart_review_unit_tests.yml b/models/data_quality/dqi/mart_review/mart_review_unit_tests.yml new file mode 100644 index 000000000..d57c83d3f --- /dev/null +++ b/models/data_quality/dqi/mart_review/mart_review_unit_tests.yml @@ -0,0 +1,353 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # STAGE MODELS + # ========================================================================= + + - name: test_stg_member_month_joins_calendar + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__stg_member_month + description: > + Joins core member_months to the calendar table to add + year_month_int and year_month_date columns. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', year_month: '202301', data_source: 'src1', payer: 'MCR', plan: 'PlanA', member_id: 'M1'} + - {person_id: 'P2', year_month: '202302', data_source: 'src1', payer: 'MCR', plan: 'PlanA', member_id: 'M2'} + - input: ref('reference_data__calendar') + rows: + - {year_month_int: 202301, full_date: '2023-01-01', day: 1} + - {year_month_int: 202301, full_date: '2023-01-15', day: 15} + - {year_month_int: 202302, full_date: '2023-02-01', day: 1} + expect: + rows: + - {person_id: 'P1', year_month: '202301', data_source: 'src1', payer: 'MCR', plan: 'PlanA', member_id: 'M1', year_month_int: 202301, year_month_date: '2023-01-01'} + - {person_id: 'P2', year_month: '202302', data_source: 'src1', payer: 'MCR', plan: 'PlanA', member_id: 'M2', year_month_int: 202302, year_month_date: '2023-02-01'} + + - name: test_stg_medical_claim_joins_calendar_for_year_month + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__stg_medical_claim + description: > + Joins core medical_claim to calendar to derive year_month from + claim_line_start_date (with claim_start_date as fallback). + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__medical_claim') + rows: + - {claim_id: 'MC1', claim_line_start_date: '2023-06-15', claim_start_date: '2023-06-01', paid_amount: 100.00, person_id: 'P1', data_source: 'src1', payer: 'MCR', plan: 'PlanA', member_month_key: 'K1', encounter_id: 'E1'} + - {claim_id: 'MC2', claim_line_start_date: null, claim_start_date: '2023-07-01', paid_amount: 200.00, person_id: 'P2', data_source: 'src1', payer: 'MCR', plan: 'PlanA', member_month_key: 'K2', encounter_id: 'E2'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-06-15', year_month_int: 202306} + - {full_date: '2023-07-01', year_month_int: 202307} + expect: + rows: + - {claim_id: 'MC1', year_month: '202306', paid_amount: 100.00, person_id: 'P1', data_source: 'src1'} + - {claim_id: 'MC2', year_month: '202307', paid_amount: 200.00, person_id: 'P2', data_source: 'src1'} + + - name: test_stg_pharmacy_claim_joins_calendar_with_fallback + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__stg_pharmacy_claim + description: > + Joins core pharmacy_claim to calendar using paid_date with + dispensing_date as fallback. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__pharmacy_claim') + rows: + - {claim_id: 'RX1', paid_date: '2023-06-15', dispensing_date: '2023-06-01', paid_amount: 50.00, person_id: 'P1', data_source: 'src1'} + - {claim_id: 'RX2', paid_date: null, dispensing_date: '2023-07-01', paid_amount: 75.00, person_id: 'P2', data_source: 'src1'} + - input: ref('reference_data__calendar') + rows: + - {full_date: '2023-06-15', year_month_int: 202306} + - {full_date: '2023-07-01', year_month_int: 202307} + expect: + rows: + - {claim_id: 'RX1', year_month: '202306', paid_amount: 50.00, person_id: 'P1', data_source: 'src1'} + - {claim_id: 'RX2', year_month: '202307', paid_amount: 75.00, person_id: 'P2', data_source: 'src1'} + + # ========================================================================= + # FINAL MODELS + # ========================================================================= + + - name: test_readmissions_filters_index_admissions + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__readmissions + description: > + Filters readmission_summary to only include rows where + index_admission_flag = 1. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('readmissions__readmission_summary') + rows: + - {encounter_id: 'E1', index_admission_flag: 1, person_id: 'P1'} + - {encounter_id: 'E2', index_admission_flag: 0, person_id: 'P2'} + - {encounter_id: 'E3', index_admission_flag: 1, person_id: 'P3'} + expect: + rows: + - {encounter_id: 'E1', index_admission_flag: 1, person_id: 'P1'} + - {encounter_id: 'E3', index_admission_flag: 1, person_id: 'P3'} + + - name: test_patient_risk_scores_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__patient_risk_scores + description: > + Passes through all CMS-HCC patient risk scores without + modification. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__patient_risk_scores') + rows: + - {person_id: 'P1', payment_year: 2024, normalized_risk_score: 1.25} + - {person_id: 'P2', payment_year: 2024, normalized_risk_score: 0.85} + expect: + rows: + - {person_id: 'P1', payment_year: 2024, normalized_risk_score: 1.25} + - {person_id: 'P2', payment_year: 2024, normalized_risk_score: 0.85} + + - name: test_patient_risk_factors_adds_dense_rank_sk + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__patient_risk_factors + description: > + Adds a patient_risk_sk column using dense_rank over + person_id, model_version, and payment_year. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('cms_hcc__patient_risk_factors') + rows: + - {person_id: 'P1', model_version: 'V24', payment_year: 2024, factor_type: 'Demographic', coefficient: 0.5} + - {person_id: 'P1', model_version: 'V24', payment_year: 2024, factor_type: 'Disease', coefficient: 0.3} + - {person_id: 'P1', model_version: 'V28', payment_year: 2024, factor_type: 'Demographic', coefficient: 0.4} + - {person_id: 'P2', model_version: 'V24', payment_year: 2024, factor_type: 'Demographic', coefficient: 0.6} + expect: + rows: + - {person_id: 'P1', model_version: 'V24', payment_year: 2024, factor_type: 'Demographic', coefficient: 0.5, patient_risk_sk: 1} + - {person_id: 'P1', model_version: 'V24', payment_year: 2024, factor_type: 'Disease', coefficient: 0.3, patient_risk_sk: 1} + - {person_id: 'P1', model_version: 'V28', payment_year: 2024, factor_type: 'Demographic', coefficient: 0.4, patient_risk_sk: 2} + - {person_id: 'P2', model_version: 'V24', payment_year: 2024, factor_type: 'Demographic', coefficient: 0.6, patient_risk_sk: 3} + + - name: test_patient_risk_buckets_score_ranges + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__patient_risk + description: > + Buckets risk scores into predefined ranges (e.g., '.5', '1', '2', etc.) + and sums coefficients per person/model/payment_year. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('mart_review__patient_risk_factors') + rows: + - {person_id: 'P1', model_version: 'V24', payment_year: 2024, coefficient: 0.3, patient_risk_sk: 1} + - {person_id: 'P1', model_version: 'V24', payment_year: 2024, coefficient: 0.1, patient_risk_sk: 1} + - {person_id: 'P2', model_version: 'V24', payment_year: 2024, coefficient: 1.2, patient_risk_sk: 2} + - {person_id: 'P2', model_version: 'V24', payment_year: 2024, coefficient: 0.5, patient_risk_sk: 2} + - {person_id: 'P3', model_version: 'V24', payment_year: 2024, coefficient: 3.0, patient_risk_sk: 3} + - {person_id: 'P3', model_version: 'V24', payment_year: 2024, coefficient: 2.5, patient_risk_sk: 3} + expect: + rows: + - {risk_score_bucket: '.5', payment_year: 2024, person_id: 'P1', model_version: 'V24', patient_risk_sk: 1, risk_score: 0.4, tuva_last_run: '2024-01-01 00:00:00'} + - {risk_score_bucket: '2', payment_year: 2024, person_id: 'P2', model_version: 'V24', patient_risk_sk: 2, risk_score: 1.7, tuva_last_run: '2024-01-01 00:00:00'} + - {risk_score_bucket: '5+', payment_year: 2024, person_id: 'P3', model_version: 'V24', patient_risk_sk: 3, risk_score: 5.5, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_quality_measures_summary_long_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__quality_measures_summary_long + description: > + Passes through all quality measure summary long records. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__summary_long') + rows: + - {measure_id: 'M1', measure_name: 'Measure A', person_id: 'P1', denominator_flag: 1, numerator_flag: 1} + - {measure_id: 'M2', measure_name: 'Measure B', person_id: 'P2', denominator_flag: 1, numerator_flag: 0} + expect: + rows: + - {measure_id: 'M1', measure_name: 'Measure A', person_id: 'P1', denominator_flag: 1, numerator_flag: 1} + - {measure_id: 'M2', measure_name: 'Measure B', person_id: 'P2', denominator_flag: 1, numerator_flag: 0} + + - name: test_quality_measures_value_set_adds_tuva_last_run + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__quality_measures_value_set + description: > + Passes through quality measures and appends tuva_last_run. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('quality_measures__measures') + rows: + - {id: 'NQF2372', name: 'Breast Cancer Screening'} + expect: + rows: + - {id: 'NQF2372', name: 'Breast Cancer Screening', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_members_with_claims_counts + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__members_with_claims + description: > + Counts members with medical claims, pharmacy claims, and any claims + by data_source and year_month. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', data_source: 'src1', year_month: '202301'} + - {person_id: 'P2', data_source: 'src1', year_month: '202301'} + - {person_id: 'P3', data_source: 'src1', year_month: '202301'} + - input: ref('mart_review__stg_medical_claim') + rows: + - {person_id: 'P1', data_source: 'src1', year_month: '202301', paid_amount: 100.00} + - input: ref('mart_review__stg_pharmacy_claim') + rows: + - {person_id: 'P2', data_source: 'src1', year_month: '202301', paid_amount: 50.00} + expect: + rows: + - {data_source: 'src1', year_month: '202301', members_with_medical_claims: 1, members_with_pharmacy_claims: 1, members_with_claims: 2, total_member_months: 3} + + - name: test_claims_with_enrollment_calculates_percentage + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__claims_with_enrollment + description: > + Calculates the percentage of medical claims that have matching + enrollment records in core member_months. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('mart_review__stg_medical_claim') + rows: + - {data_source: 'src1', year_month: '202301', payer: 'MCR', plan: 'PlanA', member_month_key: 'K1', person_id: 'P1'} + - {data_source: 'src1', year_month: '202301', payer: 'MCR', plan: 'PlanA', member_month_key: 'K2', person_id: 'P2'} + - {data_source: 'src1', year_month: '202301', payer: 'MCR', plan: 'PlanA', member_month_key: 'K3', person_id: 'P3'} + - input: ref('core__member_months') + rows: + - {person_id: 'P1', member_month_key: 'K1'} + - {person_id: 'P2', member_month_key: 'K2'} + expect: + rows: + - {data_source: 'src1', year_month: '202301', payer: 'MCR', plan: 'PlanA', claims_with_enrollment: 2, claims: 3, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_calendar_month_filters_first_day + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__calendar_month + description: > + Selects distinct year_month entries from the calendar where day = 1, + returning the first day of each month. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('reference_data__calendar') + rows: + - {year_month_int: 202301, full_date: '2023-01-01', day: 1} + - {year_month_int: 202301, full_date: '2023-01-15', day: 15} + - {year_month_int: 202302, full_date: '2023-02-01', day: 1} + - {year_month_int: 202302, full_date: '2023-02-28', day: 28} + expect: + rows: + - {year_month: '202301', full_date: '2023-01-01', tuva_last_run: '2024-01-01 00:00:00'} + - {year_month: '202302', full_date: '2023-02-01', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_data_source_collects_distinct_sources + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__data_source + description: > + Collects distinct data_source values from all core tables and + returns a deduplicated set. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__condition') + rows: + - {data_source: 'src1'} + - {data_source: 'src2'} + - input: ref('core__eligibility') + rows: + - {data_source: 'src1'} + - input: ref('core__encounter') + rows: + - {data_source: 'src1'} + - input: ref('core__location') + rows: + - {data_source: 'src1'} + - input: ref('core__medical_claim') + rows: + - {data_source: 'src2'} + - input: ref('core__member_months') + rows: + - {data_source: 'src1'} + - input: ref('core__patient') + rows: + - {data_source: 'src1'} + - input: ref('core__pharmacy_claim') + rows: + - {data_source: 'src2'} + - input: ref('core__practitioner') + rows: + - {data_source: 'src3'} + - input: ref('core__procedure') + rows: + - {data_source: 'src1'} + expect: + rows: + - {data_source: 'src1', tuva_last_run: '2024-01-01 00:00:00'} + - {data_source: 'src2', tuva_last_run: '2024-01-01 00:00:00'} + - {data_source: 'src3', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_member_months_joins_pmpm + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: mart_review__member_months + description: > + Joins core member_months with financial_pmpm prep data and + coalesces null paid amounts to 0. + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('core__member_months') + rows: + - {person_id: 'P1', member_id: 'M1', data_source: 'src1', year_month: '202301', payer: 'MCR', plan: 'PlanA'} + - {person_id: 'P2', member_id: 'M2', data_source: 'src1', year_month: '202301', payer: 'MCR', plan: 'PlanA'} + - input: ref('financial_pmpm__pmpm_prep') + rows: + - {person_id: 'P1', member_id: 'M1', data_source: 'src1', year_month: '202301', payer: 'MCR', plan: 'PlanA', total_paid: 500.00, medical_paid: 400.00, pharmacy_paid: 100.00} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', data_source: 'src1', year_month: '202301', payer: 'MCR', plan: 'PlanA', total_paid: 500.00, medical_paid: 400.00, pharmacy_paid: 100.00} + - {person_id: 'P2', member_id: 'M2', data_source: 'src1', year_month: '202301', payer: 'MCR', plan: 'PlanA', total_paid: 0, medical_paid: 0, pharmacy_paid: 0} diff --git a/models/input_layer/input_layer_unit_tests.yml b/models/input_layer/input_layer_unit_tests.yml new file mode 100644 index 000000000..feef785d1 --- /dev/null +++ b/models/input_layer/input_layer_unit_tests.yml @@ -0,0 +1,642 @@ +version: 2 + +unit_tests: + + # ========================================================================= + # APPOINTMENT + # ========================================================================= + + - name: test_input_layer_appointment_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__appointment + description: "Verifies that appointment data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('appointment') + rows: + - {appointment_id: 'APT1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', source_appointment_type_code: 'OFFICE', source_appointment_type_description: 'Office Visit', normalized_appointment_type_code: 'OV', normalized_appointment_type_description: 'Office Visit', start_datetime: '2023-06-15 09:00:00', end_datetime: '2023-06-15 10:00:00', duration: 60, location_id: 'LOC1', practitioner_id: 'PRAC1', source_status: 'completed', normalized_status: 'completed', appointment_specialty: 'Internal Medicine', reason: 'Annual checkup', source_reason_code_type: 'icd-10-cm', source_reason_code: 'Z0000', source_reason_description: 'General exam', normalized_reason_code_type: 'icd-10-cm', normalized_reason_code: 'Z0000', normalized_reason_description: 'General exam', cancellation_reason: null, source_cancellation_reason_code_type: null, source_cancellation_reason_code: null, source_cancellation_reason_description: null, normalized_cancellation_reason_code_type: null, normalized_cancellation_reason_code: null, normalized_cancellation_reason_description: null, data_source: 'clinic_a', file_name: 'appts_2023.csv', ingest_datetime: '2023-07-01 00:00:00'} + expect: + rows: + - {appointment_id: 'APT1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', source_appointment_type_code: 'OFFICE', source_appointment_type_description: 'Office Visit', normalized_appointment_type_code: 'OV', normalized_appointment_type_description: 'Office Visit', start_datetime: '2023-06-15 09:00:00', end_datetime: '2023-06-15 10:00:00', duration: 60, location_id: 'LOC1', practitioner_id: 'PRAC1', source_status: 'completed', normalized_status: 'completed', appointment_specialty: 'Internal Medicine', reason: 'Annual checkup', source_reason_code_type: 'icd-10-cm', source_reason_code: 'Z0000', source_reason_description: 'General exam', normalized_reason_code_type: 'icd-10-cm', normalized_reason_code: 'Z0000', normalized_reason_description: 'General exam', cancellation_reason: null, source_cancellation_reason_code_type: null, source_cancellation_reason_code: null, source_cancellation_reason_description: null, normalized_cancellation_reason_code_type: null, normalized_cancellation_reason_code: null, normalized_cancellation_reason_description: null, data_source: 'clinic_a', file_name: 'appts_2023.csv', ingest_datetime: '2023-07-01 00:00:00'} + + - name: test_input_layer_appointment_multiple_rows_preserve_pk + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__appointment + description: "Multiple appointments with unique appointment_id values pass through preserving primary key uniqueness" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('appointment') + rows: + - {appointment_id: 'APT1', person_id: 'P1', patient_id: 'PAT1', data_source: 'src1'} + - {appointment_id: 'APT2', person_id: 'P1', patient_id: 'PAT1', data_source: 'src1'} + - {appointment_id: 'APT3', person_id: 'P2', patient_id: 'PAT2', data_source: 'src2'} + expect: + rows: + - {appointment_id: 'APT1', person_id: 'P1', patient_id: 'PAT1', data_source: 'src1'} + - {appointment_id: 'APT2', person_id: 'P1', patient_id: 'PAT1', data_source: 'src1'} + - {appointment_id: 'APT3', person_id: 'P2', patient_id: 'PAT2', data_source: 'src2'} + + # ========================================================================= + # CONDITION + # ========================================================================= + + - name: test_input_layer_condition_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__condition + description: "Verifies that condition data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('condition') + rows: + - {condition_id: 'COND1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', claim_id: 'CLM1', recorded_date: '2023-06-15', onset_date: '2023-06-01', resolved_date: null, status: 'active', condition_type: 'billing', source_code_type: 'icd-10-cm', source_code: 'E1165', source_description: 'Type 2 diabetes with hyperglycemia', normalized_code_type: 'icd-10-cm', normalized_code: 'E1165', normalized_description: 'Type 2 diabetes mellitus with hyperglycemia', condition_rank: 1, present_on_admit_code: 'Y', present_on_admit_description: 'Yes', payer: 'MCR', data_source: 'claims_src', file_name: 'claims_2023.csv', ingest_datetime: '2023-07-01 00:00:00'} + expect: + rows: + - {condition_id: 'COND1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', claim_id: 'CLM1', recorded_date: '2023-06-15', onset_date: '2023-06-01', resolved_date: null, status: 'active', condition_type: 'billing', source_code_type: 'icd-10-cm', source_code: 'E1165', source_description: 'Type 2 diabetes with hyperglycemia', normalized_code_type: 'icd-10-cm', normalized_code: 'E1165', normalized_description: 'Type 2 diabetes mellitus with hyperglycemia', condition_rank: 1, present_on_admit_code: 'Y', present_on_admit_description: 'Yes', payer: 'MCR', data_source: 'claims_src', file_name: 'claims_2023.csv', ingest_datetime: '2023-07-01 00:00:00'} + + - name: test_input_layer_condition_multiple_conditions_same_patient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__condition + description: "Multiple conditions for the same patient pass through with unique condition_id values" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('condition') + rows: + - {condition_id: 'COND1', person_id: 'P1', normalized_code: 'E1165', condition_type: 'billing', data_source: 'src1'} + - {condition_id: 'COND2', person_id: 'P1', normalized_code: 'I10', condition_type: 'billing', data_source: 'src1'} + - {condition_id: 'COND3', person_id: 'P1', normalized_code: 'E1165', condition_type: 'problem', data_source: 'src1'} + expect: + rows: + - {condition_id: 'COND1', person_id: 'P1', normalized_code: 'E1165', condition_type: 'billing', data_source: 'src1'} + - {condition_id: 'COND2', person_id: 'P1', normalized_code: 'I10', condition_type: 'billing', data_source: 'src1'} + - {condition_id: 'COND3', person_id: 'P1', normalized_code: 'E1165', condition_type: 'problem', data_source: 'src1'} + + # ========================================================================= + # ELIGIBILITY + # ========================================================================= + + - name: test_input_layer_eligibility_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__eligibility + description: "Verifies that eligibility data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', payer_type: 'medicare', plan: 'PlanA', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'MCR', payer_type: 'medicare', plan: 'PlanA', data_source: 'src1'} + + - name: test_input_layer_eligibility_composite_pk_multiple_spans + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__eligibility + description: "Multiple eligibility spans for the same person pass through preserving composite PK (person_id, member_id, enrollment_start_date, enrollment_end_date, plan, payer, data_source)" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('eligibility') + rows: + - {person_id: 'P1', member_id: 'M1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-06-30', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', enrollment_start_date: '2023-07-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P2', member_id: 'M2', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'COM', plan: 'PlanB', data_source: 'src1'} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-06-30', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P1', member_id: 'M1', enrollment_start_date: '2023-07-01', enrollment_end_date: '2023-12-31', payer: 'MCR', plan: 'PlanA', data_source: 'src1'} + - {person_id: 'P2', member_id: 'M2', enrollment_start_date: '2023-01-01', enrollment_end_date: '2023-12-31', payer: 'COM', plan: 'PlanB', data_source: 'src1'} + + # ========================================================================= + # ENCOUNTER + # ========================================================================= + + - name: test_input_layer_encounter_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__encounter + description: "Verifies that encounter data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounter') + rows: + - {encounter_id: 'ENC1', person_id: 'P1', patient_id: 'PAT1', encounter_type: 'acute inpatient', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, admit_source_code: '1', admit_source_description: 'Non-healthcare facility', admit_type_code: '1', admit_type_description: 'Emergency', discharge_disposition_code: '01', discharge_disposition_description: 'Home', attending_provider_id: 'PROV1', attending_provider_name: 'Dr. Smith', facility_npi: '1234567890', facility_name: 'General Hospital', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'I2510', primary_diagnosis_description: 'ASCVD of native coronary artery', drg_code_type: 'ms-drg', drg_code: '280', drg_description: 'Acute MI discharged alive', paid_amount: 15000.00, allowed_amount: 18000.00, charge_amount: 25000.00, data_source: 'claims_src', file_name: 'enc_2023.csv', ingest_datetime: '2023-07-01 00:00:00'} + expect: + rows: + - {encounter_id: 'ENC1', person_id: 'P1', patient_id: 'PAT1', encounter_type: 'acute inpatient', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', length_of_stay: 4, admit_source_code: '1', admit_source_description: 'Non-healthcare facility', admit_type_code: '1', admit_type_description: 'Emergency', discharge_disposition_code: '01', discharge_disposition_description: 'Home', attending_provider_id: 'PROV1', attending_provider_name: 'Dr. Smith', facility_npi: '1234567890', facility_name: 'General Hospital', primary_diagnosis_code_type: 'icd-10-cm', primary_diagnosis_code: 'I2510', primary_diagnosis_description: 'ASCVD of native coronary artery', drg_code_type: 'ms-drg', drg_code: '280', drg_description: 'Acute MI discharged alive', paid_amount: 15000.00, allowed_amount: 18000.00, charge_amount: 25000.00, data_source: 'claims_src', file_name: 'enc_2023.csv', ingest_datetime: '2023-07-01 00:00:00'} + + - name: test_input_layer_encounter_multiple_types + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__encounter + description: "Multiple encounter types for different patients pass through preserving encounter_id uniqueness" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('encounter') + rows: + - {encounter_id: 'ENC1', person_id: 'P1', encounter_type: 'acute inpatient', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', data_source: 'src1'} + - {encounter_id: 'ENC2', person_id: 'P1', encounter_type: 'emergency department', encounter_start_date: '2023-08-10', encounter_end_date: '2023-08-10', data_source: 'src1'} + - {encounter_id: 'ENC3', person_id: 'P2', encounter_type: 'office visit', encounter_start_date: '2023-09-01', encounter_end_date: '2023-09-01', data_source: 'src1'} + expect: + rows: + - {encounter_id: 'ENC1', person_id: 'P1', encounter_type: 'acute inpatient', encounter_start_date: '2023-06-01', encounter_end_date: '2023-06-05', data_source: 'src1'} + - {encounter_id: 'ENC2', person_id: 'P1', encounter_type: 'emergency department', encounter_start_date: '2023-08-10', encounter_end_date: '2023-08-10', data_source: 'src1'} + - {encounter_id: 'ENC3', person_id: 'P2', encounter_type: 'office visit', encounter_start_date: '2023-09-01', encounter_end_date: '2023-09-01', data_source: 'src1'} + + # ========================================================================= + # IMMUNIZATION + # ========================================================================= + + - name: test_input_layer_immunization_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__immunization + description: "Verifies that immunization data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('immunization') + rows: + - {immunization_id: 'IMM1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', source_code_type: 'cvx', source_code: '208', source_description: 'COVID-19 Pfizer', normalized_code_type: 'cvx', normalized_code: '208', normalized_description: 'COVID-19 Pfizer-BioNTech', status: 'completed', status_reason: null, occurrence_date: '2023-03-15', source_dose: '0.3 mL', normalized_dose: '0.3 mL', lot_number: 'EW0150', body_site: 'Left deltoid', route: 'Intramuscular', location_id: 'LOC1', practitioner_id: 'PRAC1', data_source: 'clinic_a', file_name: 'imm_2023.csv', ingest_datetime: '2023-04-01 00:00:00'} + expect: + rows: + - {immunization_id: 'IMM1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', source_code_type: 'cvx', source_code: '208', source_description: 'COVID-19 Pfizer', normalized_code_type: 'cvx', normalized_code: '208', normalized_description: 'COVID-19 Pfizer-BioNTech', status: 'completed', status_reason: null, occurrence_date: '2023-03-15', source_dose: '0.3 mL', normalized_dose: '0.3 mL', lot_number: 'EW0150', body_site: 'Left deltoid', route: 'Intramuscular', location_id: 'LOC1', practitioner_id: 'PRAC1', data_source: 'clinic_a', file_name: 'imm_2023.csv', ingest_datetime: '2023-04-01 00:00:00'} + + - name: test_input_layer_immunization_multiple_doses + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__immunization + description: "Multiple immunization records for the same patient pass through with unique immunization_id values" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('immunization') + rows: + - {immunization_id: 'IMM1', person_id: 'P1', normalized_code: '208', occurrence_date: '2023-01-15', data_source: 'src1'} + - {immunization_id: 'IMM2', person_id: 'P1', normalized_code: '208', occurrence_date: '2023-02-15', data_source: 'src1'} + - {immunization_id: 'IMM3', person_id: 'P1', normalized_code: '213', occurrence_date: '2023-09-01', data_source: 'src1'} + expect: + rows: + - {immunization_id: 'IMM1', person_id: 'P1', normalized_code: '208', occurrence_date: '2023-01-15', data_source: 'src1'} + - {immunization_id: 'IMM2', person_id: 'P1', normalized_code: '208', occurrence_date: '2023-02-15', data_source: 'src1'} + - {immunization_id: 'IMM3', person_id: 'P1', normalized_code: '213', occurrence_date: '2023-09-01', data_source: 'src1'} + + # ========================================================================= + # LAB RESULT + # ========================================================================= + + - name: test_input_layer_lab_result_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__lab_result + description: "Verifies that lab result data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('lab_result') + rows: + - {lab_result_id: 'LAB1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', accession_number: 'ACC001', source_order_type: 'loinc', source_order_code: '4548-4', source_order_description: 'HbA1c', source_component_type: 'loinc', source_component_code: '4548-4', source_component_description: 'HbA1c', normalized_order_type: 'loinc', normalized_order_code: '4548-4', normalized_order_description: 'HbA1c', normalized_component_type: 'loinc', normalized_component_code: '4548-4', normalized_component_description: 'Hemoglobin A1c', status: 'final', result: '7.2', result_datetime: '2023-06-15 14:30:00', collection_datetime: '2023-06-15 08:00:00', source_units: '%', normalized_units: '%', source_reference_range_low: '4.0', source_reference_range_high: '5.6', normalized_reference_range_low: '4.0', normalized_reference_range_high: '5.6', source_abnormal_flag: 1, normalized_abnormal_flag: 1, specimen: 'blood', ordering_practitioner_id: 'PRAC1', data_source: 'lab_src', file_name: 'labs_2023.csv', ingest_datetime: '2023-07-01 00:00:00'} + expect: + rows: + - {lab_result_id: 'LAB1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', accession_number: 'ACC001', source_order_type: 'loinc', source_order_code: '4548-4', source_order_description: 'HbA1c', source_component_type: 'loinc', source_component_code: '4548-4', source_component_description: 'HbA1c', normalized_order_type: 'loinc', normalized_order_code: '4548-4', normalized_order_description: 'HbA1c', normalized_component_type: 'loinc', normalized_component_code: '4548-4', normalized_component_description: 'Hemoglobin A1c', status: 'final', result: '7.2', result_datetime: '2023-06-15 14:30:00', collection_datetime: '2023-06-15 08:00:00', source_units: '%', normalized_units: '%', source_reference_range_low: '4.0', source_reference_range_high: '5.6', normalized_reference_range_low: '4.0', normalized_reference_range_high: '5.6', source_abnormal_flag: 1, normalized_abnormal_flag: 1, specimen: 'blood', ordering_practitioner_id: 'PRAC1', data_source: 'lab_src', file_name: 'labs_2023.csv', ingest_datetime: '2023-07-01 00:00:00'} + + - name: test_input_layer_lab_result_multiple_results_same_patient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__lab_result + description: "Multiple lab results for the same patient pass through preserving lab_result_id uniqueness" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('lab_result') + rows: + - {lab_result_id: 'LAB1', person_id: 'P1', normalized_order_code: '4548-4', result: '7.2', data_source: 'src1'} + - {lab_result_id: 'LAB2', person_id: 'P1', normalized_order_code: '2345-7', result: '120', data_source: 'src1'} + expect: + rows: + - {lab_result_id: 'LAB1', person_id: 'P1', normalized_order_code: '4548-4', result: '7.2', data_source: 'src1'} + - {lab_result_id: 'LAB2', person_id: 'P1', normalized_order_code: '2345-7', result: '120', data_source: 'src1'} + + # ========================================================================= + # LOCATION + # ========================================================================= + + - name: test_input_layer_location_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__location + description: "Verifies that location data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('location') + rows: + - {location_id: 'LOC1', npi: '1234567890', name: 'General Hospital', facility_type: 'acute care hospital', parent_organization: 'Health System A', address: '123 Main St', city: 'Springfield', state: 'IL', zip_code: '62701', latitude: 39.7817, longitude: -89.6501, data_source: 'clinic_a'} + expect: + rows: + - {location_id: 'LOC1', npi: '1234567890', name: 'General Hospital', facility_type: 'acute care hospital', parent_organization: 'Health System A', address: '123 Main St', city: 'Springfield', state: 'IL', zip_code: '62701', latitude: 39.7817, longitude: -89.6501, data_source: 'clinic_a'} + + - name: test_input_layer_location_multiple_facilities + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__location + description: "Multiple locations pass through preserving location_id uniqueness" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('location') + rows: + - {location_id: 'LOC1', name: 'Hospital A', facility_type: 'acute care hospital', data_source: 'src1'} + - {location_id: 'LOC2', name: 'Clinic B', facility_type: 'outpatient clinic', data_source: 'src1'} + - {location_id: 'LOC3', name: 'SNF C', facility_type: 'skilled nursing facility', data_source: 'src2'} + expect: + rows: + - {location_id: 'LOC1', name: 'Hospital A', facility_type: 'acute care hospital', data_source: 'src1'} + - {location_id: 'LOC2', name: 'Clinic B', facility_type: 'outpatient clinic', data_source: 'src1'} + - {location_id: 'LOC3', name: 'SNF C', facility_type: 'skilled nursing facility', data_source: 'src2'} + + # ========================================================================= + # MEDICAL CLAIM + # ========================================================================= + + - name: test_input_layer_medical_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__medical_claim + description: "Verifies that medical claim data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {claim_id: 'CLM1', claim_line_number: 1, claim_type: 'institutional', person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', claim_start_date: '2023-06-01', claim_end_date: '2023-06-05', bill_type_code: '111', hcpcs_code: '99213', data_source: 'claims_src'} + expect: + rows: + - {claim_id: 'CLM1', claim_line_number: 1, claim_type: 'institutional', person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', claim_start_date: '2023-06-01', claim_end_date: '2023-06-05', bill_type_code: '111', hcpcs_code: '99213', data_source: 'claims_src'} + + - name: test_input_layer_medical_claim_composite_pk + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__medical_claim + description: "Multiple claim lines for the same claim pass through preserving composite PK (claim_id, claim_line_number, data_source)" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medical_claim') + rows: + - {claim_id: 'CLM1', claim_line_number: 1, person_id: 'P1', claim_type: 'professional', hcpcs_code: '99213', data_source: 'src1'} + - {claim_id: 'CLM1', claim_line_number: 2, person_id: 'P1', claim_type: 'professional', hcpcs_code: '85025', data_source: 'src1'} + - {claim_id: 'CLM2', claim_line_number: 1, person_id: 'P2', claim_type: 'institutional', hcpcs_code: '99223', data_source: 'src1'} + expect: + rows: + - {claim_id: 'CLM1', claim_line_number: 1, person_id: 'P1', claim_type: 'professional', hcpcs_code: '99213', data_source: 'src1'} + - {claim_id: 'CLM1', claim_line_number: 2, person_id: 'P1', claim_type: 'professional', hcpcs_code: '85025', data_source: 'src1'} + - {claim_id: 'CLM2', claim_line_number: 1, person_id: 'P2', claim_type: 'institutional', hcpcs_code: '99223', data_source: 'src1'} + + # ========================================================================= + # MEDICATION + # ========================================================================= + + - name: test_input_layer_medication_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__medication + description: "Verifies that medication data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medication') + rows: + - {medication_id: 'MED1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', source_code_type: 'ndc', source_code: '00002771001', source_description: 'Metformin 500mg', rxnorm_code: '860975', rxnorm_description: 'Metformin hydrochloride 500 MG', data_source: 'clinic_a'} + expect: + rows: + - {medication_id: 'MED1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', source_code_type: 'ndc', source_code: '00002771001', source_description: 'Metformin 500mg', rxnorm_code: '860975', rxnorm_description: 'Metformin hydrochloride 500 MG', data_source: 'clinic_a'} + + - name: test_input_layer_medication_multiple_meds_same_patient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__medication + description: "Multiple medications for the same patient pass through preserving medication_id uniqueness" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('medication') + rows: + - {medication_id: 'MED1', person_id: 'P1', rxnorm_code: '860975', data_source: 'src1'} + - {medication_id: 'MED2', person_id: 'P1', rxnorm_code: '197361', data_source: 'src1'} + - {medication_id: 'MED3', person_id: 'P2', rxnorm_code: '860975', data_source: 'src1'} + expect: + rows: + - {medication_id: 'MED1', person_id: 'P1', rxnorm_code: '860975', data_source: 'src1'} + - {medication_id: 'MED2', person_id: 'P1', rxnorm_code: '197361', data_source: 'src1'} + - {medication_id: 'MED3', person_id: 'P2', rxnorm_code: '860975', data_source: 'src1'} + + # ========================================================================= + # OBSERVATION + # ========================================================================= + + - name: test_input_layer_observation_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__observation + description: "Verifies that observation data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('observation') + rows: + - {observation_id: 'OBS1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', panel_id: null, source_code_type: 'loinc', source_code: '8480-6', source_description: 'Systolic blood pressure', normalized_code_type: 'loinc', normalized_code: '8480-6', normalized_description: 'Systolic blood pressure', result: '130', source_units: 'mmHg', normalized_units: 'mmHg', observation_date: '2023-06-15', data_source: 'clinic_a'} + expect: + rows: + - {observation_id: 'OBS1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', panel_id: null, source_code_type: 'loinc', source_code: '8480-6', source_description: 'Systolic blood pressure', normalized_code_type: 'loinc', normalized_code: '8480-6', normalized_description: 'Systolic blood pressure', result: '130', source_units: 'mmHg', normalized_units: 'mmHg', observation_date: '2023-06-15', data_source: 'clinic_a'} + + - name: test_input_layer_observation_multiple_vitals + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__observation + description: "Multiple observations (vitals) for the same encounter pass through preserving observation_id uniqueness" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('observation') + rows: + - {observation_id: 'OBS1', person_id: 'P1', normalized_code: '8480-6', result: '130', data_source: 'src1'} + - {observation_id: 'OBS2', person_id: 'P1', normalized_code: '8462-4', result: '85', data_source: 'src1'} + - {observation_id: 'OBS3', person_id: 'P1', normalized_code: '29463-7', result: '185', data_source: 'src1'} + expect: + rows: + - {observation_id: 'OBS1', person_id: 'P1', normalized_code: '8480-6', result: '130', data_source: 'src1'} + - {observation_id: 'OBS2', person_id: 'P1', normalized_code: '8462-4', result: '85', data_source: 'src1'} + - {observation_id: 'OBS3', person_id: 'P1', normalized_code: '29463-7', result: '185', data_source: 'src1'} + + # ========================================================================= + # PATIENT + # ========================================================================= + + - name: test_input_layer_patient_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__patient + description: "Verifies that patient data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('patient') + rows: + - {person_id: 'P1', patient_id: 'PAT1', first_name: 'John', last_name: 'Doe', sex: 'male', birth_date: '1954-01-01', death_date: null, race: 'white', data_source: 'clinic_a'} + expect: + rows: + - {person_id: 'P1', patient_id: 'PAT1', first_name: 'John', last_name: 'Doe', sex: 'male', birth_date: '1954-01-01', death_date: null, race: 'white', data_source: 'clinic_a'} + + - name: test_input_layer_patient_composite_pk_person_patient + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__patient + description: "Multiple patient records pass through preserving composite PK (person_id, patient_id) -- same person can have multiple patient_ids across source systems" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('patient') + rows: + - {person_id: 'P1', patient_id: 'PAT1A', first_name: 'John', last_name: 'Doe', sex: 'male', birth_date: '1954-01-01', data_source: 'system_a'} + - {person_id: 'P1', patient_id: 'PAT1B', first_name: 'John', last_name: 'Doe', sex: 'male', birth_date: '1954-01-01', data_source: 'system_b'} + - {person_id: 'P2', patient_id: 'PAT2', first_name: 'Jane', last_name: 'Smith', sex: 'female', birth_date: '1980-05-20', data_source: 'system_a'} + expect: + rows: + - {person_id: 'P1', patient_id: 'PAT1A', first_name: 'John', last_name: 'Doe', sex: 'male', birth_date: '1954-01-01', data_source: 'system_a'} + - {person_id: 'P1', patient_id: 'PAT1B', first_name: 'John', last_name: 'Doe', sex: 'male', birth_date: '1954-01-01', data_source: 'system_b'} + - {person_id: 'P2', patient_id: 'PAT2', first_name: 'Jane', last_name: 'Smith', sex: 'female', birth_date: '1980-05-20', data_source: 'system_a'} + + # ========================================================================= + # PHARMACY CLAIM + # ========================================================================= + + - name: test_input_layer_pharmacy_claim_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__pharmacy_claim + description: "Verifies that pharmacy claim data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', dispensing_date: '2023-06-15', ndc_code: '00002771001', quantity: 90, days_supply: 90, data_source: 'rx_src'} + expect: + rows: + - {claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', member_id: 'M1', payer: 'MCR', plan: 'PlanA', dispensing_date: '2023-06-15', ndc_code: '00002771001', quantity: 90, days_supply: 90, data_source: 'rx_src'} + + - name: test_input_layer_pharmacy_claim_composite_pk + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__pharmacy_claim + description: "Multiple pharmacy claim lines pass through preserving composite PK (claim_id, claim_line_number, data_source)" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('pharmacy_claim') + rows: + - {claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', ndc_code: '00002771001', data_source: 'src1'} + - {claim_id: 'RX1', claim_line_number: 2, person_id: 'P1', ndc_code: '00006074231', data_source: 'src1'} + - {claim_id: 'RX2', claim_line_number: 1, person_id: 'P2', ndc_code: '00002771001', data_source: 'src1'} + expect: + rows: + - {claim_id: 'RX1', claim_line_number: 1, person_id: 'P1', ndc_code: '00002771001', data_source: 'src1'} + - {claim_id: 'RX1', claim_line_number: 2, person_id: 'P1', ndc_code: '00006074231', data_source: 'src1'} + - {claim_id: 'RX2', claim_line_number: 1, person_id: 'P2', ndc_code: '00002771001', data_source: 'src1'} + + # ========================================================================= + # PRACTITIONER + # ========================================================================= + + - name: test_input_layer_practitioner_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__practitioner + description: "Verifies that practitioner data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('practitioner') + rows: + - {practitioner_id: 'PRAC1', npi: '1234567890', first_name: 'Alice', last_name: 'Johnson', practice_affiliation: 'General Hospital', specialty: 'Internal Medicine', sub_specialty: 'Endocrinology', data_source: 'clinic_a'} + expect: + rows: + - {practitioner_id: 'PRAC1', npi: '1234567890', first_name: 'Alice', last_name: 'Johnson', practice_affiliation: 'General Hospital', specialty: 'Internal Medicine', sub_specialty: 'Endocrinology', data_source: 'clinic_a'} + + - name: test_input_layer_practitioner_multiple_providers + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__practitioner + description: "Multiple practitioners pass through preserving practitioner_id uniqueness" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('practitioner') + rows: + - {practitioner_id: 'PRAC1', npi: '1234567890', specialty: 'Internal Medicine', data_source: 'src1'} + - {practitioner_id: 'PRAC2', npi: '0987654321', specialty: 'Cardiology', data_source: 'src1'} + - {practitioner_id: 'PRAC3', npi: '5678901234', specialty: 'Orthopedics', data_source: 'src2'} + expect: + rows: + - {practitioner_id: 'PRAC1', npi: '1234567890', specialty: 'Internal Medicine', data_source: 'src1'} + - {practitioner_id: 'PRAC2', npi: '0987654321', specialty: 'Cardiology', data_source: 'src1'} + - {practitioner_id: 'PRAC3', npi: '5678901234', specialty: 'Orthopedics', data_source: 'src2'} + + # ========================================================================= + # PROCEDURE + # ========================================================================= + + - name: test_input_layer_procedure_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__procedure + description: "Verifies that procedure data passes through unchanged from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('procedure') + rows: + - {procedure_id: 'PROC1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', claim_id: 'CLM1', procedure_date: '2023-06-15', source_code_type: 'icd-10-pcs', source_code: '0210093', source_description: 'CABG', normalized_code_type: 'icd-10-pcs', normalized_code: '0210093', normalized_description: 'Bypass Coronary Artery', practitioner_id: 'PRAC1', data_source: 'claims_src'} + expect: + rows: + - {procedure_id: 'PROC1', person_id: 'P1', patient_id: 'PAT1', encounter_id: 'ENC1', claim_id: 'CLM1', procedure_date: '2023-06-15', source_code_type: 'icd-10-pcs', source_code: '0210093', source_description: 'CABG', normalized_code_type: 'icd-10-pcs', normalized_code: '0210093', normalized_description: 'Bypass Coronary Artery', practitioner_id: 'PRAC1', data_source: 'claims_src'} + + - name: test_input_layer_procedure_multiple_procedures_same_encounter + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__procedure + description: "Multiple procedures for the same encounter pass through preserving procedure_id uniqueness" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('procedure') + rows: + - {procedure_id: 'PROC1', person_id: 'P1', encounter_id: 'ENC1', normalized_code: '0210093', data_source: 'src1'} + - {procedure_id: 'PROC2', person_id: 'P1', encounter_id: 'ENC1', normalized_code: '02100A3', data_source: 'src1'} + - {procedure_id: 'PROC3', person_id: 'P2', encounter_id: 'ENC2', normalized_code: '0SR9019', data_source: 'src1'} + expect: + rows: + - {procedure_id: 'PROC1', person_id: 'P1', encounter_id: 'ENC1', normalized_code: '0210093', data_source: 'src1'} + - {procedure_id: 'PROC2', person_id: 'P1', encounter_id: 'ENC1', normalized_code: '02100A3', data_source: 'src1'} + - {procedure_id: 'PROC3', person_id: 'P2', encounter_id: 'ENC2', normalized_code: '0SR9019', data_source: 'src1'} + + # ========================================================================= + # PROVIDER ATTRIBUTION + # ========================================================================= + + - name: test_input_layer_provider_attribution_passthrough_when_enabled + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__provider_attribution + description: "When provider_attribution_enabled is true, data passes through from the source ref" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + provider_attribution_enabled: true + given: + - input: ref('provider_attribution') + rows: + - {person_id: 'P1', member_id: 'M1', patient_id: 'PAT1', year_month: '2023-01', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: 'PROV1', payer_attributed_provider_practice: 'Practice A', payer_attributed_provider_organization: 'Org A', payer_attributed_provider_lob: 'Medicare', custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', patient_id: 'PAT1', year_month: '2023-01', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: 'PROV1', payer_attributed_provider_practice: 'Practice A', payer_attributed_provider_organization: 'Org A', payer_attributed_provider_lob: 'Medicare', custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null} + + - name: test_input_layer_provider_attribution_preserves_custom_fields_and_grain + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__provider_attribution + description: "Multiple attribution rows pass through unchanged, including custom attribution fields and nulls" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + provider_attribution_enabled: true + given: + - input: ref('provider_attribution') + rows: + - {person_id: 'P1', member_id: 'M1', patient_id: 'PAT1', year_month: '2023-01', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: 'PROV1', payer_attributed_provider_practice: 'Practice A', payer_attributed_provider_organization: 'Org A', payer_attributed_provider_lob: 'Medicare', custom_attributed_provider: 'CUST1', custom_attributed_provider_practice: 'Custom Practice A', custom_attributed_provider_organization: 'Custom Org A', custom_attributed_provider_lob: 'Custom LOB'} + - {person_id: 'P1', member_id: 'M1', patient_id: 'PAT1', year_month: '2023-02', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: 'PROV2', payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: 'Medicare', custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null} + - {person_id: 'P2', member_id: 'M2', patient_id: 'PAT2', year_month: '2023-01', payer: 'COM', plan: 'PlanB', data_source: 'src2', payer_attributed_provider: 'PROV3', payer_attributed_provider_practice: 'Practice B', payer_attributed_provider_organization: 'Org B', payer_attributed_provider_lob: 'Commercial', custom_attributed_provider: 'CUST2', custom_attributed_provider_practice: 'Custom Practice B', custom_attributed_provider_organization: 'Custom Org B', custom_attributed_provider_lob: 'Custom LOB B'} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', patient_id: 'PAT1', year_month: '2023-01', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: 'PROV1', payer_attributed_provider_practice: 'Practice A', payer_attributed_provider_organization: 'Org A', payer_attributed_provider_lob: 'Medicare', custom_attributed_provider: 'CUST1', custom_attributed_provider_practice: 'Custom Practice A', custom_attributed_provider_organization: 'Custom Org A', custom_attributed_provider_lob: 'Custom LOB'} + - {person_id: 'P1', member_id: 'M1', patient_id: 'PAT1', year_month: '2023-02', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: 'PROV2', payer_attributed_provider_practice: null, payer_attributed_provider_organization: null, payer_attributed_provider_lob: 'Medicare', custom_attributed_provider: null, custom_attributed_provider_practice: null, custom_attributed_provider_organization: null, custom_attributed_provider_lob: null} + - {person_id: 'P2', member_id: 'M2', patient_id: 'PAT2', year_month: '2023-01', payer: 'COM', plan: 'PlanB', data_source: 'src2', payer_attributed_provider: 'PROV3', payer_attributed_provider_practice: 'Practice B', payer_attributed_provider_organization: 'Org B', payer_attributed_provider_lob: 'Commercial', custom_attributed_provider: 'CUST2', custom_attributed_provider_practice: 'Custom Practice B', custom_attributed_provider_organization: 'Custom Org B', custom_attributed_provider_lob: 'Custom LOB B'} + + - name: test_input_layer_provider_attribution_composite_pk + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__provider_attribution + description: "Multiple attribution records pass through preserving composite PK (person_id, member_id, payer, plan, year_month, data_source)" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + provider_attribution_enabled: true + given: + - input: ref('provider_attribution') + rows: + - {person_id: 'P1', member_id: 'M1', patient_id: 'PAT1', year_month: '2023-01', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: 'PROV1'} + - {person_id: 'P1', member_id: 'M1', patient_id: 'PAT1', year_month: '2023-02', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: 'PROV1'} + - {person_id: 'P2', member_id: 'M2', patient_id: 'PAT2', year_month: '2023-01', payer: 'COM', plan: 'PlanB', data_source: 'src1', payer_attributed_provider: 'PROV2'} + expect: + rows: + - {person_id: 'P1', member_id: 'M1', patient_id: 'PAT1', year_month: '2023-01', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: 'PROV1'} + - {person_id: 'P1', member_id: 'M1', patient_id: 'PAT1', year_month: '2023-02', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: 'PROV1'} + - {person_id: 'P2', member_id: 'M2', patient_id: 'PAT2', year_month: '2023-01', payer: 'COM', plan: 'PlanB', data_source: 'src1', payer_attributed_provider: 'PROV2'} + + - name: test_input_layer_provider_attribution_returns_no_rows_when_disabled + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + model: input_layer__provider_attribution + description: "When provider_attribution_enabled is false, the model should intentionally emit no rows" + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + claims_enabled: true + provider_attribution_enabled: false + given: + - input: ref('provider_attribution') + rows: + - {person_id: 'P1', member_id: 'M1', patient_id: 'PAT1', year_month: '2023-01', payer: 'MCR', plan: 'PlanA', data_source: 'src1', payer_attributed_provider: 'PROV1'} + - {person_id: 'P2', member_id: 'M2', patient_id: 'PAT2', year_month: '2023-02', payer: 'COM', plan: 'PlanB', data_source: 'src2', payer_attributed_provider: 'PROV2'} + expect: + rows: [] diff --git a/models/normalization/_gap_unit_tests.yml b/models/normalization/_gap_unit_tests.yml new file mode 100644 index 000000000..bef803caa --- /dev/null +++ b/models/normalization/_gap_unit_tests.yml @@ -0,0 +1,44 @@ +version: 2 + +unit_tests: + + ## ══════════════════════════════════════════════════════════ + ## UNDETERMINED CLAIM TYPE MODEL + ## ══════════════════════════════════════════════════════════ + + - name: test_int_diagnosis_code_final_multiple_claims + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify diagnosis code final handles multiple claims independently + model: normalized_input__int_diagnosis_code_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_diagnosis_code_intermediate') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'diagnosis_code_1', diagnosis_code: 'E1165'} + - {claim_id: 'CLM002', data_source: 'claims_a', column_name: 'diagnosis_code_1', diagnosis_code: 'I10'} + - {claim_id: 'CLM002', data_source: 'claims_a', column_name: 'diagnosis_code_2', diagnosis_code: 'J189'} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', diagnosis_code_1: 'E1165', diagnosis_code_2: null, tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'CLM002', data_source: 'claims_a', diagnosis_code_1: 'I10', diagnosis_code_2: 'J189', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_int_medical_date_aggregation_multiple_lines + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify date aggregation picks min start and max end across multiple lines + model: normalized_input__int_medical_date_aggregation + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_medical_claim_date_normalize') + rows: + - {claim_id: 'CLM001', claim_line_number: 1, claim_type: 'institutional', data_source: 'claims_a', normalized_claim_start_date: '2024-01-15', normalized_claim_end_date: '2024-01-18', normalized_admission_date: '2024-01-15', normalized_discharge_date: '2024-01-18'} + - {claim_id: 'CLM001', claim_line_number: 2, claim_type: 'institutional', data_source: 'claims_a', normalized_claim_start_date: '2024-01-16', normalized_claim_end_date: '2024-01-20', normalized_admission_date: '2024-01-16', normalized_discharge_date: '2024-01-20'} + - {claim_id: 'CLM001', claim_line_number: 3, claim_type: 'institutional', data_source: 'claims_a', normalized_claim_start_date: '2024-01-14', normalized_claim_end_date: '2024-01-19', normalized_admission_date: '2024-01-14', normalized_discharge_date: '2024-01-19'} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', minimum_claim_start_date: '2024-01-14', maximum_claim_end_date: '2024-01-20', minimum_admission_date: '2024-01-14', maximum_discharge_date: '2024-01-20', tuva_last_run: '2024-01-01 00:00:00'} diff --git a/models/normalization/normalization_unit_tests.yml b/models/normalization/normalization_unit_tests.yml new file mode 100644 index 000000000..700813096 --- /dev/null +++ b/models/normalization/normalization_unit_tests.yml @@ -0,0 +1,532 @@ +version: 2 + +unit_tests: + + ## ══════════════════════════════════════════════════════════ + ## STAGING MODELS + ## ══════════════════════════════════════════════════════════ + + ## ────────────────────────────────────────────────────────── + ## normalized_input__stg_medical_claim + ## ────────────────────────────────────────────────────────── + + - name: test_stg_medical_claim_basic_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify staging medical claim passes through all columns from input layer + model: normalized_input__stg_medical_claim + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'CLM001', claim_line_number: 1, claim_type: 'institutional', person_id: 'P001', member_id: 'M001', payer: 'Aetna', plan: 'Gold', claim_start_date: '2024-01-15', claim_end_date: '2024-01-20', admission_date: '2024-01-15', discharge_date: '2024-01-20', admit_source_code: '1', admit_type_code: '1', discharge_disposition_code: '01', place_of_service_code: '21', bill_type_code: '111', drg_code_type: 'ms-drg', drg_code: '470', revenue_center_code: '0100', diagnosis_code_type: 'icd-10-cm', diagnosis_code_1: 'M17.11', procedure_code_type: 'icd-10-pcs', procedure_code_1: '0SR9019', data_source: 'claims_a'} + expect: + rows: + - {claim_id: 'CLM001', claim_line_number: 1, claim_type: 'institutional', person_id: 'P001', member_id: 'M001', payer: 'Aetna', plan: 'Gold', claim_start_date: '2024-01-15', claim_end_date: '2024-01-20', admission_date: '2024-01-15', discharge_date: '2024-01-20', admit_source_code: '1', admit_type_code: '1', discharge_disposition_code: '01', place_of_service_code: '21', bill_type_code: '111', drg_code_type: 'ms-drg', drg_code: '470', revenue_center_code: '0100', diagnosis_code_type: 'icd-10-cm', diagnosis_code_1: 'M17.11', procedure_code_type: 'icd-10-pcs', procedure_code_1: '0SR9019', data_source: 'claims_a'} + + - name: test_stg_medical_claim_null_optional_codes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify staging medical claim handles null optional code fields + model: normalized_input__stg_medical_claim + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__medical_claim') + rows: + - {claim_id: 'CLM002', claim_line_number: 1, claim_type: 'professional', person_id: 'P002', admit_source_code: null, admit_type_code: null, discharge_disposition_code: null, bill_type_code: null, drg_code: null, revenue_center_code: null, data_source: 'claims_a'} + expect: + rows: + - {claim_id: 'CLM002', claim_line_number: 1, claim_type: 'professional', person_id: 'P002', admit_source_code: null, admit_type_code: null, discharge_disposition_code: null, bill_type_code: null, drg_code: null, revenue_center_code: null, data_source: 'claims_a'} + + ## ────────────────────────────────────────────────────────── + ## normalized_input__stg_eligibility + ## ────────────────────────────────────────────────────────── + + - name: test_stg_eligibility_basic_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify staging eligibility passes through columns and computes person_id_key + model: normalized_input__stg_eligibility + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P001', member_id: 'M001', subscriber_id: 'S001', gender: 'female', race: 'white', birth_date: '1980-05-15', death_date: null, death_flag: 0, enrollment_start_date: '2024-01-01', enrollment_end_date: '2024-12-31', payer: 'Aetna', payer_type: 'commercial', plan: 'Gold', state: 'MA', data_source: 'elig_a'} + expect: + rows: + - {person_id: 'P001', member_id: 'M001', subscriber_id: 'S001', gender: 'female', race: 'white', birth_date: '1980-05-15', death_date: null, death_flag: 0, enrollment_start_date: '2024-01-01', enrollment_end_date: '2024-12-31', payer: 'Aetna', payer_type: 'commercial', plan: 'Gold', state: 'MA', data_source: 'elig_a'} + + - name: test_stg_eligibility_null_optional_fields + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify staging eligibility handles null optional fields in key computation + model: normalized_input__stg_eligibility + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__eligibility') + rows: + - {person_id: 'P002', member_id: null, gender: null, birth_date: null, enrollment_start_date: '2024-01-01', enrollment_end_date: '2024-06-30', payer: null, plan: null, data_source: null} + expect: + rows: + - {person_id: 'P002', member_id: null, gender: null, birth_date: null, enrollment_start_date: '2024-01-01', enrollment_end_date: '2024-06-30', payer: null, plan: null, data_source: null} + + ## ────────────────────────────────────────────────────────── + ## normalized_input__stg_pharmacy_claim + ## ────────────────────────────────────────────────────────── + + - name: test_stg_pharmacy_claim_basic_passthrough + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify staging pharmacy claim passes through all columns + model: normalized_input__stg_pharmacy_claim + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX001', claim_line_number: 1, person_id: 'P001', member_id: 'M001', payer: 'Aetna', plan: 'Gold', prescribing_provider_npi: '1234567890', dispensing_provider_npi: '0987654321', dispensing_date: '2024-02-01', ndc_code: '00002323201', quantity: 30, days_supply: 30, refills: 2, data_source: 'pharmacy_a'} + expect: + rows: + - {claim_id: 'RX001', claim_line_number: 1, person_id: 'P001', member_id: 'M001', payer: 'Aetna', plan: 'Gold', prescribing_provider_npi: '1234567890', dispensing_provider_npi: '0987654321', dispensing_date: '2024-02-01', ndc_code: '00002323201', quantity: 30, days_supply: 30, refills: 2, data_source: 'pharmacy_a'} + + - name: test_stg_pharmacy_claim_null_fields + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify staging pharmacy claim handles null fields + model: normalized_input__stg_pharmacy_claim + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('input_layer__pharmacy_claim') + rows: + - {claim_id: 'RX002', claim_line_number: 1, person_id: 'P002', ndc_code: null, quantity: null, days_supply: null, paid_amount: null, data_source: 'pharmacy_a'} + expect: + rows: + - {claim_id: 'RX002', claim_line_number: 1, person_id: 'P002', ndc_code: null, quantity: null, days_supply: null, paid_amount: null, data_source: 'pharmacy_a'} + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Diagnosis Code Pipeline + ## ══════════════════════════════════════════════════════════ + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_diagnosis_code_intermediate + ## ────────────────────────────────────────────────────────── + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_diagnosis_code_final + ## ────────────────────────────────────────────────────────── + + - name: test_int_diagnosis_code_final_pivots_back_to_wide + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify diagnosis codes are pivoted back from long to wide format + model: normalized_input__int_diagnosis_code_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_diagnosis_code_intermediate') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'diagnosis_code_1', diagnosis_code: 'E1165'} + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'diagnosis_code_2', diagnosis_code: 'I10'} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', diagnosis_code_1: 'E1165', diagnosis_code_2: 'I10', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_int_diagnosis_code_final_null_remaining_codes + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify unpopulated diagnosis code positions are null + model: normalized_input__int_diagnosis_code_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_diagnosis_code_intermediate') + rows: + - {claim_id: 'CLM002', data_source: 'claims_a', column_name: 'diagnosis_code_1', diagnosis_code: 'J189'} + expect: + rows: + - {claim_id: 'CLM002', data_source: 'claims_a', diagnosis_code_1: 'J189', diagnosis_code_2: null, diagnosis_code_3: null, tuva_last_run: '2024-01-01 00:00:00'} + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Procedure Code Pipeline + ## ══════════════════════════════════════════════════════════ + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_procedure_code_intermediate + ## ────────────────────────────────────────────────────────── + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_procedure_code_final + ## ────────────────────────────────────────────────────────── + + - name: test_int_procedure_code_final_pivots_back_to_wide + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify procedure codes are pivoted back from long to wide format + model: normalized_input__int_procedure_code_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_procedure_code_intermediate') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'procedure_code_1', procedure_code: '0SR9019'} + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'procedure_code_2', procedure_code: '0SRC0J9'} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', procedure_code_1: '0SR9019', procedure_code_2: '0SRC0J9', tuva_last_run: '2024-01-01 00:00:00'} + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Admit Source Voting Pipeline + ## ══════════════════════════════════════════════════════════ + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_admit_source_voting + ## ────────────────────────────────────────────────────────── + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_admit_source_final + ## ────────────────────────────────────────────────────────── + + - name: test_int_admit_source_final_selects_winner + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify admit source final picks the code with highest occurrence count + model: normalized_input__int_admit_source_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_admit_source_voting') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'admit_source_code', normalized_code: '1', normalized_description: 'Non-Health Care Facility', occurrence_count: 3, next_occurrence_count: 1, occurrence_row_count: 1} + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'admit_source_code', normalized_code: '4', normalized_description: 'Transfer from Hospital', occurrence_count: 1, next_occurrence_count: 0, occurrence_row_count: 2} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'admit_source_code', normalized_code: '1', normalized_description: 'Non-Health Care Facility', occurrence_count: 3, next_occurrence_count: 1, occurrence_row_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_int_admit_source_final_tie_excluded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify tied admit source codes are excluded (occurrence equals next) + model: normalized_input__int_admit_source_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_admit_source_voting') + rows: + - {claim_id: 'CLM002', data_source: 'claims_a', column_name: 'admit_source_code', normalized_code: '1', normalized_description: 'Non-Health Care Facility', occurrence_count: 2, next_occurrence_count: 2, occurrence_row_count: 1} + - {claim_id: 'CLM002', data_source: 'claims_a', column_name: 'admit_source_code', normalized_code: '4', normalized_description: 'Transfer from Hospital', occurrence_count: 2, next_occurrence_count: 0, occurrence_row_count: 2} + expect: + rows: [] + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Admit Type Voting Pipeline + ## ══════════════════════════════════════════════════════════ + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_admit_type_voting + ## ────────────────────────────────────────────────────────── + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_admit_type_final + ## ────────────────────────────────────────────────────────── + + - name: test_int_admit_type_final_selects_winner + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify admit type final picks the code with highest count and clear winner + model: normalized_input__int_admit_type_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_admit_type_voting') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'admit_type_code', normalized_code: '1', normalized_description: 'Emergency', occurrence_count: 3, next_occurrence_count: 1, occurrence_row_count: 1} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'admit_type_code', normalized_code: '1', normalized_description: 'Emergency', occurrence_count: 3, next_occurrence_count: 1, occurrence_row_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Bill Type Voting Pipeline + ## ══════════════════════════════════════════════════════════ + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_bill_type_voting + ## ────────────────────────────────────────────────────────── + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_bill_type_final + ## ────────────────────────────────────────────────────────── + + - name: test_int_bill_type_final_selects_top_row + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify bill type final picks the top-ranked row + model: normalized_input__int_bill_type_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_bill_type_voting') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'bill_type_code', normalized_code: '111', normalized_description: 'Hospital Inpatient', occurrence_count: 3, occurrence_row_count: 1} + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'bill_type_code', normalized_code: '121', normalized_description: 'Hospital Inpatient Part B', occurrence_count: 1, occurrence_row_count: 2} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'bill_type_code', normalized_code: '111', normalized_description: 'Hospital Inpatient', occurrence_count: 3, occurrence_row_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Discharge Disposition Pipeline + ## ══════════════════════════════════════════════════════════ + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_discharge_disposition_voting + ## ────────────────────────────────────────────────────────── + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_discharge_disposition_final + ## ────────────────────────────────────────────────────────── + + - name: test_int_discharge_disposition_final_selects_winner + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify discharge disposition final picks the winning code + model: normalized_input__int_discharge_disposition_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_discharge_disposition_voting') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'discharge_disposition_code', normalized_code: '01', normalized_description: 'Discharged to Home', occurrence_count: 3, next_occurrence_count: 1, occurrence_row_count: 1} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'discharge_disposition_code', normalized_code: '01', normalized_description: 'Discharged to Home', occurrence_count: 3, next_occurrence_count: 1, occurrence_row_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_int_discharge_disposition_final_tie_excluded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify tied discharge disposition codes are excluded + model: normalized_input__int_discharge_disposition_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_discharge_disposition_voting') + rows: + - {claim_id: 'CLM002', data_source: 'claims_a', column_name: 'discharge_disposition_code', normalized_code: '01', normalized_description: 'Home', occurrence_count: 2, next_occurrence_count: 2, occurrence_row_count: 1} + expect: + rows: [] + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - DRG Voting Pipeline + ## ══════════════════════════════════════════════════════════ + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_drg_voting + ## ────────────────────────────────────────────────────────── + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_drg_final + ## ────────────────────────────────────────────────────────── + + - name: test_int_drg_final_selects_winner + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify DRG final picks the code with highest count and clear winner + model: normalized_input__int_drg_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_drg_voting') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'drg_code', normalized_code: '470', normalized_description: 'Major Joint Replacement', occurrence_count: 3, next_occurrence_count: 1, occurrence_row_count: 1} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'drg_code', normalized_code: '470', normalized_description: 'Major Joint Replacement', occurrence_count: 3, next_occurrence_count: 1, occurrence_row_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Place of Service + ## ══════════════════════════════════════════════════════════ + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Revenue Center + ## ══════════════════════════════════════════════════════════ + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Medical Claim Date Normalization + ## ══════════════════════════════════════════════════════════ + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Medical Date Aggregation + ## ══════════════════════════════════════════════════════════ + + - name: test_int_medical_date_aggregation_institutional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify date aggregation for institutional claims includes admission/discharge + model: normalized_input__int_medical_date_aggregation + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_medical_claim_date_normalize') + rows: + - {claim_id: 'CLM001', claim_line_number: 1, claim_type: 'institutional', data_source: 'claims_a', normalized_claim_start_date: '2024-01-15', normalized_claim_end_date: '2024-01-20', normalized_admission_date: '2024-01-15', normalized_discharge_date: '2024-01-20'} + - {claim_id: 'CLM001', claim_line_number: 2, claim_type: 'institutional', data_source: 'claims_a', normalized_claim_start_date: '2024-01-16', normalized_claim_end_date: '2024-01-18', normalized_admission_date: '2024-01-15', normalized_discharge_date: '2024-01-20'} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', minimum_claim_start_date: '2024-01-15', maximum_claim_end_date: '2024-01-20', minimum_admission_date: '2024-01-15', maximum_discharge_date: '2024-01-20', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_int_medical_date_aggregation_professional + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify date aggregation for professional claims has null admission/discharge + model: normalized_input__int_medical_date_aggregation + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_medical_claim_date_normalize') + rows: + - {claim_id: 'CLM002', claim_line_number: 1, claim_type: 'professional', data_source: 'claims_a', normalized_claim_start_date: '2024-02-01', normalized_claim_end_date: '2024-02-01', normalized_admission_date: null, normalized_discharge_date: null} + expect: + rows: + - {claim_id: 'CLM002', data_source: 'claims_a', minimum_claim_start_date: '2024-02-01', maximum_claim_end_date: '2024-02-01', minimum_admission_date: null, maximum_discharge_date: null, tuva_last_run: '2024-01-01 00:00:00'} + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - NPI Normalization + ## ══════════════════════════════════════════════════════════ + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Eligibility Date Normalization + ## ══════════════════════════════════════════════════════════ + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Eligibility State Normalization + ## ══════════════════════════════════════════════════════════ + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Present on Admission Pipeline + ## ══════════════════════════════════════════════════════════ + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_present_on_admit_voting + ## ────────────────────────────────────────────────────────── + + - name: test_int_present_on_admit_voting_clear_winner + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify POA voting selects the code with highest occurrence + model: normalized_input__int_present_on_admit_voting + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_present_on_admit_normalize') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', diagnosis_column: 'diagnosis_poa_1', normalized_present_on_admit_code: 'Y', present_on_admit_occurrence_count: 3} + - {claim_id: 'CLM001', data_source: 'claims_a', diagnosis_column: 'diagnosis_poa_1', normalized_present_on_admit_code: 'N', present_on_admit_occurrence_count: 1} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'diagnosis_poa_1', normalized_code: 'Y', occurrence_count: 3, next_occurrence_count: 1, occurrence_row_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'diagnosis_poa_1', normalized_code: 'N', occurrence_count: 1, next_occurrence_count: 0, occurrence_row_count: 2, tuva_last_run: '2024-01-01 00:00:00'} + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_present_on_admit_final + ## ────────────────────────────────────────────────────────── + + - name: test_int_present_on_admit_final_pivots_winners + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify POA final pivots winning codes back to wide format + model: normalized_input__int_present_on_admit_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_present_on_admit_voting') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'DIAGNOSIS_POA_1', normalized_code: 'Y', occurrence_count: 3, next_occurrence_count: 1, occurrence_row_count: 1} + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'DIAGNOSIS_POA_2', normalized_code: 'N', occurrence_count: 2, next_occurrence_count: 0, occurrence_row_count: 1} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', diagnosis_poa_1: 'Y', diagnosis_poa_2: 'N', tuva_last_run: '2024-01-01 00:00:00'} + + ## ══════════════════════════════════════════════════════════ + ## INTERMEDIATE MODELS - Procedure Date Pipeline + ## ══════════════════════════════════════════════════════════ + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_procedure_date_voting + ## ────────────────────────────────────────────────────────── + + - name: test_int_procedure_date_voting_clear_winner + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify procedure date voting assigns ranks correctly + model: normalized_input__int_procedure_date_voting + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_procedure_date_normalize') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', procedure_column: 'procedure_date_1', procedure_date: '2024-01-15', procedure_date_occurrence_count: 3} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'procedure_date_1', normalized_code: '2024-01-15', occurrence_count: 3, next_occurrence_count: 0, occurrence_row_count: 1, tuva_last_run: '2024-01-01 00:00:00'} + + ## ────────────────────────────────────────────────────────── + ## normalized_input__int_procedure_date_final + ## ────────────────────────────────────────────────────────── + + - name: test_int_procedure_date_final_pivots_winners + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify procedure date final pivots winning dates back to wide format + model: normalized_input__int_procedure_date_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_procedure_date_voting') + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'procedure_date_1', normalized_code: '2024-01-15', occurrence_count: 3, next_occurrence_count: 0, occurrence_row_count: 1} + - {claim_id: 'CLM001', data_source: 'claims_a', column_name: 'procedure_date_2', normalized_code: '2024-01-16', occurrence_count: 2, next_occurrence_count: 0, occurrence_row_count: 1} + expect: + rows: + - {claim_id: 'CLM001', data_source: 'claims_a', procedure_date_1: '2024-01-15', procedure_date_2: '2024-01-16', tuva_last_run: '2024-01-01 00:00:00'} + + - name: test_int_procedure_date_final_tie_excluded + config: + enabled: "{{ var('tuva_unit_tests_enabled', false) | as_bool }}" + description: Verify tied procedure dates are excluded from final + model: normalized_input__int_procedure_date_final + overrides: + vars: + tuva_last_run: '2024-01-01 00:00:00' + given: + - input: ref('normalized_input__int_procedure_date_voting') + rows: + - {claim_id: 'CLM002', data_source: 'claims_a', column_name: 'procedure_date_1', normalized_code: '2024-01-15', occurrence_count: 2, next_occurrence_count: 2, occurrence_row_count: 1} + expect: + rows: [] + +