Skip to content

Commit

Permalink
chore: Update external_studies test code
Browse files Browse the repository at this point in the history
  • Loading branch information
opensafely-github-bot committed Dec 15, 2024
1 parent 932e6d5 commit ec2cbe9
Show file tree
Hide file tree
Showing 34 changed files with 8,919 additions and 10,314 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@
column="snomedcode",
category_column="Grouping_6",
)

lowerGI_diagnostic_codes = codelist_from_csv(
"local_codelists/phc-lowergi-endoscopy-hrg.csv", column="code"
)

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from ehrql import case, when, years, days, minimum_of, maximum_of
from ehrql.tables.core import patients, clinical_events
from ehrql.tables.core import patients
from ehrql.tables.tpp import (
addresses,
clinical_events,
practice_registrations)

import codelists
Expand Down Expand Up @@ -29,6 +30,13 @@
clinical_events.date.is_on_or_between(index_date, end_date)
).exists_for_patient()

dataset.colorectal_ca_diag_date = clinical_events.where(clinical_events.snomedct_code.is_in(codelists.colorectal_diagnosis_codes_snomed)
).where(
clinical_events.date.is_on_or_between(index_date, end_date)
).sort_by(
clinical_events.date
).first_for_patient().date

age = patients.age_on(dataset.entry_date)
dataset.age = age
dataset.age_group = case(
Expand Down Expand Up @@ -74,3 +82,29 @@
)

dataset.region = practice_registrations.for_patient_on(dataset.entry_date).practice_nuts1_region_name

def num_event(codelist, l_age, u_age):
return clinical_events.where(clinical_events.snomedct_code.is_in(codelist)
).where(
clinical_events.date.is_on_or_between(index_date, end_date)
).where(
clinical_events.date.is_on_or_between(dataset.entry_date, dataset.exit_date)
).where(
patients.age_on(clinical_events.date)>=l_age
).where(
patients.age_on(clinical_events.date)<u_age
).date.count_episodes_for_patient(days(42))

dataset.num_ida = num_event(codelists.ida_codes, 16, 111)
dataset.num_cibh = num_event(codelists.cibh_codes, 16, 111)
dataset.num_prbleed = num_event(codelists.prbleeding_codes, 16, 111)
dataset.num_wl = num_event(codelists.wl_codes, 16, 111)
dataset.num_abdomass = num_event(codelists.abdomass_codes, 16, 111)
dataset.num_abdopain = num_event(codelists.abdopain_codes, 16, 111)
dataset.num_anaemia = num_event(codelists.anaemia_codes, 16, 111)
dataset.num_prbleed_50 = num_event(codelists.prbleeding_codes, 50, 111)
dataset.num_wl_50 = num_event(codelists.wl_codes, 50, 111)
dataset.num_abdopain_50 = num_event(codelists.abdopain_codes, 50, 111)
dataset.num_anaemia_60 = num_event(codelists.anaemia_codes, 60, 111)

dataset.num_lowerGI_any_symp = num_event(codelists.colorectal_symptom_codes, 16, 111)
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@

measures.define_defaults(intervals=months(intervals).starting_on(start_date))

measures.define_measure(
name="fit_test_rate",
numerator=dataset.fit_test_any,
denominator=dataset.elig_cohort,
group_by={"imd": imd5}
)
#measures.define_measure(
#name="fit_test_rate",
#numerator=dataset.fit_test_any,
#denominator=dataset.elig_cohort,
#group_by={"imd": imd5}
#)

measures.define_measure(
name="ida_symp_rate",
Expand Down Expand Up @@ -120,16 +120,16 @@
group_by={"imd": imd5}
)

measures.define_measure(
name="fit_6_rate",
numerator=dataset.fit_6_all_lowerGI,
denominator=dataset.elig_cohort,
group_by={"imd": imd5}
)

measures.define_measure(
name="ca_6_rate",
numerator=dataset.ca_6_all_lowerGI,
denominator=dataset.lowerGI_any_symp,
group_by={"imd": imd5}
)
#measures.define_measure(
#name="fit_6_rate",
#numerator=dataset.fit_6_all_lowerGI,
#denominator=dataset.elig_cohort,
#group_by={"imd": imd5}
#)

#measures.define_measure(
#name="ca_6_rate",
#numerator=dataset.ca_6_all_lowerGI,
#denominator=dataset.lowerGI_any_symp,
#group_by={"imd": imd5}
#)
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,32 @@
column = "code"
)

# lo_opioid_codes = codelist_from_csv(
# "codelists/opensafely-long-acting-opioids-less-than-50mg-per-day-ome-dmd.csv",
# column = "code"
# )

# med_opioid_codes = codelist_from_csv(
# "codelists/opensafely-long-acting-opioids-50mg-to-119mg-per-day-ome-dmd.csv",
# column = "code"
# )

# hi_opioid_codes = codelist_from_csv(
# "codelists/opensafely-long-acting-opioids-greater-than-or-equal-to-120mg-per-day-ome-dmd.csv",
# column = "code"
# )

long_opioid_codes = codelist_from_csv(
"codelists/user-anschaf-long-acting-opioids-dmd.csv",
column = "code"
)

