Skip to content

Commit

Permalink
[DC-3787] Update query formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
brendagutman committed May 3, 2024
1 parent 1981a37 commit d2d8d90
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
com_cdr = "" # The comibend dataset
deid_base_cdr = "" # the deid dataset
pipeline = "" # the pipeline tables
run_as = "" # The account used to run checks
run_as = "[email protected]" # The account used to run checks

# +
impersonation_creds = auth.get_impersonation_credentials(
Expand Down Expand Up @@ -398,15 +398,15 @@

# has to be deid_base
query = JINJA_ENV.from_string("""
WITH multi_select as ( -- participants answered the question with multiple selections
WITH multi_select as ( -- participants answered the question with multiple selections --
SELECT o1.person_id, o1.value_source_value as primary_answer,o2.value_source_value as secondary_answer
FROM (SELECT person_id, value_source_value FROM `{{project_id}}.{{deid_base_cdr}}.observation` WHERE observation_source_concept_id = 1586140 AND value_source_value NOT LIKE '%ispanic') o1
JOIN (SELECT person_id, value_source_value FROM `{{project_id}}.{{deid_base_cdr}}.observation` WHERE observation_source_concept_id = 1586140) o2
USING (person_id)
WHERE o1.value_source_value <> o2.value_source_value
)
, single_select as ( -- participants answered the question with only one selection
, single_select as ( -- participants answered the question with only one selection --
SELECT person_id, value_source_value as primary_answer, 'None' as secondary_answer
FROM `{{project_id}}.{{deid_base_cdr}}.observation`
WHERE observation_source_concept_id = 1586140
Expand All @@ -416,13 +416,13 @@
, all_selections_transformations as (
(SELECT person_id,
CASE
WHEN primary_answer = 'WhatRaceEthnicity_Hispanic' THEN 'AoUDRC_NoneIndicated' -- only selected hispanic
WHEN primary_answer = 'WhatRaceEthnicity_Hispanic' THEN 'AoUDRC_NoneIndicated' -- only selected hispanic --
ELSE primary_answer END AS
primary_answer,
CASE
WHEN primary_answer = 'PMI_PreferNotToAnswer' THEN 'PMI_PreferNotToAnswer'
WHEN primary_answer = 'PMI_Skip' THEN 'PMI_Skip'
WHEN primary_answer = 'WhatRaceEthnicity_Hispanic' THEN 'Hispanic' -- only selected hispanic
WHEN primary_answer = 'WhatRaceEthnicity_Hispanic' THEN 'Hispanic' -- only selected hispanic --
WHEN primary_answer = 'WhatRaceEthnicity_RaceEthnicityNoneOfThese' THEN 'WhatRaceEthnicity_RaceEthnicityNoneOfThese'
ELSE 'Not Hispanic' END AS
secondary_answer,
Expand Down

0 comments on commit d2d8d90

Please sign in to comment.