## LIBRARIES - simple study definitions # cohort extractor from cohortextractor import (StudyDefinition, patients) # dictionaries of STP codes (for dummy data) from dictionaries import dict_stp # set the index date index_date = "2020-01-01" ## STUDY POPULATION study = StudyDefinition( default_expectations={ "date": { "earliest": index_date, "latest": "today" }, # date range for simulation "rate": "uniform", "incidence": 1 }, population=patients.registered_as_of(index_date), stp=patients.registered_practice_as_of(index_date, returning="stp_code", return_expectations={ "category": { "ratios": dict_stp }, }))
"incidence": 0.6, "float": { "distribution": "normal", "mean": 35, "stddev": 10 }, }, ), # https://github.com/ebmdatalab/tpp-sql-notebook/issues/54 stp=patients.registered_practice_as_of( "2020-03-01", returning="stp_code", return_expectations={ "rate": "universal", "category": { "ratios": { "STP1": 0.5, "STP2": 0.5 } }, }, ), # https://github.com/ebmdatalab/tpp-sql-notebook/issues/52 imd=patients.address_as_of( "2020-03-01", returning="index_of_multiple_deprivation", round_to_nearest=100, return_expectations={ "rate": "universal", "category": { "ratios": {
#return_expectations= { "incidence": 0.6 },), return_expectations={ "category": { "ratios": { "0": 0.5, "1": 0.5 } }, }, ), stp=patients.registered_practice_as_of( "index_date", returning="stp_code", return_expectations={ "category": { "ratios": { "STP1": 0.5, "STP2": 0.5 } }, }, ), first_dose=patients.with_these_clinical_events( first_dose_code, returning="binary_flag", between=["index_date", "index_date + 1 month"], return_expectations={"incidence": 0.4}), second_dose=patients.with_these_clinical_events( second_dose_code, returning="binary_flag", between=["index_date", "index_date + 1 month"], return_expectations={"incidence": 0.4}),
return_expectations={ "rate": "universal", "category": { "ratios": { "M": 0.49, "F": 0.5, "U": 0.01 } }, }), practice=patients.registered_practice_as_of("index_date", returning="pseudo_id", return_expectations={ "int": { "distribution": "normal", "mean": 25, "stddev": 5 }, "incidence": 0.5 }), region=patients.registered_practice_as_of( "index_date", returning="nuts1_region_name", return_expectations={ "category": { "ratios": { "North East": 0.1, "North West": 0.1, "Yorkshire and the Humber": 0.1, "East Midlands": 0.1,
}, }, ), # GEOGRAPHIC REGION CALLED STP stp=patients.registered_practice_as_of( "2019-02-01", returning="stp_code", return_expectations={ "rate": "universal", "category": { "ratios": { "STP1": 0.1, "STP2": 0.1, "STP3": 0.1, "STP4": 0.1, "STP5": 0.1, "STP6": 0.1, "STP7": 0.1, "STP8": 0.1, "STP9": 0.1, "STP10": 0.1, } }, }, ), # ETHNICITY IN 6 CATEGORIES ethnicity=patients.with_these_clinical_events( ethnicity_codes, returning="category",
}, }, ), # GEOGRAPHIC REGION CALLED STP stp=patients.registered_practice_as_of( "2020-02-01", returning="stp_code", return_expectations={ "rate": "universal", "category": { "ratios": { "STP1": 0.1, "STP2": 0.1, "STP3": 0.1, "STP4": 0.1, "STP5": 0.1, "STP6": 0.1, "STP7": 0.1, "STP8": 0.1, "STP9": 0.1, "STP10": 0.1, } }, }, ), # OTHER REGION region=patients.registered_practice_as_of( "2020-02-01", returning="nuts1_region_name",
"incidence": 0.6, "float": { "distribution": "normal", "mean": 120, "stddev": 10 }, }, ), # https://github.com/ebmdatalab/tpp-sql-notebook/issues/54 stp=patients.registered_practice_as_of( "index_date", returning="stp_code", return_expectations={ "rate": "universal", "category": { "ratios": { "STP1": 0.5, "STP2": 0.5 } }, }, ), msoa=patients.registered_practice_as_of( "index_date", returning="msoa_code", return_expectations={ "rate": "universal", "category": { "ratios": { "MSOA1": 0.5, "MSOA2": 0.5
"latest": "today" }, "rate": "uniform", }, index_date="2020-01-01", population=patients.registered_with_one_practice_between( "index_date", "index_date"), region=patients.registered_practice_as_of( "index_date", returning="nuts1_region_name", return_expectations={ "category": { "ratios": { "North East": 0.1, "North West": 0.1, "Yorkshire and the Humber": 0.1, "East Midlands": 0.1, "West Midlands": 0.1, "East of England": 0.1, "London": 0.2, "South East": 0.2, } }, "incidence": 0.8 }), sex=patients.sex(return_expectations={ "rate": "universal", "category": { "ratios": { "M": 0.49, "F": 0.51 }
chronic_liver_disease_codes, returning="binary_flag", return_expectations={ "incidence": 1.0, "date": { "earliest": "1950-01-01", "latest": "index_date" }, }, ), stp=patients.registered_practice_as_of( "index_date", returning="stp_code", return_expectations={ "rate": "universal", "category": { "ratios": { "STP1": 1.0 } }, }, ), ) measures = [ Measure( id="liver_disease_by_stp", numerator="has_chronic_liver_disease", denominator="population", group_by="stp", small_number_suppression=True, ),
"2": 0.2, "3": 0.2, "4": 0.2, "5": 0.2 } }, "incidence": 0.75, }, ), # practice pseudo id practice_id=patients.registered_practice_as_of( campaign_start, # day before vaccine campaign start returning="pseudo_id", return_expectations={ "int": { "distribution": "normal", "mean": 1000, "stddev": 100 }, "incidence": 1, }, ), # stp is an NHS administration region based on geography stp=patients.registered_practice_as_of( campaign_start, returning="stp_code", return_expectations={ "rate": "universal", "category": { "ratios": { "STP1": 0.1, "STP2": 0.1,
# Import codelists from codelists import * from datetime import date start_date = "2020-12-07" end_date = "2021-02-01" # Specifiy study definition study = StudyDefinition( default_expectations={ "date": {"earliest": start_date, "latest": end_date}, "rate": "exponential_increase", "incidence": 0.1, }, population=patients.registered_as_of(start_date), practice=patients.registered_practice_as_of( start_date, returning="pseudo_id", return_expectations={ "int": {"distribution": "normal", "mean": 25, "stddev": 5}, "incidence": 0.5} ), )
(NOT died) AND (registered) """, died=patients.died_from_any_cause(on_or_before=index_date, returning="binary_flag"), registered=patients.registered_as_of(index_date), age=patients.age_as_of(index_date), ), ### geographic/administrative groups practice=patients.registered_practice_as_of( index_date, returning="pseudo_id", return_expectations={ "int": { "distribution": "normal", "mean": 100, "stddev": 20 } }, ), stp=patients.registered_practice_as_of( index_date, returning="stp_code", return_expectations={ "category": { "ratios": dict_stp }, }, ), cholesterol=patients.with_these_clinical_events(