Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored remaining core tables #166

Merged
merged 8 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions cumulus_library/statistics/counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ def count_condition(
filter_resource="encounter",
)

def count_document(
def count_documentreference(
self,
table_name: str,
source_table: str,
table_cols: list,
where_clauses: Union[list, None] = None,
min_subject: int = 10,
) -> str:
"""wrapper method for constructing document counts tables
"""wrapper method for constructing documentreference counts tables

:param table_name: The name of the table to create. Must start with study prefix
:param source_table: The table to create counts data from
Expand All @@ -145,7 +145,8 @@ def count_document(
table_cols,
where_clauses=where_clauses,
min_subject=min_subject,
fhir_resource="document",
fhir_resource="documentreference",
filter_resource="encounter",
)

def count_encounter(
Expand Down Expand Up @@ -174,6 +175,32 @@ def count_encounter(
fhir_resource="encounter",
)

def count_medicationrequest(
self,
table_name: str,
source_table: str,
table_cols: list,
where_clauses: Union[list, None] = None,
min_subject: int = 10,
) -> str:
"""wrapper method for constructing medicationrequests counts tables

:param table_name: The name of the table to create. Must start with study prefix
:param source_table: The table to create counts data from
:param table_cols: The columns from the source table to add to the count table
:param where_clauses: An array of where clauses to use for filtering the data
:param min_subject: An integer setting the minimum bin size for inclusion
(default: 10)
"""
return self.get_count_query(
table_name,
source_table,
table_cols,
where_clauses=where_clauses,
min_subject=min_subject,
fhir_resource="medicationrequest",
)

def count_observation(
self,
table_name: str,
Expand Down
18 changes: 6 additions & 12 deletions cumulus_library/studies/core/builder_condition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from cumulus_library import base_table_builder
from cumulus_library import databases
from cumulus_library.studies.core.core_templates import core_templates
from cumulus_library.template_sql import templates
from cumulus_library.template_sql import templates, utils


expected_table_cols = {
Expand Down Expand Up @@ -42,8 +42,10 @@


class CoreConditionBuilder(base_table_builder.BaseTableBuilder):
display_text = "Creating Condition tables..."

def denormalize_codes(self):
preferred_config = templates.CodeableConceptConfig(
preferred_config = utils.CodeableConceptConfig(
source_table="condition",
source_id="id",
column_name="code",
Expand All @@ -60,7 +62,7 @@ def denormalize_codes(self):
templates.get_codeable_concept_denormalize_query(preferred_config)
)

all_config = templates.CodeableConceptConfig(
all_config = utils.CodeableConceptConfig(
source_table="condition",
source_id="id",
column_name="code",
Expand All @@ -72,14 +74,6 @@ def denormalize_codes(self):
templates.get_codeable_concept_denormalize_query(all_config)
)

def validate_schema(self, cursor: object, schema: str, expected_table_cols, parser):
validated_schema = {}
for table, cols in expected_table_cols.items():
query = templates.get_column_datatype_query(schema, table, cols.keys())
table_schema = cursor.execute(query).fetchall()
validated_schema[table] = parser.validate_table_schema(cols, table_schema)
return validated_schema

def prepare_queries(
self,
cursor: object,
Expand All @@ -89,7 +83,7 @@ def prepare_queries(
**kwargs,
):
self.denormalize_codes()
validated_schema = self.validate_schema(
validated_schema = core_templates.validate_schema(
cursor, schema, expected_table_cols, parser
)
self.queries.append(
Expand Down
176 changes: 0 additions & 176 deletions cumulus_library/studies/core/builder_condition.sql

This file was deleted.

Loading
Loading