From 6df611c9f600c4883617b7fe6ebfafbf02dc5559 Mon Sep 17 00:00:00 2001 From: Matt Garber Date: Tue, 13 Aug 2024 13:59:18 -0400 Subject: [PATCH] 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. --- .github/workflows/ci.yaml | 4 + .../{covid_symptom => }/counts.py | 8 +- .../{covid_symptom => }/counts.sql | 0 .../covid_symptom/__init__.py | 0 .../covid_symptom/table_study_period.sql | 40 ------- .../define_age_general.sql | 0 .../define_age_pediatric.sql | 0 .../{covid_symptom => }/define_dx_icd10.sql | 0 .../{covid_symptom => }/define_dx_snomed.sql | 0 .../{covid_symptom => }/define_ed_note.sql | 0 .../{covid_symptom => }/define_pcr.sql | 0 .../{covid_symptom => }/define_pcr_custom.sql | 0 .../define_pcr_negative.sql | 0 .../define_pcr_positive.sql | 0 .../define_study_period.sql | 0 .../{covid_symptom => }/define_symptom.py | 0 .../{covid_symptom => }/define_symptom.sql | 0 .../{covid_symptom => }/manifest.toml | 0 .../{covid_symptom => }/table_dx.sql | 0 .../{covid_symptom => }/table_pcr.sql | 0 .../table_prevalence_ed.sql | 0 cumulus_library_covid/table_study_period.sql | 103 ++++++++++++++++++ .../{covid_symptom => }/table_symptom.sql | 0 .../{covid_symptom => }/typesystem.py | 0 .../valueset_dx_icd10.json | 0 .../valueset_dx_snomed.json | 0 .../valueset_pcr_interpretation.json | 0 .../valueset_pcr_negative.json | 0 .../valueset_pcr_positive.json | 0 .../valueset_pcr_qualitative.json | 0 ...valueset_pcr_qualitative_quantitative.json | 0 .../{covid_symptom => }/version.sql | 0 pyproject.toml | 6 +- 33 files changed, 117 insertions(+), 44 deletions(-) rename cumulus_library_covid/{covid_symptom => }/counts.py (94%) rename cumulus_library_covid/{covid_symptom => }/counts.sql (100%) delete mode 100644 cumulus_library_covid/covid_symptom/__init__.py delete mode 100644 cumulus_library_covid/covid_symptom/table_study_period.sql rename cumulus_library_covid/{covid_symptom => }/define_age_general.sql (100%) rename cumulus_library_covid/{covid_symptom => }/define_age_pediatric.sql (100%) rename cumulus_library_covid/{covid_symptom => }/define_dx_icd10.sql (100%) rename cumulus_library_covid/{covid_symptom => }/define_dx_snomed.sql (100%) rename cumulus_library_covid/{covid_symptom => }/define_ed_note.sql (100%) rename cumulus_library_covid/{covid_symptom => }/define_pcr.sql (100%) rename cumulus_library_covid/{covid_symptom => }/define_pcr_custom.sql (100%) rename cumulus_library_covid/{covid_symptom => }/define_pcr_negative.sql (100%) rename cumulus_library_covid/{covid_symptom => }/define_pcr_positive.sql (100%) rename cumulus_library_covid/{covid_symptom => }/define_study_period.sql (100%) rename cumulus_library_covid/{covid_symptom => }/define_symptom.py (100%) rename cumulus_library_covid/{covid_symptom => }/define_symptom.sql (100%) rename cumulus_library_covid/{covid_symptom => }/manifest.toml (100%) rename cumulus_library_covid/{covid_symptom => }/table_dx.sql (100%) rename cumulus_library_covid/{covid_symptom => }/table_pcr.sql (100%) rename cumulus_library_covid/{covid_symptom => }/table_prevalence_ed.sql (100%) create mode 100644 cumulus_library_covid/table_study_period.sql rename cumulus_library_covid/{covid_symptom => }/table_symptom.sql (100%) rename cumulus_library_covid/{covid_symptom => }/typesystem.py (100%) rename cumulus_library_covid/{covid_symptom => }/valueset_dx_icd10.json (100%) rename cumulus_library_covid/{covid_symptom => }/valueset_dx_snomed.json (100%) rename cumulus_library_covid/{covid_symptom => }/valueset_pcr_interpretation.json (100%) rename cumulus_library_covid/{covid_symptom => }/valueset_pcr_negative.json (100%) rename cumulus_library_covid/{covid_symptom => }/valueset_pcr_positive.json (100%) rename cumulus_library_covid/{covid_symptom => }/valueset_pcr_qualitative.json (100%) rename cumulus_library_covid/{covid_symptom => }/valueset_pcr_qualitative_quantitative.json (100%) rename cumulus_library_covid/{covid_symptom => }/version.sql (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 33bf5fc..a21c297 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,6 +16,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + + - 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 diff --git a/cumulus_library_covid/covid_symptom/counts.py b/cumulus_library_covid/counts.py similarity index 94% rename from cumulus_library_covid/covid_symptom/counts.py rename to cumulus_library_covid/counts.py index 5780652..e31f139 100644 --- a/cumulus_library_covid/covid_symptom/counts.py +++ b/cumulus_library_covid/counts.py @@ -1,5 +1,6 @@ from pathlib import Path from cumulus_library.statistics.counts import CountsBuilder +from cumulus_library import base_utils, study_manifest class CovidCountsBuilder(CountsBuilder): @@ -98,7 +99,12 @@ 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, + config:base_utils.StudyConfig, + manifest:study_manifest.StudyManifest, + **kwargs + ): self.queries = [ self.count_dx("month"), self.count_dx("week"), diff --git a/cumulus_library_covid/covid_symptom/counts.sql b/cumulus_library_covid/counts.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/counts.sql rename to cumulus_library_covid/counts.sql diff --git a/cumulus_library_covid/covid_symptom/__init__.py b/cumulus_library_covid/covid_symptom/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/cumulus_library_covid/covid_symptom/table_study_period.sql b/cumulus_library_covid/covid_symptom/table_study_period.sql deleted file mode 100644 index 15447e3..0000000 --- a/cumulus_library_covid/covid_symptom/table_study_period.sql +++ /dev/null @@ -1,40 +0,0 @@ -CREATE TABLE covid_symptom__study_period AS -SELECT DISTINCT - v.variant_era, - s.period_start_day AS start_date, - s.period_start_week AS start_week, - s.period_start_month AS start_month, - s.period_end_day AS end_date, - s.age_at_visit, - s.author_day AS author_date, - s.author_week, - s.author_month, - s.author_year, - s.gender, - s.race_display, - s.subject_ref, - s.encounter_ref, - s.documentreference_ref, - s.diff_enc_note_days, - s.enc_class_code, - s.enc_class_display, - s.doc_type_code, - s.doc_type_display, - s.ed_note, -- TODO https://github.com/smart-on-fhir/cumulus-library-covid/issues/10 - a.age_group, - s.status -FROM core__study_period AS s, - covid_symptom__define_period AS v, - covid_symptom__define_age AS a -WHERE - s.age_at_visit = a.age - AND s.gender IN ('female', 'male') - AND s.author_day BETWEEN v.variant_start AND v.variant_end - AND s.period_start_day BETWEEN v.variant_start AND v.variant_end - AND s.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; diff --git a/cumulus_library_covid/covid_symptom/define_age_general.sql b/cumulus_library_covid/define_age_general.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/define_age_general.sql rename to cumulus_library_covid/define_age_general.sql diff --git a/cumulus_library_covid/covid_symptom/define_age_pediatric.sql b/cumulus_library_covid/define_age_pediatric.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/define_age_pediatric.sql rename to cumulus_library_covid/define_age_pediatric.sql diff --git a/cumulus_library_covid/covid_symptom/define_dx_icd10.sql b/cumulus_library_covid/define_dx_icd10.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/define_dx_icd10.sql rename to cumulus_library_covid/define_dx_icd10.sql diff --git a/cumulus_library_covid/covid_symptom/define_dx_snomed.sql b/cumulus_library_covid/define_dx_snomed.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/define_dx_snomed.sql rename to cumulus_library_covid/define_dx_snomed.sql diff --git a/cumulus_library_covid/covid_symptom/define_ed_note.sql b/cumulus_library_covid/define_ed_note.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/define_ed_note.sql rename to cumulus_library_covid/define_ed_note.sql diff --git a/cumulus_library_covid/covid_symptom/define_pcr.sql b/cumulus_library_covid/define_pcr.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/define_pcr.sql rename to cumulus_library_covid/define_pcr.sql diff --git a/cumulus_library_covid/covid_symptom/define_pcr_custom.sql b/cumulus_library_covid/define_pcr_custom.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/define_pcr_custom.sql rename to cumulus_library_covid/define_pcr_custom.sql diff --git a/cumulus_library_covid/covid_symptom/define_pcr_negative.sql b/cumulus_library_covid/define_pcr_negative.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/define_pcr_negative.sql rename to cumulus_library_covid/define_pcr_negative.sql diff --git a/cumulus_library_covid/covid_symptom/define_pcr_positive.sql b/cumulus_library_covid/define_pcr_positive.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/define_pcr_positive.sql rename to cumulus_library_covid/define_pcr_positive.sql diff --git a/cumulus_library_covid/covid_symptom/define_study_period.sql b/cumulus_library_covid/define_study_period.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/define_study_period.sql rename to cumulus_library_covid/define_study_period.sql diff --git a/cumulus_library_covid/covid_symptom/define_symptom.py b/cumulus_library_covid/define_symptom.py similarity index 100% rename from cumulus_library_covid/covid_symptom/define_symptom.py rename to cumulus_library_covid/define_symptom.py diff --git a/cumulus_library_covid/covid_symptom/define_symptom.sql b/cumulus_library_covid/define_symptom.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/define_symptom.sql rename to cumulus_library_covid/define_symptom.sql diff --git a/cumulus_library_covid/covid_symptom/manifest.toml b/cumulus_library_covid/manifest.toml similarity index 100% rename from cumulus_library_covid/covid_symptom/manifest.toml rename to cumulus_library_covid/manifest.toml diff --git a/cumulus_library_covid/covid_symptom/table_dx.sql b/cumulus_library_covid/table_dx.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/table_dx.sql rename to cumulus_library_covid/table_dx.sql diff --git a/cumulus_library_covid/covid_symptom/table_pcr.sql b/cumulus_library_covid/table_pcr.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/table_pcr.sql rename to cumulus_library_covid/table_pcr.sql diff --git a/cumulus_library_covid/covid_symptom/table_prevalence_ed.sql b/cumulus_library_covid/table_prevalence_ed.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/table_prevalence_ed.sql rename to cumulus_library_covid/table_prevalence_ed.sql diff --git a/cumulus_library_covid/table_study_period.sql b/cumulus_library_covid/table_study_period.sql new file mode 100644 index 0000000..74bdb01 --- /dev/null +++ b/cumulus_library_covid/table_study_period.sql @@ -0,0 +1,103 @@ +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; diff --git a/cumulus_library_covid/covid_symptom/table_symptom.sql b/cumulus_library_covid/table_symptom.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/table_symptom.sql rename to cumulus_library_covid/table_symptom.sql diff --git a/cumulus_library_covid/covid_symptom/typesystem.py b/cumulus_library_covid/typesystem.py similarity index 100% rename from cumulus_library_covid/covid_symptom/typesystem.py rename to cumulus_library_covid/typesystem.py diff --git a/cumulus_library_covid/covid_symptom/valueset_dx_icd10.json b/cumulus_library_covid/valueset_dx_icd10.json similarity index 100% rename from cumulus_library_covid/covid_symptom/valueset_dx_icd10.json rename to cumulus_library_covid/valueset_dx_icd10.json diff --git a/cumulus_library_covid/covid_symptom/valueset_dx_snomed.json b/cumulus_library_covid/valueset_dx_snomed.json similarity index 100% rename from cumulus_library_covid/covid_symptom/valueset_dx_snomed.json rename to cumulus_library_covid/valueset_dx_snomed.json diff --git a/cumulus_library_covid/covid_symptom/valueset_pcr_interpretation.json b/cumulus_library_covid/valueset_pcr_interpretation.json similarity index 100% rename from cumulus_library_covid/covid_symptom/valueset_pcr_interpretation.json rename to cumulus_library_covid/valueset_pcr_interpretation.json diff --git a/cumulus_library_covid/covid_symptom/valueset_pcr_negative.json b/cumulus_library_covid/valueset_pcr_negative.json similarity index 100% rename from cumulus_library_covid/covid_symptom/valueset_pcr_negative.json rename to cumulus_library_covid/valueset_pcr_negative.json diff --git a/cumulus_library_covid/covid_symptom/valueset_pcr_positive.json b/cumulus_library_covid/valueset_pcr_positive.json similarity index 100% rename from cumulus_library_covid/covid_symptom/valueset_pcr_positive.json rename to cumulus_library_covid/valueset_pcr_positive.json diff --git a/cumulus_library_covid/covid_symptom/valueset_pcr_qualitative.json b/cumulus_library_covid/valueset_pcr_qualitative.json similarity index 100% rename from cumulus_library_covid/covid_symptom/valueset_pcr_qualitative.json rename to cumulus_library_covid/valueset_pcr_qualitative.json diff --git a/cumulus_library_covid/covid_symptom/valueset_pcr_qualitative_quantitative.json b/cumulus_library_covid/valueset_pcr_qualitative_quantitative.json similarity index 100% rename from cumulus_library_covid/covid_symptom/valueset_pcr_qualitative_quantitative.json rename to cumulus_library_covid/valueset_pcr_qualitative_quantitative.json diff --git a/cumulus_library_covid/covid_symptom/version.sql b/cumulus_library_covid/version.sql similarity index 100% rename from cumulus_library_covid/covid_symptom/version.sql rename to cumulus_library_covid/version.sql diff --git a/pyproject.toml b/pyproject.toml index 61e49ee..c5013e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"