def test_patients_died_from_any_cause():
    session = make_session()
    session.add_all(
        [
            # Not dead
            Patient(),
            # Died after date cutoff
            Patient(ONSDeath=[ONSDeaths(dod="2021-01-01")]),
            # Died
            Patient(ONSDeath=[ONSDeaths(dod="2020-02-01")]),
        ]
    )
    session.commit()
    study = StudyDefinition(
        population=patients.all(),
        died=patients.died_from_any_cause(on_or_before="2020-06-01"),
        date_died=patients.died_from_any_cause(
            on_or_before="2020-06-01",
            returning="date_of_death",
            include_month=True,
            include_day=True,
        ),
    )
    results = study.to_dicts()
    assert [i["died"] for i in results] == ["0", "0", "1"]
    assert [i["date_died"] for i in results] == ["", "", "2020-02-01"]
Ejemplo n.º 2
0
def test_make_df_from_binary_default_outcome():
    study = StudyDefinition(
        population=patients.all(),
        died=patients.died_from_any_cause(return_expectations={"incidence": 0.1}),
    )
    population_size = 10000
    result = study.make_df_from_expectations(population_size)
    assert len(result[~pd.isnull(result.died)]) == 0.1 * population_size
Ejemplo n.º 3
0
     }},
 ),
 died_ons_covid_flag_underlying=patients.
 with_these_codes_on_death_certificate(
     covid_codelist,
     on_or_after="2020-03-01",
     match_only_underlying_cause=True,
     return_expectations={"date": {
         "earliest": "2020-03-01"
     }},
 ),
 died_date_ons=patients.died_from_any_cause(
     on_or_after="2020-03-01",
     returning="date_of_death",
     include_month=True,
     include_day=True,
     return_expectations={"date": {
         "earliest": "2020-03-01"
     }},
 ),
 ## DEMOGRAPHIC INFORMATION
 age=patients.age_as_of(
     "2020-02-29",
     return_expectations={
         "rate": "universal",
         "int": {
             "distribution": "population_ages"
         },
     },
 ),
 sex=patients.sex(return_expectations={
    ),
    died_date_cpns=patients.with_death_recorded_in_cpns(
        on_or_before="2020-06-01",
        returning="date_of_death",
        include_month=True,
        include_day=True,
    ),
    died_ons_covid_flag_any=patients.with_these_codes_on_death_certificate(
        covid_codelist, on_or_before="2020-06-01", match_only_underlying_cause=False
    ),
    died_ons_covid_flag_underlying=patients.with_these_codes_on_death_certificate(
        covid_codelist, on_or_before="2020-06-01", match_only_underlying_cause=True
    ),
    died_date_ons=patients.died_from_any_cause(
        on_or_before="2020-06-01",
        returning="date_of_death",
        include_month=True,
        include_day=True,
    ),

    # The rest of the lines define the covariates with associated GitHub issues
    # https://github.com/ebmdatalab/tpp-sql-notebook/issues/33
    age=patients.age_as_of("2020-02-01"),

    # https://github.com/ebmdatalab/tpp-sql-notebook/issues/46
    sex=patients.sex(),

    # https://github.com/ebmdatalab/tpp-sql-notebook/issues/52
    imd=patients.address_as_of(
        "2020-02-01", returning="index_of_multiple_deprivation", round_to_nearest=100
    ),