From eebea31b08fb32d64d2bfe20483ffb8a20476382 Mon Sep 17 00:00:00 2001 From: Matt Garber Date: Fri, 20 Oct 2023 15:10:16 -0400 Subject: [PATCH] Adds status to study tables --- cumulus_library_covid/covid_symptom/counts.py | 4 ++-- .../covid_symptom/{count.sql => counts.sql} | 22 ++++++++++++------- .../covid_symptom/table_dx.sql | 1 + .../covid_symptom/table_pcr.sql | 1 + .../covid_symptom/table_prevalence_ed.sql | 13 ++++++----- .../covid_symptom/table_study_period.sql | 4 +++- .../covid_symptom/table_symptom.sql | 5 +++-- 7 files changed, 32 insertions(+), 18 deletions(-) rename cumulus_library_covid/covid_symptom/{count.sql => counts.sql} (97%) diff --git a/cumulus_library_covid/covid_symptom/counts.py b/cumulus_library_covid/covid_symptom/counts.py index a09e310..78b914f 100644 --- a/cumulus_library_covid/covid_symptom/counts.py +++ b/cumulus_library_covid/covid_symptom/counts.py @@ -85,7 +85,7 @@ def count_symptom(self, duration="week"): covid_symptom__count_symptom_month """ view_name = self.get_table_name("count_symptom", duration) - from_table = self.get_table_name("symptom_nlp") + from_table = self.get_table_name("symptom_ctakes_negation") cols = [ f"author_{duration}", "symptom_display", @@ -115,4 +115,4 @@ def prepare_queries(self, cursor=None, schema=None): if __name__ == "__main__": builder = CovidCountsBuilder() - builder.write_counts(f"{Path(__file__).resolve().parent}/count.sql") + builder.write_counts(f"{Path(__file__).resolve().parent}/counts.sql") diff --git a/cumulus_library_covid/covid_symptom/count.sql b/cumulus_library_covid/covid_symptom/counts.sql similarity index 97% rename from cumulus_library_covid/covid_symptom/count.sql rename to cumulus_library_covid/covid_symptom/counts.sql index 3e18f06..0c20afe 100644 --- a/cumulus_library_covid/covid_symptom/count.sql +++ b/cumulus_library_covid/covid_symptom/counts.sql @@ -29,8 +29,9 @@ CREATE TABLE covid_symptom__count_dx_month AS ( "ed_note", "variant_era" FROM powerset - WHERE + WHERE cnt_subject >= 10 + ); -- ########################################################### @@ -64,8 +65,9 @@ CREATE TABLE covid_symptom__count_dx_week AS ( "ed_note", "variant_era" FROM powerset - WHERE + WHERE cnt_subject >= 10 + ); -- ########################################################### @@ -105,8 +107,9 @@ CREATE TABLE covid_symptom__count_pcr_month AS ( "gender", "race_display" FROM powerset - WHERE + WHERE cnt_subject >= 10 + ); -- ########################################################### @@ -146,8 +149,9 @@ CREATE TABLE covid_symptom__count_pcr_week AS ( "gender", "race_display" FROM powerset - WHERE + WHERE cnt_subject >= 10 + ); -- ########################################################### @@ -184,8 +188,9 @@ CREATE TABLE covid_symptom__count_study_period_month AS ( "age_group", "race_display" FROM powerset - WHERE + WHERE cnt_subject >= 10 + ); -- ########################################################### @@ -222,8 +227,9 @@ CREATE TABLE covid_symptom__count_study_period_week AS ( "age_group", "race_display" FROM powerset - WHERE + WHERE cnt_subject >= 10 + ); -- ########################################################### @@ -241,7 +247,7 @@ CREATE TABLE covid_symptom__count_symptom_week AS ( "race_display", "enc_class_code", "ed_note" - FROM covid_symptom__symptom_nlp + FROM covid_symptom__symptom_ctakes_negation GROUP BY cube( "author_week", @@ -285,7 +291,7 @@ CREATE TABLE covid_symptom__count_symptom_month AS ( "race_display", "enc_class_code", "ed_note" - FROM covid_symptom__symptom_nlp + FROM covid_symptom__symptom_ctakes_negation GROUP BY cube( "author_month", diff --git a/cumulus_library_covid/covid_symptom/table_dx.sql b/cumulus_library_covid/covid_symptom/table_dx.sql index 2505ade..4bcfa39 100644 --- a/cumulus_library_covid/covid_symptom/table_dx.sql +++ b/cumulus_library_covid/covid_symptom/table_dx.sql @@ -19,6 +19,7 @@ WITH define_dx AS ( SELECT DISTINCT c.subject_ref, c.encounter_ref, + s.status, c.code AS cond_code, -- noqa: LT01,RF02 c.recorded_week AS cond_week, c.recorded_month AS cond_month, diff --git a/cumulus_library_covid/covid_symptom/table_pcr.sql b/cumulus_library_covid/covid_symptom/table_pcr.sql index 613c4db..c05d296 100644 --- a/cumulus_library_covid/covid_symptom/table_pcr.sql +++ b/cumulus_library_covid/covid_symptom/table_pcr.sql @@ -28,6 +28,7 @@ SELECT DISTINCT o.lab_date AS covid_pcr_date, o.lab_week AS covid_pcr_week, o.lab_month AS covid_pcr_month, + s.status, s.variant_era, s.author_date, s.author_week, diff --git a/cumulus_library_covid/covid_symptom/table_prevalence_ed.sql b/cumulus_library_covid/covid_symptom/table_prevalence_ed.sql index 53d04d4..ac70068 100644 --- a/cumulus_library_covid/covid_symptom/table_prevalence_ed.sql +++ b/cumulus_library_covid/covid_symptom/table_prevalence_ed.sql @@ -1,5 +1,5 @@ CREATE TABLE covid_symptom__prevalence_ed AS -WITH from_period AS ( +WITH study_period AS ( SELECT DISTINCT encounter_ref, subject_ref, @@ -10,13 +10,15 @@ WITH from_period AS ( age_at_visit, age_group, variant_era, - enc_class_display + enc_class_display, + status FROM covid_symptom__study_period WHERE ed_note ), join_2020 AS ( SELECT DISTINCT + p.status, p.author_week, p.author_month, p.gender, @@ -31,12 +33,13 @@ join_2020 AS ( COALESCE(dx.cond_code, 'None') AS covid_icd10, (dx.cond_code IS NOT NULL OR pcr.covid_pcr_result_display = 'POSITIVE') AS covid_dx, - COALESCE(nlp.symptom_display, 'None') AS covid_symptom, + COALESCE(cn.symptom_display, 'None') AS covid_symptom, COALESCE(icd10.icd10_display, 'None') AS symptom_icd10_display - FROM from_period AS p + FROM study_period AS p LEFT JOIN covid_symptom__dx AS dx ON p.encounter_ref = dx.encounter_ref LEFT JOIN covid_symptom__pcr AS pcr ON p.encounter_ref = pcr.encounter_ref - LEFT JOIN covid_symptom__symptom_nlp AS nlp ON p.encounter_ref = nlp.encounter_ref + LEFT JOIN covid_symptom__symptom_ctakes_negation AS cn + ON p.encounter_ref = cn.encounter_ref LEFT JOIN covid_symptom__symptom_icd10 AS icd10 ON p.encounter_ref = icd10.encounter_ref ) diff --git a/cumulus_library_covid/covid_symptom/table_study_period.sql b/cumulus_library_covid/covid_symptom/table_study_period.sql index 005368e..dc89efb 100644 --- a/cumulus_library_covid/covid_symptom/table_study_period.sql +++ b/cumulus_library_covid/covid_symptom/table_study_period.sql @@ -16,11 +16,13 @@ SELECT DISTINCT s.encounter_ref, s.doc_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 + a.age_group, + s.status FROM core__study_period AS s, covid_symptom__define_period AS v, covid_symptom__define_age AS a diff --git a/cumulus_library_covid/covid_symptom/table_symptom.sql b/cumulus_library_covid/covid_symptom/table_symptom.sql index 59a8c80..9d445cc 100644 --- a/cumulus_library_covid/covid_symptom/table_symptom.sql +++ b/cumulus_library_covid/covid_symptom/table_symptom.sql @@ -17,7 +17,7 @@ -- ############################################################################ -CREATE TABLE covid_symptom__symptom_nlp AS +CREATE TABLE covid_symptom__symptom_ctakes_negation AS WITH mention AS ( SELECT t.concept, @@ -51,7 +51,8 @@ SELECT DISTINCT s.gender, s.race_display, s.enc_class_display, - s.ed_note + s.ed_note, + s.status FROM mention AS m, covid_symptom__define_symptom_cui AS def, covid_symptom__study_period AS s