Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FHIR ValueSet(s) should enable wider support for CDC Pilot sites to use other codes for PCR tests, results, etc. #12

Merged
merged 36 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ab6a377
COVID Diagnosis
comorbidity Jun 15, 2023
77c168a
COVID Diagnosis
comorbidity Jun 15, 2023
f8be1a8
COVID PCR test LOINC test codes
comorbidity Jun 15, 2023
4de56eb
Valusets for lab results POSITIVE or NEGATIVE.
comorbidity Jun 15, 2023
e399472
covid_define.sql Diagnosis (DX) defers to covid_symptom__define_dx us…
comorbidity Jun 15, 2023
67e9332
removed any mention of Influenza, potentially confusing/distracting t…
comorbidity Jun 15, 2023
f7b8a7c
BCH specific age is pediatric, other CDC pilot sites are general popu…
comorbidity Jun 15, 2023
d159def
define PCR tests and results are now externalized to
comorbidity Jun 15, 2023
8351ad5
removed covid_symptom__define_pcr_result
comorbidity Jun 15, 2023
5c30a66
simplified covid_symptom__define_symptom_cui to
comorbidity Jun 15, 2023
41fd82e
renamed : removed superfluous study prefix from filenaames, already i…
comorbidity Jun 15, 2023
b099ead
covid_define.sql was deleted, partitioned into individual SQL files
comorbidity Jun 15, 2023
93add8e
covid_symptom__site_pcr is now found in
comorbidity Jun 15, 2023
f766958
renamed covid_define.py to typesystem.py
comorbidity Jun 15, 2023
dd8065a
renamed covid_define_symptom.*
comorbidity Jun 15, 2023
1f1ae39
site_define.sql is now deprecated, see instead each "define_***.sql" …
comorbidity Jun 15, 2023
f8382c5
count tables are not generated dynamically.
comorbidity Jun 15, 2023
0d6d38f
covid counts now generated dynamically.
comorbidity Jun 15, 2023
cc391df
updated manifest.toml to include new "define" SQL.
comorbidity Jun 20, 2023
76a8e5d
changed default to GENERAL population, not BCH specific pediatric
comorbidity Jun 21, 2023
fcfe88c
comments only to reference ISSUES open as TODO
comorbidity Jun 21, 2023
96205f8
fixed missing comma ","
comorbidity Jun 21, 2023
0e6ea8b
manifest.toml restored define_study_period.sql
comorbidity Jun 21, 2023
5714a43
removed 2016 retroactive period.
comorbidity Jun 21, 2023
0ad2470
renamed covid_symptom__symptom_nlp
comorbidity Jun 21, 2023
051fff3
towards better support of PCR tests and results in different coding s…
comorbidity Jun 21, 2023
440bf05
renamed covid_symptom__define_dx_icd10
comorbidity Jun 21, 2023
a79902d
define_ed_note.sql removed "ED Social Work" note type, only ED Note t…
comorbidity Jun 21, 2023
20639fe
"Observation Interpretation"
comorbidity Jun 21, 2023
0076b23
SNOMED or ICD10 can be used to build DX table_dx.sql
comorbidity Jun 21, 2023
946b131
COVID study period can optionally be extended to before COVID
comorbidity Jun 21, 2023
52df3a4
MILESTONE: manifest.toml updated and "tested" by executing each SQL o…
comorbidity Jun 21, 2023
269af83
define_ed_note.sql
comorbidity Jun 26, 2023
feaa29d
table_dx.sql
comorbidity Jun 26, 2023
299237f
fixed minor issues in counts.py --> counts.sql
comorbidity Jun 29, 2023
aadcccc
removed start_year counts query
comorbidity Jun 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions cumulus_library_covid/covid_symptom/count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
from typing import List
from cumulus_library.schema import counts

def table(tablename: str, duration=None, study_prefix='covid_symptom') -> str:
if duration:
return f'{study_prefix}__{tablename}_{duration}'
else:
return f'{study_prefix}__{tablename}'

