generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
calculate_numerators.py
40 lines (34 loc) · 1.19 KB
/
calculate_numerators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pandas as pd
from utilities import (
OUTPUT_DIR,
match_input_files_filtered,
co_prescription,
get_date_input_file_filtered,
)
for file in OUTPUT_DIR.iterdir():
if match_input_files_filtered(file.name):
df = pd.read_feather(OUTPUT_DIR / file.name)
date = get_date_input_file_filtered(file.name)
# for indicator E
co_prescription(df, "anticoagulant", "antiplatelet_including_aspirin")
df["indicator_e_numerator"] = (
(df["anticoagulant"] == 1)
& (df["ppi"] == 0)
& (df["co_prescribed_anticoagulant_antiplatelet_including_aspirin"] == 1)
)
# for indicator F
co_prescription(df, "aspirin", "antiplatelet_excluding_aspirin")
df["indicator_f_numerator"] = (
(df["aspirin"] == 1)
& (df["ppi"] == 0)
& (df["co_prescribed_aspirin_antiplatelet_excluding_aspirin"] == 1)
)
df.loc[
:,
[
"patient_id",
"indicator_e_numerator",
"indicator_f_numerator",
"practice",
],
].to_feather(OUTPUT_DIR / f"indicator_e_f_{date}.feather")