diff --git a/.RData b/.RData index e4cf3e3..16a40f4 100644 Binary files a/.RData and b/.RData differ diff --git a/analysis/additional_comorbidities.py b/analysis/additional_comorbidities.py new file mode 100644 index 0000000..4fd61cb --- /dev/null +++ b/analysis/additional_comorbidities.py @@ -0,0 +1,328 @@ +import json, sys +from pathlib import Path + +from datetime import date, datetime +from ehrql import Dataset, case, when, maximum_of, minimum_of, years, days +from ehrql.tables.tpp import ( + patients, + medications, + ons_deaths, + addresses, + clinical_events, + practice_registrations, + household_memberships_2020, + vaccinations, + apcs, + emergency_care_attendances +) + +from variable_lib import ( + has_a_continuous_practice_registration_spanning, + most_recent_bmi, + practice_registration_as_of, + emergency_care_diagnosis_matches, + hospitalisation_diagnosis_matches +) + +import codelists + +dataset = Dataset() + +####################################################################################### +# Import study dates defined in "./analysis/design/study-dates.R" script and then exported +# to JSON +####################################################################################### +study_dates = json.loads( + Path("analysis/design/study-dates.json").read_text(), +) + +args = sys.argv + +#define dataset definition settings from command line arguments +cohort = args[1] +codelist_type = args[4] +investigation_type = args[5] + +# Change these in ./analysis/design/study-dates.R if necessary +study_start_date = study_dates[args[2]] +study_end_date = study_dates[args[3]] +index_date = study_start_date +registration_date = index_date - years(1) + +#define patients age +age_at_start = patients.age_on(study_start_date) +age_at_end = patients.age_on(study_end_date) +age_months = (index_date - patients.date_of_birth).months +age_at_start_months = (study_start_date - patients.date_of_birth).months + +#events occurring before index date +prior_events = clinical_events.where(clinical_events.date.is_on_or_before(index_date)) + +#query prior_events for existence of event-in-codelist +def has_prior_event(codelist, where = True): + return ( + prior_events.where(where) + .where(prior_events.snomedct_code.is_in(codelist)) + .exists_for_patient() + ) + +#query prior_events for date of most recent event-in-codelist +def last_prior_event(codelist, where = True): + return ( + prior_events.where(where) + .where(prior_events.snomedct_code.is_in(codelist)) + .sort_by(clinical_events.date) + .last_for_patient() + ) + +#query prior_events for date of earliest event-in-codelist +def first_prior_event(codelist, where = True): + return ( + prior_events.where(where) + .where(prior_events.snomedct_code.is_in(codelist)) + .sort_by(clinical_events.date) + .first_for_patient() + ) + +#meds occurring before booster date +prior_meds = medications.where(medications.date.is_on_or_before(index_date)) + +#query prior_meds for existence of event-in-codelist +def has_prior_meds(codelist, where = True): + return ( + prior_meds.where(where) + .where(prior_meds.dmd_code.is_in(codelist)) + .exists_for_patient() + ) + +#query prior meds for date of most recent med-in-codelist +def last_prior_meds(codelist, where = True): + return ( + prior_meds.where(where) + .where(prior_meds.dmd_code.is_in(codelist)) + .sort_by(medications.date) + .last_for_patient() + ) + +#query prior_events for date of earliest event-in-codelist +def first_prior_meds(codelist, where = True): + return ( + prior_meds.where(where) + .where(prior_meds.dmd_code.is_in(codelist)) + .sort_by(medications.date) + .first_for_patient() + ) + +##comorbidities for secondary investigation + +def filter_codes_by_category(codelist, include): + return {k:v for k,v in codelist.items() if v in include} + +#lifestyle + + +#smoking + +############################################################################### +# from https://github.com/opensafely/early-inflammatory-arthritis/blob/069e61712fcc9a0c2ec2804ff36a9b773073291c/analysis/dataset_definition.py#L136 +############################################################################### + +most_recent_smoking_code = ( + (clinical_events.where(clinical_events.ctv3_code + .is_in(codelists.clear_smoking_codes)) + .sort_by(clinical_events.date).last_for_patient() + .ctv3_code.to_category(codelists.clear_smoking_codes)) +) +ever_smoked = ( + clinical_events.where(clinical_events.ctv3_code + .is_in(filter_codes_by_category(codelists + .clear_smoking_codes, include = ["S", "E"]))) + .exists_for_patient() +) +smoking_status = (case( + when(most_recent_smoking_code == "S").then("S"), + when((most_recent_smoking_code == "E") + | ((most_recent_smoking_code == "N") + & (ever_smoked == True))).then("E"), + when((most_recent_smoking_code == "N") + & (ever_smoked == False)).then("N"), + otherwise = "M") +) + +#drinking +hazardous_drinking = has_prior_event(codelists.drinking_codelist) + +#drug usage +drug_usage = ( + (has_prior_event(codelists.drug_usage_codelist + + codelists.drug_intervention_codelist + + codelists.drug_assessment_declination_codelist)) +) + +#medication date +medication_date = index_date - years(1) + +#reactive airway disease diagnosis +has_reactive_airway = has_prior_event(codelists.reactive_airway_disease_code) + +#has asthma if there is an asthma diagnosis and a recent medication prescribed +has_asthma = ( + (has_prior_event(codelists.asthma_codelist)) + & (has_prior_meds(codelists.asthma_oral_medications, + where = medications.date.is_on_or_between(medication_date, index_date)) + |(has_prior_meds(codelists.asthma_inhaled_medications))) +) + +#copd diagnosis +has_copd = ( + (has_prior_event(codelists.copd_codelist)) + & (has_prior_meds(codelists.copd_medications)) + & (last_prior_event(codelists.copd_codelist).date + .is_on_or_after(last_prior_event(codelists + .copd_resolved_codelist).date)) +) + +#pulmonary fibrosis diagnosis +has_pulmonary_fibrosis = ( + has_prior_event(codelists + .pulmonary_fibrosis_codelist) +) + +#cystic fibrosis diagnosis +has_cystic_fibrosis = ( + clinical_events.where(clinical_events.ctv3_code. + is_in(codelists.cystic_fibrosis_codelist)) + .exists_for_patient() +) + +#diabetes diagnosis +diab_date = last_prior_event(codelists.diabetes_codelist).date +dmres_date = last_prior_event(codelists.diabetes_resolved_codelist).date +has_diabetes = (case( + when(dmres_date < diab_date).then(True), + when(diab_date.is_not_null() & dmres_date.is_null()) + .then(True), otherwise = False) +) + +#addison's disease diagnosis +has_addisons = ( + clinical_events.where(clinical_events.snomedct_code + .is_in(codelists.addisons_codelist)) + .where(clinical_events.date.is_on_or_before(index_date)) + .exists_for_patient() +) + +#Calculate BMI + +############################################################################### +# from https://github.com/opensafely/comparative-booster-spring2023/blob/main/analysis/dataset_definition.py +############################################################################### + +# BMI +bmi_measurement = most_recent_bmi( + where = clinical_events.date.is_after(index_date - years(5)), + minimum_age_at_measurement = 16, +) +bmi_value = bmi_measurement.numeric_value +bmi = case( + when(bmi_value < 30).then("Not obese"), # include this here to ensure this value is the 1st level in the factor + when((bmi_value >= 30.0) & (bmi_value < 35.0)).then("Obese I (30-34.9)"), + when((bmi_value >= 35.0) & (bmi_value < 40.0)).then("Obese II (35-39.9)"), + # Set maximum to avoid any impossibly extreme values being classified as obese + when((bmi_value >= 40.0) & (bmi_value < 100.0)).then("Obese III (40+)"), + otherwise = "Not obese", # assume missing is non-obese +) + +# Severe Obesity +bmi_stage_event = last_prior_event(codelists.bmi_stage_codelist) +sev_obesity_event = last_prior_event( + codelists.severe_obesity_codelist, + where = ((clinical_events.date >= bmi_stage_event.date) + & (clinical_events.numeric_value != 0.0)), +) +bmi_event = last_prior_event(codelists.bmi_codelist, + where = (clinical_events.numeric_value != 0.0)) +severe_obesity = case( + when(sev_obesity_event.date > bmi_event.date).then(True), + when(bmi_event.numeric_value >= 40.0).then(True), + otherwise = False +) + +#Chronic Heart Disease +has_chd = has_prior_event(codelists.chd_codelist) + +#Chronic Kidney Disease + +############################################################################### +# from https://github.com/opensafely/comparative-booster-spring2023/blob/main/analysis/dataset_definition.py +############################################################################### + +#chronic kidney disease diagnostic codes +ckd = has_prior_event(codelists.ckd_codelist) +#chronic kidney disease codes - all stages +ckd15_date = last_prior_event(codelists.ckd15_codelist).date +#chronic kidney disease codes-stages 3 - 5 +ckd35_date = last_prior_event(codelists.ckd35_codelist).date +has_ckd = case( + when(ckd).then(True), + when((ckd35_date >= ckd15_date)).then(True), + otherwise = False +) + +#Chronic Liver Disease +has_cld = has_prior_event(codelists.cld_codelist) + +#Chronic Neurological Disease including Significant Learning Disorder +has_cnd = has_prior_event(codelists.cnd_codelist) + +#Chronic Respiratory Disease +has_crd = has_prior_event(codelists.crd_codelist) + +#Cancer within 3 years +has_cancer = ( + has_prior_event(codelists.cancer_codelist + + codelists.haemotalogical_cancer_codelist + + codelists.lung_cancer_codelist, + where = clinical_events.date.is_after(index_date - years(3))) +) + +#Immunosuppression + +############################################################################### +# from https://github.com/opensafely/comparative-booster-spring2023/blob/main/analysis/dataset_definition.py +############################################################################### + +#Immunosuppression diagnosis +immdx = has_prior_event(codelists.immunosuppression_diagnosis_codelist) + +#Immunosuppression medication +immrx = has_prior_meds( + codelists.immunosuppression_medications_codelist, + where = (medications.date.is_on_or_after(index_date - years(3))) +) + +#Immunosuppression admin date +immadm = has_prior_event( + codelists.immunosuppression_admin_codelist, + where = (clinical_events.date + .is_on_or_after(index_date - years(3))) +) + +#Chemotherapy medication date +dxt_chemo = has_prior_event( + codelists.chemo_codelist, + where = (clinical_events.date + .is_on_or_after(index_date - years(3))) +) + +#Immunosuppression group +immunosuppressed = immdx | immrx | immadm | dxt_chemo + +#Sickle Cell Disease +has_sickle_cell = has_prior_event(codelists.sickle_cell_codelist) + +#Heart Failure +has_heart_failure = has_prior_event(codelists.heart_failure_codelist) + +#Prior MI +has_prior_mi = has_prior_event(codelists.prior_mi_codelist) diff --git a/analysis/codelists.py b/analysis/codelists.py index 77d40b6..51b6e33 100644 --- a/analysis/codelists.py +++ b/analysis/codelists.py @@ -61,30 +61,6 @@ column = "code", ) -# covid primary - specific -covid_primary_codelist = codelist_from_csv( - "codelists/user-emprestige-covid-19-identification-primary-care.csv", - column = "code", -) - -# covid secondary - specific -covid_secondary_codelist = codelist_from_csv( - "codelists/opensafely-covid-identification.csv", - column = "icd10_code", -) - -# flu primary - specific -flu_primary_codelist = codelist_from_csv( - "codelists/user-emprestige-influenza-identification-primary-care.csv", - column = "code", -) - -# flu secondary - specific -flu_secondary_codelist = codelist_from_csv( - "codelists/user-emprestige-influenza-identification-secondary-care.csv", - column = "code", -) - # rsv primary - sensitive rsv_sensitive_codelist = codelist_from_csv( "codelists/user-emprestige-rsv-identification-primary-care-maximal-sensitivity.csv", @@ -115,27 +91,15 @@ column = "code", ) -# covid primary - sensitive -covid_sensitive_codelist = codelist_from_csv( - "codelists/user-emprestige-covid-19-identification-primary-care-maximal-sensitivity.csv", - column = "code", -) - -# covid primary - sensitive (prescriptions) -covid_prescriptions_codelist = codelist_from_csv( - "codelists/user-emprestige-covid-19-identification-prescriptions-dmd.csv", - column = "dmd_id", -) - -# covid primary exclusion -covid_primary_exclusion_codelist = codelist_from_csv( - "codelists/user-emprestige-covid-19-exclusion-primary-care-maximal-sensitivity.csv", +# flu primary - specific +flu_primary_codelist = codelist_from_csv( + "codelists/user-emprestige-influenza-identification-primary-care.csv", column = "code", ) -# covid secondary exclusion -covid_secondary_exclusion_codelist = codelist_from_csv( - "codelists/user-emprestige-covid-19-exclusion-secondary-care-maximal-sensitivity.csv", +# flu secondary - specific +flu_secondary_codelist = codelist_from_csv( + "codelists/user-emprestige-influenza-identification-secondary-care.csv", column = "code", ) @@ -187,12 +151,60 @@ column = "code", ) +# covid primary - specific +covid_primary_codelist = codelist_from_csv( + "codelists/user-emprestige-covid-19-identification-primary-care.csv", + column = "code", +) + +# covid secondary - specific +covid_secondary_codelist = codelist_from_csv( + "codelists/opensafely-covid-identification.csv", + column = "icd10_code", +) + +# covid primary - sensitive +covid_sensitive_codelist = codelist_from_csv( + "codelists/user-emprestige-covid-19-identification-primary-care-maximal-sensitivity.csv", + column = "code", +) + +# covid primary - sensitive (prescriptions) +covid_prescriptions_codelist = codelist_from_csv( + "codelists/user-emprestige-covid-19-identification-prescriptions-dmd.csv", + column = "dmd_id", +) + +# covid primary exclusion +covid_primary_exclusion_codelist = codelist_from_csv( + "codelists/user-emprestige-covid-19-exclusion-primary-care-maximal-sensitivity.csv", + column = "code", +) + +# covid secondary exclusion +covid_secondary_exclusion_codelist = codelist_from_csv( + "codelists/user-emprestige-covid-19-exclusion-secondary-care-maximal-sensitivity.csv", + column = "code", +) + # unspecified respiratory virus primary respiratory_virus_primary_codelist = codelist_from_csv( "codelists/user-emprestige-respiratory-virus-unspecified-identification-primary-care.csv", column = "code", ) +#copd exacerbation primary +copd_exacerbation_primary_codelist = codelist_from_csv( + "codelists/bristol-copd-exacerbations-snomed.csv", + column = "code", +) + +#asthma exacerbation primary +asthma_exacerbation_primary_codelist = codelist_from_csv( + "codelists/bristol-asthma_exacerbations_snomed.csv", + column = "code", +) + # respiratory tract infection emergency attendances rtri_attendance = ["50417007", "54150009"] @@ -211,6 +223,18 @@ column = "code", ) +#copd exacerbation secondary +copd_exacerbation_secondary_codelist = codelist_from_csv( + "codelists/opensafely-copd-exacerbation.csv", + column = "code", +) + +#asthma exacerbation secondary +asthma_exacerbation_secondary_codelist = codelist_from_csv( + "codelists/opensafely-copd-exacerbation.csv", + column = "code", +) + # unspecified respiratory virus exclusion secondary respiratory_virus_secondary_exclusion_codelist = codelist_from_csv( "codelists/user-emprestige-respiratory-virus-unspecified-exclusion-secondary-care.csv", @@ -313,7 +337,7 @@ ) # addisons -addisions_codelist = codelist_from_csv( +addisons_codelist = codelist_from_csv( "codelists/primis-covid19-vacc-uptake-addis_cod.csv", column = "code", ) @@ -391,10 +415,6 @@ "codelists/opensafely-lung-cancer-snomed.csv", column = "id", ) -chemo_codelist = codelist_from_csv( - "codelists/primis-covid19-vacc-uptake-dxt_chemo_cod.csv", - column = "code", -) # immunosuppresion immunosuppression_diagnosis_codelist = codelist_from_csv( @@ -409,6 +429,10 @@ "codelists/primis-covid19-vacc-uptake-immunosuppression-admin-codes.csv", column = "code", ) +chemo_codelist = codelist_from_csv( + "codelists/primis-covid19-vacc-uptake-dxt_chemo_cod.csv", + column = "code", +) # sickle cell disease sickle_cell_codelist = codelist_from_csv( diff --git a/analysis/data_processing.R b/analysis/data_processing.R index b28aef8..acb60bb 100644 --- a/analysis/data_processing.R +++ b/analysis/data_processing.R @@ -14,10 +14,13 @@ args <- commandArgs(trailingOnly = TRUE) study_start_date <- study_dates[[args[[2]]]] study_end_date <- study_dates[[args[[3]]]] cohort <- args[[1]] +codelist_type <- args[[4]] +investigation_type <- args[[5]] df_input <- read_feather( here::here("output", paste0("input_", cohort, "_", year(study_start_date), - "_", year(study_end_date), ".arrow"))) + "_", year(study_end_date), "_", codelist_type, "_", + investigation_type,".arrow"))) #assign ethnicity group df_input <- df_input %>% @@ -86,40 +89,22 @@ df_input$end_time_severe <- study_end_date #calculate follow-up end date for mild outcomes df_input <- df_input %>% rowwise() %>% - mutate(end_time_mild = if (study_start_date >= covid_season_min) { - if (rsv_primary == TRUE) { - rsv_primary_date - } else if (covid_primary == TRUE) { - covid_primary_date - } else if (flu_primary == TRUE) { - flu_primary_date - } else {study_end_date} - } else { - if (rsv_primary == TRUE) { - rsv_primary_date - } else if (flu_primary == TRUE) { - flu_primary_date - } else {study_end_date}} - ) + mutate(end_time_mild = case_when( + study_start_date >= covid_season_min & covid_primary ~ covid_primary_date, + rsv_primary ~ rsv_primary_date, + flu_primary ~ flu_primary_date, + TRUE ~ study_end_date + )) #calculate follow-up end date for severe outcomes df_input <- df_input %>% rowwise() %>% - mutate(end_time_severe = if (study_start_date >= covid_season_min) { - if (rsv_secondary == TRUE) { - rsv_secondary_date - } else if (covid_secondary == TRUE) { - covid_secondary_date - } else if (flu_secondary == TRUE) { - flu_secondary_date - } else {study_end_date} - } else { - if (rsv_secondary == TRUE) { - rsv_secondary_date - } else if (flu_secondary == TRUE) { - flu_secondary_date - } else {study_end_date}} - ) + mutate(end_time_severe = case_when( + study_start_date >= covid_season_min & covid_secondary ~ covid_secondary_date, + rsv_secondary ~ rsv_secondary_date, + flu_secondary ~ flu_secondary_date, + TRUE ~ study_end_date + )) #calculate survival time for both outcomes (in weeks) df_input$time_mild <- difftime(df_input$end_time_mild, study_start_date, df_input, "weeks") @@ -128,4 +113,5 @@ df_input$time_severe <- difftime(df_input$end_time_severe, study_start_date, df_ #write the new input file write_feather(df_input, here::here("output", paste0("input_processed_", cohort, "_", year(study_start_date), - "_", year(study_end_date), ".arrow"))) + "_", year(study_end_date), "_", codelist_type, + "_", investigation_type, ".arrow"))) diff --git a/analysis/dataset_definition.py b/analysis/dataset_definition.py index 441e215..f5d16ed 100644 --- a/analysis/dataset_definition.py +++ b/analysis/dataset_definition.py @@ -75,14 +75,104 @@ ) has_imd = (addresses.for_patient_on(index_date).imd_rounded.is_not_null()) +##define functions for queries + +#events occurring before index date +prior_events = clinical_events.where(clinical_events.date.is_on_or_before(index_date)) + +#query prior_events for existence of event-in-codelist +def has_prior_event(codelist, where = True): + return ( + prior_events.where(where) + .where(prior_events.snomedct_code.is_in(codelist)) + .exists_for_patient() + ) + +#query prior_events for date of most recent event-in-codelist +def last_prior_event(codelist, where = True): + return ( + prior_events.where(where) + .where(prior_events.snomedct_code.is_in(codelist)) + .sort_by(events.date) + .last_for_patient() + ) + +#query prior_events for date of earliest event-in-codelist +def first_prior_event(codelist, where = True): + return ( + prior_events.where(where) + .where(prior_events.snomedct_code.is_in(codelist)) + .sort_by(events.date) + .first_for_patient() + ) + +#meds occurring before booster date +prior_meds = medications.where(medications.date.is_on_or_before(index_date)) + +#query prior_meds for existence of event-in-codelist +def has_prior_meds(codelist, where = True): + return ( + prior_meds.where(where) + .where(prior_meds.dmd_code.is_in(codelist)) + .exists_for_patient() + ) + +#query prior meds for date of most recent med-in-codelist +def last_prior_meds(codelist, where = True): + return ( + prior_meds.where(where) + .where(prior_meds.dmd_code.is_in(codelist)) + .sort_by(medications.date) + .last_for_patient() + ) + +#query prior_events for date of earliest event-in-codelist +def first_prior_meds(codelist, where = True): + return ( + prior_meds.where(where) + .where(prior_meds.dmd_code.is_in(codelist)) + .sort_by(medications.date) + .first_for_patient() + ) + +#infections occuring after index date but before study end date +infection_events = clinical_events.where(clinical_events.date.is_on_or_between(index_date, study_end_date)) + +#query infection_events for existence of event-in-codelist (get first of these) +def has_infection_event(codelist, where = True): + return ( + infection_events.where(where) + .where(infection_events.snomedct_code.is_in(codelist)) + .sort_by(clinical_events.date) + .first_for_patient() + .exists_for_patient() + ) + +#query infection_events for date of most recent event-in-codelist +def last_infection_event(codelist, where = True): + return ( + infection_events.where(where) + .where(infection_events.snomedct_code.is_in(codelist)) + .sort_by(clinical_events.date) + .last_for_patient() + ) + +#query infection_events for date of earliest event-in-codelist +def first_infection_event(codelist, where = True): + return ( + infection_events.where(where) + .where(infection_events.snomedct_code.is_in(codelist)) + .sort_by(clinical_events.date) + .first_for_patient() + ) + ##exclusion criteria #combined severe immunodeficiency syndrome if cohort == "infants" or cohort == "infants_subgroup" : severe_immunodeficiency = ( - clinical_events.where(clinical_events.snomedct_code - .is_in(codelists.severe_immunodeficiency_code)) - .exists_for_patient() + has_prior_event(codelists + .severe_immunodeficiency_code) ) #infant risk group (cardiac disease, pulmonary hypertension) @@ -155,7 +245,8 @@ #define latest ethnicity code for patient dataset.latest_ethnicity_code = ( - clinical_events.where(clinical_events.snomedct_code.is_in(codelists.ethnicity_codes)) + clinical_events.where(clinical_events + .snomedct_code.is_in(codelists.ethnicity_codes)) .where(clinical_events.date.is_on_or_before(index_date)) .sort_by(clinical_events.date) .last_for_patient() @@ -179,97 +270,6 @@ dataset.region = (practice_registrations.for_patient_on(index_date)).practice_nuts1_region_name dataset.stp = (practice_registrations.for_patient_on(index_date)).practice_stp -##define functions for queries - -#events occurring before index date -prior_events = clinical_events.where(clinical_events.date.is_on_or_before(index_date)) - -#query prior_events for existence of event-in-codelist -def has_prior_event(codelist, where = True): - return ( - prior_events.where(where) - .where(prior_events.snomedct_code.is_in(codelist)) - .exists_for_patient() - ) - -#query prior_events for date of most recent event-in-codelist -def last_prior_event(codelist, where = True): - return ( - prior_events.where(where) - .where(prior_events.snomedct_code.is_in(codelist)) - .sort_by(events.date) - .last_for_patient() - ) - -#query prior_events for date of earliest event-in-codelist -def first_prior_event(codelist, where = True): - return ( - prior_events.where(where) - .where(prior_events.snomedct_code.is_in(codelist)) - .sort_by(events.date) - .first_for_patient() - ) - -#meds occurring before booster date -prior_meds = medications.where(medications.date.is_on_or_before(index_date)) - -#query prior_meds for existence of event-in-codelist -def has_prior_meds(codelist, where = True): - return ( - prior_meds.where(where) - .where(prior_meds.dmd_code.is_in(codelist)) - .exists_for_patient() - ) - -#query prior meds for date of most recent med-in-codelist -def last_prior_meds(codelist, where = True): - return ( - prior_meds.where(where) - .where(prior_meds.dmd_code.is_in(codelist)) - .sort_by(medications.date) - .last_for_patient() - ) - -#query prior_events for date of earliest event-in-codelist -def first_prior_meds(codelist, where = True): - return ( - prior_meds.where(where) - .where(prior_meds.dmd_code.is_in(codelist)) - .sort_by(medications.date) - .first_for_patient() - ) - -#infections occuring after index date but before study end date -infection_events = clinical_events.where(clinical_events.date.is_on_or_between(index_date, study_end_date)) - -#query infection_events for existence of event-in-codelist (get first of these) -def has_infection_event(codelist, where = True): - return ( - infection_events.where(where) - .where(infection_events.snomedct_code.is_in(codelist)) - .sort_by(clinical_events.date) - .first_for_patient() - .exists_for_patient() - ) - -#query infection_events for date of most recent event-in-codelist -def last_infection_event(codelist, where = True): - return ( - infection_events.where(where) - .where(infection_events.snomedct_code.is_in(codelist)) - .sort_by(clinical_events.date) - .last_for_patient() - ) - -#query infection_events for date of earliest event-in-codelist -def first_infection_event(codelist, where = True): - return ( - infection_events.where(where) - .where(infection_events.snomedct_code.is_in(codelist)) - .sort_by(clinical_events.date) - .first_for_patient() - ) - ##comorbidities #define earliest vaccination date @@ -296,9 +296,9 @@ def first_infection_event(codelist, where = True): .count_for_patient() ) -##outcomes +##outcomes - rsv -#count number of clinical codes in sensitive codelist +#count number of clinical codes in RSV sensitive codelist rsv_code_number = ( (clinical_events.where(clinical_events .date.is_on_or_between(first_infection_event(codelists @@ -309,7 +309,7 @@ def first_infection_event(codelist, where = True): .snomedct_code.count_distinct_for_patient() ) -#first event that satisfies above condition +#date of first occurance of two of the above codes within 2 weeks rsv_codes_date = ( case(when(rsv_code_number > 1) .then(first_infection_event(codelists @@ -318,8 +318,11 @@ def first_infection_event(codelist, where = True): #occurance of event in exclusion list within one month of rsv_codes_date rsv_exclusion_primary = (case( - when(first_infection_event(codelists.rsv_primary_exclusion_codelist) + when((first_infection_event(codelists.rsv_primary_exclusion_codelist) .date.is_on_or_between(rsv_codes_date - days(30), rsv_codes_date + days(30))) + |(medications.where(medications.dmd_code + .is_in(codelists.rsv_prescriptions_codelist)).date.minimum_for_patient() + .is_on_or_between(rsv_codes_date - days(30), rsv_codes_date + days(30)))) .then(has_infection_event(codelists.rsv_primary_exclusion_codelist)) )) @@ -360,12 +363,12 @@ def first_infection_event(codelist, where = True): if codelist_type == "specific" : if cohort == "infants" or cohort == "infants_subgroup" : dataset.rsv_primary_date = ( - minimum_of((first_infection_event(codelists.rsv_primary_codelist).date), - (((emergency_care_attendances.where(emergency_care_attendances - .diagnosis_01.is_in(codelists.bronchiolitis_attendance))) - |(emergency_care_attendances.where(emergency_care_attendances - .diagnosis_02.is_in(codelists.bronchiolitis_attendance)))) - .arrival_date.minimum_for_patient())) + minimum_of(first_infection_event(codelists.rsv_primary_codelist).date, + (emergency_care_attendances.where((emergency_care_attendances + .diagnosis_01.is_in(codelists.bronchiolitis_attendance)) + |(emergency_care_attendances.diagnosis_02 + .is_in(codelists.bronchiolitis_attendance)))) + .arrival_date.minimum_for_patient()) ) else : dataset.rsv_primary_date = first_infection_event(codelists.rsv_primary_codelist).date @@ -421,8 +424,8 @@ def first_infection_event(codelist, where = True): ) if codelist_type == "sensitive" : dataset.rsv_secondary = ( - hospitalisation_diagnosis_matches(codelists.rsv_secondary_codelist) - .exists_for_patient() + (hospitalisation_diagnosis_matches(codelists.rsv_secondary_codelist) + .exists_for_patient()) |(hospitalisation_diagnosis_matches(codelists.unspecified_lrti) .exists_for_patient()) &(~rsv_exclusion_secondary) @@ -431,11 +434,13 @@ def first_infection_event(codelist, where = True): #rsv secondary care date if codelist_type == "specific" : dataset.rsv_secondary_date = ( - (apcs.where(apcs.primary_diagnosis + apcs.sort_by(apcs.admission_date) + .where(apcs.primary_diagnosis + .is_in(codelists.rsv_secondary_codelist) + |apcs.secondary_diagnosis .is_in(codelists.rsv_secondary_codelist)) - |apcs.where(apcs.secondary_diagnosis - .is_in(codelists.rsv_secondary_codelist))) - .first_for_patient().admission_date + .first_for_patient() + .admission_date ) if codelist_type == "sensitive" : dataset.rsv_secondary_date = (case( @@ -443,191 +448,382 @@ def first_infection_event(codelist, where = True): .then(rsv_secondary_sens_date)) ) -# #covid primary care -# if datetime.strptime(study_start_date, "%Y-%m-%d") >= covid_season_min : -# -# dataset.covid_primary = (case( -# when(codelist_type == "specific") -# .then(has_prior_event(codelists.covid_primary_codelist)), -# when(codelist_type == "sensitive") -# .then(has_prior_event(codelists.covid_sensitive_codelist))) -# ) -# -# #date -# dataset.covid_primary_date = (case( -# when(codelist_type == "specific") -# .then(first_prior_event(codelists.covid_primary_codelist)), -# when(codelist_type == "sensitive") -# .then(first_prior_event(codelists.covid_sensitive_codelist))) -# ) -# -# #covid secondary care -# dataset.covid_secondary = (case( -# when(codelist_type == "specific").then( -# apcs.where(apcs.primary_diagnosis -# .is_in(codelists.covid_secondary_codelist)) -# .exists_for_patient() -# |apcs.where(apcs.secondary_diagnosis -# .is_in(codelists.covid_secondary_codelist)) -# .exists_for_patient()), -# when(codelist_type == "sensitive").then( -# apcs.where(apcs.all_diagnoses -# .is_in(codelists.covid_secondary_codelist)) -# .exists_for_patient()) -# )) -# -# #date -# dataset.covid_secondary_date = (case( -# when(codelist_type == "specific") -# .then(apcs.sort_by(apcs.admission_date) -# .where(apcs.primary_diagnosis -# .is_in(codelists.covid_secondary_codelist) -# |apcs.secondary_diagnosis -# .is_in(codelists.covid_secondary_codelist)) -# .first_for_patient().admission_date), -# when(codelist_type == "sensitive") -# .then(apcs.sort_by(apcs.admission_date) -# .where(apcs.all_diagnoses -# .is_in(codelists.covid_secondary_codelist))) -# )) -# -# #flu primary care -# dataset.flu_primary = ( -# clinical_events.where(clinical_events.ctv3_code -# .is_in(codelists.covid_primary_codelist)) #change codelist when available -# .exists_for_patient() -# ) -# -# #date -# dataset.flu_primary_date = ( -# clinical_events.where(clinical_events.ctv3_code -# .is_in(codelists.covid_primary_codelist)) #change codelist when available -# .sort_by(clinical_events.date) -# .first_for_patient().date -# ) -# -# #flu secondary care -# dataset.flu_secondary = ( -# apcs.where(apcs.primary_diagnosis -# .is_in(codelists.covid_secondary_codelist)) #change codelist when available -# .exists_for_patient() -# |apcs.where(apcs.secondary_diagnosis -# .is_in(codelists.covid_secondary_codelist)) #change codelist when available -# .exists_for_patient() -# ) -# -# #date -# dataset.flu_secondary_date = ( -# apcs.sort_by(apcs.admission_date) -# .where(apcs.primary_diagnosis.is_in(codelists.covid_secondary_codelist) #change codelist when available -# |apcs.secondary_diagnosis.is_in(codelists.covid_secondary_codelist)) #change codelist when available -# .first_for_patient().admission_date -# ) - -# ##comorbidities for secondary investigation -# -# #medication date -# medication_date = index_date - years(1) -# -# if investigation_type == secondary : -# -# #has asthma if there is an asthma diagnosis and a recent medication prescribed -# if cohort != "infants" and cohort != "infants_subgroup" : -# dataset.has_asthma = ( -# clinical_events.where(clinical_events.snomedct_code.is_in(codelists.asthma_codelist)) -# .exists_for_patient() & medications.where(medications.dmd_code -# .is_in(codelists.asthma_medications)) -# .where(medications.date.is_on_or_between(medication_date, index_date)) -# .exists_for_patient() -# ) -# -# #reactive airway disease diagnosis -# if cohort == "children_adolescents" : -# dataset.has_reactive_airway = ( -# clinical_events.where(clinical_events.snomedct_code -# .is_in(reactive_airway_disease_code)) -# .exists_for_patient() -# ) -# -# if cohort == "adults" or cohort == "older_adults" : -# -# #copd diagnosis -# dataset.has_copd = ( -# clinical_events.where(clinical_events.snomedct_code.is_in(codelists.copd_codelist)) -# # & medications.where(medications.dmd_code.is_in(codelists.copd_medications)) -# .exists_for_patient() -# ) -# -# #pulmonary fibrosis diagnosis -# dataset.has_pulmonary_fibrosis = ( -# clinical_events.where(clinical_events.snomedct_code -# .is_in(codelists.pulmonary_fibrosis_codelist)) -# .where(clinical_events.date.is_on_or_before(index_date)) -# .exists_for_patient() -# ) -# -# #cystic fibrosis diagnosis -# dataset.has_cystic_fibrosis = ( -# clinical_events.where(clinical_events.snomedct_code -# .is_in(codelists.cystic_fibrosis_codelist)) -# .where(clinical_events.date.is_on_or_before(index_date)) -# .exists_for_patient() -# ) -# -# #diabetes diagnosis -# diab_date = last_prior_event(codelists.diab).date -# dmres_date = last_prior_event(codelists.dmres).date -# dataset.has_diabetes = ( -# clinical_events.where(clinical_events.snomedct_code -# .is_in(codelists.type1_diabetes_codelist)) -# .where(clinical_events.date.is_before(dmres_date)) -# .exists_for_patient() | clinical_events.where(clinical_events.snomedct_code -# .is_in(codelists.non_type1_diabetes_codelist)) -# .where(clinical_events.date.is_before(dmres_date)) -# .exists_for_patient() -# ) -# -# #addison's disease diagnosis -# dataset.has_addisons = ( -# clinical_events.where(clinical_events.snomedct_code -# .is_in(codelists.addisons_codelist)) -# .where(clinical_events.date.is_on_or_before(index_date)) -# .exists_for_patient() -# ) -# -# #Chronic Neurological Disease including Significant Learning Disorder -# dataset.chronic_neuro_disease = has_prior_event(codelists.chronic_neuro_codelist) -# -# #Chronic Respiratory Disease -# dataset.chronic_resp_disease = has_prior_event(codelists.respiratory_codelist) -# -# #Calculate BMI -# # BMI -# bmi_measurement = most_recent_bmi( -# where = events.date.is_after(index_date - days(5 * 365)), -# minimum_age_at_measurement = 16, -# ) -# bmi_value = bmi_measurement.numeric_value -# -# dataset.bmi = case( -# when(bmi_value < 30).then("Not obese"), # include this here to ensure this value is the 1st level in the factor -# when((bmi_value >= 30.0) & (bmi_value < 35.0)).then("Obese I (30-34.9)"), -# when((bmi_value >= 35.0) & (bmi_value < 40.0)).then("Obese II (35-39.9)"), -# # Set maximum to avoid any impossibly extreme values being classified as obese -# when((bmi_value >= 40.0) & (bmi_value < 100.0)).then("Obese III (40+)"), -# default = "Not obese", # assume missing is non-obese -# ) -# -# # Severe Obesity -# bmi_stage_event = last_prior_event(codelists.bmi_stage) -# sev_obesity_event = last_prior_event( -# codelists.sev_obesity, -# where = ((events.date >= bmi_stage_event.date) & (events.numeric_value != 0.0)), -# ) -# bmi_event = last_prior_event(codelists.bmi, where = (events.numeric_value != 0.0)) -# -# dataset.sev_obesity = case( -# when(sev_obesity_event.date > bmi_event.date).then(True), -# when(bmi_event.numeric_value >= 40.0).then(True), -# default = False -# ) +##outcomes - flu + +#occurance of ILI (according to WHO definition) +ILI_case = ( + (has_infection_event(codelists.ari_primary_codelist)) + & (has_infection_event(codelists.fever_codelist)) + & (has_infection_event(codelists.cough_codelist)) +) + +#date of first occurance of ILI +ILI_date = (case( + when(ILI_case).then(minimum_of(first_infection_event(codelists + .ari_primary_codelist).date, first_infection_event(codelists + .fever_codelist).date, first_infection_event(codelists + .cough_codelist).date))) +) + +#occurance of event in exclusion list within one month of ILI +flu_exclusion_primary = (case( + when((first_infection_event(codelists.flu_primary_exclusion_codelist) + .date.is_on_or_between(first_infection_event(codelists.flu_sensitive_codelist) + .date - days(30), first_infection_event(codelists.flu_sensitive_codelist) + .date + days(30)))|(first_infection_event(codelists + .flu_primary_exclusion_codelist).date + .is_on_or_between(ILI_date - days(30), ILI_date + days(30))) + |(medications.where(medications.dmd_code.is_in(codelists + .flu_prescriptions_codelist)).date.minimum_for_patient() + .is_on_or_between(ILI_date - days(30), ILI_date + days(30)))) + .then(has_infection_event(codelists.flu_primary_exclusion_codelist)) +)) + +#flu primary care +if codelist_type == "specific" : + dataset.flu_primary = has_infection_event(codelists.flu_primary_codelist) + +if codelist_type == "sensitive" : + dataset.flu_primary = ( + (has_infection_event(codelists.flu_sensitive_codelist)) + |(ILI_case)|(medications.where(medications.dmd_code + .is_in(codelists.flu_prescriptions_codelist)) + .exists_for_patient()) + &(~flu_exclusion_primary) + ) + +#flu primary care date +if codelist_type == "specific" : + dataset.flu_primary_date = ( + first_infection_event(codelists + .flu_primary_codelist).date + ) + +if codelist_type == "sensitive" : + dataset.flu_primary_date = (case( + when(~flu_exclusion_primary).then( + minimum_of((first_infection_event(codelists + .flu_sensitive_codelist).date), + (ILI_date),(medications.where(medications.dmd_code + .is_in(codelists.flu_prescriptions_codelist)) + .date.minimum_for_patient())))) + ) + +#occurance of event in exclusion list within one month of secondary care diagnosis +flu_secondary_sens_date = ( + apcs.sort_by(apcs.admission_date) + .where( + ((hospitalisation_diagnosis_matches(codelists + .flu_secondary_codelist).exists_for_patient()) + |(hospitalisation_diagnosis_matches(codelists + .ari_secondary_codelist).exists_for_patient()))) + .admission_date.minimum_for_patient() +) +flu_exclusion_secondary = (case( + when((hospitalisation_diagnosis_matches(codelists + .flu_secondary_exclusion_codelist)) + .admission_date.minimum_for_patient() + .is_on_or_between(flu_secondary_sens_date - days(30), + flu_secondary_sens_date + days(30))) + .then((hospitalisation_diagnosis_matches(codelists + .flu_secondary_exclusion_codelist)) + .exists_for_patient()) +)) + +#flu secondary care +if codelist_type == "specific" : + dataset.flu_secondary = (apcs.where(apcs.primary_diagnosis + .is_in(codelists.flu_secondary_codelist)) + .exists_for_patient() + |apcs.where(apcs.secondary_diagnosis + .is_in(codelists.flu_secondary_codelist)) + .exists_for_patient() + ) +if codelist_type == "sensitive" : + dataset.flu_secondary = ( + hospitalisation_diagnosis_matches(codelists + .flu_secondary_codelist) + .exists_for_patient() + |(hospitalisation_diagnosis_matches(codelists + .ari_secondary_codelist) + .exists_for_patient()) + &(~flu_exclusion_secondary) + ) + +#flu secondary care date +if codelist_type == "specific" : + dataset.flu_secondary_date = ( + apcs.sort_by(apcs.admission_date) + .where(apcs.primary_diagnosis + .is_in(codelists.flu_secondary_codelist) + |apcs.secondary_diagnosis + .is_in(codelists.flu_secondary_codelist)) + .first_for_patient() + .admission_date + ) +if codelist_type == "sensitive" : + dataset.flu_secondary_date = (case( + when(~flu_exclusion_secondary) + .then(flu_secondary_sens_date)) + ) + +##outcomes - covid + +#count number of clinical codes in covid symptom list +covid_code_number = ( + (clinical_events.where(clinical_events + .date.is_on_or_between(first_infection_event(codelists + .covid_sensitive_codelist).date, first_infection_event(codelists + .covid_sensitive_codelist).date + days(14))) + .where(clinical_events.snomedct_code + .is_in(codelists.covid_sensitive_codelist))) + .snomedct_code.count_distinct_for_patient() +) + +#date of first occurance of two of the above codes within 2 weeks +covid_codes_date = ( + case(when(covid_code_number > 1) + .then(first_infection_event(codelists + .covid_sensitive_codelist).date)) +) + +#occurance of event in exclusion list within one month of covid_codes_date +covid_exclusion_primary = (case( + when((first_infection_event(codelists.covid_primary_exclusion_codelist) + .date.is_on_or_between(covid_codes_date - days(30), covid_codes_date + days(30))) + |(medications.where(medications.dmd_code + .is_in(codelists.covid_prescriptions_codelist)).date.minimum_for_patient() + .is_on_or_between(covid_codes_date - days(30), covid_codes_date + days(30)))) + .then(has_infection_event(codelists.covid_primary_exclusion_codelist)) +)) + +#covid primary care +if codelist_type == "specific" : + dataset.covid_primary = has_infection_event(codelists.covid_primary_codelist) + +if codelist_type == "sensitive" : + dataset.covid_primary = ( + (has_infection_event(codelists.covid_primary_codelist)) + |(covid_code_number >1)|(medications.where(medications.dmd_code + .is_in(codelists.covid_prescriptions_codelist)).exists_for_patient()) + &(~covid_exclusion_primary) + ) + +#covid primary care date +if codelist_type == "specific" : + dataset.covid_primary_date = ( + first_infection_event(codelists + .covid_primary_codelist).date + ) + +if codelist_type == "sensitive" : + dataset.covid_primary_date = (case( + when(~covid_exclusion_primary).then( + minimum_of((first_infection_event(codelists + .covid_primary_codelist).date), + (covid_codes_date),(medications.where(medications.dmd_code + .is_in(codelists.covid_prescriptions_codelist)) + .date.minimum_for_patient())))) + ) + +#occurance of event in exclusion list within one month of secondary care diagnosis +covid_secondary_sens_date = ( + apcs.sort_by(apcs.admission_date) + .where( + ((hospitalisation_diagnosis_matches(codelists + .covid_secondary_codelist).exists_for_patient()))) + .first_for_patient().admission_date +) +covid_exclusion_secondary = (case( + when((hospitalisation_diagnosis_matches(codelists + .covid_secondary_exclusion_codelist)) + .admission_date.minimum_for_patient() + .is_on_or_between(covid_secondary_sens_date - days(30), + covid_secondary_sens_date + days(30))) + .then((hospitalisation_diagnosis_matches(codelists + .covid_secondary_exclusion_codelist)) + .exists_for_patient()) +)) + +#covid secondary care +if codelist_type == "specific" : + dataset.covid_secondary = ( + apcs.where(apcs.primary_diagnosis + .is_in(codelists.covid_secondary_codelist)) + .exists_for_patient() + |apcs.where(apcs.secondary_diagnosis + .is_in(codelists.covid_secondary_codelist)) + .exists_for_patient() + ) +if codelist_type == "sensitive" : + dataset.covid_secondary = ( + (hospitalisation_diagnosis_matches(codelists + .covid_secondary_codelist) + .exists_for_patient()) + &(~covid_exclusion_secondary) + ) + +#covid secondary care date +if codelist_type == "specific" : + dataset.covid_secondary_date = ( + apcs.sort_by(apcs.admission_date) + .where(apcs.primary_diagnosis + .is_in(codelists.covid_secondary_codelist) + |apcs.secondary_diagnosis + .is_in(codelists.covid_secondary_codelist)) + .first_for_patient() + .admission_date + ) +if codelist_type == "sensitive" : + dataset.covid_secondary_date = (case( + when(~covid_exclusion_secondary) + .then(covid_secondary_sens_date)) + ) + +##outcomes - unspecified respiratory infection + +#unspecified respiratory virus primary care +if codelist_type == "sensitive" : + if cohort == "older_adults" : + dataset.overall_resp_primary = ( + (dataset.rsv_primary)|(dataset.flu_primary) + |(dataset.covid_primary)|(has_infection_event(codelists. + respiratory_virus_primary_codelist)) + |(emergency_care_diagnosis_matches(codelists. + rtri_attendance).exists_for_patient()) + |(emergency_care_diagnosis_matches(codelists. + copd_exacerbation_attendance).exists_for_patient()) + |(has_infection_event(codelists + .copd_exacerbation_primary_codelist)) + |(has_infection_event(codelists + .asthma_exacerbation_primary_codelist)) + ) + else: + dataset.overall_resp_primary = ( + (dataset.rsv_primary)|(dataset.flu_primary) + |(dataset.covid_primary)|(has_infection_event(codelists. + respiratory_virus_primary_codelist)) + |(emergency_care_diagnosis_matches(codelists. + rtri_attendance).exists_for_patient()) + ) + +#unspecified respiratory virus primary care date +if codelist_type == "sensitive" : + if cohort == "older_adults" : + dataset.overall_resp_primary_date = ( + minimum_of(dataset.rsv_primary_date, dataset.flu_primary_date, + dataset.covid_primary_date, first_infection_event(codelists. + respiratory_virus_primary_codelist).date, + emergency_care_diagnosis_matches(codelists. + rtri_attendance).arrival_date.minimum_for_patient(), + emergency_care_diagnosis_matches(codelists. + copd_exacerbation_attendance) + .arrival_date.minimum_for_patient(), + first_infection_event(codelists + .copd_exacerbation_primary_codelist).date, + first_infection_event(codelists + .asthma_exacerbation_primary_codelist).date) + ) + else: + dataset.overall_resp_primary_date = ( + minimum_of(dataset.rsv_primary_date, dataset.flu_primary_date, + dataset.covid_primary_date, first_infection_event(codelists. + respiratory_virus_primary_codelist).date, + emergency_care_diagnosis_matches(codelists. + rtri_attendance).arrival_date.minimum_for_patient()) + ) + +#unspecified respiratory virus secondary care +if codelist_type == "sensitive" : + if cohort == "older_adults" : + dataset.overall_resp_secondary = ( + (dataset.rsv_secondary)|(dataset.flu_secondary) + |(dataset.covid_secondary) + |(hospitalisation_diagnosis_matches(codelists. + respiratory_virus_secondary_codelist) + .exists_for_patient()) + |(hospitalisation_diagnosis_matches(codelists + .copd_exacerbation_secondary_codelist) + .exists_for_patient()) + |(hospitalisation_diagnosis_matches(codelists + .asthma_exacerbation_secondary_codelist) + .exists_for_patient()) + ) + else: + dataset.overall_resp_secondary = ( + (dataset.rsv_secondary)|(dataset.flu_secondary) + |(dataset.covid_secondary) + |(hospitalisation_diagnosis_matches(codelists. + respiratory_virus_secondary_codelist) + .exists_for_patient()) + ) + +#unspecified respiratory virus secondary care date +if codelist_type == "sensitive" : + if cohort == "older_adults" : + dataset.overall_resp_secondary_date = ( + minimum_of(dataset.rsv_secondary_date, + dataset.flu_secondary_date, dataset.covid_secondary_date, + hospitalisation_diagnosis_matches(codelists. + respiratory_virus_secondary_codelist).admission_date + .minimum_for_patient(), hospitalisation_diagnosis_matches(codelists + .copd_exacerbation_secondary_codelist) + .admission_date.minimum_for_patient(), + hospitalisation_diagnosis_matches(codelists + .asthma_exacerbation_secondary_codelist) + .admission_date.minimum_for_patient()) + ) + else: + dataset.overall_resp_secondary_date = ( + minimum_of(dataset.rsv_secondary_date, + dataset.flu_secondary_date, dataset.covid_secondary_date, + hospitalisation_diagnosis_matches(codelists. + respiratory_virus_secondary_codelist) + .admission_date.minimum_for_patient()) + ) + +## comorbidities for secondary investigation + +if investigation_type == "secondary" : + + from additional_comorbidities import ( + filter_codes_by_category, smoking_status, + hazardous_drinking, drug_usage, has_asthma, + has_reactive_airway, has_copd, + has_pulmonary_fibrosis, has_cystic_fibrosis, + has_diabetes, has_addisons, severe_obesity, + has_chd, has_ckd, has_cld, has_cnd, has_crd, + has_cancer, immunosuppressed, has_sickle_cell, + has_heart_failure, has_prior_mi + ) + + if cohort == "adults" or cohort == "older_adults" : + + dataset.smoking_status = smoking_status + dataset.hazardous_drinking = hazardous_drinking + dataset.drug_usage = drug_usage + dataset.has_asthma = has_asthma + dataset.has_copd = has_copd + dataset.has_pulmonary_fibrosis = has_pulmonary_fibrosis + dataset.has_cystic_fibrosis = has_cystic_fibrosis + dataset.has_diabetes = has_diabetes + dataset.has_addisons = has_addisons + dataset.severe_obesity = severe_obesity + dataset.has_chd = has_chd + dataset.has_ckd = has_ckd + dataset.has_cld = has_cld + dataset.has_cnd = has_cnd + dataset.has_cancer = has_cancer + dataset.immunosuppressed = immunosuppressed + dataset.has_sickle_cell = has_sickle_cell + dataset.has_heart_failure = has_heart_failure + dataset.has_prior_mi = has_prior_mi + + if cohort == "children_and_adolscents" : + + dataset.has_reactive_airway = case( + when(dataset.age < 5).then(has_reactive_airway), + default = False + ) + + dataset.has_asthma = has_asthma diff --git a/analysis/dummydata/dummydata_adults.R b/analysis/dummydata/dummydata_adults.R index 65bc699..bd0fe8b 100644 --- a/analysis/dummydata/dummydata_adults.R +++ b/analysis/dummydata/dummydata_adults.R @@ -62,11 +62,6 @@ sim_list = lst( ~ factor(as.integer(runif(n = ..n, 1, 36)), levels = 1:36), ), - #whether the participant has diabetes or not - diabetes = bn_node( - ~ rbernoulli(n = ..n, p = plogis(-1 + age*0.02 + I(sex == "female")*-0.2)) - ), - #region the patient lives in region = bn_node( ~ rfactor(n = ..n, levels = c( @@ -131,7 +126,7 @@ sim_list = lst( ##comorbidities #smoking status - most_recent_smoking_code = bn_node( + smoking_status = bn_node( ~ rfactor(n = ..n, levels = c( "S", #smoker "E", #ever-smoked @@ -157,8 +152,8 @@ sim_list = lst( #copd has_copd = bn_node( - ~ rbernoulli(n = ..n, p = plogis(-1 + I(most_recent_smoking_code == "S")*-0.5 + - I(most_recent_smoking_code == "E")*-0.1)) + ~ rbernoulli(n = ..n, p = plogis(-1 + I(smoking_status == "S")*-0.5 + + I(smoking_status == "E")*-0.1)) ), #pulmonary fibrosis @@ -166,9 +161,9 @@ sim_list = lst( ~ rbernoulli(n = ..n, p = 0.001) ), - #hypertension - has_hypertension = bn_node( - ~ rbernoulli(n = ..n, p = 0.2) + #cystic fibrosis + has_cystic_fibrosis = bn_node( + ~ rbernoulli(n = ..n, p = 0.02) ), #diabetes @@ -176,6 +171,56 @@ sim_list = lst( ~ rbernoulli(n = ..n, p = plogis(-1 + age*0.02 + I(sex == "female")*-0.2)) ), + #addisons + has_addisons = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #severe obesity + severe_obesity = bn_node( + ~ rbernoulli(n = ..n, p = 0.1) + ), + + #chronic heart disease + has_chd = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #chronic kidney disease + has_ckd = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #chronic liver disease + has_cld = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #chronic respiratory disease + has_crd = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #chronic neurological disease + has_cnd = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #cancer within 3 years + has_cancer = bn_node( + ~ rbernoulli(n = ..n, p = 0.1) + ), + + #immunosuppression group + immunosuppressed = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #sickle cell disease + has_sickle_cell = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + #heart failure has_heart_failure = bn_node( ~ rbernoulli(n = ..n, p = 0.015) @@ -220,6 +265,26 @@ sim_list = lst( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), + #flu primary care + flu_primary = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #date + flu_primary_day = bn_node( + ~ as.integer(runif(n = ..n, index_day, index_day + 365)) + ), + + #flu secondary care + flu_secondary = bn_node( + ~ rbernoulli(n = ..n, p = 0.1) + ), + + #date + flu_secondary_day = bn_node( + ~ as.integer(runif(n = ..n, index_day, index_day + 365)) + ), + #covid primary care covid_primary = bn_node( ~ rbernoulli(n = ..n, p = 0.05) @@ -240,23 +305,23 @@ sim_list = lst( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #flu primary care - flu_primary = bn_node( - ~ rbernoulli(n = ..n, p = 0.01) + #unspecified respiratory infection primary care + overall_resp_primary = bn_node( + ~ rbernoulli(n = ..n, p = 0.3) ), #date - flu_primary_day = bn_node( + overall_resp_primary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #flu secondary care - flu_secondary = bn_node( - ~ rbernoulli(n = ..n, p = 0.1) + #unspecified respiratory infection secondary care + overall_resp_secondary = bn_node( + ~ rbernoulli(n = ..n, p = 0.25) ), #date - flu_secondary_day = bn_node( + overall_resp_secondary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ) diff --git a/analysis/dummydata/dummydata_children_adolescents.R b/analysis/dummydata/dummydata_children_adolescents.R index 4a12628..dcb84dd 100644 --- a/analysis/dummydata/dummydata_children_adolescents.R +++ b/analysis/dummydata/dummydata_children_adolescents.R @@ -174,6 +174,27 @@ sim_list = lst( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), + #flu primary care + flu_primary = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #date + flu_primary_day = bn_node( + ~ as.integer(runif(n = ..n, index_day, index_day + 365)) + ), + + #flu secondary care + flu_secondary = bn_node( + ~ rbernoulli(n = ..n, p = 0.1) + ), + + #date + flu_secondary_day = bn_node( + ~ as.integer(runif(n = ..n, index_day, index_day + 365)) + ), + + #covid primary care covid_primary = bn_node( ~ rbernoulli(n = ..n, p = 0.05) @@ -194,23 +215,23 @@ sim_list = lst( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #flu primary care - flu_primary = bn_node( - ~ rbernoulli(n = ..n, p = 0.01) + #unspecified respiratory infection primary care + overall_resp_primary = bn_node( + ~ rbernoulli(n = ..n, p = 0.3) ), #date - flu_primary_day = bn_node( + overall_resp_primary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #flu secondary care - flu_secondary = bn_node( - ~ rbernoulli(n = ..n, p = 0.1) + #unspecified respiratory infection secondary care + overall_resp_secondary = bn_node( + ~ rbernoulli(n = ..n, p = 0.25) ), #date - flu_secondary_day = bn_node( + overall_resp_secondary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ) diff --git a/analysis/dummydata/dummydata_infants.R b/analysis/dummydata/dummydata_infants.R index 50bd333..32b07f3 100644 --- a/analysis/dummydata/dummydata_infants.R +++ b/analysis/dummydata/dummydata_infants.R @@ -148,6 +148,26 @@ sim_list = lst( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), + #flu primary care + flu_primary = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #date + flu_primary_day = bn_node( + ~ as.integer(runif(n = ..n, index_day, index_day + 365)) + ), + + #flu secondary care + flu_secondary = bn_node( + ~ rbernoulli(n = ..n, p = 0.1) + ), + + #date + flu_secondary_day = bn_node( + ~ as.integer(runif(n = ..n, index_day, index_day + 365)) + ), + #covid primary care covid_primary = bn_node( ~ rbernoulli(n = ..n, p = 0.05) @@ -168,25 +188,25 @@ sim_list = lst( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #flu primary care - flu_primary = bn_node( - ~ rbernoulli(n = ..n, p = 0.01) + #unspecified respiratory infection primary care + overall_resp_primary = bn_node( + ~ rbernoulli(n = ..n, p = 0.3) ), #date - flu_primary_day = bn_node( + overall_resp_primary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #flu secondary care - flu_secondary = bn_node( - ~ rbernoulli(n = ..n, p = 0.1) + #unspecified respiratory infection secondary care + overall_resp_secondary = bn_node( + ~ rbernoulli(n = ..n, p = 0.25) ), #date - flu_secondary_day = bn_node( + overall_resp_secondary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) - ), + ) # ##exclusion criteria # diff --git a/analysis/dummydata/dummydata_infants_subgroup.R b/analysis/dummydata/dummydata_infants_subgroup.R index 61cf2c7..085b133 100644 --- a/analysis/dummydata/dummydata_infants_subgroup.R +++ b/analysis/dummydata/dummydata_infants_subgroup.R @@ -195,63 +195,83 @@ sim_list = lst( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #covid primary care - covid_primary = bn_node( - ~ rbernoulli(n = ..n, p = 0.05) + #flu primary care + flu_primary = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) ), #date - covid_primary_day = bn_node( + flu_primary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #covid secondary care - covid_secondary = bn_node( + #flu secondary care + flu_secondary = bn_node( ~ rbernoulli(n = ..n, p = 0.1) ), #date - covid_secondary_day = bn_node( + flu_secondary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #flu primary care - flu_primary = bn_node( - ~ rbernoulli(n = ..n, p = 0.01) + #covid primary care + covid_primary = bn_node( + ~ rbernoulli(n = ..n, p = 0.05) ), #date - flu_primary_day = bn_node( + covid_primary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #flu secondary care - flu_secondary = bn_node( + #covid secondary care + covid_secondary = bn_node( ~ rbernoulli(n = ..n, p = 0.1) ), #date - flu_secondary_day = bn_node( + covid_secondary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - ##exclusion criteria + #unspecified respiratory infection primary care + overall_resp_primary = bn_node( + ~ rbernoulli(n = ..n, p = 0.3) + ), - #severe combined immunodeficiency syndrome - severe_immmunodeficiency = bn_node( - ~ rbernoulli(n = ..n, p = 0.02) + #date + overall_resp_primary_day = bn_node( + ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #ventilator dependence - ventilator_dependent = bn_node( - ~ rbernoulli(n = ..n, p = 0.01) + #unspecified respiratory infection secondary care + overall_resp_secondary = bn_node( + ~ rbernoulli(n = ..n, p = 0.25) ), - #risk group - risk_group_infants = bn_node( - ~ rbernoulli(n = ..n, p = 0.01) + #date + overall_resp_secondary_day = bn_node( + ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ) + # ##exclusion criteria + # + # #severe combined immunodeficiency syndrome + # severe_immmunodeficiency = bn_node( + # ~ rbernoulli(n = ..n, p = 0.02) + # ), + # + # #ventilator dependence + # ventilator_dependent = bn_node( + # ~ rbernoulli(n = ..n, p = 0.01) + # ), + # + # #risk group + # risk_group_infants = bn_node( + # ~ rbernoulli(n = ..n, p = 0.01) + # ) + ) bn <- bn_create(sim_list, known_variables = known_variables) diff --git a/analysis/dummydata/dummydata_older_adults.R b/analysis/dummydata/dummydata_older_adults.R index a53a7e9..208bb8a 100644 --- a/analysis/dummydata/dummydata_older_adults.R +++ b/analysis/dummydata/dummydata_older_adults.R @@ -62,11 +62,6 @@ sim_list = lst( ~ factor(as.integer(runif(n = ..n, 1, 36)), levels = 1:36), ), - #whether the participant has diabetes or not - diabetes = bn_node( - ~ rbernoulli(n = ..n, p = plogis(-1 + age*0.02 + I(sex == "female")*-0.2)) - ), - #region the patient lives in region = bn_node( ~ rfactor(n = ..n, levels = c( @@ -131,7 +126,7 @@ sim_list = lst( ##comorbidities #smoking status - most_recent_smoking_code = bn_node( + smoking_status = bn_node( ~ rfactor(n = ..n, levels = c( "S", #smoker "E", #ever-smoked @@ -157,8 +152,8 @@ sim_list = lst( #copd has_copd = bn_node( - ~ rbernoulli(n = ..n, p = plogis(-1 + I(most_recent_smoking_code == "S")*-0.5 + - I(most_recent_smoking_code == "E")*-0.1)) + ~ rbernoulli(n = ..n, p = plogis(-1 + I(smoking_status == "S")*-0.5 + + I(smoking_status == "E")*-0.1)) ), #pulmonary fibrosis @@ -166,9 +161,9 @@ sim_list = lst( ~ rbernoulli(n = ..n, p = 0.001) ), - #hypertension - has_hypertension = bn_node( - ~ rbernoulli(n = ..n, p = 0.2) + #cystic fibrosis + has_cystic_fibrosis = bn_node( + ~ rbernoulli(n = ..n, p = 0.02) ), #diabetes @@ -176,6 +171,56 @@ sim_list = lst( ~ rbernoulli(n = ..n, p = plogis(-1 + age*0.02 + I(sex == "female")*-0.2)) ), + #addisons + has_addisons = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #severe obesity + severe_obesity = bn_node( + ~ rbernoulli(n = ..n, p = 0.1) + ), + + #chronic heart disease + has_chd = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #chronic kidney disease + has_ckd = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #chronic liver disease + has_cld = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #chronic respiratory disease + has_crd = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #chronic neurological disease + has_cnd = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #cancer within 3 years + has_cancer = bn_node( + ~ rbernoulli(n = ..n, p = 0.1) + ), + + #immunosuppression group + immunosuppressed = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #sickle cell disease + has_sickle_cell = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + #heart failure has_heart_failure = bn_node( ~ rbernoulli(n = ..n, p = 0.015) @@ -220,6 +265,26 @@ sim_list = lst( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), + #flu primary care + flu_primary = bn_node( + ~ rbernoulli(n = ..n, p = 0.01) + ), + + #date + flu_primary_day = bn_node( + ~ as.integer(runif(n = ..n, index_day, index_day + 365)) + ), + + #flu secondary care + flu_secondary = bn_node( + ~ rbernoulli(n = ..n, p = 0.1) + ), + + #date + flu_secondary_day = bn_node( + ~ as.integer(runif(n = ..n, index_day, index_day + 365)) + ), + #covid primary care covid_primary = bn_node( ~ rbernoulli(n = ..n, p = 0.05) @@ -240,25 +305,25 @@ sim_list = lst( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #flu primary care - flu_primary = bn_node( - ~ rbernoulli(n = ..n, p = 0.01) + #unspecified respiratory infection primary care + overall_resp_primary = bn_node( + ~ rbernoulli(n = ..n, p = 0.3) ), #date - flu_primary_day = bn_node( + overall_resp_primary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) ), - #flu secondary care - flu_secondary = bn_node( - ~ rbernoulli(n = ..n, p = 0.1) + #unspecified respiratory infection secondary care + overall_resp_secondary = bn_node( + ~ rbernoulli(n = ..n, p = 0.25) ), #date - flu_secondary_day = bn_node( + overall_resp_secondary_day = bn_node( ~ as.integer(runif(n = ..n, index_day, index_day + 365)) - ), + ) # ##exclusion criteria # diff --git a/analysis/dummydata/dummyextract_adults_2016_2017.arrow b/analysis/dummydata/dummyextract_adults_2016_2017.arrow index 7a89ba8..02086b5 100644 Binary files a/analysis/dummydata/dummyextract_adults_2016_2017.arrow and b/analysis/dummydata/dummyextract_adults_2016_2017.arrow differ diff --git a/analysis/dummydata/dummyextract_children_adolescents_2016_2017.arrow b/analysis/dummydata/dummyextract_children_adolescents_2016_2017.arrow index 2a262ef..3c06559 100644 Binary files a/analysis/dummydata/dummyextract_children_adolescents_2016_2017.arrow and b/analysis/dummydata/dummyextract_children_adolescents_2016_2017.arrow differ diff --git a/analysis/dummydata/dummyextract_infants_2016_2017.arrow b/analysis/dummydata/dummyextract_infants_2016_2017.arrow index 9b9fdfd..683307c 100644 Binary files a/analysis/dummydata/dummyextract_infants_2016_2017.arrow and b/analysis/dummydata/dummyextract_infants_2016_2017.arrow differ diff --git a/analysis/dummydata/dummyextract_infants_subgroup_2016_2017.arrow b/analysis/dummydata/dummyextract_infants_subgroup_2016_2017.arrow index 6f01560..8c8e49c 100644 Binary files a/analysis/dummydata/dummyextract_infants_subgroup_2016_2017.arrow and b/analysis/dummydata/dummyextract_infants_subgroup_2016_2017.arrow differ diff --git a/analysis/dummydata/dummyextract_older_adults_2016_2017.arrow b/analysis/dummydata/dummyextract_older_adults_2016_2017.arrow index 40dab74..c61245c 100644 Binary files a/analysis/dummydata/dummyextract_older_adults_2016_2017.arrow and b/analysis/dummydata/dummyextract_older_adults_2016_2017.arrow differ diff --git a/analysis/report.R b/analysis/report.R index 603cd43..d3d07a8 100644 --- a/analysis/report.R +++ b/analysis/report.R @@ -13,10 +13,13 @@ args <- commandArgs(trailingOnly = TRUE) study_start_date <- study_dates[[args[[2]]]] study_end_date <- study_dates[[args[[3]]]] cohort <- args[[1]] +codelist_type <- args[[4]] +investigation_type <- args[[5]] df_input <- read_feather( here::here("output", paste0("input_processed_", cohort, "_", year(study_start_date), - "_", year(study_end_date), ".arrow"))) + "_", year(study_end_date), "_", codelist_type, "_", + investigation_type,".arrow"))) lab <- ifelse(cohort == "infants", "Age (Months)", ifelse(cohort == "infants_subgroup", "Age (Months)", "Age (Years)")) @@ -27,7 +30,8 @@ plot_age <- ggplot(data = df_input, aes(age, frequency(age))) + geom_col(width = ggsave( plot = plot_age, filename = paste0("descriptive_", cohort, "_", year(study_start_date), - "_", year(study_end_date), ".png"), path = here::here("output"), + "_", year(study_end_date), "_", codelist_type, "_", + investigation_type,".png"), path = here::here("output"), ) diff --git a/analysis/variable_lib.py b/analysis/variable_lib.py index edfb98a..be438a5 100644 --- a/analysis/variable_lib.py +++ b/analysis/variable_lib.py @@ -3,7 +3,8 @@ from ehrql.codes import SNOMEDCTCode, CTV3Code, ICD10Code from ehrql import case, days, when -from ehrql.tables.tpp import emergency_care_attendances, apcs +from ehrql.tables.tpp import (emergency_care_attendances, +apcs, clinical_events, patients) ############################################################################### # from https://github.com/opensafely/comparative-booster-spring2023/blob/main/analysis/variables_lib.py @@ -24,7 +25,6 @@ def has_a_continuous_practice_registration_spanning(start_date, end_date): return _registrations_overlapping_period(start_date, end_date).exists_for_patient() def most_recent_bmi(*, minimum_age_at_measurement, where=True): - events = clinical_events age_threshold = patients.date_of_birth + days( # This is obviously inexact but, given that the dates of birth are rounded to # the first of the month anyway, there's no point trying to be more accurate @@ -34,10 +34,10 @@ def most_recent_bmi(*, minimum_age_at_measurement, where=True): # This captures just explicitly recorded BMI observations rather than attempting # to calculate it from height and weight measurements. Investigation has shown # this to have no real benefit it terms of coverage or accuracy. - events.where(events.ctv3_code == CTV3Code("22K..")) - .where(events.date >= age_threshold) + clinical_events.where(clinical_events.ctv3_code == CTV3Code("22K..")) + .where(clinical_events.date >= age_threshold) .where(where) - .sort_by(events.date) + .sort_by(clinical_events.date) .last_for_patient() ) @@ -82,4 +82,3 @@ def hospitalisation_diagnosis_matches(codelist): for code_string in code_strings ] return apcs.where(any_of(conditions)) - diff --git a/codelists/bristol-asthma_exacerbations_snomed.csv b/codelists/bristol-asthma_exacerbations_snomed.csv new file mode 100644 index 0000000..2def1e9 --- /dev/null +++ b/codelists/bristol-asthma_exacerbations_snomed.csv @@ -0,0 +1,37 @@ +code,term +1064811000000103,Moderate acute exacerbation of asthma +1064821000000109,Life threatening acute exacerbation of asthma +10674711000119105,Acute severe exacerbation of asthma co-occurrent with allergic rhinitis +10675471000119109,Acute severe exacerbation of severe persistent allergic asthma +10675551000119104,Acute severe exacerbation of severe persistent asthma co-occurrent with allergic rhinitis +10675911000119109,Acute severe exacerbation of mild persistent allergic asthma +10675991000119100,Acute severe exacerbation of mild persistent allergic asthma co-occurrent with allergic rhinitis +10676431000119103,Acute severe exacerbation of moderate persistent allergic asthma +10676511000119109,Acute severe exacerbation of moderate persistent asthma co-occurrent with allergic rhinitis +10692721000119102,Chronic obstructive asthma co-occurrent with acute exacerbation of asthma +1086701000000102,Life threatening acute exacerbation of allergic asthma +1086711000000100,Life threatening acute exacerbation of intrinsic asthma +135171000119106,Acute exacerbation of moderate persistent asthma +135181000119109,Acute exacerbation of mild persistent asthma +1751000119100,Acute exacerbation of chronic obstructive airways disease with asthma +281239006,Exacerbation of asthma +707445000,Exacerbation of mild persistent asthma +707446004,Exacerbation of moderate persistent asthma +707447008,Exacerbation of severe persistent asthma +707979007,Acute severe exacerbation of severe persistent asthma +707980005,Acute severe exacerbation of moderate persistent asthma +707981009,Acute severe exacerbation of mild persistent asthma +708038006,Acute exacerbation of asthma +708090002,Acute severe exacerbation of asthma +708093000,Acute exacerbation of immunoglobulin E-mediated allergic asthma +708094006,Acute exacerbation of intrinsic asthma +708095007,Acute severe exacerbation of immunoglobin E-mediated allergic asthma +708096008,Acute severe exacerbation of intrinsic asthma +733858005,Acute severe refractory exacerbation of asthma +734904007,Life threatening acute exacerbation of asthma +734905008,Moderate acute exacerbation of asthma +735587000,Acute severe exacerbation of asthma co-occurrent and due to allergic asthma +762521001,Exacerbation of allergic asthma +782513000,Acute severe exacerbation of allergic asthma +782520007,Exacerbation of allergic asthma due to infection +99031000119107,Acute exacerbation of asthma co-occurrent with allergic rhinitis diff --git a/codelists/bristol-copd-exacerbations-snomed.csv b/codelists/bristol-copd-exacerbations-snomed.csv new file mode 100644 index 0000000..2b172a3 --- /dev/null +++ b/codelists/bristol-copd-exacerbations-snomed.csv @@ -0,0 +1,54 @@ +code,term +10509002,Acute bronchitis +106001000119101,Chronic obstructive lung disease co-occurrent with acute bronchitis +138389411000119105,Acute bronchitis caused by severe acute respiratory syndrome coronavirus 2 +195717003,Acute purulent bronchitis +195719000,Acute pneumococcal bronchitis +195720006,Acute streptococcal bronchitis +195721005,Acute bronchitis caused by Haemophilus influenzae +195722003,Acute Moraxella catarrhalis bronchitis +195725001,Acute coxsackievirus bronchitis +195726000,Acute parainfluenza virus bronchitis +195727009,Acute respiratory syncytial virus bronchitis +195728004,Acute bronchitis caused by rhinovirus +195729007,Acute echovirus bronchitis +195737004,Acute exudative bronchiolitis +195739001,Acute bronchiolitis caused by respiratory syncytial virus +195742007,Acute lower respiratory tract infection +196001008,Chronic obstructive pulmonary disease with acute lower respiratory infection +233598009,Acute bacterial bronchitis +233599001,Acute mycoplasmal bronchitis +233600003,Acute chlamydial bronchitis +233601004,Acute viral bronchitis +233602006,Acute viral bronchiolitis +233603001,Acute bronchiolitis caused by adenovirus +24662006,Influenza caused by Influenza B virus +275499005,Acute wheezy bronchitis +293241000119100,Acute exacerbation of chronic obstructive bronchitis +312119006,Bacterial lower respiratory infection +312134000,Viral lower respiratory infection +312371005,Acute infective bronchitis +315642008,Influenza-like symptoms +36426008,Subacute bronchitis +425748003,Acute exacerbation of chronic bronchitis +427873006,"Influenza caused by influenza virus type A, avian, H5N1 strain" +442438000,Influenza caused by Influenza A virus +442696006,Influenza caused by Influenza A virus subtype H1N1 +448739000,Recurrent lower respiratory tract infection +450715004,Influenza caused by Influenza A virus subtype H7 +450716003,Influenza caused by Influenza A virus subtype H9 +50417007,Lower respiratory tract infection +5875001,Acute bronchitis with obstruction +6142004,Influenza +707448003,Influenza caused by Influenza A virus subtype H7N9 +711128004,"Influenza caused by influenza virus type A, avian, H3N2 strain" +713083002,Influenza caused by Influenza A virus subtype H5 +719590007,Influenza caused by seasonal influenza virus +719865001,Influenza caused by pandemic influenza virus +772810003,Influenza caused by Influenza A virus subtype H3N2 +772828001,Influenza caused by Influenza A virus subtype H5N1 +785745000,Acute bronchitis co-occurrent with wheeze +80257001,Acute bronchitis with bronchospasm +81524006,Influenza caused by Influenza C virus +880529761000119102,Infection of lower respiratory tract caused by severe acute respiratory syndrome coronavirus 2 +95891005,Influenza-like illness diff --git a/codelists/codelists.json b/codelists/codelists.json index b194925..0ba601c 100644 --- a/codelists/codelists.json +++ b/codelists/codelists.json @@ -139,22 +139,46 @@ "sha": "aa73a7f744885a01ca45abd614d19e90a25f1ccb" }, "user-emprestige-respiratory-virus-unspecified-identification-primary-care.csv": { - "id": "user/emprestige/respiratory-virus-unspecified-identification-primary-care/2b95afdb", - "url": "https://www.opencodelists.org/codelist/user/emprestige/respiratory-virus-unspecified-identification-primary-care/2b95afdb/", - "downloaded_at": "2024-02-19 15:49:02.860337Z", - "sha": "6d8d2ca9aabff6a82a9b5e3032ecbfc6128e7777" + "id": "user/emprestige/respiratory-virus-unspecified-identification-primary-care/662b7b70", + "url": "https://www.opencodelists.org/codelist/user/emprestige/respiratory-virus-unspecified-identification-primary-care/662b7b70/", + "downloaded_at": "2024-02-23 14:09:43.056462Z", + "sha": "717de6f0b1aa1ddc173841c04256d1949303fb15" + }, + "bristol-copd-exacerbations-snomed.csv": { + "id": "bristol/copd-exacerbations-snomed/162ebd1c", + "url": "https://www.opencodelists.org/codelist/bristol/copd-exacerbations-snomed/162ebd1c/", + "downloaded_at": "2024-02-23 14:09:43.191238Z", + "sha": "b0e32941638b2da1cc4584c0a6f092587a6589f7" + }, + "bristol-asthma_exacerbations_snomed.csv": { + "id": "bristol/asthma_exacerbations_snomed/137bfd26", + "url": "https://www.opencodelists.org/codelist/bristol/asthma_exacerbations_snomed/137bfd26/", + "downloaded_at": "2024-02-23 14:09:43.336603Z", + "sha": "fe2a7ff5102e2c796585f5adfe69dd84bdd8d738" }, "user-emprestige-respiratory-virus-unspecified-exclusion-primary-care.csv": { - "id": "user/emprestige/respiratory-virus-unspecified-exclusion-primary-care/26302fef", - "url": "https://www.opencodelists.org/codelist/user/emprestige/respiratory-virus-unspecified-exclusion-primary-care/26302fef/", + "id": "user/emprestige/respiratory-virus-unspecified-exclusion-primary-care/3159d510", + "url": "https://www.opencodelists.org/codelist/user/emprestige/respiratory-virus-unspecified-exclusion-primary-care/3159d510/", "downloaded_at": "2024-02-19 15:49:03.098150Z", "sha": "9f21dfc30d93a543736a62ed37c3a20f2c3e09ec" }, "user-emprestige-respiratory-virus-unspecified-identification-secondary-care.csv": { - "id": "user/emprestige/respiratory-virus-unspecified-identification-secondary-care/12863ca6", - "url": "https://www.opencodelists.org/codelist/user/emprestige/respiratory-virus-unspecified-identification-secondary-care/12863ca6/", - "downloaded_at": "2024-02-19 15:49:03.281957Z", - "sha": "d1d7d3df58785e7f54f1f6c66afa68baa4ee6a07" + "id": "user/emprestige/respiratory-virus-unspecified-identification-secondary-care/4d1c083b", + "url": "https://www.opencodelists.org/codelist/user/emprestige/respiratory-virus-unspecified-identification-secondary-care/4d1c083b/", + "downloaded_at": "2024-02-23 14:09:43.657149Z", + "sha": "0a22905a56bb46c3c5d483f8d0a3cf516121c75f" + }, + "opensafely-copd-exacerbation.csv": { + "id": "opensafely/copd-exacerbation/6858db5b", + "url": "https://www.opencodelists.org/codelist/opensafely/copd-exacerbation/6858db5b/", + "downloaded_at": "2024-02-23 14:09:43.764560Z", + "sha": "df8ebce026cf3cbbdde3e32a7698b243019b4175" + }, + "opensafely-asthma-exacerbation-secondary-care.csv": { + "id": "opensafely/asthma-exacerbation-secondary-care/229001a8", + "url": "https://www.opencodelists.org/codelist/opensafely/asthma-exacerbation-secondary-care/229001a8/", + "downloaded_at": "2024-02-23 14:09:43.881803Z", + "sha": "4539261c8a45b1c365f436400026d5859c9a7896" }, "user-emprestige-respiratory-virus-unspecified-exclusion-secondary-care.csv": { "id": "user/emprestige/respiratory-virus-unspecified-exclusion-secondary-care/0fd37cb0", diff --git a/codelists/codelists.txt b/codelists/codelists.txt index fd49e29..4305f11 100644 --- a/codelists/codelists.txt +++ b/codelists/codelists.txt @@ -1,4 +1,4 @@ -opensafely/ethnicity-snomed-0removed/2e641f61 +opensafely/ethnicity-snomed-0removed/2e641f61/ user/emprestige/rsv-identification-primary-care/47b6884f/ @@ -26,52 +26,56 @@ user/emprestige/influenza-exclusion-primary-care-maximal-sensitivity/6ad3b0ca/ user/emprestige/acute-respiratory-illness-secondary-care/1a3fd73f/ user/emprestige/influenza-exclusion-secondary-care-maximal-sensitivity/38b4ca60/ -user/emprestige/respiratory-virus-unspecified-identification-primary-care/2b95afdb/ -user/emprestige/respiratory-virus-unspecified-exclusion-primary-care/26302fef/ -user/emprestige/respiratory-virus-unspecified-identification-secondary-care/12863ca6/ +user/emprestige/respiratory-virus-unspecified-identification-primary-care/662b7b70/ +bristol/copd-exacerbations-snomed/162ebd1c/ +bristol/asthma_exacerbations_snomed/137bfd26/ +user/emprestige/respiratory-virus-unspecified-exclusion-primary-care/3159d510/ +user/emprestige/respiratory-virus-unspecified-identification-secondary-care/4d1c083b/ +opensafely/copd-exacerbation/6858db5b/ +opensafely/asthma-exacerbation-secondary-care/229001a8/ user/emprestige/respiratory-virus-unspecified-exclusion-secondary-care/0fd37cb0/ -opensafely/smoking-clear/2020-04-29 -opensafely/smoking-unclear/2020-04-29 -user/angel-wong/hazardous-drinking/3c786eff -nhsd-primary-care-domain-refsets/illsub_cod/20210127 -nhsd-primary-care-domain-refsets/illsubint_cod/20210127 -nhsd-primary-care-domain-refsets/illsubassdec_cod/20200812 +opensafely/smoking-clear/2020-04-29/ +opensafely/smoking-unclear/2020-04-29/ +user/angel-wong/hazardous-drinking/3c786eff/ +nhsd-primary-care-domain-refsets/illsub_cod/20210127/ +nhsd-primary-care-domain-refsets/illsubint_cod/20210127/ +nhsd-primary-care-domain-refsets/illsubassdec_cod/20200812/ -opensafely/chronic-cardiac-disease/2020-04-08 -nhsd-primary-care-domain-refsets/pulmohyp_cod/20210127 -nhsd-primary-care-domain-refsets/carehome_cod/20211221 -nhsd-primary-care-domain-refsets/tempcarhome_cod/20200812 +opensafely/chronic-cardiac-disease/2020-04-08/ +nhsd-primary-care-domain-refsets/pulmohyp_cod/20210127/ +nhsd-primary-care-domain-refsets/carehome_cod/20211221/ +nhsd-primary-care-domain-refsets/tempcarhome_cod/20200812/ -primis-covid19-vacc-uptake/ast/v2.5 -primis-covid19-vacc-uptake/astrxm1/v2.5 -primis-covid19-vacc-uptake/astrxm2/v2.5 -nhsd-primary-care-domain-refsets/copd_cod/20210127 -user/emprestige/copd-medications-new-dmd/1f3d48e5 -nhsd-primary-care-domain-refsets/copdres_cod/20200812 -bristol/ild-snomed/2f3e3051 -opensafely/cystic-fibrosis/2020-07-20 -primis-covid19-vacc-uptake/diab/v2.5 -primis-covid19-vacc-uptake/dmres/v2.5 -primis-covid19-vacc-uptake/addis_cod/v2.5 -primis-covid19-vacc-uptake/bmi/v2.5 -primis-covid19-vacc-uptake/bmi_stage/v2.5 -primis-covid19-vacc-uptake/sev_obesity/v2.5 -primis-covid19-vacc-uptake/chd_cov/v2.5 -primis-covid19-vacc-uptake/ckd_cov/v2.5 -primis-covid19-vacc-uptake/ckd15/v2.5 -primis-covid19-vacc-uptake/ckd35/v2.5 -primis-covid19-vacc-uptake/cld/v2.5 -primis-covid19-vacc-uptake/resp_cov/v2.5 -primis-covid19-vacc-uptake/cns_cov/v2.5 -opensafely/cancer-excluding-lung-and-haematological-snomed/2020-04-15 -opensafely/haematological-cancer-snomed/2020-04-15 -opensafely/lung-cancer-snomed/2020-04-15 -primis-covid19-vacc-uptake/dxt_chemo_cod/v2.5 -primis-covid19-vacc-uptake/immdx_cov/v2.5 -primis-covid19-vacc-uptake/immrx/v2.5 -primis-covid19-vacc-uptake/immunosuppression-admin-codes/v2.5 +primis-covid19-vacc-uptake/ast/v2.5/ +primis-covid19-vacc-uptake/astrxm1/v2.5/ +primis-covid19-vacc-uptake/astrxm2/v2.5/ +nhsd-primary-care-domain-refsets/copd_cod/20210127/ +user/emprestige/copd-medications-new-dmd/1f3d48e5/ +nhsd-primary-care-domain-refsets/copdres_cod/20200812/ +bristol/ild-snomed/2f3e3051/ +opensafely/cystic-fibrosis/2020-07-20/ +primis-covid19-vacc-uptake/diab/v2.5/ +primis-covid19-vacc-uptake/dmres/v2.5/ +primis-covid19-vacc-uptake/addis_cod/v2.5/ +primis-covid19-vacc-uptake/bmi/v2.5/ +primis-covid19-vacc-uptake/bmi_stage/v2.5/ +primis-covid19-vacc-uptake/sev_obesity/v2.5/ +primis-covid19-vacc-uptake/chd_cov/v2.5/ +primis-covid19-vacc-uptake/ckd_cov/v2.5/ +primis-covid19-vacc-uptake/ckd15/v2.5/ +primis-covid19-vacc-uptake/ckd35/v2.5/ +primis-covid19-vacc-uptake/cld/v2.5/ +primis-covid19-vacc-uptake/resp_cov/v2.5/ +primis-covid19-vacc-uptake/cns_cov/v2.5/ +opensafely/cancer-excluding-lung-and-haematological-snomed/2020-04-15/ +opensafely/haematological-cancer-snomed/2020-04-15/ +opensafely/lung-cancer-snomed/2020-04-15/ +primis-covid19-vacc-uptake/immdx_cov/v2.5/ +primis-covid19-vacc-uptake/immrx/v2.5/ +primis-covid19-vacc-uptake/immunosuppression-admin-codes/v2.5/ +primis-covid19-vacc-uptake/dxt_chemo_cod/v2.5/ opensafely/sickle-cell-disease-snomed/2020-04-14/ -nhsd-primary-care-domain-refsets/hf_cod/20210127 -nhsd-primary-care-domain-refsets/mi_cod/20210127 \ No newline at end of file +nhsd-primary-care-domain-refsets/hf_cod/20210127/ +nhsd-primary-care-domain-refsets/mi_cod/20210127/ \ No newline at end of file diff --git a/codelists/opensafely-asthma-exacerbation-secondary-care.csv b/codelists/opensafely-asthma-exacerbation-secondary-care.csv new file mode 100644 index 0000000..0944747 --- /dev/null +++ b/codelists/opensafely-asthma-exacerbation-secondary-care.csv @@ -0,0 +1,3 @@ +code,term +J45,Asthma +J46,Status asthmaticus diff --git a/codelists/opensafely-copd-exacerbation.csv b/codelists/opensafely-copd-exacerbation.csv new file mode 100644 index 0000000..23bbd23 --- /dev/null +++ b/codelists/opensafely-copd-exacerbation.csv @@ -0,0 +1,3 @@ +code,term +J440,Chronic obstructive pulmonary disease with acute lower respiratory infection +J441,"Chronic obstructive pulmonary disease with acute exacerbation, unspecified" diff --git a/codelists/user-emprestige-respiratory-virus-unspecified-identification-primary-care.csv b/codelists/user-emprestige-respiratory-virus-unspecified-identification-primary-care.csv index 4139e8a..966388d 100644 --- a/codelists/user-emprestige-respiratory-virus-unspecified-identification-primary-care.csv +++ b/codelists/user-emprestige-respiratory-virus-unspecified-identification-primary-care.csv @@ -1,42 +1,23 @@ code,term -1010619008,Inflammatory tracheobronchial papilloma -1010634002,Pneumonia caused by Acinetobacter 102453009,Peritonsillar cellulitis 10351008,Suppurative tonsillitis 10509002,Acute bronchitis 10625751000119106,Bronchopneumonia due to virus -10692681000119108,Aspirin exacerbated respiratory disease 10809006,Parainfluenza virus laryngotracheitis -1082721000119101,Pneumonia caused by Ascaris -1087061000119106,Gonococcal pneumonia 1092361000119109,Rubella pneumonia -1092951000119106,Pneumonia caused by Bordetella parapertussis 111274000,Acute abscess of nasal sinus 11134001,Acute suppuration of sphenoidal sinus 111849006,Adenoviral bronchitis -111900000,Pneumonia in aspergillosis -11316005,Granuloma of vocal cords -1149093006,Pneumonia caused by vancomycin resistant Enterococcus -1172606002,Idiopathic pleuroparenchymal fibroelastosis -1176988004,Pneumonia caused by genus Enterobacter 117723004,Infectious bronchitis virus genotype determination 1187256004,Viral pneumonia due to infectious mononucleosis caused by human herpesvirus 4 -1208602000,Pneumonia caused by Pseudomonas aeruginosa -12181000119103,Contact granuloma of larynx 122403008,Infectious bronchitis virus culture 123587001,Acute bronchopneumonia 123588006,Confluent bronchopneumonia with abscess formation -123589003,Necrotizing bronchopneumonia 123590007,Focal pneumonia 123591006,Confluent pneumonia 123592004,Acute mucous pneumonia -124691000119101,Pneumonia caused by methicillin resistant Staphylococcus aureus -1282001,Perichondritis of larynx 128711000119106,Pneumonia caused by methicillin susceptible Staphylococcus aureus 129451001,Respiratory bronchiolitis associated interstitial lung disease -129452008,Nonspecific interstitial pneumonia -129458007,Bronchiolitis obliterans organizing pneumonia -129459004,Acute interstitial pneumonia 13266007,Sphenoidal sinusitis 133171000119105,Chronic pharyngolaryngitis 13617004,Tracheobronchitis @@ -55,20 +36,14 @@ code,term 155549005,Viral pneumonia 155551009,Bronchopneumonia 155552002,Pneumonia NOS -155553007,Bacterial pneumonia NOS 155558003,Pneumonia NOS 155616009,Bronchitis NOS -157109005,Congenital pneumonia 15805002,Acute sinusitis -16036000,Acute empyema of frontal sinus 16146001,Viral bronchitis -164256007,On examination - follicular tonsillitis 17357005,Acute suppuration of frontal sinus 17741008,Acute tonsillitis 17904003,Hypertrophic laryngitis -181007,Hemorrhagic bronchopneumonia 18643000,Ethmoidal sinusitis -187052004,Pulmonary African histoplasmosis 195649005,Sinusitis (& acute) 195651009,Other acute sinusitis 195652002,Other acute sinusitis NOS @@ -110,25 +85,11 @@ code,term 195811008,Chronic simple laryngitis 195812001,Chronic catarrhal laryngitis 195813006,Chronic hyperplastic laryngitis -195854003,Fibrinous chorditis -195855002,Chorditis vocalis inferior 195880002,Viral pneumonia (& chest infection) -195881003,Pneumonia caused by respiratory syncytial virus 195882005,Viral pneumonia NEC 195883000,Viral pneumonia NOS -195886008,Group B streptococcal pneumonia -195888009,Proteus pneumonia -195889001,Legionella pneumonia -195892002,Bacterial pneumonia NOS -195896004,Pneumonia caused by pleuropneumonia-like organism 195899006,(Pneumonia) or (chest infection) with infectious diseases EC -195900001,Pneumonia due to measles -195902009,Anthrax pneumonia -195904005,Pneumonia with coccidioidomycosis 195907003,Pneumonia with other infectious diseases EC -195908008,Actinomycotic pneumonia -195909000,Nocardial pneumonia -195911009,Chickenpox pneumonia 195912002,Pneumonia with other infectious diseases EC NOS 195913007,Pneumonia with infectious diseases EC NOS 195914001,Bronchopneumonia: [unspecified organism] or [chest infection - unspecified] @@ -145,64 +106,19 @@ code,term 196196007,[X]Other acute sinusitis 196204006,[X]Other viral pneumonia 198691000000108,Acute obstructive laryngitis -206283000,Congenital staphylococcal pneumonia -206284006,Congenital group A hemolytic streptococcal pneumonia -206285007,Congenital group B hemolytic streptococcal pneumonia -206286008,Congenital Escherichia coli pneumonia -206287004,Congenital pseudomonal pneumonia -206288009,Congenital viral pneumonia -206289001,Congenital chlamydial pneumonia -206290005,Other specified congenital pneumonia -206291009,Congenital pneumonia NOS -21060003,Acute bacterial epiglottitis 214081000000107,Acute obstructive laryngitis 222008,Acute epiglottitis with obstruction 22754005,Staphylococcal pneumonia 22951000119104,Spasmodic croup -232389000,Pott's puffy tumor 232390009,Suppurative sinusitis with complications 232426008,Acute simple laryngitis 232428009,Acute membranous laryngitis 232429001,Acute subglottic laryngitis 232432003,Pediatric acute epiglottitis and supraglottitis 232433008,Adult acute epiglottitis and supraglottitis -232434002,Chronic fungal laryngitis -232439007,Relapsing polychondritis of larynx -232458003,Laryngeal sarcoidosis -232460001,Granulomatosis with polyangiitis of larynx 233597004,Chest infection - unspecified bronchitis 233601004,Acute viral bronchitis 233604007,Pneumonia -233606009,Atypical pneumonia -233607000,Pneumococcal pneumonia -233608005,Meningococcal pneumonia -233609002,Pneumonia caused by Chlamydiaceae -233610007,Neonatal chlamydial pneumonia -233611006,Fetal pneumonia -233612004,Fetal pneumonia -233613009,Fungal pneumonia -233614003,Pulmonary mucormycosis -233617005,Hemorrhagic pneumonia -233618000,Mycobacterial pneumonia -233619008,Neonatal pneumonia -233620002,Pneumonia due to parasitic infestation -233621003,Rickettsial pneumonia -233622005,Infectious mononucleosis pneumonia -233623000,Mononuclear interstitial pneumonia -233624006,Herpes simplex pneumonia -233625007,Giant cell pneumonia -233713004,Seasonal cryptogenic organizing pneumonia with biochemical cholestasis -233799004,Acute toxic tracheobronchitis -236302005,Acute interstitial pneumonia -23884004,Acute suppuration of maxillary sinus -240387006,Pulmonary glanders -240391001,Pulmonary melioidosis -240635003,Pneumonia caused by Leishmania -240741002,Acute pulmonary African histoplasmosis -24347001,Cellulitis of vocal cords -2523007,Salmonella pneumonia -25764005,Acute abscess of frontal sinus -262678008,Post-radiotherapy laryngitis 266337001,Acute epiglottitis (non-streptococcal) 266350000,Pneumococcal lobar pneumonia 266351001,Pneumonia with infectious diseases EC @@ -211,23 +127,13 @@ code,term 266378004,(Acute sinusitis: [NOS] or [ethmoidal] or [sphenoidal]) or ([pansinusitis]) 266380005,Acute: [bronchitis] or [chest infections] or [tracheobronchitis] 26650005,Acute tracheitis -26808007,Polypoid sinus degeneration -27278006,Acute empyema of sphenoidal sinus 274103002,Pneumonia NOS 275483004,Sinusitis 275484005,Maxillary sinusitis 275485006,Frontal sinusitis -275495004,Acute fibrinous laryngotracheobronchitis 275499005,Acute wheezy bronchitis 276443001,Acute laryngitis and/or tracheitis -276692000,Congenital viral pneumonia -276693005,Congenital bacterial pneumonia -276694004,Acquired neonatal pneumonia -276695003,Neonatal aspiration pneumonia -277869007,Non-tuberculous mycobacterial pneumonia 278516003,Lobar pneumonia -27878001,Follicular tonsillitis -28709001,Cellulitis of larynx 29591002,Purulent bronchitis 29608009,Acute epiglottitis 29951006,Chronic laryngitis @@ -249,172 +155,87 @@ code,term 312423006,Infective laryngitis 312424000,Infective tonsillitis 313281000000109,Acute rhinosinusitis -314978007,Postoperative pneumonia -31561003,Hypostatic bronchopneumonia -32204007,Pulmonary actinobacillosis -32286006,Pneumonia in Q fever 32398004,Bronchitis -32904004,Pneumococcal laryngitis 338111000000109,Acute rhinosinusitis 34020007,Pneumonia caused by Streptococcus -3487004,Candidiasis of lung -35031000119100,Acute aspiration pneumonia -35037009,Primary atypical interstitial pneumonia -35168006,Acute empyema of ethmoidal sinus 35301006,Acute tracheobronchitis 35339003,Primary pneumonic plague 36426008,Subacute bronchitis 36971009,Sinusitis -371103000,Granulomatous epiglottitis 371127003,Obstructive sinusitis 37426002,Ulcerative laryngitis 37948003,Acute laryngotracheitis without obstruction -38699009,Pneumonia caused by Histoplasma capsulatum -38976008,Pneumonic plague -39172002,Pneumonia caused by Proteus mirabilis 396284006,Lobular pneumonia 396285007,Bronchopneumonia 396286008,Bilateral bronchopneumonia -401300000,Atypical pneumonia screening test -40451000000103,Atypical pneumonia screening test -406529000,Pneumonia severity index 407671000,Bilateral pneumonia 408669002,Acute laryngitis with obstruction -408680002,Healthcare associated bacterial pneumonia -408681003,Healthcare associated legionnaire's disease -409664000,Pneumonia caused by anaerobic bacteria -409665004,Pneumonia caused by aerobic bacteria -41048006,Haemophilus influenzae laryngitis -41207000,Adenoviral pneumonia -41381004,Pneumonia caused by Pseudomonas -415125002,Pneumocystosis jirovecii pneumonia 41931000119102,Sinusitis co-occurrent with nasal polyps -422588002,Aspiration pneumonia -425464007,Nosocomial pneumonia -425996009,Bilateral basal pneumonia 426696003,Lingular pneumonia -42761000000106,Atypical pneumonia screening test -427780002,Laryngitis due to gastroesophageal reflux 429381000000103,[X]Other viral pneumonia 430395005,Pneumonia caused by Gram negative bacteria -430969000,Recurrent aspiration pneumonia 431231008,Acute rhinosinusitis -438764004,Postoperative aspiration pneumonia 441551009,Inflammation of larynx caused by virus 441590008,Pneumonia caused by Severe acute respiratory syndrome coronavirus -441658007,Pneumonia caused by Staphylococcus aureus -441942006,Pneumonia caused by infection caused by Streptococcus pyogenes -442094008,Pneumonia caused by Histoplasma -44274007,Lymphoid interstitial pneumonia 444814009,Viral sinusitis 445096001,Pneumonia caused by Human metapneumovirus -44549008,Aspiration pneumonia resulting from a procedure -45157009,Idiopathic fibrosing alveolitis -45312009,Pneumonia in typhoid fever 454211000000100,[X]Other acute sinusitis -45556008,Pulmonary tularemia -45841000000109,Atypical pneumonia screening test 45913009,Laryngitis -471272001,Cavitary pneumonia -49908003,Acute epiglottitis without obstruction -5028002,Acute pansinusitis -50804000,Catarrhal pneumonia 51209006,Viral tonsillitis -51530003,Pneumonia caused by Escherichia coli -53084003,Bacterial pneumonia 532291000000105,Pneumonia with infectious diseases EC -53926002,Plastic bronchitis -54287007,Ozena laryngis 55130001,Laryngotracheitis 55355000,Acute laryngopharyngitis -55419007,Tuberculosis of glottis 55679008,Peribronchial pneumonia -566801000000107,Other specified congenital pneumonia 576581000000107,Acute viral laryngitis unspecified 57702005,Unresolved pneumonia -57713008,Inflammation of vocal cord -58576005,Haemophilus influenzae epiglottitis 5875001,Acute bronchitis with obstruction -58763001,Acute empyema of nasal sinus -59454008,Laryngitis sicca -59475000,Pneumonia in pertussis 59967003,Acute laryngotracheitis with obstruction 600981000000100,Other acute sinusitis NOS 600991000000103,Acute sinusitis NOS 603091000000105,Acute laryngitis NOS 603111000000100,Pneumonia with other infectious diseases EC 603131000000108,Acute laryngitis and tracheitis NOS -603201000000106,Congenital pneumonia NOS 60363000,Pneumonia 60485005,Pleurobronchopneumonia 607911000000108,Other acute sinusitis 616111000000105,Pneumonia with other infectious diseases EC NOS 616131000000102,Pneumonia with infectious diseases EC NOS 616141000000106,Pneumonia due to unspecified organism -61711004,Acute abscess of ethmoidal sinus 617941000000107,Viral pneumonia NEC 617951000000105,Viral pneumonia NOS 617981000000104,Bacterial pneumonia NOS -61884008,Achromobacter pneumonia 621011000000106,Acute bronchitis NOS 623471000000106,Acute tonsillitis NOS 63140003,Acute suppuration of ethmoidal sinus 64369009,Acute tracheitis without obstruction 64375000,Acute laryngotracheitis 644261000000103,Chest infection - unspecified bronchitis -64667001,Interstitial pneumonia 64703005,Terminal bronchopneumonia 649111000000109,Tracheobronchitis NOS 649121000000103,Bronchitis NOS 64917006,Parainfluenza virus pneumonia 651931000000103,Subacute bronchitis unspecified 651941000000107,Acute viral bronchitis unspecified -652005,Gangrenous tonsillitis 652331000000107,Basal pneumonia due to unspecified organism 656891000000102,Lobar pneumonia due to unspecified organism 65878001,Septic bronchitis 66429007,Unresolved lobar pneumonia 6655004,Acute laryngitis 670561000000106,Bronchitis unspecified -67525007,Secondary pneumonic plague 677801000000109,Pneumonia NOS 67814005,Bronchopneumonia 67832005,Acute ethmoidal sinusitis 68272006,Acute maxillary sinusitis -68409003,Organized pneumonia 689401000000108,Bronchopneumonia due to unspecified organism 699014000,Recurrent pneumonia -700249006,Idiopathic interstitial pneumonia -70036007,Haemophilus influenzae pneumonia -70341005,Tuberculous laryngitis -7063008,Gangrenous pneumonia -707503004,Pneumonia caused by Schistosoma mansoni -707507003,Pneumonia caused by Schistosoma japonicum -707508008,Pneumonia caused by Schistosoma haematobium -708031000,Idiopathic eosinophilic pneumonia 709663002,Supraglottitis 70976000,Viral epiglottitis 71186008,Croup 713084008,Pneumonia caused by Human coronavirus -713525001,Recurrent bacterial pneumonia -713526000,Recurrent bacterial pneumonia co-occurrent with human immunodeficiency virus infection -713544008,Bacterial pneumonia co-occurrent with human immunodeficiency virus infection 714203003,Acute bronchitis co-occurrent with bronchiectasis -719218000,Cryptogenic organizing pneumonia -71926009,Infective pneumonia acquired prenatally 721586007,Pharyngotonsillitis caused by Human herpes simplex virus -72211003,Laryngeal granuloma -724499007,Idiopathic acute eosinophilic pneumonia 725917007,Acute sinusitis caused by virus -72656004,Granulomatous pneumonia -72854003,Aspiration pneumonia due to near drowning -733051000,Pneumonia caused by Gram positive bacteria -75426006,Aspiration pneumonia caused by regurgitated food 75570004,Viral pneumonia -76090006,Pittsburgh pneumonia -763888005,Necrotizing pneumonia caused by Panton-Valentine leukocidin producing Staphylococcus aureus -76511000000100,Atypical pneumonia screening test -76653009,Acute empyema of maxillary sinus 7678002,Cytomegaloviral pneumonia 77919000,Acute sphenoidal sinusitis 785728005,Bronchitis co-occurrent with wheeze @@ -422,25 +243,17 @@ code,term 785744001,Bronchitis co-occurrent with acute wheeze 785745000,Acute bronchitis co-occurrent with wheeze 78737005,Frontal sinusitis -78895009,Congenital pneumonia -80003002,Tuberculous pneumonia 80257001,Acute bronchitis with bronchospasm 80384002,Epiglottitis 80600003,Acute suppuration of nasal sinus 80771000000105,Atypical pneumonia screening test -81164001,Ornithosis with pneumonia 82690000,Suppurative laryngitis 83271005,Chronic laryngotracheitis 84753008,Pneumonia in systemic mycosis 85083002,Streptococcal laryngitis 8519009,Acute tracheitis with obstruction -85469005,Hypostatic pneumonia -8549006,Desquamative interstitial pneumonia 85832003,Parainfluenza virus laryngitis 85915003,Laryngotracheobronchitis -866901000000103,Eosinophilic bronchitis -86773000,Edematous laryngitis -870573008,Interstitial pneumonia with autoimmune features 878818001,Pharyngotonsillitis 882784691000119100,Pneumonia caused by severe acute respiratory syndrome coronavirus 2 88348008,Maxillary sinusitis @@ -449,5 +262,3 @@ code,term 897656009,Rhinosinusitis 90176007,Tonsillitis 91038008,Acute frontal sinusitis -99251000000100,Bilateral pneumonia -993251000000108,Atypical pneumonia screening test diff --git a/codelists/user-emprestige-respiratory-virus-unspecified-identification-secondary-care.csv b/codelists/user-emprestige-respiratory-virus-unspecified-identification-secondary-care.csv index d01e063..ddea289 100644 --- a/codelists/user-emprestige-respiratory-virus-unspecified-identification-secondary-care.csv +++ b/codelists/user-emprestige-respiratory-virus-unspecified-identification-secondary-care.csv @@ -26,13 +26,9 @@ J171,Pneumonia in viral diseases classified elsewhere J178,Pneumonia in other diseases classified elsewhere J180,"Bronchopneumonia, unspecified" J181,"Lobar pneumonia, unspecified" -J182,"Hypostatic pneumonia, unspecified" J189,"Pneumonia, unspecified" J20,Acute bronchitis J208,Acute bronchitis due to other specified organisms J209,"Acute bronchitis, unspecified" J40,"Bronchitis, not specified as acute or chronic" J851,Abscess of lung with pneumonia -P23,Congenital pneumonia -P230,Congenital pneumonia due to viral agent -P239,"Congenital pneumonia, unspecified" diff --git a/project.yaml b/project.yaml index bc44a51..2039cc8 100644 --- a/project.yaml +++ b/project.yaml @@ -13,105 +13,98 @@ actions: generate_dataset_older_adults_s1_spec: run: > ehrql:v1 generate-dataset analysis/dataset_definition.py - --output output/input_older_adults_2016_2017_spec.arrow + --output output/input_older_adults_2016_2017_specific_primary.arrow --dummy-data-file analysis/dummydata/dummyextract_older_adults_2016_2017.arrow -- older_adults season1_start_date season1_end_date specific primary outputs: highly_sensitive: - dataset: output/input_older_adults_2016_2017_spec.arrow - + dataset: output/input_older_adults_2016_2017_specific_primary.arrow process_dataset_older_adults_s1_spec: run: r:latest analysis/data_processing.R older_adults season1_start_date season1_end_date specific primary needs: [generate_dataset_older_adults_s1_spec] outputs: highly_sensitive: - cohort: output/input_processed_older_adults_2016_2017_spec.arrow - + cohort: output/input_processed_older_adults_2016_2017_specific_primary.arrow describe_dataset_older_adults_s1_spec: run: r:latest analysis/report.R older_adults season1_start_date season1_end_date specific primary needs: [process_dataset_older_adults_s1_spec] outputs: moderately_sensitive: - cohort: output/descriptive_older_adults_2016_2017_spec.png + cohort: output/descriptive_older_adults_2016_2017_specific_primary.png generate_dataset_adults_s1_spec: run: > ehrql:v1 generate-dataset analysis/dataset_definition.py - --output output/input_adults_2016_2017_spec.arrow + --output output/input_adults_2016_2017_specific_primary.arrow --dummy-data-file analysis/dummydata/dummyextract_adults_2016_2017.arrow -- adults season1_start_date season1_end_date specific primary outputs: highly_sensitive: - dataset: output/input_adults_2016_2017_spec.arrow + dataset: output/input_adults_2016_2017_specific_primary.arrow process_dataset_adults_s1_spec: run: r:latest analysis/data_processing.R adults season1_start_date season1_end_date specific primary needs: [generate_dataset_adults_s1_spec] outputs: highly_sensitive: - cohort: output/input_processed_adults_2016_2017_spec.arrow - + cohort: output/input_processed_adults_2016_2017_specific_primary.arrow describe_dataset_adults_s1_spec: run: r:latest analysis/report.R adults season1_start_date season1_end_date specific primary needs: [process_dataset_adults_s1_spec] outputs: moderately_sensitive: - cohort: output/descriptive_adults_2016_2017_spec.png + cohort: output/descriptive_adults_2016_2017_specific_primary.png generate_dataset_children_adolescents_s1_spec: run: > ehrql:v1 generate-dataset analysis/dataset_definition.py - --output output/input_children_adolescents_2016_2017_spec.arrow + --output output/input_children_adolescents_2016_2017_specific_primary.arrow --dummy-data-file analysis/dummydata/dummyextract_children_adolescents_2016_2017.arrow -- children_and_adolescents season1_start_date season1_end_date specific primary outputs: highly_sensitive: - dataset: output/input_children_adolescents_2016_2017_spec.arrow - + dataset: output/input_children_adolescents_2016_2017_specific_primary.arrow process_dataset_children_adolescents_s1_spec: run: r:latest analysis/data_processing.R children_adolescents season1_start_date season1_end_date specific primary needs: [generate_dataset_children_adolescents_s1_spec] outputs: highly_sensitive: - cohort: output/input_processed_children_adolescents_2016_2017_spec.arrow - + cohort: output/input_processed_children_adolescents_2016_2017_specific_primary.arrow describe_dataset_children_adolescents_s1_spec: run: r:latest analysis/report.R children_adolescents season1_start_date season1_end_date specific primary needs: [process_dataset_children_adolescents_s1_spec] outputs: moderately_sensitive: - cohort: output/descriptive_children_adolescents_2016_2017_spec.png + cohort: output/descriptive_children_adolescents_2016_2017_specific_primary.png generate_dataset_infants_s1_spec: run: > ehrql:v1 generate-dataset analysis/dataset_definition.py - --output output/input_infants_2016_2017_spec.arrow + --output output/input_infants_2016_2017_specific_primary.arrow --dummy-data-file analysis/dummydata/dummyextract_infants_2016_2017.arrow -- infants season1_start_date season1_end_date specific primary outputs: highly_sensitive: - dataset: output/input_infants_2016_2017_spec.arrow + dataset: output/input_infants_2016_2017_specific_primary.arrow process_dataset_infants_s1_spec: run: r:latest analysis/data_processing.R infants season1_start_date season1_end_date specific primary needs: [generate_dataset_infants_s1_spec] outputs: highly_sensitive: - cohort: output/input_processed_infants_2016_2017_spec.arrow - + cohort: output/input_processed_infants_2016_2017_specific_primary.arrow describe_dataset_infants_s1_spec: run: r:latest analysis/report.R infants season1_start_date season1_end_date specific primary needs: [process_dataset_infants_s1_spec] outputs: moderately_sensitive: - cohort: output/descriptive_infants_2016_2017_spec.png - + cohort: output/descriptive_infants_2016_2017_specific_primary.png ### sensitivity analysis @@ -120,102 +113,139 @@ actions: generate_dataset_older_adults_s1_sens: run: > ehrql:v1 generate-dataset analysis/dataset_definition.py - --output output/input_older_adults_2016_2017_sens.arrow + --output output/input_older_adults_2016_2017_sensitive_primary.arrow --dummy-data-file analysis/dummydata/dummyextract_older_adults_2016_2017.arrow -- older_adults season1_start_date season1_end_date sensitive primary outputs: highly_sensitive: - dataset: output/input_older_adults_2016_2017_sens.arrow - + dataset: output/input_older_adults_2016_2017_sensitive_primary.arrow process_dataset_older_adults_s1_sens: run: r:latest analysis/data_processing.R older_adults season1_start_date season1_end_date sensitive primary needs: [generate_dataset_older_adults_s1_sens] outputs: highly_sensitive: - cohort: output/input_processed_older_adults_2016_2017_sens.arrow - + cohort: output/input_processed_older_adults_2016_2017_sensitive_primary.arrow describe_dataset_older_adults_s1_sens: run: r:latest analysis/report.R older_adults season1_start_date season1_end_date sensitive primary needs: [process_dataset_older_adults_s1_sens] outputs: moderately_sensitive: - cohort: output/descriptive_older_adults_2016_2017_sens.png + cohort: output/descriptive_older_adults_2016_2017_sensitive_primary.png generate_dataset_adults_s1_sens: run: > ehrql:v1 generate-dataset analysis/dataset_definition.py - --output output/input_adults_2016_2017_sens.arrow + --output output/input_adults_2016_2017_sensitive_primary.arrow --dummy-data-file analysis/dummydata/dummyextract_adults_2016_2017.arrow -- adults season1_start_date season1_end_date sensitive primary outputs: highly_sensitive: - dataset: output/input_adults_2016_2017_sens.arrow + dataset: output/input_adults_2016_2017_sensitive_primary.arrow process_dataset_adults_s1_sens: run: r:latest analysis/data_processing.R adults season1_start_date season1_end_date sensitive primary needs: [generate_dataset_adults_s1_sens] outputs: highly_sensitive: - cohort: output/input_processed_adults_2016_2017_sens.arrow - + cohort: output/input_processed_adults_2016_2017_sensitive_primary.arrow describe_dataset_adults_s1_sens: run: r:latest analysis/report.R adults season1_start_date season1_end_date sensitive primary needs: [process_dataset_adults_s1_sens] outputs: moderately_sensitive: - cohort: output/descriptive_adults_2016_2017_sens.png + cohort: output/descriptive_adults_2016_2017_sensitive_primary.png generate_dataset_children_adolescents_s1_sens: run: > ehrql:v1 generate-dataset analysis/dataset_definition.py - --output output/input_children_adolescents_2016_2017_sens.arrow + --output output/input_children_adolescents_2016_2017_sensitive_primary.arrow --dummy-data-file analysis/dummydata/dummyextract_children_adolescents_2016_2017.arrow -- children_and_adolescents season1_start_date season1_end_date sensitive primary outputs: highly_sensitive: - dataset: output/input_children_adolescents_2016_2017_sens.arrow - + dataset: output/input_children_adolescents_2016_2017_sensitive_primary.arrow process_dataset_children_adolescents_s1_sens: run: r:latest analysis/data_processing.R children_adolescents season1_start_date season1_end_date sensitive primary needs: [generate_dataset_children_adolescents_s1_sens] outputs: highly_sensitive: - cohort: output/input_processed_children_adolescents_2016_2017_sens.arrow - + cohort: output/input_processed_children_adolescents_2016_2017_sensitive_primary.arrow describe_dataset_children_adolescents_s1_sens: run: r:latest analysis/report.R children_adolescents season1_start_date season1_end_date sensitive primary needs: [process_dataset_children_adolescents_s1_sens] outputs: moderately_sensitive: - cohort: output/descriptive_children_adolescents_2016_2017_sens.png + cohort: output/descriptive_children_adolescents_2016_2017_sensitive_primary.png generate_dataset_infants_s1_sens: run: > ehrql:v1 generate-dataset analysis/dataset_definition.py - --output output/input_infants_2016_2017_sens.arrow + --output output/input_infants_2016_2017_sensitive_primary.arrow --dummy-data-file analysis/dummydata/dummyextract_infants_2016_2017.arrow -- infants season1_start_date season1_end_date sensitive primary outputs: highly_sensitive: - dataset: output/input_infants_2016_2017_sens.arrow + dataset: output/input_infants_2016_2017_sensitive_primary.arrow process_dataset_infants_s1_sens: run: r:latest analysis/data_processing.R infants season1_start_date season1_end_date sensitive primary needs: [generate_dataset_infants_s1_sens] outputs: highly_sensitive: - cohort: output/input_processed_infants_2016_2017_sens.arrow - + cohort: output/input_processed_infants_2016_2017_sensitive_primary.arrow describe_dataset_infants_s1_sens: run: r:latest analysis/report.R infants season1_start_date season1_end_date sensitive primary needs: [process_dataset_infants_s1_sens] outputs: moderately_sensitive: - cohort: output/descriptive_infants_2016_2017_sens.png - + cohort: output/descriptive_infants_2016_2017_sensitive_primary.png + +# ### secondary analysis +# +# ## season 1 (2016/17) +# +# generate_dataset_older_adults_s1_sens_sec: +# run: > +# ehrql:v1 generate-dataset analysis/dataset_definition.py +# --output output/input_older_adults_2016_2017_sens_sec.arrow +# --dummy-data-file analysis/dummydata/dummyextract_older_adults_2016_2017.arrow +# -- older_adults season1_start_date season1_end_date sensitive secondary +# outputs: +# highly_sensitive: +# dataset: output/input_older_adults_2016_2017_sens_sec.arrow +# +# generate_dataset_adults_s1_sens_sec: +# run: > +# ehrql:v1 generate-dataset analysis/dataset_definition.py +# --output output/input_adults_2016_2017_sens_sec.arrow +# --dummy-data-file analysis/dummydata/dummyextract_adults_2016_2017.arrow +# -- adults season1_start_date season1_end_date sensitive secondary +# outputs: +# highly_sensitive: +# dataset: output/input_adults_2016_2017_sens_sec.arrow +# +# generate_dataset_children_adolescents_s1_sens_sec: +# run: > +# ehrql:v1 generate-dataset analysis/dataset_definition.py +# --output output/input_children_adolescents_2016_2017_sens_sec.arrow +# --dummy-data-file analysis/dummydata/dummyextract_children_adolescents_2016_2017.arrow +# -- children_and_adolescents season1_start_date season1_end_date sensitive secondary +# outputs: +# highly_sensitive: +# dataset: output/input_children_adolescents_2016_2017_sens_sec.arrow +# +# generate_dataset_infants_s1_sens_sec: +# run: > +# ehrql:v1 generate-dataset analysis/dataset_definition.py +# --output output/input_infants_2016_2017_sens_sec.arrow +# --dummy-data-file analysis/dummydata/dummyextract_infants_2016_2017.arrow +# -- infants season1_start_date season1_end_date sensitive secondary +# outputs: +# highly_sensitive: +# dataset: output/input_infants_2016_2017_sens_sec.arrow \ No newline at end of file