Skip to content

Commit

Permalink
Light cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dogversioning committed Mar 21, 2024
1 parent b521457 commit 4e2ceaa
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 116 deletions.
2 changes: 1 addition & 1 deletion cumulus_library/studies/core/builder_documentreference.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def prepare_queries(
sql_utils.CodingConfig(
source_table="documentreference",
source_id="id",
column_hierarchy=[("format", dict), ("content", dict)],
column_hierarchy=[("content", list), ("format", dict)],
target_table="core__documentreference_dn_format",
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,38 @@ CREATE TABLE core__documentreference_dn_category AS (

-- ###########################################################

CREATE TABLE IF NOT EXISTS "main"."core__documentreference_dn_format"
AS (
SELECT * FROM (
VALUES
(cast(NULL AS varchar),cast(NULL AS varchar),cast(NULL AS varchar),cast(NULL AS varchar))
CREATE TABLE core__documentreference_dn_format AS (
WITH

system_format_0 AS (
SELECT DISTINCT
s.id AS id,
u.parent_col.format.code,
u.parent_col.format.display,
u.parent_col.format.system AS code_system
FROM
documentreference AS s,
UNNEST(s.content) AS u (parent_col)
), --noqa: LT07

union_table AS (
SELECT
id,
code_system,
code,
display
FROM system_format_0

)
AS t ("id","code","code_system","display")
SELECT
id,
code,
code_system,
display
FROM union_table
);


-- ###########################################################


Expand Down
4 changes: 3 additions & 1 deletion cumulus_library/template_sql/base_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def get_codeable_concept_denormalize_query(
:param config: a CodableConeptConfig
"""

assert len(config.column_hierarchy) <= 2
# If we get a None for code systems, we want one dummy value so the jinja
# for loop will do a single pass. This implicitly means that we're not
# filtering, so this parameter will be otherwise ignored
Expand All @@ -86,7 +87,7 @@ def get_codeable_concept_denormalize_query(
parent_field=None
if len(config.column_hierarchy) == 1
else config.column_hierarchy[0][0],
is_array=True if config.column_hierarchy[0][1] == list else False,
is_array=(config.column_hierarchy[0][1] == list),
target_table=config.target_table,
filter_priority=config.filter_priority,
code_systems=config.code_systems,
Expand All @@ -107,6 +108,7 @@ def get_coding_denormalize_query(
:param config: a CodingConfig
"""

assert len(config.column_hierarchy) == 2
# If we get a None for code systems, we want one dummy value so the jinja
# for loop will do a single pass. This implicitly means that we're not
# filtering, so this parameter will be otherwise ignored
Expand Down
5 changes: 1 addition & 4 deletions cumulus_library/template_sql/sql_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ def _check_schema_if_exists(
cursor: databases.DatabaseCursor,
source_table: str,
source_col: str,
target_field: str,
expected=None,
) -> bool:
"""Validation check for a column existing, and having the expected schema
Expand All @@ -243,9 +242,7 @@ def _check_schema_if_exists(
:param cursor: a PEP-249 compliant database cursor
:param source_table: The table to query against
:param source_col: The column to check the schema against
:param target_field: The name of the nested value to check for inside the
schema of source_col
:param expected: a list of elements that should be present in target_field.
:param expected: a list of elements that should be present in source_col.
If none, we assume it is a CodeableConcept.
:returns: a boolean indicating if the schema was found.
"""
Expand Down
Loading

0 comments on commit 4e2ceaa

Please sign in to comment.