meta-edc 1.0.6__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.
Files changed (79) hide show
  1. meta_ae/action_items.py +10 -2
  2. meta_ae/baker_recipes.py +1 -2
  3. meta_ae/tests/tests/test_actions.py +1 -2
  4. meta_analytics/dataframes/__init__.py +3 -0
  5. meta_analytics/dataframes/constants.py +1 -1
  6. meta_analytics/dataframes/get_eos_df.py +15 -2
  7. meta_analytics/dataframes/get_glucose_df.py +149 -0
  8. meta_analytics/dataframes/get_glucose_fbg_df.py +27 -0
  9. meta_analytics/dataframes/get_glucose_fbg_ogtt_df.py +22 -0
  10. meta_analytics/dataframes/glucose_endpoints/endpoint_by_date.py +106 -120
  11. meta_analytics/dataframes/glucose_endpoints/glucose_endpoints_by_date.py +36 -227
  12. meta_analytics/dataframes/utils.py +18 -4
  13. meta_analytics/notebooks/anu.ipynb +95 -0
  14. meta_analytics/notebooks/appointment_planning.ipynb +329 -0
  15. meta_analytics/notebooks/arvs.ipynb +103 -0
  16. meta_analytics/notebooks/cleaning/consent_v1_ext.ipynb +227 -0
  17. meta_analytics/notebooks/cleaning/offschedule_eos.ipynb +353 -0
  18. meta_analytics/notebooks/dsmc/renal_dysfunction.ipynb +435 -0
  19. meta_analytics/notebooks/endpoints/meta_endpoints_by_date.ipynb +664 -0
  20. meta_analytics/notebooks/followup_examination.ipynb +141 -0
  21. meta_analytics/notebooks/hba1c.ipynb +136 -0
  22. meta_analytics/notebooks/hiv_regimens.ipynb +429 -0
  23. meta_analytics/notebooks/incidence.ipynb +232 -0
  24. meta_analytics/notebooks/liver.ipynb +389 -0
  25. meta_analytics/notebooks/magreth.ipynb +645 -0
  26. meta_analytics/notebooks/monitoring_report.ipynb +1751 -0
  27. meta_analytics/notebooks/pharmacy.ipynb +1070 -0
  28. meta_analytics/notebooks/pharmacy_stock_202410.ipynb +306 -0
  29. meta_analytics/notebooks/steering.ipynb +61 -0
  30. meta_analytics/notebooks/undiagnosed/meta3_screening_consort_chart.ipynb +1176 -0
  31. meta_analytics/notebooks/undiagnosed/meta3_screening_undiagnosed.ipynb +519 -0
  32. meta_analytics/notebooks/undiagnosed/meta_screening_table2.ipynb +964 -0
  33. meta_analytics/notebooks/undiagnosed/screen_undiagnosed_or.ipynb +296 -0
  34. meta_analytics/notebooks/undiagnosed/screening.ipynb +273 -0
  35. meta_analytics/notebooks/undiagnosed/screening2.ipynb +958 -0
  36. meta_analytics/notebooks/undiagnosed/screening_undiagnosed_20241002.ipynb +958 -0
  37. meta_analytics/notebooks/ven.ipynb +191 -0
  38. meta_analytics/notebooks/vitals.ipynb +263 -0
  39. meta_analytics/utils.py +81 -0
  40. meta_edc/settings/debug.py +3 -2
  41. meta_edc/urls.py +1 -0
  42. {meta_edc-1.0.6.dist-info → meta_edc-1.1.0.dist-info}/METADATA +6 -5
  43. {meta_edc-1.0.6.dist-info → meta_edc-1.1.0.dist-info}/RECORD +77 -36
  44. {meta_edc-1.0.6.dist-info → meta_edc-1.1.0.dist-info}/WHEEL +1 -1
  45. meta_edc-1.1.0.dist-info/licenses/AUTHORS.rst +8 -0
  46. meta_labs/reportables.py +14 -11
  47. meta_labs/tests/test_reportables.py +33 -12
  48. meta_pharmacy/notebooks/pharmacy.ipynb +41 -0
  49. meta_prn/migrations/0063_historicaloffstudymedication_singleton_field_and_more.py +37 -0
  50. meta_prn/migrations/0064_auto_20250602_2143.py +18 -0
  51. meta_prn/models/end_of_study.py +2 -0
  52. meta_prn/models/off_study_medication.py +2 -0
  53. meta_reports/migrations/0054_auto_20250422_2003.py +81 -0
  54. meta_reports/migrations/0055_alter_glucosesummary_table.py +17 -0
  55. meta_reports/migrations/0056_auto_20250422_2214.py +54 -0
  56. meta_reports/migrations/0057_auto_20250422_2224.py +54 -0
  57. meta_reports/migrations/0058_auto_20250422_2232.py +54 -0
  58. meta_reports/models/dbviews/glucose_summary/unmanaged_model.py +13 -1
  59. meta_reports/models/dbviews/glucose_summary/view_definition.py +8 -5
  60. meta_screening/eligibility/eligibility_part_three/base_eligibility_part_three.py +59 -47
  61. meta_screening/form_validators/screening_part_three.py +6 -1
  62. meta_screening/tests/meta_test_case_mixin.py +3 -0
  63. meta_screening/tests/tests/test_forms.py +9 -2
  64. meta_screening/tests/tests/test_screening_part_three.py +11 -14
  65. meta_subject/action_items.py +1 -2
  66. meta_subject/choices.py +2 -1
  67. meta_subject/form_validators/glucose_form_validator.py +16 -1
  68. meta_subject/forms/blood_results/blood_results_rft_form.py +60 -3
  69. meta_subject/forms/study_medication_form.py +5 -3
  70. meta_subject/migrations/0221_auto_20250402_1913.py +42 -0
  71. meta_subject/migrations/0222_alter_historicalstudymedication_stock_codes_and_more.py +46 -0
  72. meta_subject/migrations/0223_bloodresultsfbc_errors_bloodresultsgludummy_errors_and_more.py +83 -0
  73. meta_subject/migrations/0224_bloodresultsfbc_abnormal_summary_and_more.py +153 -0
  74. meta_subject/tests/tests/test_egfr.py +5 -5
  75. meta_analytics/dataframes/enrolled/__init__.py +0 -1
  76. meta_analytics/dataframes/enrolled/get_glucose_df.py +0 -122
  77. /meta_edc-1.0.6.dist-info/AUTHORS → /meta_analytics/dataframes/glucose_endpoints/utils.py +0 -0
  78. {meta_edc-1.0.6.dist-info → meta_edc-1.1.0.dist-info/licenses}/LICENSE +0 -0
  79. {meta_edc-1.0.6.dist-info → meta_edc-1.1.0.dist-info}/top_level.txt +0 -0
@@ -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
+ }