Skip to content

Commit

Permalink
Make codelist names consistent, and remove repeated codelists.
Browse files Browse the repository at this point in the history
  • Loading branch information
viv3ckj committed Jan 9, 2025
1 parent 339cdfb commit 69b7566
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 41 deletions.
41 changes: 19 additions & 22 deletions analysis/codelists.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,59 @@
category_column="term",
)

acute_otitis_media_tx_cod = codelist_from_csv(
acute_otitis_media_tx_codelist = codelist_from_csv(
"codelists/opensafely-pharmacy-first-acute-otitis-media-treatment-dmd.csv",
column="code",
)

impetigo_treatment_tx_cod = codelist_from_csv(
impetigo_treatment_tx_codelist = codelist_from_csv(
"codelists/opensafely-pharmacy-first-impetigo-treatment-dmd.csv",
column="code",
)

infected_insect_bites_tx_cod = codelist_from_csv(
infected_insect_bites_tx_codelist = codelist_from_csv(
"codelists/opensafely-pharmacy-first-infected-insect-bites-treatment-dmd.csv",
column="code",
)

shingles_treatment_tx_cod = codelist_from_csv(
shingles_treatment_tx_codelist = codelist_from_csv(
"codelists/opensafely-pharmacy-first-shingles-treatment-dmd.csv",
column="code",
)

sinusitis_tx_cod = codelist_from_csv(
sinusitis_tx_codelist = codelist_from_csv(
"codelists/opensafely-pharmacy-first-sinusitis-treatment-dmd.csv",
column="code",
)

sore_throat_tx_cod = codelist_from_csv(
sore_throat_tx_codelist = codelist_from_csv(
"codelists/opensafely-pharmacy-first-sore-throat-treatment-dmd.csv",
column="code",
)

urinary_tract_infection_tx_cod = codelist_from_csv(
urinary_tract_infection_tx_codelist = codelist_from_csv(
"codelists/opensafely-pharmacy-first-urinary-tract-infection-treatment-dmd.csv",
column="code",
)

pharmacy_first_med_codelist = (
acute_otitis_media_tx_cod
+ impetigo_treatment_tx_cod
+ infected_insect_bites_tx_cod
+ shingles_treatment_tx_cod
+ sinusitis_tx_cod
+ sore_throat_tx_cod
+ urinary_tract_infection_tx_cod
acute_otitis_media_tx_codelist
+ impetigo_treatment_tx_codelist
+ infected_insect_bites_tx_codelist
+ shingles_treatment_tx_codelist
+ sinusitis_tx_codelist
+ sore_throat_tx_codelist
+ urinary_tract_infection_tx_codelist
)
# Community Pharmacist Consultation Service for minor illness - 1577041000000109
# Pharmacy First service - 983341000000102
# Community Pharmacy First Service - 2129921000000100
pharmacy_first_consultation_codelist = ["1577041000000109", "983341000000102", "2129921000000100"]

# PF codes separated for individual analysis
pharmacy_first_event_codes = {
pharmacy_first_event_codelist = {
# Community Pharmacist (CP) Consultation Service for minor illness (procedure)
"consultation_service": ["1577041000000109"],
"pf_consultation_cp_minorillness": ["1577041000000109"],
# Pharmacy First service (qualifier value)
"pharmacy_first_service": ["983341000000102"],
"pf_consultation_service": ["983341000000102"],
# Community Pharmacy Pharmacy First Service
"community_pharmacy_first_service": ["2129921000000100"],
"combined_pf_service": ["1577041000000109", "983341000000102", "2129921000000100"],
"pf_consultation_cp_service": ["2129921000000100"],
"pf_consultation_services_combined": ["1577041000000109", "983341000000102", "2129921000000100"],
}
6 changes: 3 additions & 3 deletions analysis/measures_definition_pf_breakdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)

from pf_dataset import get_latest_ethnicity
from codelists import pharmacy_first_event_codes, pharmacy_first_consultation_codelist
from codelists import pharmacy_first_event_codelist
from config import start_date_measure_pf_breakdown, monthly_intervals_measure_pf_breakdown
from pf_variables_library import select_events

Expand Down Expand Up @@ -59,7 +59,7 @@
otherwise="Missing",
)

pharmacy_first_ids = select_events(clinical_events, codelist=pharmacy_first_consultation_codelist).consultation_id
pharmacy_first_ids = select_events(clinical_events, codelist=pharmacy_first_event_codelist["pf_consultation_services_combined"]).consultation_id

# # Select clinical events in interval date range
selected_events = select_events(clinical_events, start_date=INTERVAL.start_date, end_date=INTERVAL.end_date).where(
Expand All @@ -79,7 +79,7 @@
denominator = registration.exists_for_patient() & patients.sex.is_in(["male", "female"])

# Create measures for pharmacy first services
for pharmacy_first_event, codelist in pharmacy_first_event_codes.items():
for pharmacy_first_event, codelist in pharmacy_first_event_codelist.items():
condition_events = selected_events.where(
selected_events.snomedct_code.is_in(codelist)
)
Expand Down
4 changes: 2 additions & 2 deletions analysis/measures_definition_pf_condition_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
pharmacy_first_conditions_codes,
imd_quintile,
)
from codelists import pharmacy_first_consultation_codelist
from codelists import pharmacy_first_event_codelist
from config import start_date_measure_condition_provider, monthly_intervals_measure_condition_provider
from pf_variables_library import select_events

Expand All @@ -23,7 +23,7 @@
selected_events = select_events(clinical_events, start_date=INTERVAL.start_date, end_date=INTERVAL.end_date)

# Create variable which contains boolean values of whether pharmacy first event exists for patient
has_pharmacy_first = select_events(selected_events, codelist=pharmacy_first_consultation_codelist).exists_for_patient()
has_pharmacy_first = select_events(selected_events, codelist=pharmacy_first_event_codelist["pf_consultation_services_combined"]).exists_for_patient()

for condition_name, condition_code in pharmacy_first_conditions_codes.items():
condition_events = selected_events.where(
Expand Down
4 changes: 2 additions & 2 deletions analysis/measures_definition_pf_consultation_med_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from config import start_date_measure_med_counts, monthly_intervals_measure_med_counts
from codelists import (
pharmacy_first_consultation_codelist,
pharmacy_first_event_codelist,
pharmacy_first_med_codelist,
)
from pf_variables_library import select_events
Expand All @@ -29,7 +29,7 @@
start_date=INTERVAL.start_date,
end_date=INTERVAL.end_date).where(
clinical_events.snomedct_code.is_in(
pharmacy_first_consultation_codelist
pharmacy_first_event_codelist["pf_consultation_services_combined"]
)
)

Expand Down
4 changes: 2 additions & 2 deletions analysis/measures_definition_pf_descriptive_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pf_variables_library import select_events
from codelists import (
pharmacy_first_med_codelist,
pharmacy_first_consultation_codelist,
pharmacy_first_event_codelist,
pharmacy_first_conditions_codelist,
)
from config import (
Expand Down Expand Up @@ -39,7 +39,7 @@
# Select all Pharmacy First consultation events
pf_consultation_events = select_events(
selected_events,
codelist=pharmacy_first_consultation_codelist,
codelist=pharmacy_first_event_codelist["pf_consultation_services_combined"],
)

# Extract Pharmacy First consultation IDs and dates
Expand Down
4 changes: 2 additions & 2 deletions analysis/measures_definition_pf_medications.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
practice_registrations,
)
from ehrql.tables.raw.tpp import medications
from codelists import pharmacy_first_consultation_codelist, pharmacy_first_med_codelist
from codelists import pharmacy_first_event_codelist, pharmacy_first_med_codelist
from config import start_date_measure_medications, monthly_intervals_measure_medications
from pf_variables_library import select_events

Expand All @@ -21,7 +21,7 @@

# Select Pharmacy First consultations during interval date range
pharmacy_first_events = select_events(clinical_events, start_date=INTERVAL.start_date, end_date=INTERVAL.end_date).where(
clinical_events.snomedct_code.is_in(pharmacy_first_consultation_codelist)
clinical_events.snomedct_code.is_in(pharmacy_first_event_codelist["pf_consultation_services_combined"])
)

pharmacy_first_ids = pharmacy_first_events.consultation_id
Expand Down
16 changes: 8 additions & 8 deletions lib/functions/tidy_measures.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Define dictionaries with tidy names and mappings for measures
pf_measures_name_dict <- list(
consultation_service = "Consultation Service",
pharmacy_first_service = "Pharmacy First Consultation",
community_pharmacy_first_service = "Community Pharmacy First Service",
combined_pf_service = "Pharmacy First Consultations (Combined)",
pf_consultation_cp_minorillness = "Consultation Service",
pf_consultation_service = "Pharmacy First Consultation",
pf_consultation_cp_service = "Community Pharmacy First Service",
pf_consultation_services_combined = "Pharmacy First Consultations (Combined)",
acute_otitis_media = "Acute Otitis Media",
herpes_zoster = "Herpes Zoster",
acute_sinusitis = "Acute Sinusitis",
Expand All @@ -14,10 +14,10 @@ pf_measures_name_dict <- list(
)

pf_measures_name_mapping <- list(
consultation_service = "clinical_service",
pharmacy_first_service = "clinical_service",
community_pharmacy_first_service = "clinical_service",
combined_pf_service = "pharmacy_first_services",
pf_consultation_cp_minorillness = "clinical_service",
pf_consultation_service = "clinical_service",
pf_consultation_cp_service = "clinical_service",
pf_consultation_services_combined = "pharmacy_first_services",
acute_otitis_media = "clinical_condition",
herpes_zoster = "clinical_condition",
acute_sinusitis = "clinical_condition",
Expand Down

0 comments on commit 69b7566

Please sign in to comment.