Skip to content

Commit

Permalink
Merge pull request #17 from opensafely/update-apr-19
Browse files Browse the repository at this point in the history
Update apr 19
  • Loading branch information
brianmackenna authored Apr 19, 2021
2 parents 473d352 + 3fa3faf commit 216deb4
Show file tree
Hide file tree
Showing 73 changed files with 56,179 additions and 30,705 deletions.
4 changes: 4 additions & 0 deletions analysis/codelists.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,7 @@
wider_ld_codes = codelist_from_csv(
"codelists/primis-covid19-vacc-uptake-learndis.csv", system="snomed", column="code"
)

covid_vacc_declined = codelist_from_csv(
"codelists/primis-covid19-vacc-uptake-cov1decl.csv", system="snomed", column="code"
)
60 changes: 30 additions & 30 deletions analysis/study_definition_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,30 @@
returning="binary_flag",
return_expectations={"incidence": 0.01,},
),
cystic_fibrosis=patients.with_these_clinical_events(
cystic_fibrosis_codes,
on_or_before=index_date,
returning="binary_flag",
return_expectations={"incidence": 0.01,},
),
sickle_cell_disease=patients.with_these_clinical_events(
sickle_cell_disease_codes,
on_or_before=index_date,
returning="binary_flag",
return_expectations={"incidence": 0.01,},
),
permanant_immunosuppression=patients.with_these_clinical_events(
permanent_immunosuppression_codes,
on_or_before=index_date,
returning="binary_flag",
return_expectations={"incidence": 0.01,},
),
temporary_immunosuppression=patients.with_these_clinical_events(
temporary_immunosuppression_codes,
on_or_before=index_date,
returning="binary_flag",
return_expectations={"incidence": 0.01,},
),
# cystic_fibrosis=patients.with_these_clinical_events(
# cystic_fibrosis_codes,
# on_or_before=index_date,
# returning="binary_flag",
# return_expectations={"incidence": 0.01,},
# ),
# sickle_cell_disease=patients.with_these_clinical_events(
# sickle_cell_disease_codes,
# on_or_before=index_date,
# returning="binary_flag",
# return_expectations={"incidence": 0.01,},
# ),
# permanant_immunosuppression=patients.with_these_clinical_events(
# permanent_immunosuppression_codes,
# on_or_before=index_date,
# returning="binary_flag",
# return_expectations={"incidence": 0.01,},
# ),
# temporary_immunosuppression=patients.with_these_clinical_events(
# temporary_immunosuppression_codes,
# on_or_before=index_date,
# returning="binary_flag",
# return_expectations={"incidence": 0.01,},
# ),
#
psychosis_schiz_bipolar=patients.with_these_clinical_events(
psychosis_schizophrenia_bipolar_affective_disease_codes,
Expand All @@ -199,12 +199,12 @@
),

# https://github.com/opensafely/codelist-development/issues/4
asplenia=patients.with_these_clinical_events(
asplenia_codes,
on_or_before=index_date,
returning="binary_flag",
return_expectations={"incidence": 0.01,},
),
# asplenia=patients.with_these_clinical_events(
# asplenia_codes,
# on_or_before=index_date,
# returning="binary_flag",
# return_expectations={"incidence": 0.01,},
# ),

###############################################################################
# COVID VACCINATION
Expand Down
79 changes: 25 additions & 54 deletions analysis/study_definition_delivery_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,24 @@
OR
shielded
OR
(care_home)
OR
(LD)
)
"""
""",
registered=patients.registered_as_of(
index_date,
),
has_died=patients.died_from_any_cause(
on_or_before=index_date,
returning="binary_flag",
),
),

has_follow_up=patients.registered_with_one_practice_between(
start_date="index_date - 12 months",
end_date=index_date,
return_expectations={"incidence": 0.90},
),
registered=patients.registered_as_of(
index_date,
return_expectations={"incidence": 0.98},
),
has_died=patients.died_from_any_cause(
on_or_before=index_date,
returning="binary_flag",
return_expectations={"incidence": 0.05},
),



