|
15 | 15 | # Pharmacy First service (qualifier value)
|
16 | 16 | "pharmacy_first_service": ["983341000000102"],
|
17 | 17 | }
|
18 |
| -# The following codes come from codelists/user-chriswood-pharmacy-first-clinical-pathway-conditions.csv file. |
19 |
| -# Currently written as a hardcoded dictionary to allow for easy for looping (ln66-83), but will be imported from codelist csv in future commits. |
20 |
| -# Pharmacy First seven clinical conditions codelist |
21 |
| -pharmacy_first_conditions_codes = { |
22 |
| - # Community Pharmacy (CP) Blood Pressure (BP) Check Service (procedure) |
23 |
| - "acute_otitis_media": ["3110003"], |
24 |
| - # Community Pharmacy (CP) Contraception Service (procedure) |
25 |
| - "herpes_zoster": ["4740000"], |
26 |
| - # Community Pharmacist (CP) Consultation Service for minor illness (procedure) |
27 |
| - "acute_sinusitis": ["15805002"], |
28 |
| - # Pharmacy First service (qualifier value) |
29 |
| - "impetigo": ["48277006"], |
30 |
| - # Community Pharmacy (CP) Contraception Service (procedure) |
31 |
| - "infected_insect_bite": ["262550002"], |
32 |
| - # Community Pharmacist (CP) Consultation Service for minor illness (procedure) |
33 |
| - "acute_pharyngitis": ["363746003"], |
34 |
| - # Pharmacy First service (qualifier value) |
35 |
| - "uncomplicated_urinary_tract_infection": ["1090711000000102"], |
36 |
| -} |
37 | 18 |
|
| 19 | +# Import the codelist from CSV |
| 20 | +pharmacy_first_codelist = codelist_from_csv( |
| 21 | + "codelists/user-chriswood-pharmacy-first-clinical-pathway-conditions.csv", |
| 22 | + column="code", category_column = "term" |
| 23 | +) |
| 24 | + |
| 25 | +pharmacy_first_conditions_codes = {} |
| 26 | +# Iterate through codelist, forming a dictionary |
| 27 | +for codes, term in pharmacy_first_codelist.items(): |
| 28 | + normalised_term = term.lower().replace(" ", "_") |
| 29 | + codes = [codes] |
| 30 | + pharmacy_first_conditions_codes[normalised_term] = codes |
| 31 | + |
38 | 32 | registration = practice_registrations.for_patient_on(INTERVAL.end_date)
|
39 | 33 |
|
40 | 34 | # Select clinical events in interval date range
|
41 | 35 | selected_events = clinical_events.where(
|
42 | 36 | clinical_events.date.is_on_or_between(INTERVAL.start_date, INTERVAL.end_date)
|
43 | 37 | )
|
44 | 38 |
|
45 |
| -# Loop through each condition to create a measure |
| 39 | +# Loop through each CLINICAL SERVICE to create a measure |
46 | 40 | for pharmacy_first_event, codelist in pharmacy_first_event_codes.items():
|
47 | 41 | condition_events = selected_events.where(
|
48 | 42 | clinical_events.snomedct_code.is_in(codelist)
|
|
51 | 45 | # Define the numerator as the count of events for the condition
|
52 | 46 | numerator = condition_events.count_for_patient()
|
53 | 47 |
|
54 |
| - |
55 | 48 | # Define the denominator as the number of patients registered
|
56 | 49 | denominator = registration.exists_for_patient()
|
57 | 50 |
|
|
62 | 55 | intervals=months(8).starting_on("2023-11-01")
|
63 | 56 | )
|
64 | 57 |
|
65 |
| -# Loop through each CLINICAL condition to create a measure |
| 58 | +# Loop through each CLINICAL CONDITION to create a measure |
66 | 59 | for condition_name, condition_code in pharmacy_first_conditions_codes.items():
|
67 | 60 | condition_events = selected_events.where(
|
68 | 61 | clinical_events.snomedct_code.is_in(condition_code)
|
|
71 | 64 | # Define the numerator as the count of events for the condition
|
72 | 65 | numerator = condition_events.count_for_patient()
|
73 | 66 |
|
74 |
| - |
75 | 67 | # Define the denominator as the number of patients registered
|
76 | 68 | denominator = registration.exists_for_patient()
|
77 | 69 |
|
|
0 commit comments