Skip to content

Commit

Permalink
Moved study period source from core (#41)
Browse files Browse the repository at this point in the history
* Moved study period source from core

This takes the core__study_period table (which was really
specific to this study) and moves it into this study as part
of the covid_symptom__study_period table.

This also removes the no longer required interstitial directory,
and updates the counts builder/pyproject.toml to the 3.0 input
format.

* Ruff cutover

* ci indenting, more generic args

* removed unused imports

* ruff format
  • Loading branch information
dogversioning authored Aug 20, 2024
1 parent ea07250 commit 5b0b01a
Show file tree
Hide file tree
Showing 33 changed files with 145 additions and 127 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,30 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Get library from main
run: pip install git+https://github.com/smart-on-fhir/cumulus-library.git

- name: Install linters
run: |
python -m pip install --upgrade pip
pip install ".[dev]"
- name: Run sqlfluff on jinja templates
run: |
sqlfluff lint
- name: Run black
if: success() || failure() # still run black if above checks fails
- name: Run ruff
if: success() || failure() # still run ruff if above checks fails
run: |
black --check --verbose .
ruff check
ruff format --check
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path

from cumulus_library.statistics.counts import CountsBuilder


Expand Down Expand Up @@ -98,7 +99,7 @@ def count_symptom(self, duration="week"):
]
return self.count_encounter(view_name, from_table, cols)

def prepare_queries(self, cursor=None, schema=None, **kwargs):
def prepare_queries(self, *args, **kwargs):
self.queries = [
self.count_dx("month"),
self.count_dx("week"),
Expand Down
File renamed without changes.
Empty file.
40 changes: 0 additions & 40 deletions cumulus_library_covid/covid_symptom/table_study_period.sql

This file was deleted.

76 changes: 0 additions & 76 deletions cumulus_library_covid/covid_symptom/typesystem.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" util for sql view creation"""
"""util for sql view creation"""

import ctakesclient

Expand All @@ -15,7 +15,7 @@ def main():

table_cols = "AS t (cui, tui, code, system, text, pref);"
create_view = (
"create or replace view covid_symptom__define_symptom as "
"create or replace view covid_symptom__define_symptom as " # noqa: S608
f"select * from (VALUES \n {values_sql}) \n {table_cols}"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
106 changes: 106 additions & 0 deletions cumulus_library_covid/table_study_period.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
CREATE TABLE covid_symptom__study_period AS
WITH documented_encounter AS (
SELECT DISTINCT
ce.period_start_day,
ce.period_start_week,
ce.period_start_month,
ce.period_end_day,
ce.age_at_visit,
cdr.author_day,
cdr.author_week,
cdr.author_month,
cdr.author_year,
cp.gender,
cp.race_display,
cp.ethnicity_display,
cp.subject_ref,
ce.encounter_ref,
ce.status,
cdr.documentreference_ref,
date_diff(
'day', ce.period_start_day, date(cdr.author_day)
) AS diff_enc_note_days,
coalesce(ce.class_code, 'None') AS enc_class_code,
coalesce(ce.class_display, 'None') AS enc_class_display,
coalesce(cdr.type_code, 'None') AS doc_type_code,
coalesce(cdr.type_display, 'None') AS doc_type_display
FROM
core__patient AS cp,
core__encounter AS ce,
core__documentreference AS cdr
WHERE
(cp.subject_ref = ce.subject_ref)
AND (ce.encounter_ref = cdr.encounter_ref)
AND (cdr.author_day BETWEEN date('2016-06-01') AND current_date)
AND (ce.period_start_day BETWEEN date('2016-06-01') AND current_date)
AND (ce.period_end_day BETWEEN date('2016-06-01') AND current_date)
),

encounter_with_note AS (
SELECT
de.period_start_day,
de.period_start_week,
de.period_start_month,
de.period_end_day,
de.age_at_visit,
de.author_day,
de.author_week,
de.author_month,
de.author_year,
de.gender,
de.race_display,
de.ethnicity_display,
de.subject_ref,
de.encounter_ref,
de.status,
de.documentreference_ref,
de.diff_enc_note_days,
de.enc_class_code,
de.enc_class_display,
de.doc_type_code,
de.doc_type_display,
coalesce(ed.code IS NOT NULL, FALSE) AS ed_note
FROM documented_encounter AS de
LEFT JOIN core__ed_note AS ed
ON de.doc_type_code = ed.from_code
)

SELECT DISTINCT
v.variant_era,
e.period_start_day AS start_date,
e.period_start_week AS start_week,
e.period_start_month AS start_month,
e.period_end_day AS end_date,
e.age_at_visit,
e.author_day AS author_date,
e.author_week,
e.author_month,
e.author_year,
e.gender,
e.race_display,
e.subject_ref,
e.encounter_ref,
e.documentreference_ref,
e.diff_enc_note_days,
e.enc_class_code,
e.enc_class_display,
e.doc_type_code,
e.doc_type_display,
e.ed_note,
a.age_group,
e.status
FROM encounter_with_note AS e,
covid_symptom__define_period AS v,
covid_symptom__define_age AS a
WHERE
e.age_at_visit = a.age
AND e.gender IN ('female', 'male')
AND e.author_day BETWEEN v.variant_start AND v.variant_end
AND e.period_start_day BETWEEN v.variant_start AND v.variant_end
AND e.diff_enc_note_days BETWEEN -30 AND 30;

CREATE TABLE covid_symptom__meta_date AS
SELECT
min(start_date) AS min_date,
max(end_date) AS max_date
FROM covid_symptom__study_period;
File renamed without changes.
File renamed without changes.
25 changes: 21 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[project]
name = "cumulus-library-covid"
requires-python = ">= 3.10"
version = "1.0.0"
requires-python = ">= 3.11"
version = "2.0.0"
dependencies = [
"cumulus-library >= 2.0, <3",
"cumulus-library >= 3.0, <4",
"sqlfluff >= 3"
]
description = "SQL generation for cumulus covid symptom analysis"
Expand All @@ -28,9 +28,26 @@ build-backend = "flit_core.buildapi"

[project.optional-dependencies]
dev = [
"black >= 24.3, <25",
# if you update the ruff version, also update .pre-commit-config.yaml
"ruff < 0.6",
"pylint",
]

[tool.flit.sdist]
include = ["covid_symptom/"]

[tool.ruff]
line-length = 100

[tool.ruff.lint]
allowed-confusables = [""] # allow proper apostrophes
select = [
"A", # prevent using keywords that clobber python builtins
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"PLE", # pylint errors
"RUF", # the ruff developer's own rules
"S", # bandit security warnings
"UP", # alert you when better syntax is available in your python version
]

0 comments on commit 5b0b01a

Please sign in to comment.