### PRIMIS care home flag
Expand Down Expand Up @@ -94,37 +91,6 @@
},
},
),
# age bands for patients not in care homes (ie living in the community)
# this is used to define eligible groups not defined by clinical criteria
ageband_community=patients.categorised_as(
{
"care home" : "DEFAULT",
"16-29": """ age >= 16 AND age < 30 AND NOT care_home""",
"30-39": """ age >= 30 AND age < 40 AND NOT care_home""",
"40-49": """ age >= 40 AND age < 50 AND NOT care_home""",
"50-59": """ age >= 50 AND age < 60 AND NOT care_home""",
"60-64": """ age >= 60 AND age < 65 AND NOT care_home""",
"65-69": """ age >= 65 AND age < 70 AND NOT care_home""",
"70-79": """ age >= 70 AND age < 80 AND NOT care_home""",
"80+": """ age >= 80 AND age < 120 AND NOT care_home""",
},
return_expectations={
"rate": "universal",
"category": {
"ratios": {
"care home":0.125,
"16-29": 0.125,
"30-39": 0.125,
"40-49": 0.125,
"50-59": 0.125,
"60-64": 0.0625,
"65-69": 0.0625,
"70-79": 0.125,
"80+": 0.125,
}
},
},
),

# 5 year age bands
ageband_5yr=patients.categorised_as(
Expand Down Expand Up @@ -300,17 +266,7 @@
returning="binary_flag",
return_expectations={"incidence": 0.01,},
),
adrenaline_pen=patients.with_these_medications(
adrenaline_pen,
on_or_after="index_date - 24 months", # look for last two years
returning="binary_flag",
return_last_date_in_period=False,
include_month=False,
return_expectations={
"date": {"earliest": "2018-12-01", "latest": index_date},
"incidence": 0.001,
},
),



### PRIMIS overall flag for shielded group
Expand Down Expand Up @@ -387,5 +343,20 @@
wider_ld_codes,
return_expectations={"incidence": 0.02,},
),

# declined vaccination / vaccination course / first dose (not including declined second dose)
covid_vacc_declined_date = patients.with_these_clinical_events(
covid_vacc_declined,
returning="date",
find_first_match_in_period=True,
date_format = "YYYY-MM-DD",
return_expectations={
"date": {
"earliest": "2020-12-08", # first vaccine administered on the 8/12
"latest": index_date,
},
"incidence":0.04
},
),

)
12 changes: 6 additions & 6 deletions codelists/codelists.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,17 @@
"downloaded_at": "2021-02-10 14:28:12.124536Z",
"sha": "99f6c0787e17e16430549a4cfb5084612faba2ac"
},
"user-peter-inglesby-eth2001.csv": {
"id": "user/peter-inglesby/eth2001/0f56fa3b",
"url": "https://codelists.opensafely.org/codelist/user/peter-inglesby/eth2001/0f56fa3b/",
"downloaded_at": "2021-02-10 14:28:12.230527Z",
"sha": "708774541b925cf190016e2e160eec31b02d2512"
},
"primis-covid19-vacc-uptake-learndis.csv": {
"id": "primis-covid19-vacc-uptake/learndis/v1",
"url": "https://codelists.opensafely.org/codelist/primis-covid19-vacc-uptake/learndis/v1/",
"downloaded_at": "2021-03-09 11:58:49.613669Z",
"sha": "41f81fcb9fadb082a77cadd6cf60614d7c8d860f"
},
"primis-covid19-vacc-uptake-cov1decl.csv": {
"id": "primis-covid19-vacc-uptake/cov1decl/v1.1",
"url": "https://codelists.opensafely.org/codelist/primis-covid19-vacc-uptake/cov1decl/v1.1/",
"downloaded_at": "2021-04-19 13:00:27.222055Z",
"sha": "c8f6ef075bb2f267ee8524453967ba927703fe9d"
}
}
}
2 changes: 1 addition & 1 deletion codelists/codelists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ opensafely/sickle-cell-disease/2020-04-14
opensafely/solid-organ-transplantation/2020-04-10
opensafely/permanent-immunosuppression/2020-06-02
opensafely/temporary-immunosuppression/2020-04-24
user/peter-inglesby/eth2001/0f56fa3b
primis-covid19-vacc-uptake/learndis/v1
primis-covid19-vacc-uptake/cov1decl/v1.1
4 changes: 4 additions & 0 deletions codelists/primis-covid19-vacc-uptake-cov1decl.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
code,term
1324721000000108,Severe acute respiratory syndrome coronavirus 2 vaccination dose declined
1324741000000101,Severe acute respiratory syndrome coronavirus 2 vaccination first dose declined
1324811000000107,Severe acute respiratory syndrome coronavirus 2 immunisation course declined
83 changes: 0 additions & 83 deletions codelists/user-peter-inglesby-eth2001.csv

