meta-edc 1.0.7__py3-none-any.whl → 1.1.1__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/README.rst +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 +721 -448
- 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.1.dist-info}/METADATA +3 -3
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.1.dist-info}/RECORD +62 -35
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.1.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/admin/offschedule_pregnancy_admin.py +3 -3
- meta_prn/admin/onschedule_dm_referral_admin.py +5 -5
- meta_prn/form_validators/end_of_study.py +2 -2
- 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_reports/admin/last_imp_refill_admin.py +3 -2
- 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 +2 -3
- meta_subject/choices.py +2 -1
- meta_subject/form_validators/delivery_form_validator.py +1 -0
- meta_subject/forms/blood_results/blood_results_rft_form.py +60 -3
- meta_subject/forms/delivery_form.py +2 -0
- 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.1.dist-info}/licenses/AUTHORS.rst +0 -0
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.1.dist-info}/licenses/LICENSE +0 -0
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,227 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"id": "0",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [],
|
9
|
+
"source": []
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"cell_type": "code",
|
13
|
+
"execution_count": null,
|
14
|
+
"id": "1",
|
15
|
+
"metadata": {},
|
16
|
+
"outputs": [],
|
17
|
+
"source": [
|
18
|
+
"%%capture\n",
|
19
|
+
"import pandas as pd\n",
|
20
|
+
"from django_pandas.io import read_frame\n",
|
21
|
+
"from pathlib import Path\n",
|
22
|
+
"from dj_notebook import activate\n",
|
23
|
+
"\n",
|
24
|
+
"plus = activate(dotenv_file=\"/Users/erikvw/source/edc_source/meta-edc/.env\")\n",
|
25
|
+
"report_folder = Path(\"/Users/erikvw/Documents/ucl/protocols/meta3/reports/\")\n",
|
26
|
+
"# output is suppressed -- normally would spew out all the edc loading messages\n"
|
27
|
+
]
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"cell_type": "code",
|
31
|
+
"execution_count": null,
|
32
|
+
"id": "2",
|
33
|
+
"metadata": {},
|
34
|
+
"outputs": [],
|
35
|
+
"source": [
|
36
|
+
"from edc_registration.models import RegisteredSubject\n",
|
37
|
+
"from edc_appointment.analytics import get_appointment_df\n",
|
38
|
+
"from meta_prn.models import OnSchedule, OffSchedule, OffSchedulePregnancy, OffSchedulePostnatal, OnScheduleDmReferral, \\\n",
|
39
|
+
" EndOfStudy\n",
|
40
|
+
"\n",
|
41
|
+
"df_onschedule = read_frame(OnSchedule.objects.all(), verbose=True)\n",
|
42
|
+
"df_offschedule = read_frame(OffSchedule.objects.all(), verbose=True)\n",
|
43
|
+
"df_onschedule_preg = read_frame(OffSchedulePregnancy.objects.all(), verbose=True)\n",
|
44
|
+
"df_onschedule_postnatal = read_frame(OffSchedulePostnatal.objects.all(), verbose=True)\n",
|
45
|
+
"df_onschedule_dm = read_frame(OnScheduleDmReferral.objects.all(), verbose=True)\n",
|
46
|
+
"df_eos = read_frame(EndOfStudy.objects.all(), verbose=True)\n",
|
47
|
+
"df_appt = get_appointment_df()\n",
|
48
|
+
"df_rs = read_frame(RegisteredSubject.objects.values(\"subject_identifier\", \"registration_datetime\").all(), verbose=True)\n"
|
49
|
+
]
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"cell_type": "code",
|
53
|
+
"execution_count": null,
|
54
|
+
"id": "3",
|
55
|
+
"metadata": {},
|
56
|
+
"outputs": [],
|
57
|
+
"source": [
|
58
|
+
"df_appt[df_appt.visit_code > 1360][[\"visit_code\", \"schedule_name\"]].schedule_name.value_counts()"
|
59
|
+
]
|
60
|
+
},
|
61
|
+
{
|
62
|
+
"cell_type": "code",
|
63
|
+
"execution_count": null,
|
64
|
+
"id": "4",
|
65
|
+
"metadata": {},
|
66
|
+
"outputs": [],
|
67
|
+
"source": [
|
68
|
+
"df_appt[(df_appt.visit_code > 1360) & (df_appt.schedule_name == \"schedule\")][[\"visit_code\", \"schedule_name\"]].visit_code.value_counts()"
|
69
|
+
]
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"cell_type": "code",
|
73
|
+
"execution_count": null,
|
74
|
+
"id": "5",
|
75
|
+
"metadata": {},
|
76
|
+
"outputs": [],
|
77
|
+
"source": [
|
78
|
+
"df_appt[(df_appt.visit_code > 1360) & (df_appt.schedule_name == \"schedule\")][[\"subject_identifier\", \"appt_datetime\", \"visit_code\", \"appt_status\"]].sort_values(\"subject_identifier\")"
|
79
|
+
]
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"cell_type": "code",
|
83
|
+
"execution_count": null,
|
84
|
+
"id": "6",
|
85
|
+
"metadata": {},
|
86
|
+
"outputs": [],
|
87
|
+
"source": [
|
88
|
+
"df_appt = get_appointment_df()\n",
|
89
|
+
"\n",
|
90
|
+
"df_appt = df_appt[(df_appt.visit_code >= 1360) & (df_appt.schedule_name == \"schedule\")][[\"subject_identifier\", \"appt_datetime\", \"visit_code\", \"appt_status\"]]"
|
91
|
+
]
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"cell_type": "code",
|
95
|
+
"execution_count": null,
|
96
|
+
"id": "7",
|
97
|
+
"metadata": {},
|
98
|
+
"outputs": [],
|
99
|
+
"source": [
|
100
|
+
"df_magreth = pd.read_csv(Path(\"/Users/erikvw/Documents/ucl/protocols/meta3/reports/\") / \"consented_v1_ext_magreth.csv\")\n"
|
101
|
+
]
|
102
|
+
},
|
103
|
+
{
|
104
|
+
"cell_type": "code",
|
105
|
+
"execution_count": null,
|
106
|
+
"id": "8",
|
107
|
+
"metadata": {},
|
108
|
+
"outputs": [],
|
109
|
+
"source": [
|
110
|
+
"df_magreth"
|
111
|
+
]
|
112
|
+
},
|
113
|
+
{
|
114
|
+
"cell_type": "code",
|
115
|
+
"execution_count": null,
|
116
|
+
"id": "9",
|
117
|
+
"metadata": {},
|
118
|
+
"outputs": [],
|
119
|
+
"source": [
|
120
|
+
"df_main = pd.merge(df_appt[[\"subject_identifier\", \"appt_datetime\", \"visit_code\", \"appt_status\"]], df_magreth, on=\"subject_identifier\", how=\"right\").groupby([\"subject_identifier\", \"agreed\"]).agg({\"visit_code\": \"min\", \"date_reconsented\": \"max\"})"
|
121
|
+
]
|
122
|
+
},
|
123
|
+
{
|
124
|
+
"cell_type": "code",
|
125
|
+
"execution_count": null,
|
126
|
+
"id": "10",
|
127
|
+
"metadata": {},
|
128
|
+
"outputs": [],
|
129
|
+
"source": [
|
130
|
+
"df_main = df_main.merge(df_appt[[\"subject_identifier\", \"visit_code\", \"appt_status\", \"appt_datetime\"]], on=[\"subject_identifier\", \"visit_code\"], how=\"left\")\n",
|
131
|
+
"df_main\n"
|
132
|
+
]
|
133
|
+
},
|
134
|
+
{
|
135
|
+
"cell_type": "code",
|
136
|
+
"execution_count": null,
|
137
|
+
"id": "11",
|
138
|
+
"metadata": {},
|
139
|
+
"outputs": [],
|
140
|
+
"source": [
|
141
|
+
"df_rs"
|
142
|
+
]
|
143
|
+
},
|
144
|
+
{
|
145
|
+
"cell_type": "code",
|
146
|
+
"execution_count": null,
|
147
|
+
"id": "12",
|
148
|
+
"metadata": {},
|
149
|
+
"outputs": [],
|
150
|
+
"source": [
|
151
|
+
"from meta_consent.models import SubjectConsentV1Ext\n",
|
152
|
+
"df_v1ext = read_frame(SubjectConsentV1Ext.objects.values(\"subject_identifier\", \"report_datetime\", \"agrees_to_extension\").all(), verbose=True)\n",
|
153
|
+
"df_v1ext"
|
154
|
+
]
|
155
|
+
},
|
156
|
+
{
|
157
|
+
"cell_type": "code",
|
158
|
+
"execution_count": null,
|
159
|
+
"id": "13",
|
160
|
+
"metadata": {},
|
161
|
+
"outputs": [],
|
162
|
+
"source": [
|
163
|
+
"df_main = df_main.merge(df_rs, on=\"subject_identifier\", how=\"left\")"
|
164
|
+
]
|
165
|
+
},
|
166
|
+
{
|
167
|
+
"cell_type": "code",
|
168
|
+
"execution_count": null,
|
169
|
+
"id": "14",
|
170
|
+
"metadata": {},
|
171
|
+
"outputs": [],
|
172
|
+
"source": [
|
173
|
+
"df_main = df_main.merge(df_v1ext, on=\"subject_identifier\", how=\"outer\")\n",
|
174
|
+
"df_main.rename(columns={\"report_datetime\": \"v1_ext_datetime\", \"agrees_to_extension\": \"agreed\", \"visit_code\": \"last_visit_code\"}, inplace=True)\n"
|
175
|
+
]
|
176
|
+
},
|
177
|
+
{
|
178
|
+
"cell_type": "code",
|
179
|
+
"execution_count": null,
|
180
|
+
"id": "15",
|
181
|
+
"metadata": {},
|
182
|
+
"outputs": [],
|
183
|
+
"source": [
|
184
|
+
"df_main = df_main.merge(df_eos[[\"subject_identifier\", \"offstudy_datetime\"]], on=\"subject_identifier\", how=\"left\")\n"
|
185
|
+
]
|
186
|
+
},
|
187
|
+
{
|
188
|
+
"cell_type": "code",
|
189
|
+
"execution_count": null,
|
190
|
+
"id": "16",
|
191
|
+
"metadata": {},
|
192
|
+
"outputs": [],
|
193
|
+
"source": [
|
194
|
+
"df_main[[\"subject_identifier\",\"registration_datetime\", \"last_visit_code\", \"appt_status\", \"appt_datetime\", \"date_reconsented\", \"v1_ext_datetime\", \"agreed\"]]"
|
195
|
+
]
|
196
|
+
},
|
197
|
+
{
|
198
|
+
"cell_type": "code",
|
199
|
+
"execution_count": null,
|
200
|
+
"id": "17",
|
201
|
+
"metadata": {},
|
202
|
+
"outputs": [],
|
203
|
+
"source": []
|
204
|
+
}
|
205
|
+
],
|
206
|
+
"metadata": {
|
207
|
+
"kernelspec": {
|
208
|
+
"display_name": "Python 3",
|
209
|
+
"language": "python",
|
210
|
+
"name": "python3"
|
211
|
+
},
|
212
|
+
"language_info": {
|
213
|
+
"codemirror_mode": {
|
214
|
+
"name": "ipython",
|
215
|
+
"version": 2
|
216
|
+
},
|
217
|
+
"file_extension": ".py",
|
218
|
+
"mimetype": "text/x-python",
|
219
|
+
"name": "python",
|
220
|
+
"nbconvert_exporter": "python",
|
221
|
+
"pygments_lexer": "ipython2",
|
222
|
+
"version": "2.7.6"
|
223
|
+
}
|
224
|
+
},
|
225
|
+
"nbformat": 4,
|
226
|
+
"nbformat_minor": 5
|
227
|
+
}
|
@@ -0,0 +1,353 @@
|
|
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 pandas as pd\n",
|
12
|
+
"from django_pandas.io import read_frame\n",
|
13
|
+
"from pathlib import Path\n",
|
14
|
+
"from dj_notebook import activate\n",
|
15
|
+
"\n",
|
16
|
+
"plus = activate(dotenv_file=\"/Users/erikvw/source/edc_source/meta-edc/.env\")\n",
|
17
|
+
"report_folder = Path(\"/Users/erikvw/Documents/ucl/protocols/meta3/reports/\")\n",
|
18
|
+
"# output is suppressed -- normally would spew out all the edc loading messages\n"
|
19
|
+
]
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"cell_type": "code",
|
23
|
+
"execution_count": null,
|
24
|
+
"id": "1",
|
25
|
+
"metadata": {},
|
26
|
+
"outputs": [],
|
27
|
+
"source": [
|
28
|
+
"from meta_prn.models import OnSchedule, OffSchedule, EndOfStudy, OffSchedulePostnatal, OffSchedulePregnancy, \\\n",
|
29
|
+
" OnScheduleDmReferral, OffStudyMedication\n",
|
30
|
+
"from meta_lists.models import OffstudyReasons\n",
|
31
|
+
"from meta_analytics.dataframes import GlucoseEndpointsByDate"
|
32
|
+
]
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"cell_type": "code",
|
36
|
+
"execution_count": null,
|
37
|
+
"id": "2",
|
38
|
+
"metadata": {},
|
39
|
+
"outputs": [],
|
40
|
+
"source": [
|
41
|
+
"df_onschedule = read_frame(OnSchedule.objects.all(), verbose=True)\n",
|
42
|
+
"df_offschedule = read_frame(OffSchedule.objects.all(), verbose=True)\n",
|
43
|
+
"df_onschedule_preg = read_frame(OffSchedulePregnancy.objects.all(), verbose=True)\n",
|
44
|
+
"df_onschedule_postnatal = read_frame(OffSchedulePostnatal.objects.all(), verbose=True)\n",
|
45
|
+
"df_onschedule_dm = read_frame(OnScheduleDmReferral.objects.all(), verbose=True)\n",
|
46
|
+
"df_offstudy_medication = read_frame(OffStudyMedication.objects.all(), verbose=True)\n",
|
47
|
+
"\n",
|
48
|
+
"df_eos = read_frame(EndOfStudy.objects.values(\"id\", \"subject_identifier\", \"offstudy_datetime\",\"offstudy_reason\", \"other_offstudy_reason\", \"action_item__action_type__name\", \"parent_action_item__action_type__name\").all(), verbose=False)\n",
|
49
|
+
"df_eos.rename(columns={\"offstudy_reason\": \"offstudy_reason_id\", \"action_item__action_type__name\": \"action_item_name\", \"parent_action_item__action_type__name\": \"parent_action_item_name\"}, inplace=True)\n",
|
50
|
+
"\n",
|
51
|
+
"df_offstudy_reasons = read_frame(OffstudyReasons.objects.all(), verbose=False)\n",
|
52
|
+
"df_offstudy_reasons.rename(columns={\"id\": \"offstudy_reason_id\", \"name\": \"offstudy_reason\", \"display_name\": \"offstudy_reason_display\"}, inplace=True)"
|
53
|
+
]
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"cell_type": "code",
|
57
|
+
"execution_count": null,
|
58
|
+
"id": "3",
|
59
|
+
"metadata": {},
|
60
|
+
"outputs": [],
|
61
|
+
"source": [
|
62
|
+
"# merge df_eos with offstudyreasons\n",
|
63
|
+
"df_eos = df_eos.merge(df_offstudy_reasons[[\"offstudy_reason_id\", \"offstudy_reason\", \"offstudy_reason_display\"]], on=\"offstudy_reason_id\")\n"
|
64
|
+
]
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"cell_type": "code",
|
68
|
+
"execution_count": null,
|
69
|
+
"id": "4",
|
70
|
+
"metadata": {},
|
71
|
+
"outputs": [],
|
72
|
+
"source": [
|
73
|
+
"# summarize offstudy\n",
|
74
|
+
"df_eos_summary = df_eos[[\"offstudy_reason_id\", \"offstudy_reason\"]].value_counts().to_frame().reset_index().sort_values(\"offstudy_reason_id\", ascending=True).reset_index(drop=True)\n",
|
75
|
+
"df_eos_summary.rename(columns={\"count\": \"subtotal\"}, inplace=True)\n",
|
76
|
+
"df_eos_summary[\"cumfreq\"] = df_eos_summary.subtotal.cumsum()\n",
|
77
|
+
"df_eos_summary\n"
|
78
|
+
]
|
79
|
+
},
|
80
|
+
{
|
81
|
+
"cell_type": "code",
|
82
|
+
"execution_count": null,
|
83
|
+
"id": "5",
|
84
|
+
"metadata": {},
|
85
|
+
"outputs": [],
|
86
|
+
"source": []
|
87
|
+
},
|
88
|
+
{
|
89
|
+
"cell_type": "markdown",
|
90
|
+
"id": "6",
|
91
|
+
"metadata": {},
|
92
|
+
"source": [
|
93
|
+
"* Need to validate that all subjects off study went off study medication first.\n",
|
94
|
+
"* Action items are linked to this flow and block the EndOfStudy.save() if EndOfStudy was submitted before this workflow was implemented.\n"
|
95
|
+
]
|
96
|
+
},
|
97
|
+
{
|
98
|
+
"cell_type": "code",
|
99
|
+
"execution_count": null,
|
100
|
+
"id": "7",
|
101
|
+
"metadata": {},
|
102
|
+
"outputs": [],
|
103
|
+
"source": [
|
104
|
+
"# df_eos[df_eos.offstudy_reason_id==11][[\"subject_identifier\", \"offstudy_reason_id\", \"other_offstudy_reason\"]]\n",
|
105
|
+
"pd.merge(df_eos, df_offstudy_medication[[\"subject_identifier\", \"stop_date\"]], on=\"subject_identifier\", how=\"left\")\n"
|
106
|
+
]
|
107
|
+
},
|
108
|
+
{
|
109
|
+
"cell_type": "code",
|
110
|
+
"execution_count": null,
|
111
|
+
"id": "8",
|
112
|
+
"metadata": {},
|
113
|
+
"outputs": [],
|
114
|
+
"source": []
|
115
|
+
},
|
116
|
+
{
|
117
|
+
"cell_type": "code",
|
118
|
+
"execution_count": null,
|
119
|
+
"id": "9",
|
120
|
+
"metadata": {},
|
121
|
+
"outputs": [],
|
122
|
+
"source": [
|
123
|
+
"df_onschedule_preg"
|
124
|
+
]
|
125
|
+
},
|
126
|
+
{
|
127
|
+
"cell_type": "code",
|
128
|
+
"execution_count": null,
|
129
|
+
"id": "10",
|
130
|
+
"metadata": {},
|
131
|
+
"outputs": [],
|
132
|
+
"source": [
|
133
|
+
"df_dm = df_onschedule_dm[[\"subject_identifier\"]].copy()\n",
|
134
|
+
"df_dm.reset_index(drop=True, inplace=True)\n",
|
135
|
+
"df_dm[\"dm\"] =1\n",
|
136
|
+
"\n",
|
137
|
+
"df_preg = df_onschedule_preg[[\"subject_identifier\"]].copy()\n",
|
138
|
+
"df_preg[\"preg\"] = 1\n",
|
139
|
+
"df_preg.reset_index(drop=True, inplace=True)\n",
|
140
|
+
"#\n",
|
141
|
+
"df_eos = df_eos[[\"subject_identifier\", \"offstudy_datetime\", \"offstudy_reason\", \"other_offstudy_reason\"]].copy()\n",
|
142
|
+
"df_eos[\"eos\"] = 1\n",
|
143
|
+
"df_eos.reset_index(drop=True, inplace=True)\n",
|
144
|
+
"\n",
|
145
|
+
"df = df_onschedule[[\"subject_identifier\", \"onschedule_datetime\"]].copy()\n",
|
146
|
+
"df[\"onschedule\"] = 1\n",
|
147
|
+
"df.reset_index(drop=True, inplace=True)\n",
|
148
|
+
"\n"
|
149
|
+
]
|
150
|
+
},
|
151
|
+
{
|
152
|
+
"cell_type": "code",
|
153
|
+
"execution_count": null,
|
154
|
+
"id": "11",
|
155
|
+
"metadata": {},
|
156
|
+
"outputs": [],
|
157
|
+
"source": [
|
158
|
+
"# df[df.offstudy_reason.isna()]"
|
159
|
+
]
|
160
|
+
},
|
161
|
+
{
|
162
|
+
"cell_type": "code",
|
163
|
+
"execution_count": null,
|
164
|
+
"id": "12",
|
165
|
+
"metadata": {},
|
166
|
+
"outputs": [],
|
167
|
+
"source": [
|
168
|
+
"df = df.merge(df_dm, on=[\"subject_identifier\"], how=\"left\", suffixes=(\"\", \"_y\"))\n",
|
169
|
+
"df = df.merge(df_preg, on=[\"subject_identifier\"], how=\"left\", suffixes=(\"\", \"_y\"))\n"
|
170
|
+
]
|
171
|
+
},
|
172
|
+
{
|
173
|
+
"cell_type": "code",
|
174
|
+
"execution_count": null,
|
175
|
+
"id": "13",
|
176
|
+
"metadata": {},
|
177
|
+
"outputs": [],
|
178
|
+
"source": [
|
179
|
+
"df_offschedule = df_offschedule[[\"subject_identifier\", \"offschedule_datetime\"]].copy()\n",
|
180
|
+
"df_offschedule[\"offschedule\"] = 1\n",
|
181
|
+
"df_offschedule.reset_index(drop=True, inplace=True)\n",
|
182
|
+
"df = df.merge(df_offschedule, on=[\"subject_identifier\"], how=\"left\", suffixes=(\"\", \"_y\"))\n",
|
183
|
+
"df = df.merge(df_eos, on=[\"subject_identifier\"], how=\"left\", suffixes=(\"\", \"_y\"))"
|
184
|
+
]
|
185
|
+
},
|
186
|
+
{
|
187
|
+
"cell_type": "code",
|
188
|
+
"execution_count": null,
|
189
|
+
"id": "14",
|
190
|
+
"metadata": {},
|
191
|
+
"outputs": [],
|
192
|
+
"source": [
|
193
|
+
"cls = GlucoseEndpointsByDate()\n",
|
194
|
+
"cls.run()"
|
195
|
+
]
|
196
|
+
},
|
197
|
+
{
|
198
|
+
"cell_type": "code",
|
199
|
+
"execution_count": null,
|
200
|
+
"id": "15",
|
201
|
+
"metadata": {},
|
202
|
+
"outputs": [],
|
203
|
+
"source": [
|
204
|
+
"df_endpoint = cls.df\n",
|
205
|
+
"df_endpoint = df_endpoint[(df_endpoint.endpoint==1)][[\"subject_identifier\", \"endpoint\"]]\n",
|
206
|
+
"df = df.merge(df_endpoint, on=[\"subject_identifier\"], how=\"left\", suffixes=(\"\", \"_y\"))"
|
207
|
+
]
|
208
|
+
},
|
209
|
+
{
|
210
|
+
"cell_type": "code",
|
211
|
+
"execution_count": null,
|
212
|
+
"id": "16",
|
213
|
+
"metadata": {},
|
214
|
+
"outputs": [],
|
215
|
+
"source": [
|
216
|
+
"df.fillna({\"dm\": 0, \"preg\":0, \"offschedule\":0, \"eos\": 0, \"endpoint\": 0}, inplace=True)"
|
217
|
+
]
|
218
|
+
},
|
219
|
+
{
|
220
|
+
"cell_type": "code",
|
221
|
+
"execution_count": null,
|
222
|
+
"id": "17",
|
223
|
+
"metadata": {},
|
224
|
+
"outputs": [],
|
225
|
+
"source": [
|
226
|
+
"df.dm.value_counts()"
|
227
|
+
]
|
228
|
+
},
|
229
|
+
{
|
230
|
+
"cell_type": "code",
|
231
|
+
"execution_count": null,
|
232
|
+
"id": "18",
|
233
|
+
"metadata": {},
|
234
|
+
"outputs": [],
|
235
|
+
"source": [
|
236
|
+
"df.preg.value_counts()"
|
237
|
+
]
|
238
|
+
},
|
239
|
+
{
|
240
|
+
"cell_type": "code",
|
241
|
+
"execution_count": null,
|
242
|
+
"id": "19",
|
243
|
+
"metadata": {},
|
244
|
+
"outputs": [],
|
245
|
+
"source": [
|
246
|
+
"df_export = df[(df.offschedule_datetime.notna()) & (df.eos==0) & ((df.dm==0) & (df.preg==0))][[\"subject_identifier\", \"onschedule_datetime\", \"offschedule_datetime\", \"onschedule\", \"offschedule\", \"dm\", \"preg\", \"endpoint\", \"eos\"]].copy()\n",
|
247
|
+
"df_export.reset_index(drop=True, inplace=True)\n",
|
248
|
+
"df_export[\"offschedule_datetime\"] = df_export.offschedule_datetime.dt.tz_localize(None)\n",
|
249
|
+
"df_export[\"offschedule_datetime\"] = df_export.offschedule_datetime.dt.normalize()\n",
|
250
|
+
"df_export[\"onschedule_datetime\"] = df_export.onschedule_datetime.dt.tz_localize(None)\n",
|
251
|
+
"df_export[\"onschedule_datetime\"] = df_export.onschedule_datetime.dt.normalize()\n",
|
252
|
+
"df_export.sort_values(by=[\"offschedule_datetime\"], inplace=True)\n",
|
253
|
+
"df_export.to_csv(report_folder / \"offschedule_eos.csv\", index=False)"
|
254
|
+
]
|
255
|
+
},
|
256
|
+
{
|
257
|
+
"cell_type": "code",
|
258
|
+
"execution_count": null,
|
259
|
+
"id": "20",
|
260
|
+
"metadata": {},
|
261
|
+
"outputs": [],
|
262
|
+
"source": [
|
263
|
+
"df"
|
264
|
+
]
|
265
|
+
},
|
266
|
+
{
|
267
|
+
"cell_type": "code",
|
268
|
+
"execution_count": null,
|
269
|
+
"id": "21",
|
270
|
+
"metadata": {},
|
271
|
+
"outputs": [],
|
272
|
+
"source": [
|
273
|
+
"df[df.endpoint==1]"
|
274
|
+
]
|
275
|
+
},
|
276
|
+
{
|
277
|
+
"cell_type": "code",
|
278
|
+
"execution_count": null,
|
279
|
+
"id": "22",
|
280
|
+
"metadata": {},
|
281
|
+
"outputs": [],
|
282
|
+
"source": [
|
283
|
+
"# DM Referrals onstudy/off study\n",
|
284
|
+
"df.groupby(by=[\"dm\", \"eos\"]).size().reset_index(name=\"counts\")"
|
285
|
+
]
|
286
|
+
},
|
287
|
+
{
|
288
|
+
"cell_type": "code",
|
289
|
+
"execution_count": null,
|
290
|
+
"id": "23",
|
291
|
+
"metadata": {},
|
292
|
+
"outputs": [],
|
293
|
+
"source": [
|
294
|
+
"df.groupby(by=[\"preg\", \"eos\"]).size().reset_index(name=\"counts\")"
|
295
|
+
]
|
296
|
+
},
|
297
|
+
{
|
298
|
+
"cell_type": "code",
|
299
|
+
"execution_count": null,
|
300
|
+
"id": "24",
|
301
|
+
"metadata": {},
|
302
|
+
"outputs": [],
|
303
|
+
"source": [
|
304
|
+
"df_eos[(df_eos.other_offstudy_reason != \"\")][[\"subject_identifier\", \"offstudy_reason\", \"other_offstudy_reason\"]]"
|
305
|
+
]
|
306
|
+
},
|
307
|
+
{
|
308
|
+
"cell_type": "code",
|
309
|
+
"execution_count": null,
|
310
|
+
"id": "25",
|
311
|
+
"metadata": {},
|
312
|
+
"outputs": [],
|
313
|
+
"source": [
|
314
|
+
"df_eos.offstudy_reason.value_counts()"
|
315
|
+
]
|
316
|
+
},
|
317
|
+
{
|
318
|
+
"cell_type": "code",
|
319
|
+
"execution_count": null,
|
320
|
+
"id": "26",
|
321
|
+
"metadata": {},
|
322
|
+
"outputs": [],
|
323
|
+
"source": [
|
324
|
+
"df_eos = read_frame(EndOfStudy.objects.all(), verbose=False)\n",
|
325
|
+
"df_offstudy_reasons = read_frame(OffstudyReasons.objects.all(), verbose=False)\n",
|
326
|
+
"df_offstudy_reasons.rename(columns={\"id\": \"offstudy_reason_id\", \"name\": \"offstudy_reason\"}, inplace=True)\n",
|
327
|
+
"df_eos = df_eos.merge(df_offstudy_reasons[\"offstudy_reason_id\", \"offstudy_reason\"], on=\"offstudy_reason_id\")\n",
|
328
|
+
"df_eos.offstudy_reason.value_counts()"
|
329
|
+
]
|
330
|
+
}
|
331
|
+
],
|
332
|
+
"metadata": {
|
333
|
+
"kernelspec": {
|
334
|
+
"display_name": "Python 3",
|
335
|
+
"language": "python",
|
336
|
+
"name": "python3"
|
337
|
+
},
|
338
|
+
"language_info": {
|
339
|
+
"codemirror_mode": {
|
340
|
+
"name": "ipython",
|
341
|
+
"version": 2
|
342
|
+
},
|
343
|
+
"file_extension": ".py",
|
344
|
+
"mimetype": "text/x-python",
|
345
|
+
"name": "python",
|
346
|
+
"nbconvert_exporter": "python",
|
347
|
+
"pygments_lexer": "ipython2",
|
348
|
+
"version": "2.7.6"
|
349
|
+
}
|
350
|
+
},
|
351
|
+
"nbformat": 4,
|
352
|
+
"nbformat_minor": 5
|
353
|
+
}
|