pyprevent 0.1.3__cp311-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyprevent/__init__.py ADDED
@@ -0,0 +1,16 @@
1
+ from .ascvd_calc import (
2
+ batch_calculate_10_yr_ascvd_risk,
3
+ batch_calculate_30_yr_ascvd_risk,
4
+ calculate_10_yr_ascvd_risk,
5
+ calculate_30_yr_ascvd_risk,
6
+ )
7
+
8
+
9
+ from .heart_failure import (
10
+ batch_calculate_10_yr_heart_failure_risk,
11
+ batch_calculate_30_yr_heart_failure_risk,
12
+ calculate_10_yr_heart_failure_risk,
13
+ calculate_30_yr_heart_failure_risk,
14
+ )
15
+
16
+ from .cvd import *
Binary file
@@ -0,0 +1,327 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+ from pyprevent import _pyprevent
4
+
5
+ from .utils import _prepare_df_for_batch, _report_any_null_values
6
+
7
+
8
+ def calculate_10_yr_ascvd_risk(
9
+ sex: str,
10
+ age: float,
11
+ total_cholesterol: float,
12
+ hdl_cholesterol: float,
13
+ systolic_bp: float,
14
+ has_diabetes: bool,
15
+ current_smoker: bool,
16
+ bmi: float,
17
+ egfr: float,
18
+ on_htn_meds: bool,
19
+ on_cholesterol_meds: bool,
20
+ ) -> float:
21
+ """
22
+ Calculate the 10-year risk of atherosclerotic cardiovascular disease (ASCVD).
23
+
24
+ This function uses various health and lifestyle parameters to estimate the risk
25
+ of developing ASCVD over the next 10 years. The input values must fall within
26
+ specified ranges for the calculation to be valid.
27
+
28
+ Parameters:
29
+ - sex (str): The sex of the individual ('male' or 'female'). Case insensitive.
30
+ - age (float): Age of the individual in years. Must be between 30 and 79.
31
+ - total_cholesterol (float): Total cholesterol level (mg/dL). Must be between 130 and 320.
32
+ - hdl_cholesterol (float): High-density lipoprotein cholesterol level (mg/dL). Must be between 20 and 100.
33
+ - systolic_bp (float): Systolic blood pressure (mmHg). Must be between 90 and 200.
34
+ - has_diabetes (bool): Indicates if the individual has diabetes (True or False).
35
+ - current_smoker (bool): Indicates if the individual is a current smoker (True or False).
36
+ - bmi (float): Body mass index (kg/m^2). Must be between 18.5 and 39.9.
37
+ - egfr (float): Estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140.
38
+ - on_htn_meds (bool): Indicates if the individual is on hypertension medication (True or False).
39
+ - on_cholesterol_meds (bool): Indicates if the individual is on cholesterol-lowering medication (True or False).
40
+
41
+ Returns:
42
+ float: The estimated 10-year ASCVD risk percentage.
43
+
44
+ Raises:
45
+ ValueError: If any of the input parameters are outside their valid ranges.
46
+
47
+ Example:
48
+ >>> calculate_10_yr_ascvd_risk(
49
+ ... sex="male",
50
+ ... age=45,
51
+ ... total_cholesterol=210,
52
+ ... hdl_cholesterol=55,
53
+ ... systolic_bp=130,
54
+ ... has_diabetes=False,
55
+ ... current_smoker=True,
56
+ ... bmi=28,
57
+ ... egfr=65,
58
+ ... on_htn_meds=False,
59
+ ... on_cholesterol_meds=False,
60
+ ... )
61
+ # Returns: Estimated 10-year ASCVD risk percentage (e.g., 12.3)
62
+ """
63
+ return _pyprevent.calculate_10_yr_ascvd_rust(
64
+ sex,
65
+ age,
66
+ total_cholesterol,
67
+ hdl_cholesterol,
68
+ systolic_bp,
69
+ has_diabetes,
70
+ current_smoker,
71
+ bmi,
72
+ egfr,
73
+ on_htn_meds,
74
+ on_cholesterol_meds,
75
+ )
76
+
77
+
78
+ def calculate_30_yr_ascvd_risk(
79
+ sex: str,
80
+ age: float,
81
+ total_cholesterol: float,
82
+ hdl_cholesterol: float,
83
+ systolic_bp: float,
84
+ has_diabetes: bool,
85
+ current_smoker: bool,
86
+ bmi: float,
87
+ egfr: float,
88
+ on_htn_meds: bool,
89
+ on_cholesterol_meds: bool,
90
+ ) -> float:
91
+ """
92
+ Calculate the 30-year risk of atherosclerotic cardiovascular disease (ASCVD).
93
+
94
+ This function uses various health and lifestyle parameters to estimate the risk
95
+ of developing ASCVD over the next 30 years. The input values must fall within
96
+ specified ranges for the calculation to be valid.
97
+
98
+ Parameters:
99
+ - sex (str): The sex of the individual ('male' or 'female'). Case insensitive.
100
+ - age (float): Age of the individual in years. Must be between 30 and 59.
101
+ - total_cholesterol (float): Total cholesterol level (mg/dL). Must be between 130 and 320.
102
+ - hdl_cholesterol (float): High-density lipoprotein cholesterol level (mg/dL). Must be between 20 and 100.
103
+ - systolic_bp (float): Systolic blood pressure (mmHg). Must be between 90 and 200.
104
+ - has_diabetes (bool): Indicates if the individual has diabetes (True or False).
105
+ - current_smoker (bool): Indicates if the individual is a current smoker (True or False).
106
+ - bmi (float): Body mass index (kg/m^2). Must be between 18.5 and 39.9.
107
+ - egfr (float): Estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140.
108
+ - on_htn_meds (bool): Indicates if the individual is on hypertension medication (True or False).
109
+ - on_cholesterol_meds (bool): Indicates if the individual is on cholesterol-lowering medication (True or False).
110
+
111
+ Returns:
112
+ float: The estimated 30-year ASCVD risk percentage.
113
+
114
+ Raises:
115
+ ValueError: If any of the input parameters are outside their valid ranges.
116
+
117
+ Example:
118
+ >>> calculate_30_yr_ascvd_risk(
119
+ ... sex="male",
120
+ ... age=45,
121
+ ... total_cholesterol=210,
122
+ ... hdl_cholesterol=55,
123
+ ... systolic_bp=130,
124
+ ... has_diabetes=False,
125
+ ... current_smoker=True,
126
+ ... bmi=28,
127
+ ... egfr=65,
128
+ ... on_htn_meds=False,
129
+ ... on_cholesterol_meds=False,
130
+ ... )
131
+ # Returns: Estimated 30-year ASCVD risk percentage (e.g., 12.3)
132
+ """
133
+ return _pyprevent.calculate_30_yr_ascvd_rust(
134
+ sex,
135
+ age,
136
+ total_cholesterol,
137
+ hdl_cholesterol,
138
+ systolic_bp,
139
+ has_diabetes,
140
+ current_smoker,
141
+ bmi,
142
+ egfr,
143
+ on_htn_meds,
144
+ on_cholesterol_meds,
145
+ )
146
+
147
+
148
+ def batch_calculate_10_yr_ascvd_risk(
149
+ df: pd.DataFrame,
150
+ sex: str = "sex",
151
+ age: str = "age",
152
+ total_cholesterol: str = "total_cholesterol",
153
+ hdl_cholesterol: str = "hdl_cholesterol",
154
+ systolic_bp: str = "systolic_bp",
155
+ has_diabetes: str = "has_diabetes",
156
+ current_smoker: str = "current_smoker",
157
+ bmi: str = "bmi",
158
+ egfr: str = "egfr",
159
+ on_htn_meds: str = "on_htn_meds",
160
+ on_cholesterol_meds: str = "on_cholesterol_meds",
161
+ **kwargs,
162
+ ) -> np.ndarray:
163
+ """
164
+ Batch calculate the 10-year risk of atherosclerotic cardiovascular disease (ASCVD) for a dataset.
165
+
166
+ This function processes a DataFrame with health and lifestyle parameters to estimate
167
+ the 10-year ASCVD risk for each individual in the dataset. The input values must fall
168
+ within specified ranges for the calculation to be valid.
169
+
170
+ Parameters:
171
+ - df (pd.DataFrame): DataFrame containing the required data.
172
+ - sex (str): Column name for the sex of the individuals ('male' or 'female'). Case insensitive. Default 'sex'.
173
+ - age (str): Column name for the age of the individuals in years. Must be between 30 and 79. Default 'age'.
174
+ - total_cholesterol (str): Column name for the total cholesterol level (mg/dL). Must be between 130 and 320. Default 'total_cholesterol'.
175
+ - hdl_cholesterol (str): Column name for the HDL cholesterol level (mg/dL). Must be between 20 and 100. Default 'hdl_cholesterol'.
176
+ - systolic_bp (str): Column name for the systolic blood pressure (mmHg). Must be between 90 and 200. Default 'systolic_bp'.
177
+ - has_diabetes (str): Column name indicating if the individual has diabetes (True or False). Default 'has_diabetes'.
178
+ - current_smoker (str): Column name indicating if the individual is a current smoker (True or False). Default 'current_smoker'.
179
+ - bmi (str): Column name for the body mass index (kg/m^2). Must be between 18.5 and 39.9. Default 'bmi'.
180
+ - egfr (str): Column name for the estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140. Default 'egfr'.
181
+ - on_htn_meds (str): Column name indicating if the individual is on hypertension medication (True or False). Default 'on_htn_meds'.
182
+ - on_cholesterol_meds (str): Column name indicating if the individual is on cholesterol-lowering medication (True or False). Default 'on_cholesterol_meds'.
183
+ - **kwargs: Optional keyword arguments for custom column mappings.
184
+
185
+ Returns:
186
+ numpy.ndarray: A numpy array of estimated 10-year ASCVD risk percentages for each individual in the DataFrame.
187
+
188
+ Raises:
189
+ ValueError: If any of the input parameters are outside their valid ranges or if the specified columns are not found in the DataFrame.
190
+
191
+ Example:
192
+ >>> df = pd.DataFrame({...})
193
+ >>> risks = batch_calculate_10_yr_ascvd_risk(df, sex='gender', age='patient_age', ...)
194
+ >>> print(risks)
195
+ # Returns: A np.array of estimated 10-year ASCVD risk percentages
196
+
197
+ Alternatively, can pass in a dictionary of column mappings
198
+ >>> df = pd.DataFrame({...})
199
+ >>> column_mappings = {
200
+ ... 'sex': 'gender_column',
201
+ ... 'age': 'age_column',
202
+ ... 'total_cholesterol': 'cholesterol_total',
203
+ ... 'hdl_cholesterol': 'cholesterol_hdl',
204
+ ... 'systolic_bp': 'bp_systolic',
205
+ ... 'has_diabetes': 'diabetes_status',
206
+ ... 'current_smoker': 'smoker_status',
207
+ ... 'bmi': 'body_mass_index',
208
+ ... 'egfr': 'glomerular_rate',
209
+ ... 'on_htn_meds': 'hypertension_meds',
210
+ ... 'on_cholesterol_meds': 'cholesterol_meds'
211
+ ... }
212
+ >>> risks = batch_calculate_10_yr_ascvd_risk(df, **column_mappings)
213
+ # Returns: A np.array of estimated 10-year ASCVD risk percentages
214
+ """
215
+
216
+ data = _prepare_df_for_batch(
217
+ df,
218
+ sex,
219
+ age,
220
+ total_cholesterol,
221
+ hdl_cholesterol,
222
+ systolic_bp,
223
+ has_diabetes,
224
+ current_smoker,
225
+ bmi,
226
+ egfr,
227
+ on_htn_meds,
228
+ on_cholesterol_meds,
229
+ **kwargs,
230
+ )
231
+
232
+ # Calculate ASCVD risk for each row
233
+ result = _pyprevent.calculate_10_yr_ascvd_rust_parallel_np(data=data)
234
+ _report_any_null_values(result)
235
+
236
+ return result
237
+
238
+
239
+ def batch_calculate_30_yr_ascvd_risk(
240
+ df: pd.DataFrame,
241
+ sex: str = "sex",
242
+ age: str = "age",
243
+ total_cholesterol: str = "total_cholesterol",
244
+ hdl_cholesterol: str = "hdl_cholesterol",
245
+ systolic_bp: str = "systolic_bp",
246
+ has_diabetes: str = "has_diabetes",
247
+ current_smoker: str = "current_smoker",
248
+ bmi: str = "bmi",
249
+ egfr: str = "egfr",
250
+ on_htn_meds: str = "on_htn_meds",
251
+ on_cholesterol_meds: str = "on_cholesterol_meds",
252
+ **kwargs,
253
+ ) -> np.ndarray:
254
+ """
255
+ Batch calculate the 30-year risk of atherosclerotic cardiovascular disease (ASCVD) for a dataset.
256
+
257
+ This function processes a DataFrame with health and lifestyle parameters to estimate
258
+ the 30-year ASCVD risk for each individual in the dataset. The input values must fall
259
+ within specified ranges for the calculation to be valid.
260
+
261
+ Parameters:
262
+ - df (pd.DataFrame): DataFrame containing the required data.
263
+ - sex (str): Column name for the sex of the individuals ('male' or 'female'). Case insensitive. Default 'sex'.
264
+ - age (str): Column name for the age of the individuals in years. Must be between 30 and 59. Default 'age'.
265
+ - total_cholesterol (str): Column name for the total cholesterol level (mg/dL). Must be between 130 and 320. Default 'total_cholesterol'.
266
+ - hdl_cholesterol (str): Column name for the HDL cholesterol level (mg/dL). Must be between 20 and 100. Default 'hdl_cholesterol'.
267
+ - systolic_bp (str): Column name for the systolic blood pressure (mmHg). Must be between 90 and 200. Default 'systolic_bp'.
268
+ - has_diabetes (str): Column name indicating if the individual has diabetes (True or False). Default 'has_diabetes'.
269
+ - current_smoker (str): Column name indicating if the individual is a current smoker (True or False). Default 'current_smoker'.
270
+ - bmi (str): Column name for the body mass index (kg/m^2). Must be between 18.5 and 39.9. Default 'bmi'.
271
+ - egfr (str): Column name for the estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140. Default 'egfr'.
272
+ - on_htn_meds (str): Column name indicating if the individual is on hypertension medication (True or False). Default 'on_htn_meds'.
273
+ - on_cholesterol_meds (str): Column name indicating if the individual is on cholesterol-lowering medication (True or False). Default 'on_cholesterol_meds'.
274
+ - **kwargs: Optional keyword arguments for custom column mappings.
275
+
276
+ Returns:
277
+ numpy.ndarray: A list of estimated 30-year ASCVD risk percentages for each individual in the DataFrame.
278
+
279
+ Raises:
280
+ ValueError: If any of the input parameters are outside their valid ranges or if the specified columns are not found in the DataFrame.
281
+
282
+ Example:
283
+ >>> df = pd.DataFrame({...})
284
+ >>> risks = batch_calculate_30_yr_ascvd_risk(df, sex='gender', age='patient_age', ...)
285
+ >>> print(risks)
286
+ # Returns: A numpy array of estimated 30-year ASCVD risk percentages
287
+
288
+ Alternatively, can pass in a dictionary of column mappings
289
+ >>> df = pd.DataFrame({...})
290
+ >>> column_mappings = {
291
+ ... 'sex': 'gender_column',
292
+ ... 'age': 'age_column',
293
+ ... 'total_cholesterol': 'cholesterol_total',
294
+ ... 'hdl_cholesterol': 'cholesterol_hdl',
295
+ ... 'systolic_bp': 'bp_systolic',
296
+ ... 'has_diabetes': 'diabetes_status',
297
+ ... 'current_smoker': 'smoker_status',
298
+ ... 'bmi': 'body_mass_index',
299
+ ... 'egfr': 'glomerular_rate',
300
+ ... 'on_htn_meds': 'hypertension_meds',
301
+ ... 'on_cholesterol_meds': 'cholesterol_meds'
302
+ ... }
303
+ >>> risks = batch_calculate_30_yr_ascvd_risk(df, **column_mappings)
304
+ # Returns: A numpy array of estimated 30-year ASCVD risk percentages
305
+ """
306
+ # Default column names
307
+ data = _prepare_df_for_batch(
308
+ df,
309
+ sex,
310
+ age,
311
+ total_cholesterol,
312
+ hdl_cholesterol,
313
+ systolic_bp,
314
+ has_diabetes,
315
+ current_smoker,
316
+ bmi,
317
+ egfr,
318
+ on_htn_meds,
319
+ on_cholesterol_meds,
320
+ **kwargs,
321
+ )
322
+
323
+ # Calculate ASCVD risk for each row
324
+ result = _pyprevent.calculate_30_yr_ascvd_rust_parallel_np(data=data)
325
+ _report_any_null_values(result)
326
+
327
+ return result
pyprevent/cvd.py ADDED
@@ -0,0 +1,384 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+ from pyprevent import _pyprevent
4
+
5
+ from .utils import _prepare_df_for_batch, _report_any_null_values
6
+
7
+ """
8
+ def calculate_10_yr_ascvd_risk(
9
+ sex: str,
10
+ age: float,
11
+ total_cholesterol: float,
12
+ hdl_cholesterol: float,
13
+ systolic_bp: float,
14
+ has_diabetes: bool,
15
+ current_smoker: bool,
16
+ bmi: float,
17
+ egfr: float,
18
+ on_htn_meds: bool,
19
+ on_cholesterol_meds: bool,
20
+ ) -> float:
21
+ return _pyprevent.calculate_10_yr_ascvd_rust(
22
+ sex,
23
+ age,
24
+ total_cholesterol,
25
+ hdl_cholesterol,
26
+ systolic_bp,
27
+ has_diabetes,
28
+ current_smoker,
29
+ bmi,
30
+ egfr,
31
+ on_htn_meds,
32
+ on_cholesterol_meds,
33
+ )
34
+
35
+
36
+ def calculate_30_yr_ascvd_risk(
37
+ sex: str,
38
+ age: float,
39
+ total_cholesterol: float,
40
+ hdl_cholesterol: float,
41
+ systolic_bp: float,
42
+ has_diabetes: bool,
43
+ current_smoker: bool,
44
+ bmi: float,
45
+ egfr: float,
46
+ on_htn_meds: bool,
47
+ on_cholesterol_meds: bool,
48
+ ) -> float:
49
+ return _pyprevent.calculate_30_yr_ascvd_rust(
50
+ sex,
51
+ age,
52
+ total_cholesterol,
53
+ hdl_cholesterol,
54
+ systolic_bp,
55
+ has_diabetes,
56
+ current_smoker,
57
+ bmi,
58
+ egfr,
59
+ on_htn_meds,
60
+ on_cholesterol_meds,
61
+ )
62
+ """
63
+
64
+
65
+ def calculate_10_yr_cvd_risk(
66
+ sex: str,
67
+ age: float,
68
+ total_cholesterol: float,
69
+ hdl_cholesterol: float,
70
+ systolic_bp: float,
71
+ has_diabetes: bool,
72
+ current_smoker: bool,
73
+ bmi: float,
74
+ egfr: float,
75
+ on_htn_meds: bool,
76
+ on_cholesterol_meds: bool,
77
+ ) -> float:
78
+ """
79
+ Calculate the 10-year risk of cardiovascular disease .
80
+
81
+ This function uses various health and lifestyle parameters to estimate the risk
82
+ of developing CVD over the next 10 years. The input values must fall within
83
+ specified ranges for the calculation to be valid.
84
+
85
+ Parameters:
86
+ - sex (str): The sex of the individual ('male' or 'female'). Case insensitive.
87
+ - age (float): Age of the individual in years. Must be between 30 and 79.
88
+ - total_cholesterol (float): Total cholesterol level (mg/dL). Must be between 130 and 320.
89
+ - hdl_cholesterol (float): High-density lipoprotein cholesterol level (mg/dL). Must be between 20 and 100.
90
+ - systolic_bp (float): Systolic blood pressure (mmHg). Must be between 90 and 200.
91
+ - has_diabetes (bool): Indicates if the individual has diabetes (True or False).
92
+ - current_smoker (bool): Indicates if the individual is a current smoker (True or False).
93
+ - bmi (float): Body mass index (kg/m^2). Must be between 18.5 and 39.9.
94
+ - egfr (float): Estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140.
95
+ - on_htn_meds (bool): Indicates if the individual is on hypertension medication (True or False).
96
+ - on_cholesterol_meds (bool): Indicates if the individual is on cholesterol-lowering medication (True or False).
97
+
98
+ Returns:
99
+ float: The estimated 10-year CVD risk percentage.
100
+
101
+ Raises:
102
+ ValueError: If any of the input parameters are outside their valid ranges.
103
+
104
+ Example:
105
+ >>> calculate_10_yr_cvd_risk(
106
+ ... sex="male",
107
+ ... age=45,
108
+ ... total_cholesterol=210,
109
+ ... hdl_cholesterol=55,
110
+ ... systolic_bp=130,
111
+ ... has_diabetes=False,
112
+ ... current_smoker=True,
113
+ ... bmi=28,
114
+ ... egfr=65,
115
+ ... on_htn_meds=False,
116
+ ... on_cholesterol_meds=False,
117
+ ... )
118
+ # Returns: Estimated 10-year CVD risk percentage (e.g., 12.3)
119
+ """
120
+ return _pyprevent.calculate_10_yr_cvd_rust(
121
+ sex,
122
+ age,
123
+ total_cholesterol,
124
+ hdl_cholesterol,
125
+ systolic_bp,
126
+ has_diabetes,
127
+ current_smoker,
128
+ bmi,
129
+ egfr,
130
+ on_htn_meds,
131
+ on_cholesterol_meds,
132
+ )
133
+
134
+
135
+ def calculate_30_yr_cvd_risk(
136
+ sex: str,
137
+ age: float,
138
+ total_cholesterol: float,
139
+ hdl_cholesterol: float,
140
+ systolic_bp: float,
141
+ has_diabetes: bool,
142
+ current_smoker: bool,
143
+ bmi: float,
144
+ egfr: float,
145
+ on_htn_meds: bool,
146
+ on_cholesterol_meds: bool,
147
+ ) -> float:
148
+ """
149
+ Calculate the 30-year risk of cardiovascular disease (CVD).
150
+
151
+ This function uses various health and lifestyle parameters to estimate the risk
152
+ of developing CVD over the next 30 years. The input values must fall within
153
+ specified ranges for the calculation to be valid.
154
+
155
+ Parameters:
156
+ - sex (str): The sex of the individual ('male' or 'female'). Case insensitive.
157
+ - age (float): Age of the individual in years. Must be between 30 and 59.
158
+ - total_cholesterol (float): Total cholesterol level (mg/dL). Must be between 130 and 320.
159
+ - hdl_cholesterol (float): High-density lipoprotein cholesterol level (mg/dL). Must be between 20 and 100.
160
+ - systolic_bp (float): Systolic blood pressure (mmHg). Must be between 90 and 200.
161
+ - has_diabetes (bool): Indicates if the individual has diabetes (True or False).
162
+ - current_smoker (bool): Indicates if the individual is a current smoker (True or False).
163
+ - bmi (float): Body mass index (kg/m^2). Must be between 18.5 and 39.9.
164
+ - egfr (float): Estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140.
165
+ - on_htn_meds (bool): Indicates if the individual is on hypertension medication (True or False).
166
+ - on_cholesterol_meds (bool): Indicates if the individual is on cholesterol-lowering medication (True or False).
167
+
168
+ Returns:
169
+ float: The estimated 30-year CVD risk percentage.
170
+
171
+ Raises:
172
+ ValueError: If any of the input parameters are outside their valid ranges.
173
+
174
+ Example:
175
+ >>> calculate_30_yr_cvd_risk(
176
+ ... sex="male",
177
+ ... age=45,
178
+ ... total_cholesterol=210,
179
+ ... hdl_cholesterol=55,
180
+ ... systolic_bp=130,
181
+ ... has_diabetes=False,
182
+ ... current_smoker=True,
183
+ ... bmi=28,
184
+ ... egfr=65,
185
+ ... on_htn_meds=False,
186
+ ... on_cholesterol_meds=False,
187
+ ... )
188
+ # Returns: Estimated 30-year CVD risk percentage (e.g., 12.3)
189
+ """
190
+ return _pyprevent.calculate_30_yr_cvd_rust(
191
+ sex,
192
+ age,
193
+ total_cholesterol,
194
+ hdl_cholesterol,
195
+ systolic_bp,
196
+ has_diabetes,
197
+ current_smoker,
198
+ bmi,
199
+ egfr,
200
+ on_htn_meds,
201
+ on_cholesterol_meds,
202
+ )
203
+
204
+
205
+ def batch_calculate_10_yr_cvd_risk(
206
+ df: pd.DataFrame,
207
+ sex: str = "sex",
208
+ age: str = "age",
209
+ total_cholesterol: str = "total_cholesterol",
210
+ hdl_cholesterol: str = "hdl_cholesterol",
211
+ systolic_bp: str = "systolic_bp",
212
+ has_diabetes: str = "has_diabetes",
213
+ current_smoker: str = "current_smoker",
214
+ bmi: str = "bmi",
215
+ egfr: str = "egfr",
216
+ on_htn_meds: str = "on_htn_meds",
217
+ on_cholesterol_meds: str = "on_cholesterol_meds",
218
+ **kwargs,
219
+ ) -> np.ndarray:
220
+ """
221
+ Batch calculate the 10-year risk of cardiovascular disease (CVD) for a dataset.
222
+
223
+ This function processes a DataFrame with health and lifestyle parameters to estimate
224
+ the 10-year CVD risk for each individual in the dataset. The input values must fall
225
+ within specified ranges for the calculation to be valid.
226
+
227
+ Parameters:
228
+ - df (pd.DataFrame): DataFrame containing the required data.
229
+ - sex (str): Column name for the sex of the individuals ('male' or 'female'). Case insensitive. Default 'sex'.
230
+ - age (str): Column name for the age of the individuals in years. Must be between 30 and 79. Default 'age'.
231
+ - total_cholesterol (str): Column name for the total cholesterol level (mg/dL). Must be between 130 and 320. Default 'total_cholesterol'.
232
+ - hdl_cholesterol (str): Column name for the HDL cholesterol level (mg/dL). Must be between 20 and 100. Default 'hdl_cholesterol'.
233
+ - systolic_bp (str): Column name for the systolic blood pressure (mmHg). Must be between 90 and 200. Default 'systolic_bp'.
234
+ - has_diabetes (str): Column name indicating if the individual has diabetes (True or False). Default 'has_diabetes'.
235
+ - current_smoker (str): Column name indicating if the individual is a current smoker (True or False). Default 'current_smoker'.
236
+ - bmi (str): Column name for the body mass index (kg/m^2). Must be between 18.5 and 39.9. Default 'bmi'.
237
+ - egfr (str): Column name for the estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140. Default 'egfr'.
238
+ - on_htn_meds (str): Column name indicating if the individual is on hypertension medication (True or False). Default 'on_htn_meds'.
239
+ - on_cholesterol_meds (str): Column name indicating if the individual is on cholesterol-lowering medication (True or False). Default 'on_cholesterol_meds'.
240
+ - **kwargs: Optional keyword arguments for custom column mappings.
241
+
242
+ Returns:
243
+ np.ndarray: A numpy array of estimated 10-year CVD risk percentages for each individual in the DataFrame.
244
+
245
+ Raises:
246
+ ValueError: If any of the input parameters are outside their valid ranges or if the specified columns are not found in the DataFrame.
247
+
248
+ Example:
249
+ >>> df = pd.DataFrame({...})
250
+ >>> risks = batch_calculate_10_yr_cvd_risk(df, sex='gender', age='patient_age', ...)
251
+ >>> print(risks)
252
+ # Returns: A numpy array of estimated 10-year CVD risk percentages
253
+
254
+ Alternatively, can pass in a dictionary of column mappings
255
+ >>> df = pd.DataFrame({...})
256
+ >>> column_mappings = {
257
+ ... 'sex': 'gender_column',
258
+ ... 'age': 'age_column',
259
+ ... 'total_cholesterol': 'cholesterol_total',
260
+ ... 'hdl_cholesterol': 'cholesterol_hdl',
261
+ ... 'systolic_bp': 'bp_systolic',
262
+ ... 'has_diabetes': 'diabetes_status',
263
+ ... 'current_smoker': 'smoker_status',
264
+ ... 'bmi': 'body_mass_index',
265
+ ... 'egfr': 'glomerular_rate',
266
+ ... 'on_htn_meds': 'hypertension_meds',
267
+ ... 'on_cholesterol_meds': 'cholesterol_meds'
268
+ ... }
269
+ >>> risks = batch_calculate_10_yr_cvd_risk(df, **column_mappings)
270
+ # Returns: A numpy array of estimated 10-year CVD risk percentages
271
+ """
272
+
273
+ data = _prepare_df_for_batch(
274
+ df,
275
+ sex,
276
+ age,
277
+ total_cholesterol,
278
+ hdl_cholesterol,
279
+ systolic_bp,
280
+ has_diabetes,
281
+ current_smoker,
282
+ bmi,
283
+ egfr,
284
+ on_htn_meds,
285
+ on_cholesterol_meds,
286
+ **kwargs,
287
+ )
288
+
289
+ # Calculate ASCVD risk for each row
290
+ result = _pyprevent.calculate_10_yr_cvd_rust_parallel_np(data=data)
291
+ _report_any_null_values(result)
292
+
293
+ return result
294
+
295
+
296
+ def batch_calculate_30_yr_cvd_risk(
297
+ df: pd.DataFrame,
298
+ sex: str = "sex",
299
+ age: str = "age",
300
+ total_cholesterol: str = "total_cholesterol",
301
+ hdl_cholesterol: str = "hdl_cholesterol",
302
+ systolic_bp: str = "systolic_bp",
303
+ has_diabetes: str = "has_diabetes",
304
+ current_smoker: str = "current_smoker",
305
+ bmi: str = "bmi",
306
+ egfr: str = "egfr",
307
+ on_htn_meds: str = "on_htn_meds",
308
+ on_cholesterol_meds: str = "on_cholesterol_meds",
309
+ **kwargs,
310
+ ) -> np.ndarray:
311
+ """
312
+ Batch calculate the 30-year risk of cardiovascular disease (CVD) for a dataset.
313
+
314
+ This function processes a DataFrame with health and lifestyle parameters to estimate
315
+ the 30-year CVD risk for each individual in the dataset. The input values must fall
316
+ within specified ranges for the calculation to be valid.
317
+
318
+ Parameters:
319
+ - df (pd.DataFrame): DataFrame containing the required data.
320
+ - sex (str): Column name for the sex of the individuals ('male' or 'female'). Case insensitive. Default 'sex'.
321
+ - age (str): Column name for the age of the individuals in years. Must be between 30 and 59. Default 'age'.
322
+ - total_cholesterol (str): Column name for the total cholesterol level (mg/dL). Must be between 130 and 320. Default 'total_cholesterol'.
323
+ - hdl_cholesterol (str): Column name for the HDL cholesterol level (mg/dL). Must be between 20 and 100. Default 'hdl_cholesterol'.
324
+ - systolic_bp (str): Column name for the systolic blood pressure (mmHg). Must be between 90 and 200. Default 'systolic_bp'.
325
+ - has_diabetes (str): Column name indicating if the individual has diabetes (True or False). Default 'has_diabetes'.
326
+ - current_smoker (str): Column name indicating if the individual is a current smoker (True or False). Default 'current_smoker'.
327
+ - bmi (str): Column name for the body mass index (kg/m^2). Must be between 18.5 and 39.9. Default 'bmi'.
328
+ - egfr (str): Column name for the estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140. Default 'egfr'.
329
+ - on_htn_meds (str): Column name indicating if the individual is on hypertension medication (True or False). Default 'on_htn_meds'.
330
+ - on_cholesterol_meds (str): Column name indicating if the individual is on cholesterol-lowering medication (True or False). Default 'on_cholesterol_meds'.
331
+ - **kwargs: Optional keyword arguments for custom column mappings.
332
+
333
+ Returns:
334
+ np.ndarray: A numpy array of estimated 30-year CVD risk percentages for each individual in the DataFrame.
335
+
336
+ Raises:
337
+ ValueError: If any of the input parameters are outside their valid ranges or if the specified columns are not found in the DataFrame.
338
+
339
+ Example:
340
+ >>> df = pd.DataFrame({...})
341
+ >>> risks = batch_calculate_30_yr_cvd_risk(df, sex='gender', age='patient_age', ...)
342
+ >>> print(risks)
343
+ # Returns: A numpy array of estimated 30-year CVD risk percentages
344
+
345
+ Alternatively, can pass in a dictionary of column mappings
346
+ >>> df = pd.DataFrame({...})
347
+ >>> column_mappings = {
348
+ ... 'sex': 'gender_column',
349
+ ... 'age': 'age_column',
350
+ ... 'total_cholesterol': 'cholesterol_total',
351
+ ... 'hdl_cholesterol': 'cholesterol_hdl',
352
+ ... 'systolic_bp': 'bp_systolic',
353
+ ... 'has_diabetes': 'diabetes_status',
354
+ ... 'current_smoker': 'smoker_status',
355
+ ... 'bmi': 'body_mass_index',
356
+ ... 'egfr': 'glomerular_rate',
357
+ ... 'on_htn_meds': 'hypertension_meds',
358
+ ... 'on_cholesterol_meds': 'cholesterol_meds'
359
+ ... }
360
+ >>> risks = batch_calculate_30_yr_cvd_risk(df, **column_mappings)
361
+ # Returns: A numpy array of estimated 30-year CVD risk percentages
362
+ """
363
+
364
+ data = _prepare_df_for_batch(
365
+ df,
366
+ sex,
367
+ age,
368
+ total_cholesterol,
369
+ hdl_cholesterol,
370
+ systolic_bp,
371
+ has_diabetes,
372
+ current_smoker,
373
+ bmi,
374
+ egfr,
375
+ on_htn_meds,
376
+ on_cholesterol_meds,
377
+ **kwargs,
378
+ )
379
+
380
+ # Calculate ASCVD risk for each row
381
+ result = _pyprevent.calculate_30_yr_cvd_rust_parallel_np(data=data)
382
+ _report_any_null_values(result)
383
+
384
+ return result
@@ -0,0 +1,327 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+ from pyprevent import _pyprevent
4
+
5
+ from .utils import _prepare_df_for_batch, _report_any_null_values
6
+
7
+
8
+ def calculate_10_yr_heart_failure_risk(
9
+ sex: str,
10
+ age: float,
11
+ total_cholesterol: float,
12
+ hdl_cholesterol: float,
13
+ systolic_bp: float,
14
+ has_diabetes: bool,
15
+ current_smoker: bool,
16
+ bmi: float,
17
+ egfr: float,
18
+ on_htn_meds: bool,
19
+ on_cholesterol_meds: bool,
20
+ ) -> float:
21
+ """
22
+ Calculate the 10-year risk of developing heart failure (HF).
23
+
24
+ This function uses various health and lifestyle parameters to estimate the risk
25
+ of developing HF over the next 10 years. The input values must fall within
26
+ specified ranges for the calculation to be valid.
27
+
28
+ Parameters:
29
+ - sex (str): The sex of the individual ('male' or 'female'). Case insensitive.
30
+ - age (float): Age of the individual in years. Must be between 30 and 79.
31
+ - total_cholesterol (float): Total cholesterol level (mg/dL). Must be between 130 and 320.
32
+ - hdl_cholesterol (float): High-density lipoprotein cholesterol level (mg/dL). Must be between 20 and 100.
33
+ - systolic_bp (float): Systolic blood pressure (mmHg). Must be between 90 and 200.
34
+ - has_diabetes (bool): Indicates if the individual has diabetes (True or False).
35
+ - current_smoker (bool): Indicates if the individual is a current smoker (True or False).
36
+ - bmi (float): Body mass index (kg/m^2). Must be between 18.5 and 39.9.
37
+ - egfr (float): Estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140.
38
+ - on_htn_meds (bool): Indicates if the individual is on hypertension medication (True or False).
39
+ - on_cholesterol_meds (bool): Indicates if the individual is on cholesterol-lowering medication (True or False).
40
+
41
+ Returns:
42
+ float: The estimated 10-year HF risk percentage.
43
+
44
+ Raises:
45
+ ValueError: If any of the input parameters are outside their valid ranges.
46
+
47
+ Example:
48
+ >>> calculate_10_yr_heart_failure_risk(
49
+ ... sex="male",
50
+ ... age=45,
51
+ ... total_cholesterol=210,
52
+ ... hdl_cholesterol=55,
53
+ ... systolic_bp=130,
54
+ ... has_diabetes=False,
55
+ ... current_smoker=True,
56
+ ... bmi=28,
57
+ ... egfr=65,
58
+ ... on_htn_meds=False,
59
+ ... on_cholesterol_meds=False,
60
+ ... )
61
+ # Returns: Estimated 10-year HF risk percentage (e.g., 12.3)
62
+ """
63
+ return _pyprevent.calculate_10_yr_heart_failure_rust(
64
+ sex,
65
+ age,
66
+ total_cholesterol,
67
+ hdl_cholesterol,
68
+ systolic_bp,
69
+ has_diabetes,
70
+ current_smoker,
71
+ bmi,
72
+ egfr,
73
+ on_htn_meds,
74
+ on_cholesterol_meds,
75
+ )
76
+
77
+
78
+ def calculate_30_yr_heart_failure_risk(
79
+ sex: str,
80
+ age: float,
81
+ total_cholesterol: float,
82
+ hdl_cholesterol: float,
83
+ systolic_bp: float,
84
+ has_diabetes: bool,
85
+ current_smoker: bool,
86
+ bmi: float,
87
+ egfr: float,
88
+ on_htn_meds: bool,
89
+ on_cholesterol_meds: bool,
90
+ ) -> float:
91
+ """
92
+ Calculate the 30-year risk of developing heart failure (HF).
93
+
94
+ This function uses various health and lifestyle parameters to estimate the risk
95
+ of developing HF over the next 30 years. The input values must fall within
96
+ specified ranges for the calculation to be valid.
97
+
98
+ Parameters:
99
+ - sex (str): The sex of the individual ('male' or 'female'). Case insensitive.
100
+ - age (float): Age of the individual in years. Must be between 30 and 59.
101
+ - total_cholesterol (float): Total cholesterol level (mg/dL). Must be between 130 and 320.
102
+ - hdl_cholesterol (float): High-density lipoprotein cholesterol level (mg/dL). Must be between 20 and 100.
103
+ - systolic_bp (float): Systolic blood pressure (mmHg). Must be between 90 and 200.
104
+ - has_diabetes (bool): Indicates if the individual has diabetes (True or False).
105
+ - current_smoker (bool): Indicates if the individual is a current smoker (True or False).
106
+ - bmi (float): Body mass index (kg/m^2). Must be between 18.5 and 39.9.
107
+ - egfr (float): Estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140.
108
+ - on_htn_meds (bool): Indicates if the individual is on hypertension medication (True or False).
109
+ - on_cholesterol_meds (bool): Indicates if the individual is on cholesterol-lowering medication (True or False).
110
+
111
+ Returns:
112
+ float: The estimated 30-year HF risk percentage.
113
+
114
+ Raises:
115
+ ValueError: If any of the input parameters are outside their valid ranges.
116
+
117
+ Example:
118
+ >>> calculate_30_yr_heart_failure_risk(
119
+ ... sex="male",
120
+ ... age=45,
121
+ ... total_cholesterol=210,
122
+ ... hdl_cholesterol=55,
123
+ ... systolic_bp=130,
124
+ ... has_diabetes=False,
125
+ ... current_smoker=True,
126
+ ... bmi=28,
127
+ ... egfr=65,
128
+ ... on_htn_meds=False,
129
+ ... on_cholesterol_meds=False,
130
+ ... )
131
+ # Returns: Estimated 30-year CVD risk percentage (e.g., 12.3)
132
+ """
133
+ return _pyprevent.calculate_30_yr_heart_failure_rust(
134
+ sex,
135
+ age,
136
+ total_cholesterol,
137
+ hdl_cholesterol,
138
+ systolic_bp,
139
+ has_diabetes,
140
+ current_smoker,
141
+ bmi,
142
+ egfr,
143
+ on_htn_meds,
144
+ on_cholesterol_meds,
145
+ )
146
+
147
+
148
+ def batch_calculate_10_yr_heart_failure_risk(
149
+ df: pd.DataFrame,
150
+ sex: str = "sex",
151
+ age: str = "age",
152
+ total_cholesterol: str = "total_cholesterol",
153
+ hdl_cholesterol: str = "hdl_cholesterol",
154
+ systolic_bp: str = "systolic_bp",
155
+ has_diabetes: str = "has_diabetes",
156
+ current_smoker: str = "current_smoker",
157
+ bmi: str = "bmi",
158
+ egfr: str = "egfr",
159
+ on_htn_meds: str = "on_htn_meds",
160
+ on_cholesterol_meds: str = "on_cholesterol_meds",
161
+ **kwargs,
162
+ ) -> np.ndarray:
163
+ """
164
+ Batch calculate the 10-year risk of heart failure (HF) for a dataset.
165
+
166
+ This function processes a DataFrame with health and lifestyle parameters to estimate
167
+ the 10-year HF risk for each individual in the dataset. The input values must fall
168
+ within specified ranges for the calculation to be valid.
169
+
170
+ Parameters:
171
+ - df (pd.DataFrame): DataFrame containing the required data.
172
+ - sex (str): Column name for the sex of the individuals ('male' or 'female'). Case insensitive. Default 'sex'.
173
+ - age (str): Column name for the age of the individuals in years. Must be between 30 and 79. Default 'age'.
174
+ - total_cholesterol (str): Column name for the total cholesterol level (mg/dL). Must be between 130 and 320. Default 'total_cholesterol'.
175
+ - hdl_cholesterol (str): Column name for the HDL cholesterol level (mg/dL). Must be between 20 and 100. Default 'hdl_cholesterol'.
176
+ - systolic_bp (str): Column name for the systolic blood pressure (mmHg). Must be between 90 and 200. Default 'systolic_bp'.
177
+ - has_diabetes (str): Column name indicating if the individual has diabetes (True or False). Default 'has_diabetes'.
178
+ - current_smoker (str): Column name indicating if the individual is a current smoker (True or False). Default 'current_smoker'.
179
+ - bmi (str): Column name for the body mass index (kg/m^2). Must be between 18.5 and 39.9. Default 'bmi'.
180
+ - egfr (str): Column name for the estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140. Default 'egfr'.
181
+ - on_htn_meds (str): Column name indicating if the individual is on hypertension medication (True or False). Default 'on_htn_meds'.
182
+ - on_cholesterol_meds (str): Column name indicating if the individual is on cholesterol-lowering medication (True or False). Default 'on_cholesterol_meds'.
183
+ - **kwargs: Optional keyword arguments for custom column mappings.
184
+
185
+ Returns:
186
+ np.ndarray: A numpy array of estimated 10-year HF risk percentages for each individual in the DataFrame.
187
+
188
+ Raises:
189
+ ValueError: If any of the input parameters are outside their valid ranges or if the specified columns are not found in the DataFrame.
190
+
191
+ Example:
192
+ >>> df = pd.DataFrame({...})
193
+ >>> risks = batch_calculate_10_yr_heart_failure_risk(df, sex='gender', age='patient_age', ...)
194
+ >>> print(risks)
195
+ # Returns: A numpy array of estimated 10-year HF risk percentages
196
+
197
+ Alternatively, can pass in a dictionary of column mappings
198
+ >>> df = pd.DataFrame({...})
199
+ >>> column_mappings = {
200
+ ... 'sex': 'gender_column',
201
+ ... 'age': 'age_column',
202
+ ... 'total_cholesterol': 'cholesterol_total',
203
+ ... 'hdl_cholesterol': 'cholesterol_hdl',
204
+ ... 'systolic_bp': 'bp_systolic',
205
+ ... 'has_diabetes': 'diabetes_status',
206
+ ... 'current_smoker': 'smoker_status',
207
+ ... 'bmi': 'body_mass_index',
208
+ ... 'egfr': 'glomerular_rate',
209
+ ... 'on_htn_meds': 'hypertension_meds',
210
+ ... 'on_cholesterol_meds': 'cholesterol_meds'
211
+ ... }
212
+ >>> risks = batch_calculate_10_yr_heart_failure_risk(df, **column_mappings)
213
+ # Returns: A numpy array of estimated 10-year HF risk percentages
214
+ """
215
+
216
+ data = _prepare_df_for_batch(
217
+ df,
218
+ sex,
219
+ age,
220
+ total_cholesterol,
221
+ hdl_cholesterol,
222
+ systolic_bp,
223
+ has_diabetes,
224
+ current_smoker,
225
+ bmi,
226
+ egfr,
227
+ on_htn_meds,
228
+ on_cholesterol_meds,
229
+ **kwargs,
230
+ )
231
+
232
+ # Calculate risk for each row
233
+ result = _pyprevent.calculate_10_yr_hf_rust_parallel_np(data=data)
234
+ _report_any_null_values(result)
235
+
236
+ return result
237
+
238
+
239
+ def batch_calculate_30_yr_heart_failure_risk(
240
+ df: pd.DataFrame,
241
+ sex: str = "sex",
242
+ age: str = "age",
243
+ total_cholesterol: str = "total_cholesterol",
244
+ hdl_cholesterol: str = "hdl_cholesterol",
245
+ systolic_bp: str = "systolic_bp",
246
+ has_diabetes: str = "has_diabetes",
247
+ current_smoker: str = "current_smoker",
248
+ bmi: str = "bmi",
249
+ egfr: str = "egfr",
250
+ on_htn_meds: str = "on_htn_meds",
251
+ on_cholesterol_meds: str = "on_cholesterol_meds",
252
+ **kwargs,
253
+ ) -> np.ndarray:
254
+ """
255
+ Batch calculate the 30-year risk of heart failure (HF) for a dataset.
256
+
257
+ This function processes a DataFrame with health and lifestyle parameters to estimate
258
+ the 30-year HF risk for each individual in the dataset. The input values must fall
259
+ within specified ranges for the calculation to be valid.
260
+
261
+ Parameters:
262
+ - df (pd.DataFrame): DataFrame containing the required data.
263
+ - sex (str): Column name for the sex of the individuals ('male' or 'female'). Case insensitive. Default 'sex'.
264
+ - age (str): Column name for the age of the individuals in years. Must be between 30 and 59. Default 'age'.
265
+ - total_cholesterol (str): Column name for the total cholesterol level (mg/dL). Must be between 130 and 320. Default 'total_cholesterol'.
266
+ - hdl_cholesterol (str): Column name for the HDL cholesterol level (mg/dL). Must be between 20 and 100. Default 'hdl_cholesterol'.
267
+ - systolic_bp (str): Column name for the systolic blood pressure (mmHg). Must be between 90 and 200. Default 'systolic_bp'.
268
+ - has_diabetes (str): Column name indicating if the individual has diabetes (True or False). Default 'has_diabetes'.
269
+ - current_smoker (str): Column name indicating if the individual is a current smoker (True or False). Default 'current_smoker'.
270
+ - bmi (str): Column name for the body mass index (kg/m^2). Must be between 18.5 and 39.9. Default 'bmi'.
271
+ - egfr (str): Column name for the estimated glomerular filtration rate (mL/min/1.73 m^2). Must be between 15 and 140. Default 'egfr'.
272
+ - on_htn_meds (str): Column name indicating if the individual is on hypertension medication (True or False). Default 'on_htn_meds'.
273
+ - on_cholesterol_meds (str): Column name indicating if the individual is on cholesterol-lowering medication (True or False). Default 'on_cholesterol_meds'.
274
+ - **kwargs: Optional keyword arguments for custom column mappings.
275
+
276
+ Returns:
277
+ np.ndarray: A numpy array of estimated 30-year HF risk percentages for each individual in the DataFrame.
278
+
279
+ Raises:
280
+ ValueError: If any of the input parameters are outside their valid ranges or if the specified columns are not found in the DataFrame.
281
+
282
+ Example:
283
+ >>> df = pd.DataFrame({...})
284
+ >>> risks = batch_calculate_30_yr_heart_failure_risk(df, sex='gender', age='patient_age', ...)
285
+ >>> print(risks)
286
+ # Returns: A numpy array of estimated 30-year HF risk percentages
287
+
288
+ Alternatively, can pass in a dictionary of column mappings
289
+ >>> df = pd.DataFrame({...})
290
+ >>> column_mappings = {
291
+ ... 'sex': 'gender_column',
292
+ ... 'age': 'age_column',
293
+ ... 'total_cholesterol': 'cholesterol_total',
294
+ ... 'hdl_cholesterol': 'cholesterol_hdl',
295
+ ... 'systolic_bp': 'bp_systolic',
296
+ ... 'has_diabetes': 'diabetes_status',
297
+ ... 'current_smoker': 'smoker_status',
298
+ ... 'bmi': 'body_mass_index',
299
+ ... 'egfr': 'glomerular_rate',
300
+ ... 'on_htn_meds': 'hypertension_meds',
301
+ ... 'on_cholesterol_meds': 'cholesterol_meds'
302
+ ... }
303
+ >>> risks = batch_calculate_30_yr_heart_failure_risk(df, **column_mappings)
304
+ # Returns: A numpy array of estimated 30-year HF risk percentages
305
+ """
306
+ # Default column names
307
+ data = _prepare_df_for_batch(
308
+ df,
309
+ sex,
310
+ age,
311
+ total_cholesterol,
312
+ hdl_cholesterol,
313
+ systolic_bp,
314
+ has_diabetes,
315
+ current_smoker,
316
+ bmi,
317
+ egfr,
318
+ on_htn_meds,
319
+ on_cholesterol_meds,
320
+ **kwargs,
321
+ )
322
+
323
+ # Calculate risk for each row
324
+ result = _pyprevent.calculate_30_yr_hf_rust_parallel_np(data=data)
325
+ _report_any_null_values(result)
326
+
327
+ return result
pyprevent/utils.py ADDED
@@ -0,0 +1,69 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+
4
+
5
+ def _prepare_df_for_batch(
6
+ df: pd.DataFrame,
7
+ sex: str = "sex",
8
+ age: str = "age",
9
+ total_cholesterol: str = "total_cholesterol",
10
+ hdl_cholesterol: str = "hdl_cholesterol",
11
+ systolic_bp: str = "systolic_bp",
12
+ has_diabetes: str = "has_diabetes",
13
+ current_smoker: str = "current_smoker",
14
+ bmi: str = "bmi",
15
+ egfr: str = "egfr",
16
+ on_htn_meds: str = "on_htn_meds",
17
+ on_cholesterol_meds: str = "on_cholesterol_meds",
18
+ **kwargs,
19
+ ) -> np.ndarray:
20
+ # Default column names
21
+ column_mapping = {
22
+ "sex": sex,
23
+ "age": age,
24
+ "total_cholesterol": total_cholesterol,
25
+ "hdl_cholesterol": hdl_cholesterol,
26
+ "systolic_bp": systolic_bp,
27
+ "has_diabetes": has_diabetes,
28
+ "current_smoker": current_smoker,
29
+ "bmi": bmi,
30
+ "egfr": egfr,
31
+ "on_htn_meds": on_htn_meds,
32
+ "on_cholesterol_meds": on_cholesterol_meds,
33
+ }
34
+
35
+ # Update column names with mappings from kwargs if provided
36
+ column_mapping.update(kwargs)
37
+
38
+ # Ensure all required column names exist in the DataFrame
39
+ for key, col in column_mapping.items():
40
+ if col not in df.columns:
41
+ raise ValueError(
42
+ f"Column '{col}' for parameter '{key}' not found in DataFrame."
43
+ )
44
+
45
+ reordered_df = df[[column_mapping[key] for key in column_mapping]].copy()
46
+
47
+ sex_col = column_mapping["sex"]
48
+ reordered_df[sex_col] = (
49
+ reordered_df[sex_col].str.lower().map({"female": 0, "male": 1})
50
+ )
51
+
52
+ # Convert boolean columns to integers based on the column names from column_mapping
53
+ bool_cols = [
54
+ column_mapping["has_diabetes"],
55
+ column_mapping["current_smoker"],
56
+ column_mapping["on_htn_meds"],
57
+ column_mapping["on_cholesterol_meds"],
58
+ ]
59
+ reordered_df[bool_cols] = reordered_df[bool_cols].astype(int)
60
+ return reordered_df.values.astype(np.float64)
61
+
62
+
63
+ def _report_any_null_values(result: np.ndarray) -> None:
64
+ null_rows = np.isnan(result).sum()
65
+ if null_rows > 0:
66
+ print(
67
+ f"WARNING: {null_rows} patients were unable to have the score calculated"
68
+ f"as their input parameters were out of the range."
69
+ )
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyprevent
3
+ Version: 0.1.3
4
+ License-File: LICENSE.txt
5
+ Summary: Python implementation of 2024 AHA PREVENT calculator
6
+ Author-email: lhegstrom@nference.net
7
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
8
+ Project-URL: Source, https://github.com/lhegstrom/PyPrevent/
9
+ Project-URL: Tracker, https://github.com/lhegstrom/PyPrevent/issues
10
+
11
+ # PyPREVENT :anatomical_heart:
12
+
13
+ ###### 2024 updates from AHA on ASCVD (Atherosclerotic and Cardiovascular Disease), CVD (cardiovascular disease) and Heart Failure (HF)
14
+
15
+ <h1 align="center">
16
+ <img src="https://github.com/lhegstrom/PyPREVENT/blob/main/images/PyPreventLogo.png?raw=true" width="100%">
17
+ <br>
18
+ </h1>
19
+
20
+ ![Python- 3.7 --> 3.12](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)
21
+ ![Rust](https://img.shields.io/badge/rust-%23000000.svg?style=for-the-badge&logo=rust&logoColor=white)
22
+
23
+ ## Introduction
24
+ The PyPREVENT Equations package offers 2024 updates from the [American Heart Association (AHA) on Atherosclerotic and
25
+ Cardiovascular Disease (ASCVD), Cardiovascular Disease (CVD), and Heart Failure
26
+ (HF)](https://professional.heart.org/en/guidelines-and-statements/prevent-calculator)[^1][^2]. It's a mixed Rust and Python
27
+ module, leveraging the speed of Rust for equation implementation and the flexibility of Python for ease of use.
28
+
29
+ ## Installation
30
+ **Requirements:**
31
+ - Python 3.7 to 3.12 on a Silicon Mac / Linux system (more compatibility coming soon)
32
+
33
+
34
+ To install the package, pip install using:
35
+ ```bash
36
+ pip install pyprevent
37
+ ```
38
+
39
+ ## TL;DR
40
+
41
+ ```python
42
+ import pyprevent
43
+
44
+ pyprevent.calculate_30_yr_ascvd_risk(
45
+ sex="MALE",
46
+ age=40,
47
+ total_cholesterol=200,
48
+ hdl_cholesterol=50,
49
+ systolic_bp=120,
50
+ has_diabetes=False,
51
+ current_smoker=False,
52
+ bmi=25,
53
+ egfr=70,
54
+ on_htn_meds=False,
55
+ on_cholesterol_meds=False,
56
+ )
57
+ ```
58
+
59
+ ## Examples
60
+
61
+ [A longer, and more thorough example is located here.](example_notebooks/Example%20Notebook.ipynb)
62
+
63
+
64
+ ## Implementation Status
65
+
66
+ | Formula | Status |
67
+ |----------------------------------|--------------------|
68
+ | 10 yr ASCVD (individual) | :white_check_mark: |
69
+ | 10 yr ASCVD (batch) | :white_check_mark: |
70
+ | 30 yr ASCVD (individual) | :white_check_mark: |
71
+ | 30 yr ASCVD (batch) | :white_check_mark: |
72
+ | 10 yr Heart Failure (individual) | :white_check_mark: |
73
+ | 10 yr Heart Failure (batch) | :white_check_mark: |
74
+ | 30 yr Heart Failure (individual) | :white_check_mark: |
75
+ | 30 yr Heart Failure (batch) | :white_check_mark: |
76
+ | 10 yr CVD (individual) | :white_check_mark: |
77
+ | 10 yr CVD (batch) | :white_check_mark: |
78
+ | 30 yr CVD (individual) | :white_check_mark: |
79
+ | 30 yr CVD (batch) | :white_check_mark: |
80
+
81
+
82
+ ## Program Structure
83
+
84
+ This is a mixed [Rust](https://www.rust-lang.org/) and Python module.
85
+
86
+ The rust source code is used to implement the equations. This is a lower level language that requires compilation prior to being run -- and thus is many times faster than pure python.
87
+
88
+ The rust source code is located in the /src directory.
89
+ The individual functions are written in their respective files, and registered to the rust_aha_formulas python module within the lib.rs file.
90
+
91
+ The python source is located in the /pyprevent directory.
92
+
93
+ Unit tests are implemented in the /tests directory using [slash](https://getslash.github.io/slash/).
94
+
95
+
96
+ [^1]: Khan SS, Matsushita K, Sang Y, et al. Development and Validation of the American Heart Association Predicting Risk of Cardiovascular Disease EVENTs (PREVENTTM) Equations. Circulation 2023. DOI: [10.1161/CIRCULATIONAHA.123.067626](https://www.ahajournals.org/doi/10.1161/CIRCULATIONAHA.123.067626)
97
+ [^2]: Khan SS, Coresh J, Pencina MJ, et al. Novel Prediction Equations for Absolute Risk Assessment of Total Cardiovascular Disease Incorporating Cardiovascular-Kidney-Metabolic Health: A Scientific Statement From the American Heart Association. Circulation 2023;148(24):1982-2004. DOI: [10.1161/CIR.0000000000001191](https://www.ahajournals.org/doi/10.1161/CIR.0000000000001191)
98
+
99
+
@@ -0,0 +1,10 @@
1
+ pyprevent-0.1.3.dist-info/METADATA,sha256=9slpLJvRaMH3qIcklIvk3hAeDPw8J3_jIGSPHahLARg,4238
2
+ pyprevent-0.1.3.dist-info/WHEEL,sha256=QWeP2iNVclb1lqJMYxkB3S_jGRNF2KI-alH1eOqR1Tk,95
3
+ pyprevent-0.1.3.dist-info/license_files/LICENSE.txt,sha256=pKu9-Z5HMzqIf7cElXf6Sl6jNqCUKxVILnH3PcghAX4,1095
4
+ pyprevent/ascvd_calc.py,sha256=TaZ8w-_8coUlvF2J-_908qUS_X6u3a6K154wxD5llNk,13924
5
+ pyprevent/cvd.py,sha256=H-yhmEVT7baev_ySJIfEbFAi3hS-3sefmS2YDuVDr5M,14981
6
+ pyprevent/heart_failure.py,sha256=I0bfm9LLBZcRMwdnshMECtCIxhXYhMeyAQ8xyfZayWE,13877
7
+ pyprevent/utils.py,sha256=h8MSy11dVatiog1XnJkb9rZYIMTHpLJZHjyqc3_ZpdI,2304
8
+ pyprevent/__init__.py,sha256=ccZ4SpVqycMpkqOIBra1NMlaxuhbFFWUgG5281ATrNA,409
9
+ pyprevent/_pyprevent.cp311-win_amd64.pyd,sha256=x6-XfsHMwInQJ-nH2WkrXT4pCcT0_vok3dgfFKhJXAo,474624
10
+ pyprevent-0.1.3.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.4.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp311-none-win_amd64
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Lars Hegstrom, MD
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.