Skip to content

Commit

Permalink
Adds status to study tables (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogversioning authored Oct 23, 2023
1 parent df9edea commit 659aa62
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cumulus_library_covid/covid_symptom/counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ CREATE TABLE covid_symptom__count_dx_month AS (
"ed_note",
"variant_era"
FROM powerset
WHERE
WHERE
cnt_subject >= 10

);

-- ###########################################################
Expand Down Expand Up @@ -64,8 +65,9 @@ CREATE TABLE covid_symptom__count_dx_week AS (
"ed_note",
"variant_era"
FROM powerset
WHERE
WHERE
cnt_subject >= 10

);

-- ###########################################################
Expand Down Expand Up @@ -105,8 +107,9 @@ CREATE TABLE covid_symptom__count_pcr_month AS (
"gender",
"race_display"
FROM powerset
WHERE
WHERE
cnt_subject >= 10

);

-- ###########################################################
Expand Down Expand Up @@ -146,8 +149,9 @@ CREATE TABLE covid_symptom__count_pcr_week AS (
"gender",
"race_display"
FROM powerset
WHERE
WHERE
cnt_subject >= 10

);

-- ###########################################################
Expand Down Expand Up @@ -184,8 +188,9 @@ CREATE TABLE covid_symptom__count_study_period_month AS (
"age_group",
"race_display"
FROM powerset
WHERE
WHERE
cnt_subject >= 10

);

-- ###########################################################
Expand Down Expand Up @@ -222,8 +227,9 @@ CREATE TABLE covid_symptom__count_study_period_week AS (
"age_group",
"race_display"
FROM powerset
WHERE
WHERE
cnt_subject >= 10

);

-- ###########################################################
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions cumulus_library_covid/covid_symptom/table_dx.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions cumulus_library_covid/covid_symptom/table_pcr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 8 additions & 5 deletions cumulus_library_covid/covid_symptom/table_prevalence_ed.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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
)
Expand Down
4 changes: 3 additions & 1 deletion cumulus_library_covid/covid_symptom/table_study_period.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions cumulus_library_covid/covid_symptom/table_symptom.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 659aa62

Please sign in to comment.