diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index be5889e..9b18481 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,7 +32,8 @@ jobs: - 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 diff --git a/cumulus_library_covid/counts.py b/cumulus_library_covid/counts.py index e31f139..b258a13 100644 --- a/cumulus_library_covid/counts.py +++ b/cumulus_library_covid/counts.py @@ -1,6 +1,7 @@ from pathlib import Path -from cumulus_library.statistics.counts import CountsBuilder + from cumulus_library import base_utils, study_manifest +from cumulus_library.statistics.counts import CountsBuilder class CovidCountsBuilder(CountsBuilder): @@ -100,10 +101,7 @@ def count_symptom(self, duration="week"): return self.count_encounter(view_name, from_table, cols) def prepare_queries( - self, - config:base_utils.StudyConfig, - manifest:study_manifest.StudyManifest, - **kwargs + self, config: base_utils.StudyConfig, manifest: study_manifest.StudyManifest, **kwargs ): self.queries = [ self.count_dx("month"), diff --git a/cumulus_library_covid/define_symptom.py b/cumulus_library_covid/define_symptom.py index 2bcf34f..4db2edc 100644 --- a/cumulus_library_covid/define_symptom.py +++ b/cumulus_library_covid/define_symptom.py @@ -1,4 +1,4 @@ -""" util for sql view creation""" +"""util for sql view creation""" import ctakesclient @@ -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}" ) diff --git a/cumulus_library_covid/table_study_period.sql b/cumulus_library_covid/table_study_period.sql index 74bdb01..447d532 100644 --- a/cumulus_library_covid/table_study_period.sql +++ b/cumulus_library_covid/table_study_period.sql @@ -17,7 +17,9 @@ WITH documented_encounter AS ( ce.encounter_ref, ce.status, cdr.documentreference_ref, - date_diff('day', ce.period_start_day, date(cdr.author_day)) AS diff_enc_note_days, + 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, @@ -33,33 +35,34 @@ WITH documented_encounter AS ( 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 + 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 @@ -83,7 +86,7 @@ SELECT DISTINCT e.enc_class_display, e.doc_type_code, e.doc_type_display, - e.ed_note, + e.ed_note, a.age_group, e.status FROM encounter_with_note AS e, diff --git a/cumulus_library_covid/typesystem.py b/cumulus_library_covid/typesystem.py deleted file mode 100644 index 69527da..0000000 --- a/cumulus_library_covid/typesystem.py +++ /dev/null @@ -1,76 +0,0 @@ -""" Utility classes for verifying/generating covid sql definitions""" - -from cumulus_library.schema.columns import Coding, Vocab -from cumulus_library.library.schema.typesystem import Period -from cumulus_library.library.schema.valueset import ( - ValueSet, - ObservationInterpretationDetection, -) - - -class CovidDiagnosis(Coding): - """ - COVID19 diagnosis is either coded (positive) or unknown. - Lacking a coded diagnosis does not strictly imply no covid. - """ - - positive = ("Positive", "COVID Diagnosis recorded") - none = ("NONE", "No COVID recorded") - - -class CovidPCR(Coding): - """defininition for ICD PCR tests""" - - positive = (ObservationInterpretationDetection.positive.value, "Positive COVID PCR") - negative = (ObservationInterpretationDetection.negative.value, "Negative COVID PCR") - indeterminate = ( - ObservationInterpretationDetection.negative.value, - "Indeterminate: COVID PCR performed but no pos/neg value", - ) - none = ("NONE", "No COVID PCR result found") - - def __init__(self, code, display): - super().__init__(code, display, ValueSet.ObservationInterpretation.url) - - -class CovidSymptom(Coding): - """definition for ICD covid symptoms""" - - C0027424 = "Congestion or runny nose" - C1260880 = "Congestion or runny nose" - C0010200 = "Cough" - C0850149 = "Cough" - C0239134 = "Cough" - C0011991 = "Diarrhea" - C0015672 = "Fatigue" - C0231218 = "Fatigue" - C0085593 = "Fever or chills" - C0015967 = "Fever or chills" - C0085594 = "Fever or chills" - C0018681 = "Headache" - C0231528 = "Muscle or body aches" - C0281856 = "Muscle or body aches" - C0027497 = "Nausea or vomiting" - C0042963 = "Nausea or vomiting" - C0027498 = "Nausea or vomiting" - C0003126 = "Loss of taste or smell" - C1332239 = "Loss of taste or smell" - C0013404 = "Dyspnea" - C0242429 = "Sore throat" - - def __init__(self, display): - super().__init__(self.name, display, Vocab.UMLS.url) - - -class CovidVariantEra(Coding): - """ - -- Variant eras are defined using COVID-19 data for Massachusetts from CoVariant [16]. - -- Pre-Delta era was defined as March 1, 2020 to June 20, 2021 - -- Delta era as June 21, 2021 to December 19, 2021 - -- Omicron era as December 20, 2021 onwards. - """ - - before_covid = Period("2016-01-01", "2021-02-28").as_json() - before_delta = Period("2020-03-01", "2021-06-20").as_json() - delta = Period("2021-06-20", "2021-12-19").as_json() - omicron = Period("2021-12-20").as_json() diff --git a/pyproject.toml b/pyproject.toml index c5013e2..0a704ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 +]