This file was deleted.

15 changes: 8 additions & 7 deletions lib/data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@



def load_data(input_file='input_delivery.csv', input_path="output"):
def load_data(input_file='input_delivery.csv.gz', input_path="output"):
"""
This reads in a csv that must be in output/ directory and cleans the
data ready for use in the graphs and tables
Expand All @@ -33,7 +33,7 @@ def load_data(input_file='input_delivery.csv', input_path="output"):
"""

# import data and fill nulls with 0
df = pd.read_csv(os.path.join("..",input_path, input_file)).fillna(0)
df = pd.read_csv(os.path.join("..",input_path, input_file), compression='gzip').fillna(0)

# fill unknown ethnicity from GP records with ethnicity from SUS (secondary care)
df.loc[df["ethnicity"]==0, "ethnicity"] = df["ethnicity_6_sus"]
Expand Down Expand Up @@ -62,6 +62,9 @@ def load_data(input_file='input_delivery.csv', input_path="output"):
covid_vacc_2nd = np.where(df["covid_vacc_second_dose_date"]!=0, 1, 0),
covid_vacc_bin = np.where(df["covid_vacc_date"]!=0, 1, 0))

# declined - suppress if vaccine has been received
df["covid_vacc_declined_date"] = np.where(df["covid_vacc_date"]==0, df["covid_vacc_declined_date"], 0)

# create an additional field for 2nd dose to use as a flag for each eligible group
df["2nd_dose"] = df["covid_vacc_2nd"]

Expand All @@ -84,7 +87,7 @@ def load_data(input_file='input_delivery.csv', input_path="output"):

# drop unnecssary columns or columns created for processing
df = df.drop(["imd","ethnicity_16", "ethnicity", 'ethnicity_6_sus',
'ethnicity_16_sus', "adrenaline_pen", "has_died", "has_follow_up"], 1)
'ethnicity_16_sus', "has_follow_up"], 1)

# categorise into priority groups (similar to the national groups but not exactly the same)
conditions = [
Expand All @@ -111,9 +114,7 @@ def load_data(input_file='input_delivery.csv', input_path="output"):
for c in ["2nd_dose", "LD", "newly_shielded_since_feb_15", "dementia",
"chronic_cardiac_disease", "current_copd", "dialysis", "dmards","psychosis_schiz_bipolar",
"solid_organ_transplantation", "chemo_or_radio", "intel_dis_incl_downs_syndrome","ssri",
"lung_cancer", "cancer_excl_lung_and_haem", "haematological_cancer", "bone_marrow_transplant",
"cystic_fibrosis", "sickle_cell_disease", "permanant_immunosuppression",
"temporary_immunosuppression", "asplenia"]:
"lung_cancer", "cancer_excl_lung_and_haem", "haematological_cancer"]:
df[c] = np.where(df[c]==1, "yes", "no")


Expand All @@ -122,7 +123,7 @@ def load_data(input_file='input_delivery.csv', input_path="output"):
df = df.merge(stps, left_on="stp", right_on="stp_id", how="left").rename(columns={"name":"stp_name"})

# drop additional columns
df = df.drop(['registered', 'care_home', 'age',"stp_id", "ageband_community"], 1)
df = df.drop(['care_home', 'age',"stp_id"], 1)

return df

Expand Down
Loading

0 comments on commit 216deb4

Please sign in to comment.