meta-edc 1.0.7__py3-none-any.whl → 1.1.0__py3-none-any.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.
- meta_ae/action_items.py +10 -2
- meta_ae/baker_recipes.py +1 -2
- meta_ae/tests/tests/test_actions.py +1 -2
- meta_analytics/notebooks/anu.ipynb +95 -0
- meta_analytics/notebooks/appointment_planning.ipynb +329 -0
- meta_analytics/notebooks/arvs.ipynb +103 -0
- meta_analytics/notebooks/cleaning/consent_v1_ext.ipynb +227 -0
- meta_analytics/notebooks/cleaning/offschedule_eos.ipynb +353 -0
- meta_analytics/notebooks/dsmc/renal_dysfunction.ipynb +435 -0
- meta_analytics/notebooks/endpoints/meta_endpoints_by_date.ipynb +664 -0
- meta_analytics/notebooks/followup_examination.ipynb +141 -0
- meta_analytics/notebooks/hba1c.ipynb +136 -0
- meta_analytics/notebooks/hiv_regimens.ipynb +122 -118
- meta_analytics/notebooks/incidence.ipynb +232 -0
- meta_analytics/notebooks/liver.ipynb +389 -0
- meta_analytics/notebooks/magreth.ipynb +645 -0
- meta_analytics/notebooks/monitoring_report.ipynb +435 -245
- meta_analytics/notebooks/pharmacy.ipynb +405 -306
- meta_analytics/notebooks/pharmacy_stock_202410.ipynb +306 -0
- meta_analytics/notebooks/steering.ipynb +61 -0
- meta_analytics/notebooks/undiagnosed/meta3_screening_consort_chart.ipynb +1176 -0
- meta_analytics/notebooks/undiagnosed/meta3_screening_undiagnosed.ipynb +519 -0
- meta_analytics/notebooks/undiagnosed/meta_screening_table2.ipynb +964 -0
- meta_analytics/notebooks/undiagnosed/screen_undiagnosed_or.ipynb +296 -0
- meta_analytics/notebooks/undiagnosed/screening.ipynb +273 -0
- meta_analytics/notebooks/undiagnosed/screening2.ipynb +958 -0
- meta_analytics/notebooks/undiagnosed/screening_undiagnosed_20241002.ipynb +958 -0
- meta_analytics/notebooks/ven.ipynb +191 -0
- meta_analytics/notebooks/vitals.ipynb +263 -0
- meta_edc/settings/debug.py +3 -2
- meta_edc/urls.py +1 -0
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.0.dist-info}/METADATA +3 -3
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.0.dist-info}/RECORD +55 -28
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.0.dist-info}/WHEEL +1 -1
- meta_labs/reportables.py +14 -11
- meta_labs/tests/test_reportables.py +33 -12
- meta_pharmacy/notebooks/pharmacy.ipynb +41 -0
- meta_prn/migrations/0063_historicaloffstudymedication_singleton_field_and_more.py +37 -0
- meta_prn/migrations/0064_auto_20250602_2143.py +18 -0
- meta_prn/models/end_of_study.py +2 -0
- meta_prn/models/off_study_medication.py +2 -0
- meta_screening/eligibility/eligibility_part_three/base_eligibility_part_three.py +59 -47
- meta_screening/form_validators/screening_part_three.py +6 -1
- meta_screening/tests/meta_test_case_mixin.py +3 -0
- meta_screening/tests/tests/test_forms.py +9 -2
- meta_screening/tests/tests/test_screening_part_three.py +11 -14
- meta_subject/action_items.py +1 -2
- meta_subject/choices.py +2 -1
- meta_subject/forms/blood_results/blood_results_rft_form.py +60 -3
- meta_subject/migrations/0223_bloodresultsfbc_errors_bloodresultsgludummy_errors_and_more.py +83 -0
- meta_subject/migrations/0224_bloodresultsfbc_abnormal_summary_and_more.py +153 -0
- meta_subject/tests/tests/test_egfr.py +5 -5
- meta_analytics/dataframes/enrolled/__init__.py +0 -0
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.0.dist-info}/licenses/AUTHORS.rst +0 -0
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.0.dist-info}/licenses/LICENSE +0 -0
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,645 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"id": "0",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [],
|
9
|
+
"source": [
|
10
|
+
"%%capture\n",
|
11
|
+
"import os\n",
|
12
|
+
"import pandas as pd\n",
|
13
|
+
"import numpy as np\n",
|
14
|
+
"from dj_notebook import activate\n",
|
15
|
+
"from pathlib import Path\n",
|
16
|
+
"\n",
|
17
|
+
"env_file = os.environ[\"META_ENV\"]\n",
|
18
|
+
"reports_folder = Path(os.environ[\"META_REPORTS_FOLDER\"])\n",
|
19
|
+
"analysis_folder = Path(os.environ[\"META_ANALYSIS_FOLDER\"])\n",
|
20
|
+
"plus = activate(dotenv_file=env_file)\n"
|
21
|
+
]
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"cell_type": "code",
|
25
|
+
"execution_count": null,
|
26
|
+
"id": "1",
|
27
|
+
"metadata": {},
|
28
|
+
"outputs": [],
|
29
|
+
"source": [
|
30
|
+
"\"\"\"\n",
|
31
|
+
"Magreth data request\n",
|
32
|
+
"* Medication adherence statistics\n",
|
33
|
+
"* Median (interquartile) age of the cohort\n",
|
34
|
+
"* Median follow-up duration and range\n",
|
35
|
+
"\"\"\""
|
36
|
+
]
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"cell_type": "code",
|
40
|
+
"execution_count": null,
|
41
|
+
"id": "2",
|
42
|
+
"metadata": {},
|
43
|
+
"outputs": [],
|
44
|
+
"source": [
|
45
|
+
"from meta_consent.models import SubjectConsent\n",
|
46
|
+
"from edc_pdutils.dataframes import get_subject_consent, get_subject_visit, get_eos\n",
|
47
|
+
"from edc_constants.constants import FEMALE, MALE\n",
|
48
|
+
"from edc_pdutils.dataframes import get_crf\n",
|
49
|
+
"from datetime import datetime"
|
50
|
+
]
|
51
|
+
},
|
52
|
+
{
|
53
|
+
"cell_type": "code",
|
54
|
+
"execution_count": null,
|
55
|
+
"id": "3",
|
56
|
+
"metadata": {},
|
57
|
+
"outputs": [],
|
58
|
+
"source": [
|
59
|
+
"cutoff_datetime = datetime(2025, 2,1, 0, 0, 0)"
|
60
|
+
]
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"cell_type": "code",
|
64
|
+
"execution_count": null,
|
65
|
+
"id": "4",
|
66
|
+
"metadata": {},
|
67
|
+
"outputs": [],
|
68
|
+
"source": [
|
69
|
+
"df_consent = get_subject_consent(model_cls=SubjectConsent)"
|
70
|
+
]
|
71
|
+
},
|
72
|
+
{
|
73
|
+
"cell_type": "code",
|
74
|
+
"execution_count": null,
|
75
|
+
"id": "5",
|
76
|
+
"metadata": {},
|
77
|
+
"outputs": [],
|
78
|
+
"source": [
|
79
|
+
"# df_consent"
|
80
|
+
]
|
81
|
+
},
|
82
|
+
{
|
83
|
+
"cell_type": "code",
|
84
|
+
"execution_count": null,
|
85
|
+
"id": "6",
|
86
|
+
"metadata": {},
|
87
|
+
"outputs": [],
|
88
|
+
"source": [
|
89
|
+
"df_consent.gender.value_counts()"
|
90
|
+
]
|
91
|
+
},
|
92
|
+
{
|
93
|
+
"cell_type": "code",
|
94
|
+
"execution_count": null,
|
95
|
+
"id": "7",
|
96
|
+
"metadata": {},
|
97
|
+
"outputs": [],
|
98
|
+
"source": [
|
99
|
+
"df_consent.age_in_years.describe()\n"
|
100
|
+
]
|
101
|
+
},
|
102
|
+
{
|
103
|
+
"cell_type": "code",
|
104
|
+
"execution_count": null,
|
105
|
+
"id": "8",
|
106
|
+
"metadata": {},
|
107
|
+
"outputs": [],
|
108
|
+
"source": [
|
109
|
+
"df_visit = get_subject_visit(\"meta_subject.subjectvisit\")\n",
|
110
|
+
"df_visit = df_visit[df_visit.visit_datetime < pd.Timestamp(cutoff_datetime)]\n",
|
111
|
+
"df_visit.reset_index(drop=True, inplace=True)"
|
112
|
+
]
|
113
|
+
},
|
114
|
+
{
|
115
|
+
"cell_type": "code",
|
116
|
+
"execution_count": null,
|
117
|
+
"id": "9",
|
118
|
+
"metadata": {},
|
119
|
+
"outputs": [],
|
120
|
+
"source": [
|
121
|
+
"df_visit.dtypes"
|
122
|
+
]
|
123
|
+
},
|
124
|
+
{
|
125
|
+
"cell_type": "code",
|
126
|
+
"execution_count": null,
|
127
|
+
"id": "10",
|
128
|
+
"metadata": {},
|
129
|
+
"outputs": [],
|
130
|
+
"source": [
|
131
|
+
"\n",
|
132
|
+
"df_eos = get_eos(\"meta_prn.endofstudy\")\n",
|
133
|
+
"df_visit = df_visit.merge(df_eos[[\"subject_identifier\", \"offstudy_datetime\", \"offstudy_reason\"]], on=\"subject_identifier\", how=\"left\")\n"
|
134
|
+
]
|
135
|
+
},
|
136
|
+
{
|
137
|
+
"cell_type": "code",
|
138
|
+
"execution_count": null,
|
139
|
+
"id": "11",
|
140
|
+
"metadata": {},
|
141
|
+
"outputs": [],
|
142
|
+
"source": [
|
143
|
+
"def get_cells_for_categorical(df:pd.DataFrame, col:str, categories:list[str]|None=None, arm:str|None=None)->list[str]:\n",
|
144
|
+
" if arm:\n",
|
145
|
+
" n = len(df[(df['assignment']==arm) & (df[col].notna())])\n",
|
146
|
+
" counts = df[(df['assignment'] == arm) & (df[col].notna())][col].value_counts()\n",
|
147
|
+
" percentages = df[(df['assignment'] == arm) & (df[col].notna())][col].value_counts(normalize=True) * 100\n",
|
148
|
+
" else:\n",
|
149
|
+
" n = len(df[(df[col].notna())])\n",
|
150
|
+
" counts = df[(df[col].notna())][col].value_counts()\n",
|
151
|
+
" percentages = df[(df[col].notna())][col].value_counts(normalize=True) * 100\n",
|
152
|
+
" cells = [n]\n",
|
153
|
+
" for cat in categories:\n",
|
154
|
+
" cells.append(f\"{counts.get(cat, 0)} ({percentages.get(cat, 0):.1f}%)\",)\n",
|
155
|
+
" return cells\n",
|
156
|
+
"\n",
|
157
|
+
"def get_cells_for_continuous(df)->list[str]:\n",
|
158
|
+
" \"\"\" From describe(), format 3 cells as:\n",
|
159
|
+
"\n",
|
160
|
+
" +======================+\n",
|
161
|
+
" | 930 |\n",
|
162
|
+
" +----------------------+\n",
|
163
|
+
" | 127.69(16.84) |\n",
|
164
|
+
" +----------------------+\n",
|
165
|
+
" | 127.00(82.00–183.00) |\n",
|
166
|
+
" +----------------------+\n",
|
167
|
+
" \"\"\"\n",
|
168
|
+
" return [\n",
|
169
|
+
" f\"{int(df['count'])}\",\n",
|
170
|
+
" f\"{df['mean']:.2f}({df['std']:.2f})\",\n",
|
171
|
+
" f\"{df['50%']:.2f}({df['min']:.2f}–{df['max']:.2f})\"\n",
|
172
|
+
" ]\n",
|
173
|
+
"\n",
|
174
|
+
"def get_formatted_rows(df, col:str|None=None):\n",
|
175
|
+
" \"\"\"Returns 5 columns\"\"\"\n",
|
176
|
+
"\n",
|
177
|
+
" df = df[df[col].notna()].copy()\n",
|
178
|
+
" df_all = df[col].describe()\n",
|
179
|
+
"\n",
|
180
|
+
" return {\n",
|
181
|
+
" # 'Timepoint': ['Baseline', '', '', 'Endline', '', ''],\n",
|
182
|
+
" 'Statistics': ['n', 'Mean(sd)', 'Median(min-max)'],\n",
|
183
|
+
" 'All': [\n",
|
184
|
+
" *get_cells_for_continuous(df_all),\n",
|
185
|
+
" ],\n",
|
186
|
+
" }\n",
|
187
|
+
"\n",
|
188
|
+
"def get_formatted_rows_mf(df, col:str|None=None):\n",
|
189
|
+
" \"\"\"Returns 5 columns\"\"\"\n",
|
190
|
+
"\n",
|
191
|
+
" df = df[df[col].notna()].copy()\n",
|
192
|
+
" df_all = df[col].describe()\n",
|
193
|
+
"\n",
|
194
|
+
" return {\n",
|
195
|
+
" # 'Timepoint': ['Baseline', '', '', 'Endline', '', ''],\n",
|
196
|
+
" 'Statistics': ['n', 'Mean(sd)', 'Median(min-max)'],\n",
|
197
|
+
" 'All': [\n",
|
198
|
+
" *get_cells_for_continuous(df_all),\n",
|
199
|
+
" ],\n",
|
200
|
+
" 'Female': [\n",
|
201
|
+
" *get_cells_for_continuous(df[df.gender==FEMALE][col].describe()),\n",
|
202
|
+
" ],\n",
|
203
|
+
" 'Male': [\n",
|
204
|
+
" *get_cells_for_continuous(df[df.gender==MALE][col].describe()),\n",
|
205
|
+
" ],\n",
|
206
|
+
" }\n"
|
207
|
+
]
|
208
|
+
},
|
209
|
+
{
|
210
|
+
"cell_type": "code",
|
211
|
+
"execution_count": null,
|
212
|
+
"id": "12",
|
213
|
+
"metadata": {},
|
214
|
+
"outputs": [],
|
215
|
+
"source": [
|
216
|
+
"def days_on_study(s):\n",
|
217
|
+
" return (s[\"endline_visit_datetime\"] - s[\"baseline_datetime\"]).days\n",
|
218
|
+
"df_visit[\"days_on_study\"] = df_visit.apply(days_on_study, axis=1)"
|
219
|
+
]
|
220
|
+
},
|
221
|
+
{
|
222
|
+
"cell_type": "code",
|
223
|
+
"execution_count": null,
|
224
|
+
"id": "13",
|
225
|
+
"metadata": {},
|
226
|
+
"outputs": [],
|
227
|
+
"source": [
|
228
|
+
"df_visit[\"months_on_study\"] = df_visit[\"days_on_study\"]/30"
|
229
|
+
]
|
230
|
+
},
|
231
|
+
{
|
232
|
+
"cell_type": "code",
|
233
|
+
"execution_count": null,
|
234
|
+
"id": "14",
|
235
|
+
"metadata": {},
|
236
|
+
"outputs": [],
|
237
|
+
"source": [
|
238
|
+
"\n",
|
239
|
+
"\n",
|
240
|
+
"# ALL\n",
|
241
|
+
"\n",
|
242
|
+
"table1a = {'Category': ['Age at consent', '', '']}\n",
|
243
|
+
"table1a.update({\n",
|
244
|
+
" 'Parameter': ['Age (Years)', '', ''],\n",
|
245
|
+
" **get_formatted_rows_mf(df_consent, \"age_in_years\"),\n",
|
246
|
+
"\n",
|
247
|
+
"})\n",
|
248
|
+
"\n",
|
249
|
+
"# all\n",
|
250
|
+
"df_months = df_visit[(df_visit.visit_code<=1480.9)].groupby(by=['subject_identifier'])[\"months_on_study\"].max().to_frame().reset_index()\n",
|
251
|
+
"df_months = df_months.merge(df_consent[['subject_identifier', 'gender']], on='subject_identifier', how='left')\n",
|
252
|
+
"table1 = {'Category': ['Follow-up (main)', '', '']}\n",
|
253
|
+
"table1.update({\n",
|
254
|
+
" 'Parameter': ['>= 0m', '', ''],\n",
|
255
|
+
" **get_formatted_rows_mf(df_months, \"months_on_study\")\n",
|
256
|
+
"})\n",
|
257
|
+
"\n",
|
258
|
+
"# reach at least 12m\n",
|
259
|
+
"table2a = {'Category': ['', '', '']}\n",
|
260
|
+
"df_months = df_visit[(df_visit.visit_code>=1120.0) & (df_visit.visit_code<=1480.9)].groupby(by=['subject_identifier'])[\"months_on_study\"].max().to_frame().reset_index()\n",
|
261
|
+
"df_months = df_months.merge(df_consent[['subject_identifier', 'gender']], on='subject_identifier', how='left')\n",
|
262
|
+
"table2a.update({\n",
|
263
|
+
" 'Parameter': ['>= 12m', '', ''],\n",
|
264
|
+
" **get_formatted_rows_mf(df_months, \"months_on_study\")\n",
|
265
|
+
"})\n",
|
266
|
+
"\n",
|
267
|
+
"# reach at least 24m\n",
|
268
|
+
"table2b = {'Category': ['', '', '']}\n",
|
269
|
+
"df_months = df_visit[(df_visit.visit_code>=1240.0) & (df_visit.visit_code<=1480.9)].groupby(by=['subject_identifier'])[\"months_on_study\"].max().to_frame().reset_index()\n",
|
270
|
+
"df_months = df_months.merge(df_consent[['subject_identifier', 'gender']], on='subject_identifier', how='left')\n",
|
271
|
+
"table2b.update({\n",
|
272
|
+
" 'Parameter': ['>= 24m', '', ''],\n",
|
273
|
+
" **get_formatted_rows_mf(df_months, \"months_on_study\")\n",
|
274
|
+
"})\n",
|
275
|
+
"\n",
|
276
|
+
"# reach at least 36m\n",
|
277
|
+
"table3a = {'Category': ['', '', '']}\n",
|
278
|
+
"df_months = df_visit[(df_visit.visit_code>=1360.0) & (df_visit.visit_code<=1480.9)].groupby(by=['subject_identifier'])[\"months_on_study\"].max().to_frame().reset_index()\n",
|
279
|
+
"df_months = df_months.merge(df_consent[['subject_identifier', 'gender']], on='subject_identifier', how='left')\n",
|
280
|
+
"table3a.update({\n",
|
281
|
+
" 'Parameter': ['>= 36m', '', ''],\n",
|
282
|
+
" **get_formatted_rows_mf(df_months, \"months_on_study\")\n",
|
283
|
+
"})\n",
|
284
|
+
"\n",
|
285
|
+
"# reach at least 36m\n",
|
286
|
+
"table3b = {'Category': ['', '', '']}\n",
|
287
|
+
"df_months = df_visit[(df_visit.visit_code>1360.0) & (df_visit.visit_code<=1480.9)].groupby(by=['subject_identifier'])[\"months_on_study\"].max().to_frame().reset_index()\n",
|
288
|
+
"df_months = df_months.merge(df_consent[['subject_identifier', 'gender']], on='subject_identifier', how='left')\n",
|
289
|
+
"table3b.update({\n",
|
290
|
+
" 'Parameter': ['> 36m', '', ''],\n",
|
291
|
+
" **get_formatted_rows_mf(df_months, \"months_on_study\")\n",
|
292
|
+
"})\n",
|
293
|
+
"\n",
|
294
|
+
"# reach at least 48m\n",
|
295
|
+
"table3c = {'Category': ['', '', '']}\n",
|
296
|
+
"df_months = df_visit[(df_visit.visit_code==1480.0)].groupby(by=['subject_identifier'])[\"months_on_study\"].max().to_frame().reset_index()\n",
|
297
|
+
"df_months = df_months.merge(df_consent[['subject_identifier', 'gender']], on='subject_identifier', how='left')\n",
|
298
|
+
"table3c.update({\n",
|
299
|
+
" 'Parameter': ['48m', '', ''],\n",
|
300
|
+
" **get_formatted_rows_mf(df_months, \"months_on_study\")\n",
|
301
|
+
"})\n",
|
302
|
+
"\n",
|
303
|
+
"table4 = {'Category': ['Pregnancy cohort', '', '']}\n",
|
304
|
+
"df_months = df_visit[(df_visit.visit_code>=2000.0) & (df_visit.visit_code<3000.0)].groupby(by=['subject_identifier'])[\"months_on_study\"].max().to_frame().reset_index()\n",
|
305
|
+
"df_months = df_months.merge(df_consent[['subject_identifier', 'gender']], on='subject_identifier', how='left')\n",
|
306
|
+
"table4.update({\n",
|
307
|
+
" 'Parameter': ['months', '', ''],\n",
|
308
|
+
" **get_formatted_rows_mf(df_months, \"months_on_study\")\n",
|
309
|
+
"})\n",
|
310
|
+
"\n",
|
311
|
+
"table5 = {'Category': ['Diabetes cohort', '', '']}\n",
|
312
|
+
"df_months = df_visit[(df_visit.visit_code>=3000.0)].groupby(by=['subject_identifier'])[\"months_on_study\"].max().to_frame().reset_index()\n",
|
313
|
+
"df_months = df_months.merge(df_consent[['subject_identifier', 'gender']], on='subject_identifier', how='left')\n",
|
314
|
+
"table5.update({\n",
|
315
|
+
" 'Parameter': ['months', '', ''],\n",
|
316
|
+
" **get_formatted_rows_mf(df_months, \"months_on_study\")\n",
|
317
|
+
"})\n",
|
318
|
+
"\n",
|
319
|
+
"# NOTE: this may need to be the delta from baseline to offstudy_datetime instead of to endline_visit_datetime\n",
|
320
|
+
"table6 = {'Category': ['Offstudy (main)', '', '']}\n",
|
321
|
+
"df_months = df_visit[(df_visit.offstudy_datetime.notna())].groupby(by=['subject_identifier'])[\"months_on_study\"].max().to_frame().reset_index()\n",
|
322
|
+
"df_months = df_months.merge(df_consent[['subject_identifier', 'gender']], on='subject_identifier', how='left')\n",
|
323
|
+
"table6.update({\n",
|
324
|
+
" 'Parameter': ['months', '', ''],\n",
|
325
|
+
" **get_formatted_rows_mf(df_months, \"months_on_study\")\n",
|
326
|
+
"})\n",
|
327
|
+
"\n",
|
328
|
+
"\n",
|
329
|
+
"table1a_df = pd.DataFrame(table1a)\n",
|
330
|
+
"table1_df = pd.DataFrame(table1)\n",
|
331
|
+
"table2a_df = pd.DataFrame(table2a)\n",
|
332
|
+
"table2b_df = pd.DataFrame(table2b)\n",
|
333
|
+
"table3a_df = pd.DataFrame(table3a)\n",
|
334
|
+
"table3b_df = pd.DataFrame(table3b)\n",
|
335
|
+
"table3c_df = pd.DataFrame(table3c)\n",
|
336
|
+
"table4_df = pd.DataFrame(table4)\n",
|
337
|
+
"table5_df = pd.DataFrame(table5)\n",
|
338
|
+
"table6_df = pd.DataFrame(table6)\n",
|
339
|
+
"table_df = pd.concat([table1a_df, table1_df, table2a_df, table2b_df, table3a_df, table3b_df, table3c_df, table4_df, table5_df, table6_df])\n",
|
340
|
+
"\n",
|
341
|
+
"# export as csv\n",
|
342
|
+
"path = analysis_folder / 'meta3_magreth_followup.csv'\n",
|
343
|
+
"table_df.to_csv(path_or_buf=path, index=False)\n",
|
344
|
+
"\n"
|
345
|
+
]
|
346
|
+
},
|
347
|
+
{
|
348
|
+
"cell_type": "code",
|
349
|
+
"execution_count": null,
|
350
|
+
"id": "15",
|
351
|
+
"metadata": {},
|
352
|
+
"outputs": [],
|
353
|
+
"source": [
|
354
|
+
"from tabulate import tabulate\n",
|
355
|
+
"\n",
|
356
|
+
"table_formatted = tabulate(table_df, headers='keys', tablefmt='grid')\n",
|
357
|
+
"\n",
|
358
|
+
"path = analysis_folder / 'meta3_magreth_followup.txt'\n",
|
359
|
+
"with open(path, 'w') as file:\n",
|
360
|
+
" file.write(table_formatted)\n",
|
361
|
+
"\n",
|
362
|
+
"print(table_formatted)\n"
|
363
|
+
]
|
364
|
+
},
|
365
|
+
{
|
366
|
+
"cell_type": "code",
|
367
|
+
"execution_count": null,
|
368
|
+
"id": "16",
|
369
|
+
"metadata": {},
|
370
|
+
"outputs": [],
|
371
|
+
"source": []
|
372
|
+
},
|
373
|
+
{
|
374
|
+
"cell_type": "code",
|
375
|
+
"execution_count": null,
|
376
|
+
"id": "17",
|
377
|
+
"metadata": {},
|
378
|
+
"outputs": [],
|
379
|
+
"source": [
|
380
|
+
"# medical adherence"
|
381
|
+
]
|
382
|
+
},
|
383
|
+
{
|
384
|
+
"cell_type": "code",
|
385
|
+
"execution_count": null,
|
386
|
+
"id": "18",
|
387
|
+
"metadata": {},
|
388
|
+
"outputs": [],
|
389
|
+
"source": [
|
390
|
+
"df_adherence = get_crf(model=\"meta_subject.medicationadherence\", subject_visit_model=\"meta_subject.subjectvisit\")\n",
|
391
|
+
"df_adherence = df_adherence[df_adherence.visit_datetime < pd.Timestamp(cutoff_datetime)]\n",
|
392
|
+
"df_adherence.reset_index(drop=True, inplace=True)\n"
|
393
|
+
]
|
394
|
+
},
|
395
|
+
{
|
396
|
+
"cell_type": "code",
|
397
|
+
"execution_count": null,
|
398
|
+
"id": "19",
|
399
|
+
"metadata": {},
|
400
|
+
"outputs": [],
|
401
|
+
"source": [
|
402
|
+
"df_adherence = df_adherence.merge(df_consent[['subject_identifier', 'gender', \"age_in_years\"]], on='subject_identifier', how='left')"
|
403
|
+
]
|
404
|
+
},
|
405
|
+
{
|
406
|
+
"cell_type": "code",
|
407
|
+
"execution_count": null,
|
408
|
+
"id": "20",
|
409
|
+
"metadata": {},
|
410
|
+
"outputs": [],
|
411
|
+
"source": [
|
412
|
+
"# calculate mean per subject by visit\n",
|
413
|
+
"mean_visual_score_by_visit = df_adherence.groupby(by=['subject_identifier', 'visit_code'])['visual_score_confirmed'].mean().to_frame().reset_index()\n",
|
414
|
+
"# merge w/ consent\n",
|
415
|
+
"mean_visual_score_by_visit = mean_visual_score_by_visit.merge(df_consent[['subject_identifier', 'gender', 'age_in_years']], on='subject_identifier', how='left')\n",
|
416
|
+
"\n",
|
417
|
+
"# calculate mean of means\n",
|
418
|
+
"mean_visual_score_confirmed = df_adherence.groupby(by=['subject_identifier'])['visual_score_confirmed'].mean().to_frame().reset_index()\n",
|
419
|
+
"# merge w/ consent\n",
|
420
|
+
"mean_visual_score_confirmed = mean_visual_score_confirmed.merge(df_consent[['subject_identifier', 'gender', 'age_in_years']], on='subject_identifier', how='left')\n"
|
421
|
+
]
|
422
|
+
},
|
423
|
+
{
|
424
|
+
"cell_type": "code",
|
425
|
+
"execution_count": null,
|
426
|
+
"id": "21",
|
427
|
+
"metadata": {},
|
428
|
+
"outputs": [],
|
429
|
+
"source": [
|
430
|
+
"#\n",
|
431
|
+
"table0 = {'Category': ['', '', '']}\n",
|
432
|
+
"table0.update({\n",
|
433
|
+
" 'Parameter': ['at 2 weeks (%)', '', ''],\n",
|
434
|
+
" **get_formatted_rows_mf(mean_visual_score_by_visit[mean_visual_score_by_visit.visit_code==1005.0], \"visual_score_confirmed\")\n",
|
435
|
+
"})\n",
|
436
|
+
"\n",
|
437
|
+
"table1 = {'Category': ['', '', '']}\n",
|
438
|
+
"table1.update({\n",
|
439
|
+
" 'Parameter': ['at 12m (%)', '', ''],\n",
|
440
|
+
" **get_formatted_rows_mf(mean_visual_score_by_visit[mean_visual_score_by_visit.visit_code==1120.0], \"visual_score_confirmed\")\n",
|
441
|
+
"})\n",
|
442
|
+
"\n",
|
443
|
+
"table2 = {'Category': ['', '', '']}\n",
|
444
|
+
"table2.update({\n",
|
445
|
+
" 'Parameter': ['at 24m (%)', '', ''],\n",
|
446
|
+
" **get_formatted_rows_mf(mean_visual_score_by_visit[mean_visual_score_by_visit.visit_code==1240.0], \"visual_score_confirmed\")\n",
|
447
|
+
"})\n",
|
448
|
+
"\n",
|
449
|
+
"table3 = {'Category': ['', '', '']}\n",
|
450
|
+
"table3.update({\n",
|
451
|
+
" 'Parameter': ['at 36m (%)', '', ''],\n",
|
452
|
+
" **get_formatted_rows_mf(mean_visual_score_by_visit[mean_visual_score_by_visit.visit_code==1360.0], \"visual_score_confirmed\")\n",
|
453
|
+
"})\n",
|
454
|
+
"\n",
|
455
|
+
"table4 = {'Category': ['', '', '']}\n",
|
456
|
+
"table4.update({\n",
|
457
|
+
" 'Parameter': ['at 48m (%)', '', ''],\n",
|
458
|
+
" **get_formatted_rows_mf(mean_visual_score_by_visit[mean_visual_score_by_visit.visit_code==1480.0], \"visual_score_confirmed\")\n",
|
459
|
+
"})\n",
|
460
|
+
"\n",
|
461
|
+
"#\n",
|
462
|
+
"table5 = {'Category': ['Adherence', '', '']}\n",
|
463
|
+
"table5.update({\n",
|
464
|
+
" 'Parameter': ['mean of means %', '', ''],\n",
|
465
|
+
" **get_formatted_rows_mf(mean_visual_score_confirmed, \"visual_score_confirmed\")\n",
|
466
|
+
"})\n"
|
467
|
+
]
|
468
|
+
},
|
469
|
+
{
|
470
|
+
"cell_type": "code",
|
471
|
+
"execution_count": null,
|
472
|
+
"id": "22",
|
473
|
+
"metadata": {},
|
474
|
+
"outputs": [],
|
475
|
+
"source": [
|
476
|
+
"\n",
|
477
|
+
"table0_df = pd.DataFrame(table0)\n",
|
478
|
+
"table1_df = pd.DataFrame(table1)\n",
|
479
|
+
"table2_df = pd.DataFrame(table2)\n",
|
480
|
+
"table3_df = pd.DataFrame(table3)\n",
|
481
|
+
"table4_df = pd.DataFrame(table4)\n",
|
482
|
+
"table5_df = pd.DataFrame(table5)\n",
|
483
|
+
"table_df = pd.concat([table1a_df, table5_df, table0_df, table1_df, table2_df, table3_df, table4_df])\n",
|
484
|
+
"table_df\n"
|
485
|
+
]
|
486
|
+
},
|
487
|
+
{
|
488
|
+
"cell_type": "code",
|
489
|
+
"execution_count": null,
|
490
|
+
"id": "23",
|
491
|
+
"metadata": {},
|
492
|
+
"outputs": [],
|
493
|
+
"source": [
|
494
|
+
"table = tabulate(table_df, headers='keys', tablefmt='grid')\n",
|
495
|
+
"path = analysis_folder / 'meta3_magreth_adherence.csv'\n",
|
496
|
+
"table_df.to_csv(path_or_buf=path, index=False)\n",
|
497
|
+
"\n",
|
498
|
+
"path = analysis_folder / 'meta3_magreth_adherence.txt'\n",
|
499
|
+
"with open(path, 'w') as file:\n",
|
500
|
+
" file.write(table)\n"
|
501
|
+
]
|
502
|
+
},
|
503
|
+
{
|
504
|
+
"cell_type": "code",
|
505
|
+
"execution_count": null,
|
506
|
+
"id": "24",
|
507
|
+
"metadata": {},
|
508
|
+
"outputs": [],
|
509
|
+
"source": [
|
510
|
+
"df = df_adherence.copy()\n",
|
511
|
+
"df.set_index('visit_datetime', inplace=True)\n",
|
512
|
+
"\n"
|
513
|
+
]
|
514
|
+
},
|
515
|
+
{
|
516
|
+
"cell_type": "code",
|
517
|
+
"execution_count": null,
|
518
|
+
"id": "25",
|
519
|
+
"metadata": {},
|
520
|
+
"outputs": [],
|
521
|
+
"source": [
|
522
|
+
"correlation = df[['pill_count', 'visual_score_confirmed']].corr()\n",
|
523
|
+
"print(correlation)"
|
524
|
+
]
|
525
|
+
},
|
526
|
+
{
|
527
|
+
"cell_type": "code",
|
528
|
+
"execution_count": null,
|
529
|
+
"id": "26",
|
530
|
+
"metadata": {},
|
531
|
+
"outputs": [],
|
532
|
+
"source": [
|
533
|
+
"df[['pill_count']].plot()"
|
534
|
+
]
|
535
|
+
},
|
536
|
+
{
|
537
|
+
"cell_type": "code",
|
538
|
+
"execution_count": null,
|
539
|
+
"id": "27",
|
540
|
+
"metadata": {},
|
541
|
+
"outputs": [],
|
542
|
+
"source": [
|
543
|
+
"df1 = df[df.visit_code_sequence==0].groupby(\"visit_code\")[\"visual_score_confirmed\"].mean().to_frame().reset_index()\n",
|
544
|
+
"df1.set_index('visit_code', inplace=True)\n"
|
545
|
+
]
|
546
|
+
},
|
547
|
+
{
|
548
|
+
"cell_type": "code",
|
549
|
+
"execution_count": null,
|
550
|
+
"id": "28",
|
551
|
+
"metadata": {},
|
552
|
+
"outputs": [],
|
553
|
+
"source": [
|
554
|
+
"import matplotlib.pyplot as plt\n",
|
555
|
+
"import seaborn as sns\n",
|
556
|
+
"plt.figure(figsize=(10, 6))\n",
|
557
|
+
"sns.scatterplot(x='visit_code', y='visual_score_confirmed', data=df1)\n",
|
558
|
+
"plt.title('Scatter Plot Visual Score Confirmed')\n",
|
559
|
+
"plt.xlabel('visit')\n",
|
560
|
+
"plt.ylabel('Visual Score Confirmed')\n",
|
561
|
+
"plt.show()\n"
|
562
|
+
]
|
563
|
+
},
|
564
|
+
{
|
565
|
+
"cell_type": "code",
|
566
|
+
"execution_count": null,
|
567
|
+
"id": "29",
|
568
|
+
"metadata": {},
|
569
|
+
"outputs": [],
|
570
|
+
"source": [
|
571
|
+
"df1 = df.groupby(\"visit_code\")[\"visual_score_confirmed\"].mean()\n"
|
572
|
+
]
|
573
|
+
},
|
574
|
+
{
|
575
|
+
"cell_type": "code",
|
576
|
+
"execution_count": null,
|
577
|
+
"id": "30",
|
578
|
+
"metadata": {},
|
579
|
+
"outputs": [],
|
580
|
+
"source": [
|
581
|
+
"df1"
|
582
|
+
]
|
583
|
+
},
|
584
|
+
{
|
585
|
+
"cell_type": "code",
|
586
|
+
"execution_count": null,
|
587
|
+
"id": "31",
|
588
|
+
"metadata": {},
|
589
|
+
"outputs": [],
|
590
|
+
"source": [
|
591
|
+
"df2 = df_adherence.copy()\n",
|
592
|
+
"df2.set_index('visit_code', inplace=True)\n",
|
593
|
+
"df2.sort_values(by='visit_code', inplace=True)\n",
|
594
|
+
"mean_pill_count = df[df.visit_code_sequence==0].groupby(\"visit_code\")[\"pill_count\"].mean().to_frame().reset_index()\n",
|
595
|
+
"\n"
|
596
|
+
]
|
597
|
+
},
|
598
|
+
{
|
599
|
+
"cell_type": "code",
|
600
|
+
"execution_count": null,
|
601
|
+
"id": "32",
|
602
|
+
"metadata": {},
|
603
|
+
"outputs": [],
|
604
|
+
"source": [
|
605
|
+
"import matplotlib.pyplot as plt\n",
|
606
|
+
"plt.figure(figsize=(10, 6))\n",
|
607
|
+
"plt.plot(mean_pill_count['visit_code'], mean_pill_count['pill_count'], marker='o')\n",
|
608
|
+
"plt.title('Pill count')\n",
|
609
|
+
"plt.xlabel('visit_code')\n",
|
610
|
+
"plt.ylabel('pills')\n",
|
611
|
+
"plt.xlim(1000, 1400)\n",
|
612
|
+
"plt.show()\n"
|
613
|
+
]
|
614
|
+
},
|
615
|
+
{
|
616
|
+
"cell_type": "code",
|
617
|
+
"execution_count": null,
|
618
|
+
"id": "33",
|
619
|
+
"metadata": {},
|
620
|
+
"outputs": [],
|
621
|
+
"source": []
|
622
|
+
}
|
623
|
+
],
|
624
|
+
"metadata": {
|
625
|
+
"kernelspec": {
|
626
|
+
"display_name": "Python 3",
|
627
|
+
"language": "python",
|
628
|
+
"name": "python3"
|
629
|
+
},
|
630
|
+
"language_info": {
|
631
|
+
"codemirror_mode": {
|
632
|
+
"name": "ipython",
|
633
|
+
"version": 2
|
634
|
+
},
|
635
|
+
"file_extension": ".py",
|
636
|
+
"mimetype": "text/x-python",
|
637
|
+
"name": "python",
|
638
|
+
"nbconvert_exporter": "python",
|
639
|
+
"pygments_lexer": "ipython2",
|
640
|
+
"version": "2.7.6"
|
641
|
+
}
|
642
|
+
},
|
643
|
+
"nbformat": 4,
|
644
|
+
"nbformat_minor": 5
|
645
|
+
}
|