def test_meds(): session = make_session() asthma_medication = MedicationDictionary( FullName="Asthma Drug", DMD_ID="0", MultilexDrug_ID="0" ) patient_with_med = Patient() patient_with_med.MedicationIssues = [ MedicationIssue(MedicationDictionary=asthma_medication) ] patient_without_med = Patient() session.add(patient_with_med) session.add(patient_without_med) session.commit() study = StudyDefinition( population=patients.all(), asthma_meds=patients.with_these_medications( codelist(asthma_medication.DMD_ID, "snomed") ), ) results = study.to_dicts() assert [x["asthma_meds"] for x in results] == ["1", "0"]
def test_meds_with_count(): session = make_session() asthma_medication = MedicationDictionary( FullName="Asthma Drug", DMD_ID="0", MultilexDrug_ID="0" ) patient_with_med = Patient() patient_with_med.MedicationIssues = [ MedicationIssue( MedicationDictionary=asthma_medication, ConsultationDate="2010-01-01" ), MedicationIssue( MedicationDictionary=asthma_medication, ConsultationDate="2015-01-01" ), MedicationIssue( MedicationDictionary=asthma_medication, ConsultationDate="2018-01-01" ), MedicationIssue( MedicationDictionary=asthma_medication, ConsultationDate="2020-01-01" ), ] patient_without_med = Patient() session.add(patient_with_med) session.add(patient_without_med) session.commit() study = StudyDefinition( population=patients.all(), asthma_meds=patients.with_these_medications( codelist(asthma_medication.DMD_ID, "snomed"), on_or_after="2012-01-01", return_number_of_matches_in_period=True, ), ) results = study.to_dicts() assert [x["asthma_meds"] for x in results] == ["3", "0"]
ever_smoked AND has_follow_up AND NOT recent_asthma AND NOT other_respiratory AND NOT nebules AND NOT ltra_single """, has_follow_up=patients.registered_with_one_practice_between( "2019-02-28", "2020-02-29"), recent_asthma=patients.with_these_clinical_events( asthma_codes, between=["2017-02-28", "2020-02-29"], ), #### NEBULES nebules=patients.with_these_medications( nebulised_med_codes, between=["2019-02-28", "2020-02-29"], ), ), ## OUTCOMES (at least one outcome or covariate is required) icu_date_admitted=patients.admitted_to_icu( on_or_after="2020-03-01", include_day=True, returning="date_admitted", return_expectations={"date": { "earliest": "2020-03-01" }}, ), died_date_cpns=patients.with_death_recorded_in_cpns( on_or_after="2020-03-01", returning="date_of_death", include_month=True,
}, }, ), rural_urban=patients.address_as_of( "2020-02-01", returning="rural_urban_classification", return_expectations={ "rate": "universal", "category": { "ratios": { "rural": 0.1, "urban": 0.9 } }, }, ), recent_salbutamol_count=patients.with_these_medications( salbutamol_codes, between=["2018-02-01", "2020-02-01"], returning="number_of_matches_in_period", return_expectations={ "incidence": 0.6, "int": { "distribution": "normal", "mean": 8, "stddev": 2 }, }, ), )
has_follow_up=patients.registered_with_one_practice_between( "2019-02-28", "2020-02-29", return_expectations={"incidence": 0.9}), copd=patients.with_these_clinical_events( copd_codes, on_or_before="2020-02-29", return_expectations={"incidence": 0.05}, ), ### OTHER RESPIRATORY other_respiratory=patients.with_these_clinical_events( other_respiratory_codes, on_or_before="2020-02-29", return_expectations={"incidence": 0.05}, ), nebules=patients.with_these_medications( nebulised_med_codes, between=["2019-02-28", "2020-02-29"], return_expectations={"incidence": 0.05}, ), #### HIGH DOSE ICS - all preparation high_dose_ics=patients.with_these_medications( high_dose_ics_med_codes, between=["2019-11-01", "2020-02-29"], return_expectations={"incidence": 0.05}, ), #### HIGH DOSE ICS - single ingredient preparations high_dose_ics_single_ing=patients.with_these_medications( high_dose_ics_single_ingredient_med_codes, between=["2019-11-01", "2020-02-29"], return_expectations={"incidence": 0.05}, ), #### HIGH DOSE ICS - multiple ingredient preparation
ever_smoked=patients.with_these_clinical_events( filter_codes_by_category(clear_smoking_codes, include=["S", "E"]), on_or_before="2020-02-29", return_expectations={"incidence": 0.9}, ), has_follow_up=patients.registered_with_one_practice_between( "2019-02-28", "2020-02-29", return_expectations={"incidence": 0.9}, ), recent_asthma=patients.with_these_clinical_events( asthma_codes, between=["2017-02-28", "2020-02-29"], return_expectations={"incidence": 0.05}, ), other_respiratory=patients.with_these_clinical_events( other_respiratory_codes, on_or_before="2020-02-29", return_expectations={"incidence": 0.05}, ), #### NEBULES nebules=patients.with_these_medications( nebulised_med_codes, between=["2019-02-28", "2020-02-29"], return_expectations={"incidence": 0.05}, ), ltra_single=patients.with_these_medications( leukotriene_med_codes, between=["2019-11-01", "2020-02-29"], return_expectations={"incidence": 0.05}, ), )
) ) AND prednisolone_last_year > 0 AND prednisolone_last_year < 5 """, }, recent_asthma_code=patients.with_these_clinical_events( asthma_codes, between=['2017-02-01', '2020-02-01'], ), asthma_code_ever=patients.with_these_clinical_events(asthma_codes), copd_code_ever=patients.with_these_clinical_events(chronic_respiratory_disease_codes), prednisolone_last_year=patients.with_these_medications( pred_codes, between=['2019-02-01', '2020-02-01'], returning="number_of_matches_in_period", ), ), # https://github.com/ebmdatalab/tpp-sql-notebook/issues/7 chronic_cardiac_disease=patients.with_these_clinical_events( chronic_cardiac_disease_codes, return_first_date_in_period=True, include_month=True, ), # https://github.com/ebmdatalab/tpp-sql-notebook/issues/30 diabetes=patients.with_these_clinical_events( diabetes_codes, return_first_date_in_period=True,
low_med_dose_ics_multiple_ingredient OR low_med_dose_ics OR ics_single OR laba_ics OR laba_lama_ics ) ) """, has_asthma=patients.with_these_clinical_events( asthma_codes, between=["2017-02-28", "2020-02-29"], ), has_follow_up=patients.registered_with_one_practice_between( "2019-02-28", "2020-02-29"), nebules=patients.with_these_medications( nebulised_med_codes, between=["2019-02-28", "2020-02-29"], ), any_asthma_med=patients.satisfying(""" ltra_single OR laba_lama_ics OR laba_lama OR laba_ics OR lama_single OR laba_single OR sama_single OR saba_single OR ics_single OR low_med_dose_ics OR low_med_dose_ics_multiple_ingredient OR low_med_dose_ics_single_ingredient OR high_dose_ics_multiple_ingredient OR