def count_dx(duration='week'):
"""
covid_symptom__count_dx_week
covid_symptom__count_dx_month
"""
view_name = table('count_dx', duration)
from_table = table('dx')
cols = [f'cond_{duration}',
'enc_class_code',
'age_at_visit',
'ed_note',
'variant_era']
return counts.count_encounter(view_name, from_table, cols)

def count_pcr(duration='week'):
"""
covid_symptom__count_pcr_week
covid_symptom__count_pcr_month
"""
view_name = table('count_pcr', duration)
from_table = table('pcr')
cols = [f'covid_pcr_{duration}',
'covid_pcr_result_display',
'variant_era',
'ed_note',
'age_at_visit',
'gender',
'race_display']
return counts.count_encounter(view_name, from_table, cols)

def count_study_period(duration='month'):
"""
covid_symptom__count_study_period_week
covid_symptom__count_study_period_month
covid_symptom__count_study_period_year
"""
view_name = table('count_study_period', duration)
from_table = table('study_period')
cols = [f'start_{duration}',
'variant_era', 'start_month', 'ed_note',
'gender', 'age_group', 'race_display']
return counts.count_encounter(view_name, from_table, cols)

def count_prevalence_ed(duration='month'):
view_name = table('count_prevalence_ed', duration)
from_table = table('prevalence_ed')
cols = [
'covid_dx',
'covid_icd10',
'covid_pcr_result',
'covid_symptom',
'symptom_icd10_display',
'variant_era',
'author_month',
'age_group']
return counts.count_encounter(view_name, from_table, cols)

def count_symptom(duration='week'):
"""
covid_symptom__count_symptom_week
covid_symptom__count_symptom_month
"""
view_name = table('count_symptom', duration)
from_table = table('symptom')
cols = ['symptom_display',
'variant_era',
'author_week',
'age_group',
'gender',
'race_display',
'enc_class_code',
'ed_note']
return counts.count_encounter(view_name, from_table, cols)

def concat_view_sql(create_view_list: List[str]) -> str:
"""
:param create_view_list: SQL prepared statements
:param filename: path to output file, default 'count.sql' in PWD
"""
seperator = '-- ###########################################################'
concat = list()

for create_view in create_view_list:
concat.append(seperator + create_view + '\n')

return '\n'.join(concat)

def write_view_sql(view_list_sql: List[str], filename='count.sql') -> None:
"""
:param view_list_sql: SQL prepared statements
:param filename: path to output file, default 'count.sql' in PWD
"""
with open(filename, 'w') as fout:
fout.write(concat_view_sql(view_list_sql))


if __name__ == '__main__':

write_view_sql([
count_dx('week'),
count_dx('month'),
count_pcr('week'),
count_pcr('month'),
count_study_period('week'),
count_study_period('month'),
count_study_period('year')])
139 changes: 139 additions & 0 deletions cumulus_library_covid/covid_symptom/count.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
-- ####################################
CREATE or replace VIEW covid_symptom__count_dx_week AS
with powerset as
(
select
count(distinct subject_ref) as cnt_subject
, count(distinct encounter_ref) as cnt_encounter
, cond_week, enc_class_code, age_at_visit, ed_note, variant_era
FROM covid_symptom__dx
group by CUBE
( cond_week, enc_class_code, age_at_visit, ed_note, variant_era )
)
select
cnt_encounter as cnt
, cond_week, enc_class_code, age_at_visit, ed_note, variant_era
from powerset
WHERE cnt_subject >= 10
ORDER BY cnt desc;


-- ####################################
CREATE or replace VIEW covid_symptom__count_dx_month AS
with powerset as
(
select
count(distinct subject_ref) as cnt_subject
, count(distinct encounter_ref) as cnt_encounter
, cond_month, enc_class_code, age_at_visit, ed_note, variant_era
dogversioning marked this conversation as resolved.
Show resolved Hide resolved
FROM covid_symptom__dx
group by CUBE
( cond_month, enc_class_code, age_at_visit, ed_note, variant_era )
)
select
cnt_encounter as cnt
, cond_month, enc_class_code, age_at_visit, ed_note, variant_era
from powerset
WHERE cnt_subject >= 10
ORDER BY cnt desc;


