def test_address_dtype_generation(): study = StudyDefinition( # This line defines the study population population=patients.all(), rural_urban=patients.address_as_of( "2020-02-01", returning="rural_urban_classification" ), ) result = _converters_to_names(study.pandas_csv_args) assert result == { "dtype": {"rural_urban": "category"}, "parse_dates": [], "date_col_for": {}, "converters": {}, }
"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": { "100": 0.1, "200": 0.2, "300": 0.7 } }, }, ), #SMOKING smoking_status=patients.categorised_as( { "S": "most_recent_smoking_code = 'S'", "E": """ most_recent_smoking_code = 'E' OR ( most_recent_smoking_code = 'N' AND ever_smoked )
from datetime import date from cohortextractor import StudyDefinition, patients today = str(date.today()) study = StudyDefinition( default_expectations={ "date": { "earliest": "1900-01-01", "latest": "today" }, "rate": "exponential_increase", }, population=patients.registered_as_of(today), imd=patients.address_as_of( today, returning="index_of_multiple_deprivation", round_to_nearest=100, return_expectations={ "incidence": 0.8, "category": { "ratios": {100 * (n + 1): 1 / 330 for n in range(330)} }, }, ), )
} ), # SEX sex = patients.sex(return_expectations={ "rate": "universal", "category": {"ratios":{"M": 0.49, "F":0.51}}, } ), # DEPRIVIATION imd=patients.address_as_of( "today", returning="index_of_multiple_deprivation", round_to_nearest=100, return_expectations={ "rate": "universal", "category": {"ratios": {"1": 0.2, "2": 0.2, "3": 0.2, "4": 0.2, "5":0.2}}, } ), # GEOGRAPHIC REGION CALLED STP stp = patients.registered_practice_as_of( "2020-01-01", returning="stp_code", return_expectations={ "category": {"ratios": dict_stp}, } ), # # https://codelists.opensafely.org/codelist/opensafely/severe-and-profound-learning-disability-flags/44ef542a/#full-list
"ratios": { "MSOA1": 0.5, "MSOA2": 0.5 } }, }, ), # https://github.com/ebmdatalab/tpp-sql-notebook/issues/52 imd=patients.address_as_of( "index_date", returning="index_of_multiple_deprivation", round_to_nearest=100, return_expectations={ "rate": "universal", "category": { "ratios": { "100": 0.1, "200": 0.2, "300": 0.7 } }, }, ), rural_urban=patients.address_as_of( "index_date", returning="rural_urban_classification", return_expectations={ "rate": "universal", "category": { "ratios": { "rural": 0.1,
imd=patients.categorised_as( { "0": "DEFAULT", "1": """index_of_multiple_deprivation >=1 AND index_of_multiple_deprivation < 32844*1/5""", "2": """index_of_multiple_deprivation >= 32844*1/5 AND index_of_multiple_deprivation < 32844*2/5""", "3": """index_of_multiple_deprivation >= 32844*2/5 AND index_of_multiple_deprivation < 32844*3/5""", "4": """index_of_multiple_deprivation >= 32844*3/5 AND index_of_multiple_deprivation < 32844*4/5""", "5": """index_of_multiple_deprivation >= 32844*4/5 """, }, index_of_multiple_deprivation=patients.address_as_of( "index_date", returning="index_of_multiple_deprivation", round_to_nearest=100, ), return_expectations={ "rate": "universal", "category": { "ratios": { "0": 0.01, "1": 0.20, "2": 0.20, "3": 0.20, "4": 0.20, "5": 0.19, } }, }),
"0": "DEFAULT", "1": """index_of_multiple_deprivation >=1 AND index_of_multiple_deprivation < 32844*1/5""", "2": """index_of_multiple_deprivation >= 32844*1/5 AND index_of_multiple_deprivation < 32844*2/5""", "3": """index_of_multiple_deprivation >= 32844*2/5 AND index_of_multiple_deprivation < 32844*3/5""", "4": """index_of_multiple_deprivation >= 32844*3/5 AND index_of_multiple_deprivation < 32844*4/5""", "5": """index_of_multiple_deprivation >= 32844*4/5 AND index_of_multiple_deprivation < 32844""", }, index_of_multiple_deprivation=patients.address_as_of( campaign_start, returning="index_of_multiple_deprivation", round_to_nearest=100, ), return_expectations={ "rate": "universal", "category": { "ratios": { "0": 0.05, "1": 0.19, "2": 0.19, "3": 0.19, "4": 0.19, "5": 0.19, } }, },
"M": 0.49, "F": 0.51 } }, }), # DEPRIVIATION imd=patients.address_as_of( "sgss_pos_inrange", returning="index_of_multiple_deprivation", round_to_nearest=100, return_expectations={ "rate": "universal", "category": { "ratios": { "100": 0.1, "200": 0.2, "300": 0.2, "400": 0.2, "500": 0.2, "600": 0.1 } }, }, ), # GEOGRAPHIC REGION CALLED STP stp=patients.registered_practice_as_of( "sgss_pos_inrange", returning="stp_code", return_expectations={ "rate": "universal",