Skip to content

Commit fa84e3d

Browse files
chase-jonesMike Krahulec
authored andcommitted
970 | Creating de-duplication logic for patients in both claims and clinical (#971)
* 970 | Creating de-duplication logic for patients in both claims and clinical Made decision to choose claims over clinical for datasets. Patient table has an expectation of PK on the person_id column. * Specify only wanting columns from clinical patient
1 parent 73f6a94 commit fa84e3d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

models/core/final/core__patient.sql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66

77
{% if var('clinical_enabled', var('tuva_marts_enabled',False)) == true and var('claims_enabled', var('tuva_marts_enabled',False)) == true -%}
88

9-
select * from {{ ref('core__stg_claims_patient') }}
9+
with person_list_to_exclude_because_in_claims as (
10+
select distinct person_id
11+
from {{ ref('core__stg_claims_patient') }}
12+
)
13+
select *
14+
from {{ ref('core__stg_claims_patient') }}
1015
union all
11-
select * from {{ ref('core__stg_clinical_patient') }}
16+
select cscp.*
17+
from {{ ref('core__stg_clinical_patient') }} as cscp
18+
left outer join person_list_to_exclude_because_in_claims as pltebic on cscp.person_id = pltebic.person_id
19+
/* IF EXISTS IN CLAIMS, CHOOSE CLAIMS RECORD OVER CLINICAL RECORD */
20+
where pltebic.person_id is null
1221

1322
{% elif var('clinical_enabled', var('tuva_marts_enabled',False)) == true -%}
1423

0 commit comments

Comments
 (0)