def test_patients_registered_with_one_practice_between():
    session = make_session()

    patient_registered_in_2001 = Patient()
    patient_registered_in_2002 = Patient()
    patient_unregistered_in_2002 = Patient()
    patient_registered_in_2001.RegistrationHistory = [
        RegistrationHistory(StartDate="2001-01-01", EndDate="9999-01-01")
    ]
    patient_registered_in_2002.RegistrationHistory = [
        RegistrationHistory(StartDate="2002-01-01", EndDate="9999-01-01")
    ]
    patient_unregistered_in_2002.RegistrationHistory = [
        RegistrationHistory(StartDate="2001-01-01", EndDate="2002-01-01")
    ]

    session.add(patient_registered_in_2001)
    session.add(patient_registered_in_2002)
    session.add(patient_unregistered_in_2002)
    session.commit()

    study = StudyDefinition(
        population=patients.registered_with_one_practice_between(
            "2001-12-01", "2003-01-01"
        )
    )
    results = study.to_dicts()
    assert [x["patient_id"] for x in results] == [
        str(patient_registered_in_2001.Patient_ID)
    ]
Ejemplo n.º 2
0
     "rate": "uniform",
     "incidence": 0.2,
 },
 ## STUDY POPULATION (required)
 population=patients.satisfying(
     """
     copd AND
     (age >=35 AND age <= 110) AND
     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",
Ejemplo n.º 3
0
    column="id",
)
systolic_blood_pressure_codes = codelist(["2469."], system="ctv3")
diastolic_blood_pressure_codes = codelist(["246A."], system="ctv3")

study = StudyDefinition(
    # Configure the expectations framework
    default_expectations={
        "date": {
            "earliest": "1900-01-01",
            "latest": "today"
        },
        "rate": "exponential_increase",
    },
    # This line defines the study population
    population=patients.registered_with_one_practice_between(
        "2019-02-01", "2020-02-01"),
    # 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": {
                "distribution": "population_ages"
            },
        },
    ),
    # https://github.com/ebmdatalab/tpp-sql-notebook/issues/46
    sex=patients.sex(return_expectations={
        "rate": "universal",
        "category": {
     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},