Ejemplo n.º 1
0
from cohortextractor import StudyDefinition, patients, codelist, codelist_from_csv


study = StudyDefinition(
    default_expectations={
        "date": {"earliest": "1900-01-01", "latest": "today"},
        "rate": "uniform",
        "incidence": 0.5,
    },
    population=patients.registered_with_one_practice_between(
        "2019-02-01", "2020-02-01"
    ),
 age=patients.age_as_of(
        "2019-09-01",
        return_expectations={
            "rate": "universal",
            "int": {"distribution": "population_ages"},
        },
    ),

)
Ejemplo n.º 2
0
     return_expectations={"incidence": 0.8},
 ),
 age_cat=patients.satisfying(
     "age >=18 AND age <= 110",
     return_expectations={"incidence": 0.9},
     age=patients.age_as_of(
         "2020-02-29",
         return_expectations={
             "rate": "universal",
             "int": {
                 "distribution": "population_ages"
             },
         },
     ),
 ),
 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},
 default_expectations={
     "date": {
         "earliest": "1900-01-01",
         "latest": "today"
     },
     "rate": "uniform",
     "incidence": 0.1,
 },
 # This line defines the study population
 population=patients.satisfying(
     """
         has_follow_up AND
         (age >=18 AND age <= 110) AND
         (sex = "M" OR sex = "F")
         """,
     has_follow_up=patients.registered_with_one_practice_between(
         "2019-02-28", "2020-02-29")),
 # Outcomes
 icu_date_admitted=patients.admitted_to_icu(
     on_or_after="2020-03-01",
     include_day=True,
     returning="date_admitted",
     find_first_match_in_period=True,
     return_expectations={
         "date": {
             "earliest": "2020-03-01"
         },
         "incidence": 0.1
     },
 ),
 died_ons_covid_flag_any=patients.with_these_codes_on_death_certificate(
     covid_identification,
Ejemplo n.º 4
0
from_date = "2020-02-01"
to_date = "2021-11-28"

study = StudyDefinition(
    index_date=from_date,
    default_expectations={
        "date": {
            "earliest": "1970-01-01",
            "latest": "today"
        },
        "rate": "uniform",
        "incidence": 0.2,
    },
    # This line defines the study population
    population=patients.registered_with_one_practice_between(
        from_date, to_date),
    # demographic info
    # https://github.com/ebmdatalab/tpp-sql-notebook/issues/33
    age=patients.age_as_of(
        from_date,
        return_expectations={
            "rate": "universal",
            "int": {
                "distribution": "population_ages"
            },
        },
    ),
    # https://github.com/ebmdatalab/tpp-sql-notebook/issues/46
    sex=patients.sex(return_expectations={
        "rate": "universal",
        "category": {
Ejemplo n.º 5
0
)
systolic_blood_pressure_codes = codelist(["2469."], system="ctv3")
diastolic_blood_pressure_codes = codelist(["246A."], system="ctv3")

study = StudyDefinition(
    index_date="2020-02-01",
    # Configure the expectations framework
    default_expectations={
        "date": {
            "earliest": "1900-01-01",
            "latest": "index_date"
        },
        "rate": "exponential_increase",
    },
    # This line defines the study population
    population=patients.registered_with_one_practice_between(
        "index_date - 1 year", "index_date"),
    # 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(
        "index_date",
        return_expectations={
            "rate": "universal",
            "int": {
                "distribution": "population_ages"
            },
        },
    ),
    # https://github.com/ebmdatalab/tpp-sql-notebook/issues/46
    sex=patients.sex(return_expectations={
        "rate": "universal",
        "category": {
Ejemplo n.º 6
0
from codelists import *

# STUDY DEFINITION
# Defines both the study population and points to the important covariates and outcomes
study = StudyDefinition(
    default_expectations={
        "date": {
            "earliest": "1970-01-01",
            "latest": "today"
        },
        "rate": "uniform",
        "incidence": 0.2,
    },

    # STUDY POPULATION
    population=patients.registered_with_one_practice_between(
        "2019-11-01", "2020-02-01"),
    dereg_date=patients.date_deregistered_from_all_supported_practices(
        on_or_after="2020-02-01",
        date_format="YYYY-MM",
    ),

    # FOLLOW UP
    has_12_m_follow_up=patients.registered_with_one_practice_between(
        "2019-02-01",
        "2020-01-31",  ### 12 months prior to 1st Feb 2020
        return_expectations={
            "incidence": 0.95,
        }),

    # OUTCOMES
    died_ons_covid_flag_any=patients.with_these_codes_on_death_certificate(
study = StudyDefinition(
    default_expectations={
        "date": {
            "earliest": "1980-01-01",
            "latest": "today"
        },
        "rate": "uniform",
        "incidence": 0.05,
    },
    index_date="2019-02-01",
    population=patients.satisfying(
        """
            has_follow_up
        AND (age >=18 AND age <= 110)
        """,
        has_follow_up=patients.registered_with_one_practice_between(
            "index_date - 1 year", "index_date"),
        age=patients.age_as_of(
            "index_date",
            return_expectations={
                "rate": "universal",
                "int": {
                    "distribution": "population_ages"
                },
            },
        ),
    ),
    covid_hospitalisation=patients.categorised_as(
        {
            "COVID-19 positive": "covid_positive AND NOT covid_hospitalised",
            "COVID-19 hospitalised": "covid_hospitalised",
            "General population": "DEFAULT",
Ejemplo n.º 8
0
    # This line defines the study population
    population=patients.satisfying("""
        registered = 1
        AND
        (covid_vacc_date
        OR
        (age >=70 AND age <= 110) 
        OR
        (care_home_type))
        AND
        NOT has_died

        """),
    has_follow_up=patients.registered_with_one_practice_between(
        start_date="2019-12-01",
        end_date=campaign_start,
        return_expectations={"incidence": 0.90},
    ),
    registered=patients.registered_as_of(
        campaign_start,  # day before vaccination campaign starts - discuss with team if this should be "today"
        return_expectations={"incidence": 0.98},
    ),
    has_died=patients.died_from_any_cause(
        on_or_before=campaign_start,
        returning="binary_flag",
        return_expectations={"incidence": 0.05},
    ),

    # Demographic information

    # CAREHOME STATUS
Ejemplo n.º 9
0
# STUDY DEFINITION
# Defines both the study population and points to the important covariates and outcomes
study = StudyDefinition(
    default_expectations={
        "date": {
            "earliest": "1970-01-01",
            "latest": "today"
        },
        "rate": "uniform",
        "incidence": 0.2,
    },

    # STUDY POPULATION - registered 1 year prior to November 16th 2020
    population=patients.satisfying(
        "one_practice AND sgss_pos_inrange",
        one_practice=patients.registered_with_one_practice_between(
            "2019-11-16", "2020-11-16"),
    ),
    dereg_date=patients.date_deregistered_from_all_supported_practices(
        on_or_after="2020-11-16",
        date_format="YYYY-MM",
    ),

    # OUTCOMES - ONS death dates
    died_ons_covid_flag_any=patients.with_these_codes_on_death_certificate(
        covid_codelist,
        on_or_after="2020-02-01",
        match_only_underlying_cause=False,
        return_expectations={
            "date": {
                "earliest": "2020-02-01"
            },
    #        """
    #        has_follow_up AND
    #        (age >=18 AND age <= 110) AND
    #        (sex = "M" OR sex = "F") AND
    #        imd > 0 AND
    #        (rheumatoid OR sle) AND NOT
    #        chloroquine_not_hcq
    #        """,
    #        has_follow_up=patients.registered_with_one_practice_between(
    #        "2019-02-28", "2020-02-29"
    #    ),

    #),
    has_12mfollow_up=patients.registered_with_one_practice_between(
        "2019-02-01",
        "2020-02-01",
        return_expectations={"incidence": 0.9},
    ),
    under_fup_1feb=patients.registered_with_one_practice_between(
        "2020-02-01",
        "2020-02-01",
        return_expectations={"incidence": 0.9},
    ),

    # 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",
        return_expectations={
            "rate": "universal",
            "int": {