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

Soe sequence of events #85

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .sqlfluffignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ show_views.sql.jinja
# This is a temporary ignore due to time pressure - not sure of root cause,
# but the table in question builds
codeable_concept_denormalize.sql.jinja

output.sql
1 change: 1 addition & 0 deletions cumulus_library/.sqlfluff
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ conditions = ["1 > 0", "1 < 2"]
dataset = [["foo","foo"],["bar","bar"]]
ext_systems = ["omb", "text"]
field = 'column_name'
field_config = {'col1':{'present':True, 'type': 'varchar'},'col2':{'present':False, 'type': 'varchar'}}
fhir_extension = fhir_extension
id = 'id'
medication_datasources = {"by_contained_ref" : True, "by_external_ref" : True}
Expand Down
1 change: 1 addition & 0 deletions cumulus_library/base_table_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def execute_queries(
table_name = table_name.split(".")[1].replace('"', "")
table_names.append(table_name)
for table_name in table_names:
table_name = table_name.replace('"', "")
cursor.execute(f"DROP TABLE IF EXISTS {table_name}")
with get_progress_bar(disable=verbose) as progress:
task = progress.add_task(
Expand Down
57 changes: 57 additions & 0 deletions cumulus_library/studies/core/builder_soe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
""" Module for generating condition codeableConcept table"""
import re
from cumulus_library.base_table_builder import BaseTableBuilder
from cumulus_library.helper import get_progress_bar, query_console_output
from cumulus_library.template_sql.templates import (
get_column_datatype_query,
get_object_denormalize_query,
)


class SOEBuilder(BaseTableBuilder):
display_text = "Creating SoE support tables..."

def prepare_queries(self, cursor: object, schema: str):
"""Constructs tables for SOE QA verification

:param cursor: A database cursor object
:param schema: the schema/db name, matching the cursor

"""
table = "documentreference"
column = "context"
with get_progress_bar(transient=True) as progress:
mikix marked this conversation as resolved.
Show resolved Hide resolved
task = progress.add_task(
"Detecting SOE...",
total=1,
)

query = get_column_datatype_query(schema, table, column)
cursor.execute(query)
progress.advance(task)
result = str(cursor.fetchone()[0])
field_config = {
"start": {
"present": False,
"type": "varchar",
},
"end": {"present": False, "type": "varchar"},
}
if "period row" in result:
# The following will get all text between parenthesis following
# period row - i.e. the schema of the period object
field_schema_str = re.search(r"period row\(\s*([^\n\r]*)\),", result)[1]
for key in field_config.keys():
if f"{key} {field_config[key]['type']}" in field_schema_str:
field_config[key]["present"] = True

self.queries.append(
get_object_denormalize_query(
schema,
table,
"id",
f"{column}.period",
field_config,
"core__soe_doc_period",
)
)
5 changes: 5 additions & 0 deletions cumulus_library/studies/core/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ file_names = [
"builder_encounter_coding.py",
"builder_core_medication.py",
"builder_patient_extension.py",
"builder_soe.py"
]

[sql_config]
Expand All @@ -23,6 +24,7 @@ file_names = [
"observation_vital_signs.sql",
"medication_request.sql",
"study_period.sql",
"soe_sequence_of_events.sql",
]

[counts_builder_config]
Expand All @@ -42,4 +44,7 @@ export_list = [
"core__count_medicationrequest_month",
"core__meta_date",
"core__meta_version",
"core__count_soe_cond_week",
"core__count_soe_document_week",
"core__count_soe_medreq_week"
]
Loading