|
34 | 34 | medications.date.is_on_or_between(INTERVAL.start_date, INTERVAL.end_date)
|
35 | 35 | )
|
36 | 36 |
|
| 37 | +selected_clinical_pathways = select_events( |
| 38 | + clinical_events, codelist=pharmacy_first_conditions_codelist |
| 39 | +).where(clinical_events.date.is_on_or_between(INTERVAL.start_date, INTERVAL.end_date)) |
| 40 | + |
37 | 41 | # Create variable which contains boolean values of whether pharmacy first event exists for patient
|
38 | 42 | has_pf_consultation = select_events(
|
39 | 43 | selected_clinical_events, codelist=pharmacy_first_consultation_codelist).exists_for_patient()
|
|
43 | 47 | selected_clinical_events, codelist=pharmacy_first_conditions_codelist).exists_for_patient()
|
44 | 48 |
|
45 | 49 | # Dates of pharmacy first consultations
|
46 |
| -pharmacy_first_dates = select_events(clinical_events, codelist=pharmacy_first_ids).date |
| 50 | +pharmacy_first_dates = select_events(clinical_events, codelist=pharmacy_first_consultation_codelist).date |
47 | 51 |
|
48 | 52 | # Specify whether a patient has been prescribed a PF medication on the same day as a PF consultation code
|
49 |
| -has_pfmed_on_pfdate = selected_med_events.where(medications.date.is_in(pharmacy_first_dates)) |
| 53 | +has_pfmed_on_pfdate = selected_med_events.where(medications.date.is_in(pharmacy_first_dates)).exists_for_patient() |
50 | 54 |
|
51 | 55 | # Specify whether a patient has a PF condition
|
52 |
| -has_pfpathway_on_pfdate = has_pf_condition.where( |
53 |
| - has_pf_condition.date.is_in(pharmacy_first_dates) |
54 |
| -) |
| 56 | +has_pfpathway_on_pfdate = selected_clinical_pathways.where( |
| 57 | + selected_clinical_pathways.date.is_in(pharmacy_first_dates) |
| 58 | +).exists_for_patient() |
55 | 59 |
|
56 | 60 | # PF consultations with prescribed PF medication
|
57 | 61 | has_pf_medication = selected_med_events.where(
|
|
0 commit comments