Skip to content

Commit

Permalink
replace views with tables (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogversioning authored Jun 21, 2023
1 parent 36b6ebd commit 6797bb5
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 27 deletions.
1 change: 0 additions & 1 deletion cumulus_library/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ def main(cli_args=None):

if args.get("data_path"):
args["data_path"] = get_abs_posix_path(args["data_path"])

return run_cli(args)


Expand Down
4 changes: 2 additions & 2 deletions cumulus_library/studies/core/condition.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ FROM temp_condition AS tc,
unnest(code.coding) AS t_coding (code_row) --noqa
WHERE tc.recordeddate BETWEEN date('2016-01-01') AND current_date;

CREATE OR REPLACE VIEW core__join_condition_icd AS
CREATE TABLE core__join_condition_icd AS
SELECT
cc.subject_ref,
cc.encounter_ref,
Expand All @@ -60,7 +60,7 @@ WHERE
cc.encounter_ref = ce.encounter_ref
AND cc.cond_code.coding[1].code = vil.code; --noqa

CREATE OR REPLACE VIEW core__count_condition_icd10_month AS
CREATE TABLE core__count_condition_icd10_month AS
WITH powerset AS (
SELECT
count(DISTINCT cc.subject_ref) AS cnt_subject,
Expand Down
2 changes: 1 addition & 1 deletion cumulus_library/studies/core/documentreference.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ FROM temp_documentreference AS tdr,
WHERE author_date BETWEEN date('2016-06-01') AND current_date;

-- count *group by* DocumentReference.type
CREATE OR REPLACE VIEW core__count_documentreference_month AS
CREATE TABLE core__count_documentreference_month AS
WITH powerset AS (
SELECT
count(DISTINCT d.subject_ref) AS cnt_subject,
Expand Down
15 changes: 6 additions & 9 deletions cumulus_library/studies/core/encounter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ WHERE
e.subject_ref = p.subject_ref
AND start_date BETWEEN date('2016-06-01') AND current_date;

CREATE OR REPLACE VIEW core__join_encounter_patient AS
CREATE TABLE core__join_encounter_patient AS
SELECT
ce.enc_class,
ce.enc_type,
Expand All @@ -58,7 +58,7 @@ FROM core__encounter AS ce, core__patient AS cp
WHERE ce.subject_ref = cp.subject_ref;


CREATE OR REPLACE VIEW core__count_encounter_month AS
CREATE TABLE core__count_encounter_month AS
WITH powerset AS (
SELECT
count(DISTINCT ce.subject_ref) AS cnt_subject,
Expand All @@ -68,8 +68,7 @@ WITH powerset AS (
ce.age_at_visit,
cp.gender,
cp.race_display,
cp.ethnicity_display,
cp.postalcode3
cp.ethnicity_display
FROM core__encounter AS ce, core__patient AS cp
WHERE ce.subject_ref = cp.subject_ref
GROUP BY
Expand All @@ -79,8 +78,7 @@ WITH powerset AS (
ce.age_at_visit,
cp.gender,
cp.race_display,
cp.ethnicity_display,
cp.postalcode3
cp.ethnicity_display
)
)

Expand All @@ -91,14 +89,13 @@ SELECT DISTINCT
powerset.age_at_visit,
powerset.gender,
powerset.race_display,
powerset.ethnicity_display,
powerset.postalcode3
powerset.ethnicity_display
FROM powerset
WHERE powerset.cnt_subject >= 10
ORDER BY
powerset.start_month ASC, powerset.enc_class_code ASC, powerset.age_at_visit ASC;

CREATE OR REPLACE VIEW core__count_encounter_day AS
CREATE TABLE core__count_encounter_day AS
WITH powerset AS (
SELECT
count(DISTINCT ce.subject_ref) AS cnt_subject,
Expand Down
4 changes: 2 additions & 2 deletions cumulus_library/studies/core/fhir_define.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- ############################################################
-- FHIR Terminology

CREATE OR REPLACE VIEW core__fhir_vocab AS SELECT * FROM
CREATE TABLE core__fhir_vocab AS SELECT * FROM
(
VALUES
('ICD10', 'http://hl7.org/fhir/sid/icd-10-cm'),
Expand Down Expand Up @@ -43,7 +43,7 @@ CREATE OR REPLACE VIEW core__fhir_vocab AS SELECT * FROM
-- ############################################################
-- FHIR StructureDefinition

CREATE OR REPLACE VIEW core__fhir_define AS
CREATE TABLE core__fhir_define AS
SELECT * FROM
(
VALUES
Expand Down
2 changes: 1 addition & 1 deletion cumulus_library/studies/core/medication_request.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ FROM medicationrequest AS mr,
WHERE med_coding.system = 'http://www.nlm.nih.gov/research/umls/rxnorm';


CREATE OR REPLACE VIEW core__count_medicationrequest_month AS
CREATE TABLE core__count_medicationrequest_month AS
WITH powerset AS (
SELECT
count(DISTINCT cmr.subject_id) AS cnt_subject,
Expand Down
2 changes: 1 addition & 1 deletion cumulus_library/studies/core/observation_lab.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ WHERE tol.effectivedatetime BETWEEN date('2016-06-01') AND current_date;
-- ###########################################################################
-- COUNT Patients, Encounters, Lab Results
-- ###########################################################################
CREATE OR REPLACE VIEW core__count_observation_lab_month AS
CREATE TABLE core__count_observation_lab_month AS
WITH powerset AS (
SELECT
count(DISTINCT o.subject_ref) AS cnt_subject,
Expand Down
2 changes: 1 addition & 1 deletion cumulus_library/studies/core/patient.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ WHERE
AND tp.gender IS NOT NULL;


CREATE OR REPLACE VIEW core__count_patient AS
CREATE TABLE core__count_patient AS
WITH powerset AS (
SELECT
count(DISTINCT cp.subject_ref) AS cnt_subject,
Expand Down
2 changes: 1 addition & 1 deletion cumulus_library/studies/core/setup.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Emergency Department Notes
--
CREATE OR REPLACE VIEW core__ed_note AS
CREATE TABLE core__ed_note AS
SELECT
t.from_system,
t.from_code,
Expand Down
2 changes: 1 addition & 1 deletion cumulus_library/studies/template/counts.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE VIEW template__count_influenza_test_month AS
CREATE TABLE template__count_influenza_test_month AS
WITH powerset AS (
SELECT
count(DISTINCT tflo.subject_ref) AS cnt_subject,
Expand Down
2 changes: 1 addition & 1 deletion cumulus_library/studies/template/setup.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE VIEW template__influenza_codes AS
CREATE TABLE template__influenza_codes AS
SELECT
t.from_system,
t.analyte,
Expand Down
2 changes: 1 addition & 1 deletion cumulus_library/studies/vocab/icd_legend.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE VIEW vocab__icd_legend AS
CREATE TABLE vocab__icd_legend AS
SELECT
code,
display,
Expand Down
6 changes: 2 additions & 4 deletions cumulus_library/studies/vocab/vocab_icd_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

from pathlib import Path

from rich.progress import Progress

from cumulus_library.base_runner import BaseRunner
from cumulus_library.helper import query_console_output
from cumulus_library.helper import query_console_output, get_progress_bar
from cumulus_library.template_sql.templates import (
get_ctas_query,
get_insert_into_query,
Expand Down Expand Up @@ -49,7 +47,7 @@ def create_icd_legend(
sum(1 for i in open(f"{path}/{filename}.bsv", "rb")) / partition_size
)

with Progress(disable=verbose) as progress:
with get_progress_bar(disable=verbose) as progress:
task = progress.add_task(
f"Uploading {table_name} data...",
total=query_count,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cumulus-library"
version = "0.3.0"
version = "0.3.1"
# In order to support 3.12, we wil need to refactor out load_module, which is
# targeted for deprecation in that version.
requires-python = ">= 3.9, <3.12"
Expand Down

0 comments on commit 6797bb5

Please sign in to comment.