strong_opioid_codes = codelist_from_csv(
strong_opioid_codes1 = codelist_from_csv(
"codelists/opensafely-strongopioidsCW-dmd.csv",
column = "code"
)

strong_opioid_codes2 = codelist_from_csv(
"codelists/user-anschaf-strong-opioids-exc-tramadol-and-tapentadol-dmd.csv",
column = "code"
)

weak_opioid_codes = codelist_from_csv(
"codelists/user-anschaf-weak-opioids-dmd.csv",
column = "code"
)

moderate_opioid_codes = codelist_from_csv(
"codelists/user-anschaf-tramadol-and-tapentadol-dmd.csv",
column = "code"
)


short_opioid_codes = set(opioid_codes) - set(long_opioid_codes)


Expand Down Expand Up @@ -109,8 +105,8 @@
)

osteoarthritis_codes = codelist_from_csv(
"codelists/opensafely-osteoarthritis.csv",
column = "CTV3ID"
"codelists/user-speed-vm-osteoarthritis-snomed-ct.csv",
column = "code"
)

depression_codes = codelist_from_csv(
Expand All @@ -129,41 +125,65 @@
)

cardiac_codes = codelist_from_csv(
"codelists/opensafely-chronic-cardiac-disease.csv",
column = "CTV3ID"
"codelists/primis-covid19-vacc-uptake-chd_cov.csv",
column = "code"
)

ckd_codes = codelist_from_csv(
"codelists/opensafely-chronic-kidney-disease-snomed.csv",
column = "id"
"codelists/primis-covid19-vacc-uptake-ckd15.csv",
column = "code"
)

liver_codes = codelist_from_csv(
"codelists/opensafely-chronic-liver-disease.csv",
column = "CTV3ID"
"codelists/primis-covid19-vacc-uptake-cld.csv",
column = "code"
)

diabetes_codes = codelist_from_csv(
"codelists/opensafely-diabetes.csv",
column = "CTV3ID"
"codelists/primis-covid19-vacc-uptake-diab.csv",
column = "code"
)

copd_codes = codelist_from_csv(
"codelists/opensafely-chronic-respiratory-disease.csv",
column = "CTV3ID"
"codelists/primis-covid19-vacc-uptake-resp_cov.csv",
column = "code"
)

ra_codes = codelist_from_csv(
"codelists/opensafely-rheumatoid-arthritis.csv",
column = "CTV3ID"
"codelists/user-markdrussell-new-rheumatoid-arthritis.csv",
column = "code"
)

oud_codes = codelist_from_csv(
"codelists/user-hjforbes-opioid-dependency-clinical-diagnosis.csv",
column = "code"
)

pain_codes = codelist_from_csv(
"codelists/opensafely-symptoms-pain.csv",
column = "code"
)
### HRG codes
hip_codes = ["HN12A","HN12B","HN12C","HN12D","HN12E","HN12F","HN13A","HN13B","HN13C","HN13D","HN13E","HN13F","HN13G","HN13H",
"HN14A","HN14B","HN14C","HN14D","HN14E","HN14F","HN14G","HN14H","HN15A","HN15B","HN16A","HN16B","HN16C"]

knee_codes = ["HN22A","HN22B","HN22C","HN22D","HN22E","HN23A","HN23B","HN23C","HN23D","HN23E",
"HN24A","HN24B","HN24C","HN24D","HN24E","HN24F","HN25A","HN25B","HN26A","HN26B","HN26C"]

foot_codes = ["HN32A","HN32B","HN32C","HN33A","HN33B","HN33C","HN33D","HN34A","HN34B","HN34C","HN34D","HN35A","HN35B","HN36Z"]

hand_codes = ["HN42A","HN42B","HN43A","HN43B","HN43C","HN44A","HN44B","HN44C","HN44D","HN45A","HN45B","HN45C","HN46Z"]

shoulder_codes = ["HN52A","HN52B","HN52C","HN53A","HN53B","HN53C",
"HN54A","HN54B","HN54C","HN54D","HN55Z","HN56Z"]

elbow_codes = ["HN62A","HN62B","HN63A","HN63B","HN64A","HN64B","HN64C","HN64D","HN65Z","HN66Z"]

complex_codes = ["HN80A","HN80B","HN80C","HN80D","HN81A","HN81B","HN81C","HN81D","HN81E","HN85Z","HN86A","HN86B","HN93Z"]

pain_codes = ["AB11Z","AB12Z","AB13Z","AB14Z","AB15Z","AB16Z","AB17Z","AB18Z","AB19Z","AB20Z",
"AB21Z","AB22Z","AB23Z","AB24Z","AB25Z","AB26Z","AB27Z","AB28Z"]

trauma_codes = ["HT12A","HT12B","HT12C","HT12D","HT12E","HT13A","HT13B","HT13C","HT13D","HT13E",
"HT14A","HT14B","HT14C","HT15Z","HT22A","HT22B","HT22C","HT23A","HT23B","HT23C","HT23D","HT23E",
"HT24A","HT24B","HT24C","HT24D","HT25Z","HT32A","HT32B","HT32C","HT33A","HT33B","HT33C","HT33D","HT33E",
"HT34A","HT34B","HT34C","HT34D","HT34E","HT35Z","HT42A","HT42B","HT43A","HT43B","HT43C","HT43D","HT43E",
"HT44A","HT44B","HT44C","HT44D","HT44E","HT45Z","HT52A","HT52B","HT52C","HT53A","HT53B","HT53C","HT53D","HT53E",
"HT54A","HT54B","HT54C","HT54D","HT55Z","HT62A","HT62B","HT63A","HT63B","HT63C","HT63D","HT63E","HT63F",
"HT64A","HT64B","HT64C","HT64D","HT65Z","HT81A","HT81B","HT81C","HT81D","HT86A","HT86B","HT86C"]
Loading

0 comments on commit ec2cbe9

Please sign in to comment.