-- ####################################
CREATE or replace VIEW covid_symptom__count_pcr_week AS
with powerset as
(
select
count(distinct subject_ref) as cnt_subject
, count(distinct encounter_ref) as cnt_encounter
, covid_pcr_week, covid_pcr_result_display, variant_era, ed_note, age_at_visit, gender, race_display
FROM covid_symptom__pcr
group by CUBE
( covid_pcr_week, covid_pcr_result_display, variant_era, ed_note, age_at_visit, gender, race_display )
)
select
cnt_encounter as cnt
, covid_pcr_week, covid_pcr_result_display, variant_era, ed_note, age_at_visit, gender, race_display
from powerset
WHERE cnt_subject >= 10
ORDER BY cnt desc;


-- ####################################
CREATE or replace VIEW covid_symptom__count_pcr_month AS
with powerset as
(
select
count(distinct subject_ref) as cnt_subject
, count(distinct encounter_ref) as cnt_encounter
, covid_pcr_month, covid_pcr_result_display, variant_era, ed_note, age_at_visit, gender, race_display
FROM covid_symptom__pcr
group by CUBE
( covid_pcr_month, covid_pcr_result_display, variant_era, ed_note, age_at_visit, gender, race_display )
)
select
cnt_encounter as cnt
, covid_pcr_month, covid_pcr_result_display, variant_era, ed_note, age_at_visit, gender, race_display
from powerset
WHERE cnt_subject >= 10
ORDER BY cnt desc;


-- ####################################
CREATE or replace VIEW covid_symptom__count_study_period_week AS
dogversioning marked this conversation as resolved.
Show resolved Hide resolved
with powerset as
(
select
count(distinct subject_ref) as cnt_subject
, count(distinct encounter_ref) as cnt_encounter
, start_week, variant_era, start_month, ed_note, gender, age_group, race_display
FROM covid_symptom__study_period
group by CUBE
( start_week, variant_era, start_month, ed_note, gender, age_group, race_display )
)
select
cnt_encounter as cnt
, start_week, variant_era, start_month, ed_note, gender, age_group, race_display
from powerset
WHERE cnt_subject >= 10
ORDER BY cnt desc;


-- ####################################
CREATE or replace VIEW covid_symptom__count_study_period_month AS
with powerset as
(
select
count(distinct subject_ref) as cnt_subject
, count(distinct encounter_ref) as cnt_encounter
, start_month, variant_era, start_month, ed_note, gender, age_group, race_display
FROM covid_symptom__study_period
group by CUBE
( start_month, variant_era, start_month, ed_note, gender, age_group, race_display )
)
select
cnt_encounter as cnt
, start_month, variant_era, start_month, ed_note, gender, age_group, race_display
from powerset
WHERE cnt_subject >= 10
ORDER BY cnt desc;


-- ####################################
CREATE or replace VIEW covid_symptom__count_study_period_year AS
with powerset as
(
select
count(distinct subject_ref) as cnt_subject
, count(distinct encounter_ref) as cnt_encounter
, start_year, variant_era, start_month, ed_note, gender, age_group, race_display
FROM covid_symptom__study_period
group by CUBE
( start_year, variant_era, start_month, ed_note, gender, age_group, race_display )
)
select
cnt_encounter as cnt
, start_year, variant_era, start_month, ed_note, gender, age_group, race_display
from powerset
WHERE cnt_subject >= 10
ORDER BY cnt desc;

19 changes: 0 additions & 19 deletions cumulus_library_covid/covid_symptom/count_covid.py

This file was deleted.

50 changes: 0 additions & 50 deletions cumulus_library_covid/covid_symptom/count_covid_dx.sql

This file was deleted.

Loading