meta-edc 1.1.8__py3-none-any.whl → 1.1.12__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.
Potentially problematic release.
This version of meta-edc might be problematic. Click here for more details.
- meta_ae/action_items.py +2 -1
- meta_ae/admin/__init__.py +11 -0
- meta_ae/admin/ae_susar_admin.py +1 -1
- meta_ae/admin/death_report_admin.py +1 -1
- meta_ae/admin/modeladmin_mixins.py +10 -12
- meta_ae/baker_recipes.py +3 -3
- meta_ae/forms/__init__.py +13 -0
- meta_ae/forms/modelform_mixins.py +2 -2
- meta_ae/migrations/0001_initial.py +27 -27
- meta_ae/migrations/0006_aelocalreview_aesponsorreview.py +5 -5
- meta_ae/migrations/0022_historicalhospitalization_hospitalization.py +5 -13
- meta_ae/migrations/0023_alter_aefollowup_action_identifier_and_more.py +2017 -0
- meta_ae/model_mixins/__init__.py +2 -0
- meta_ae/model_mixins/ae_review_model_mixin.py +6 -6
- meta_ae/model_mixins/death_report_model_mixin.py +3 -3
- meta_ae/models/__init__.py +13 -0
- meta_ae/models/hospitalization.py +3 -3
- meta_ae/pdf_reports/__init__.py +2 -0
- meta_analytics/.DS_Store +0 -0
- meta_analytics/dataframes/__init__.py +24 -0
- meta_analytics/dataframes/get_eos_df.py +1 -2
- meta_analytics/dataframes/get_glucose_df.py +6 -7
- meta_analytics/dataframes/get_glucose_fbg_df.py +2 -3
- meta_analytics/dataframes/get_glucose_fbg_ogtt_df.py +1 -2
- meta_analytics/dataframes/get_last_imp_visits_df.py +5 -6
- meta_analytics/dataframes/glucose_endpoints/__init__.py +2 -0
- meta_analytics/dataframes/glucose_endpoints/endpoint_by_date.py +13 -20
- meta_analytics/dataframes/glucose_endpoints/glucose_endpoints_by_date.py +9 -10
- meta_analytics/dataframes/screening/__init__.py +2 -0
- meta_analytics/dataframes/screening/get_glucose_tested_only_df.py +1 -2
- meta_analytics/dataframes/screening/get_screening_df.py +6 -10
- meta_analytics/dataframes/utils.py +3 -8
- meta_analytics/get_tables.py +1 -2
- meta_analytics/tables/__init__.py +2 -0
- meta_consent/action_items.py +2 -1
- meta_consent/admin/__init__.py +6 -0
- meta_consent/admin/actions/__init__.py +2 -0
- meta_consent/admin/actions/create_missing_prescriptions.py +1 -1
- meta_consent/admin/list_filters.py +2 -2
- meta_consent/admin/modeladmin_mixins.py +3 -4
- meta_consent/admin/subject_consent_v1_ext_admin.py +2 -2
- meta_consent/baker_recipes.py +7 -8
- meta_consent/form_validators/__init__.py +2 -0
- meta_consent/forms/__init__.py +7 -0
- meta_consent/forms/subject_consent_v1_ext_form.py +2 -3
- meta_consent/forms/subject_reconsent_form.py +4 -4
- meta_consent/management/commands/create_missing_prescriptions.py +4 -2
- meta_consent/migrations/0001_initial.py +9 -9
- meta_consent/migrations/0024_historicalsubjectconsentv1.py +3 -8
- meta_consent/migrations/0026_historicalsubjectconsentv1ext_subjectconsentv1ext.py +5 -14
- meta_consent/migrations/0032_alter_historicalsubjectconsent_device_created_and_more.py +678 -0
- meta_consent/models/__init__.py +9 -0
- meta_consent/models/model_mixins.py +1 -2
- meta_consent/models/signals.py +9 -10
- meta_consent/models/subject_consent.py +1 -1
- meta_consent/models/subject_reconsent.py +3 -3
- meta_dashboard/patterns.py +1 -1
- meta_dashboard/templatetags/meta_dashboard_extras.py +1 -1
- meta_dashboard/view_utils/__init__.py +7 -0
- meta_dashboard/view_utils/subject_screening_button.py +9 -16
- meta_dashboard/views/__init__.py +8 -0
- meta_dashboard/views/ae/__init__.py +2 -0
- meta_dashboard/views/ae/ae_listboard_view.py +1 -1
- meta_dashboard/views/ae/death_report_listboard_view.py +1 -1
- meta_dashboard/views/screening/__init__.py +2 -0
- meta_dashboard/views/subject/__init__.py +2 -0
- meta_dashboard/views/subject/dashboard/__init__.py +2 -0
- meta_dashboard/views/subject/dashboard/dashboard_view.py +1 -1
- meta_dashboard/views/subject/listboard/__init__.py +2 -0
- meta_edc/__init__.py +5 -9
- meta_edc/celery.py +1 -1
- meta_edc/celery_live.py +1 -1
- meta_edc/celery_uat.py +1 -1
- meta_edc/management/commands/update_forms_reference.py +10 -12
- meta_edc/settings/debug.py +5 -4
- meta_edc/settings/defaults.py +18 -3
- meta_edc/settings/live.py +3 -1
- meta_edc/settings/logging.py +9 -4
- meta_edc/settings/minimal.py +4 -5
- meta_edc/settings/uat.py +3 -1
- meta_edc/views/__init__.py +2 -0
- meta_edc-1.1.12.dist-info/METADATA +174 -0
- {meta_edc-1.1.8.dist-info → meta_edc-1.1.12.dist-info}/RECORD +413 -526
- meta_edc-1.1.12.dist-info/WHEEL +4 -0
- meta_lists/migrations/0020_alter_abnormalfootappearanceobservations_extra_value_and_more.py +404 -0
- meta_pharmacy/admin/__init__.py +5 -0
- meta_pharmacy/admin/substitutions_admin.py +2 -2
- meta_pharmacy/forms/__init__.py +2 -0
- meta_pharmacy/forms/substitutions_form.py +6 -4
- meta_pharmacy/labels/__init__.py +4 -2
- meta_pharmacy/labels/draw_label_for_subject_with_barcode.py +1 -2
- meta_pharmacy/labels/draw_label_with_test_data.py +2 -2
- meta_pharmacy/labels/label_data.py +1 -2
- meta_pharmacy/labels/print_sheets.py +4 -6
- meta_pharmacy/migrations/0002_initial.py +7 -20
- meta_pharmacy/migrations/0003_auto_20240909_2335.py +3 -2
- meta_pharmacy/migrations/0006_lotnumber_label.py +5 -14
- meta_pharmacy/migrations/0008_remove_lotnumber_medication_and_more.py +5 -6
- meta_pharmacy/migrations/0010_alter_historicallabeldata_device_created_and_more.py +382 -0
- meta_pharmacy/models/__init__.py +7 -0
- meta_pharmacy/models/label_data.py +4 -5
- meta_pharmacy/models/substitutions.py +3 -3
- meta_pharmacy/prepare_meta_pharmacy.py +1 -1
- meta_pharmacy/utils/__init__.py +2 -0
- meta_pharmacy/utils/update_initial_pharmacy_data.py +1 -1
- meta_prn/admin/__init__.py +16 -0
- meta_prn/admin/dm_referral_admin.py +2 -1
- meta_prn/admin/end_of_study_admin.py +6 -7
- meta_prn/admin/loss_to_followup_admin.py +3 -2
- meta_prn/admin/off_study_medication_admin.py +5 -6
- meta_prn/admin/offschedule_admin.py +5 -6
- meta_prn/admin/offschedule_dm_referral_admin.py +6 -6
- meta_prn/admin/offschedule_postnatal_admin.py +7 -7
- meta_prn/admin/offschedule_pregnancy_admin.py +8 -7
- meta_prn/admin/onschedule_admin.py +7 -8
- meta_prn/admin/onschedule_dm_referral_admin.py +6 -7
- meta_prn/admin/pregnancy_notification_admin.py +5 -6
- meta_prn/admin/protocol_incident_admin.py +1 -1
- meta_prn/admin/subject_transfer_admin.py +1 -1
- meta_prn/baker_recipes.py +4 -4
- meta_prn/form_validators/__init__.py +5 -0
- meta_prn/form_validators/end_of_study.py +2 -2
- meta_prn/forms/__init__.py +13 -0
- meta_prn/migrations/0001_initial.py +25 -25
- meta_prn/migrations/0017_auto_20220307_1929.py +5 -5
- meta_prn/migrations/0018_auto_20220309_2106.py +9 -9
- meta_prn/migrations/0021_auto_20220316_2147.py +13 -13
- meta_prn/migrations/0022_auto_20220318_0133.py +9 -9
- meta_prn/migrations/0032_historicalegfrnotification_egfrnotification.py +5 -13
- meta_prn/migrations/0038_alter_endofstudy_delivery_date_and_more.py +5 -13
- meta_prn/migrations/0041_endofstudy_transfer_date_and_more.py +5 -13
- meta_prn/migrations/0057_historicalonscheduledmreferral_and_more.py +13 -38
- meta_prn/migrations/0067_alter_offschedule_managers_and_more.py +2557 -0
- meta_prn/models/__init__.py +20 -0
- meta_prn/models/offschedule.py +4 -4
- meta_prn/models/protocol_incident.py +1 -1
- meta_prn/models/subject_transfer.py +8 -0
- meta_rando/migrations/0001_initial.py +5 -5
- meta_rando/migrations/0006_alter_historicalrandomizationlist_allocated_user_and_more.py +130 -0
- meta_reports/__init__.py +2 -0
- meta_reports/admin/__init__.py +16 -0
- meta_reports/admin/dbviews/__init__.py +13 -0
- meta_reports/admin/dbviews/glucose_summary_admin.py +6 -6
- meta_reports/admin/dbviews/imp_substitutions_admin.py +12 -11
- meta_reports/admin/dbviews/missing_screening_ogtt_admin/__init__.py +5 -0
- meta_reports/admin/dbviews/missing_screening_ogtt_admin/note_model_admin.py +27 -3
- meta_reports/admin/dbviews/missing_screening_ogtt_admin/unmanaged_model_admin.py +6 -6
- meta_reports/admin/dbviews/on_study_missing_lab_values_admin/__init__.py +2 -0
- meta_reports/admin/dbviews/on_study_missing_lab_values_admin/unmanaged_model_admin.py +0 -3
- meta_reports/admin/dbviews/on_study_missing_values_admin/__init__.py +2 -0
- meta_reports/admin/dbviews/patient_history_missing_baseline_cd4_admin.py +8 -8
- meta_reports/admin/dbviews/unattended_three_in_row2_admin.py +6 -6
- meta_reports/admin/dbviews/unattended_three_in_row_admin.py +5 -5
- meta_reports/admin/dbviews/unattended_two_in_row_admin.py +5 -5
- meta_reports/admin/endpoints_admin.py +1 -1
- meta_reports/admin/last_imp_refill_admin.py +9 -9
- meta_reports/admin/list_filters.py +2 -2
- meta_reports/admin/modeladmin_mixins.py +9 -16
- meta_reports/death_report.py +1 -1
- meta_reports/forms/__init__.py +2 -0
- meta_reports/forms/missing_ogtt_note_form.py +2 -3
- meta_reports/management/commands/generate_endpoints.py +5 -4
- meta_reports/migrations/0035_historicalmissingogttnote_missingogttnote.py +5 -14
- meta_reports/migrations/0059_alter_endpoints_created_and_more.py +161 -0
- meta_reports/models/__init__.py +17 -0
- meta_reports/models/dbviews/__init__.py +14 -0
- meta_reports/models/dbviews/glucose_summary/__init__.py +2 -0
- meta_reports/models/dbviews/glucose_summary/unmanaged_model.py +4 -5
- meta_reports/models/dbviews/imp_substitutions/__init__.py +2 -0
- meta_reports/models/dbviews/imp_substitutions/view_definition.py +1 -1
- meta_reports/models/dbviews/missing_screening_ogtt/__init__.py +2 -0
- meta_reports/models/dbviews/missing_screening_ogtt/note_model.py +1 -1
- meta_reports/models/dbviews/missing_screening_ogtt/unmanaged_model.py +4 -3
- meta_reports/models/dbviews/on_study_missing_lab_values/__init__.py +2 -0
- meta_reports/models/dbviews/on_study_missing_lab_values/qa_cases.py +13 -11
- meta_reports/models/dbviews/on_study_missing_values/__init__.py +2 -0
- meta_reports/models/dbviews/on_study_missing_values/qa_cases.py +18 -0
- meta_reports/models/dbviews/patient_history_missing_baseline_cd4/__init__.py +2 -0
- meta_reports/models/dbviews/unattended_three_in_row/__init__.py +2 -0
- meta_reports/models/dbviews/unattended_three_in_row2/__init__.py +2 -0
- meta_reports/models/dbviews/unattended_two_in_row/__init__.py +2 -0
- meta_reports/models/endpoints.py +4 -4
- meta_reports/models/last_imp_refill.py +2 -3
- meta_reports/pdf_report.py +2 -2
- meta_reports/tasks.py +1 -1
- meta_screening/admin/__init__.py +8 -0
- meta_screening/admin/fieldsets.py +13 -14
- meta_screening/admin/list_filters.py +6 -4
- meta_screening/admin/screening_part_one_admin.py +1 -2
- meta_screening/admin/screening_part_three_admin.py +2 -3
- meta_screening/admin/screening_part_two_admin.py +7 -10
- meta_screening/admin/subject_refusal_admin.py +5 -3
- meta_screening/admin/subject_screening_admin.py +4 -4
- meta_screening/baker_recipes.py +9 -9
- meta_screening/eligibility/__init__.py +9 -0
- meta_screening/eligibility/eligibility.py +7 -7
- meta_screening/eligibility/eligibility_part_three/__init__.py +2 -0
- meta_screening/eligibility/eligibility_part_three/base_eligibility_part_three.py +8 -8
- meta_screening/eligibility/eligibility_part_three/eligibility_part_three_phase_three.py +13 -14
- meta_screening/form_validators/__init__.py +8 -0
- meta_screening/forms/__init__.py +20 -0
- meta_screening/forms/field_lists.py +16 -17
- meta_screening/forms/screening_part_one_form.py +2 -2
- meta_screening/forms/screening_part_three_form.py +5 -3
- meta_screening/forms/screening_part_two_form.py +1 -5
- meta_screening/forms/subject_refusal_form.py +0 -4
- meta_screening/forms/subject_screening_form.py +0 -4
- meta_screening/migrations/0001_initial.py +15 -15
- meta_screening/migrations/0010_auto_20191106_0828.py +5 -5
- meta_screening/migrations/0068_alter_historicalscreeningpartone_acute_condition_and_more.py +1579 -0
- meta_screening/model_mixins/__init__.py +8 -0
- meta_screening/model_mixins/eligibility_model_mixin.py +5 -3
- meta_screening/model_mixins/part_one_fields_model_mixin.py +5 -9
- meta_screening/model_mixins/part_three_fields_model_mixin.py +5 -6
- meta_screening/model_mixins/part_two_fields_model_mixin.py +18 -16
- meta_screening/models/__init__.py +9 -0
- meta_screening/models/icp_referral.py +5 -5
- meta_screening/models/signals.py +10 -11
- meta_screening/models/subject_refusal.py +1 -1
- meta_screening/models/subject_screening.py +1 -3
- meta_subject/action_items.py +13 -15
- meta_subject/admin/__init__.py +39 -0
- meta_subject/admin/birth_outcome_admin.py +4 -8
- meta_subject/admin/blood_results/__init__.py +9 -0
- meta_subject/admin/blood_results/blood_results_fbc_admin.py +1 -1
- meta_subject/admin/blood_results/blood_results_hba1c_admin.py +1 -1
- meta_subject/admin/blood_results/blood_results_ins_admin.py +1 -1
- meta_subject/admin/blood_results/blood_results_lft_admin.py +1 -1
- meta_subject/admin/blood_results/blood_results_lipids_admin.py +1 -1
- meta_subject/admin/blood_results/blood_results_rft_admin.py +3 -5
- meta_subject/admin/complications_glycemia_admin.py +1 -1
- meta_subject/admin/delivery_admin.py +7 -10
- meta_subject/admin/diabetes/__init__.py +2 -0
- meta_subject/admin/diabetes/dm_endpoint_admin.py +2 -2
- meta_subject/admin/diabetes/dm_followup_admin.py +3 -2
- meta_subject/admin/egfr_drop_notification_admin.py +1 -1
- meta_subject/admin/followup_examination_admin.py +10 -9
- meta_subject/admin/followup_vitals_admin.py +4 -5
- meta_subject/admin/glucose_admin.py +2 -4
- meta_subject/admin/glucose_fbg_admin.py +1 -3
- meta_subject/admin/health_economics/__init__.py +2 -0
- meta_subject/admin/health_economics/health_economics_simple_admin.py +1 -1
- meta_subject/admin/health_economics/health_economics_update_admin.py +1 -1
- meta_subject/admin/hepatitis_test_admin.py +1 -1
- meta_subject/admin/list_filters.py +1 -1
- meta_subject/admin/mnsi_admin.py +7 -5
- meta_subject/admin/other_arv_regimens_admin.py +3 -3
- meta_subject/admin/patient_history_admin.py +4 -4
- meta_subject/admin/physical_exam_admin.py +1 -1
- meta_subject/admin/pregnancy_update_admin.py +1 -1
- meta_subject/admin/study_medication_admin.py +8 -15
- meta_subject/admin/subject_requisition_admin.py +1 -1
- meta_subject/admin/subject_visit_admin.py +1 -1
- meta_subject/admin/subject_visit_missed_admin.py +1 -1
- meta_subject/admin/urine_dipstick_test_admin.py +1 -1
- meta_subject/admin/urine_pregnancy_admin.py +1 -1
- meta_subject/baker_recipes.py +15 -15
- meta_subject/form_validators/__init__.py +11 -0
- meta_subject/form_validators/delivery_form_validator.py +2 -3
- meta_subject/form_validators/dm_endpoint_form_validator.py +1 -1
- meta_subject/form_validators/dm_followup_form_validator.py +7 -6
- meta_subject/form_validators/glucose_form_validator.py +3 -5
- meta_subject/forms/__init__.py +41 -0
- meta_subject/forms/blood_results/__init__.py +9 -0
- meta_subject/forms/blood_results/blood_results_rft_form.py +1 -2
- meta_subject/forms/diabetes/__init__.py +2 -0
- meta_subject/forms/diabetes/dm_followup_form.py +2 -2
- meta_subject/forms/followup_vitals_form.py +3 -8
- meta_subject/forms/health_economics/__init__.py +2 -0
- meta_subject/forms/next_appointment_form.py +2 -3
- meta_subject/forms/slider_widget.py +1 -1
- meta_subject/forms/study_medication_form.py +11 -8
- meta_subject/management/commands/create_missing_refills.py +3 -3
- meta_subject/management/commands/create_missing_rx.py +1 -1
- meta_subject/management/commands/missed.py +20 -23
- meta_subject/metadata_rules/__init__.py +2 -0
- meta_subject/metadata_rules/predicates.py +25 -32
- meta_subject/migrations/0001_initial.py +61 -61
- meta_subject/migrations/0002_auto_20191021_0353.py +5 -5
- meta_subject/migrations/0012_auto_20200118_2334.py +5 -5
- meta_subject/migrations/0014_auto_20200120_1622.py +5 -5
- meta_subject/migrations/0018_coronakap_historicalcoronakap.py +5 -5
- meta_subject/migrations/0033_auto_20200516_2356.py +5 -5
- meta_subject/migrations/0038_auto_20200520_0020.py +5 -5
- meta_subject/migrations/0040_auto_20200527_2155.py +1 -1
- meta_subject/migrations/0045_auto_20200530_1801.py +1 -1
- meta_subject/migrations/0051_auto_20200617_2117.py +5 -5
- meta_subject/migrations/0063_auto_20210715_0337.py +5 -5
- meta_subject/migrations/0066_auto_20210721_0335.py +9 -9
- meta_subject/migrations/0067_auto_20210726_0340.py +5 -5
- meta_subject/migrations/0068_auto_20210728_1809.py +5 -5
- meta_subject/migrations/0072_auto_20210805_1545.py +7 -7
- meta_subject/migrations/0073_auto_20210809_0055.py +5 -5
- meta_subject/migrations/0077_auto_20210809_2323.py +3 -3
- meta_subject/migrations/0082_auto_20210823_1612.py +3 -3
- meta_subject/migrations/0083_auto_20210823_1620.py +3 -3
- meta_subject/migrations/0088_auto_20210924_0027.py +5 -5
- meta_subject/migrations/0090_auto_20210924_0424.py +5 -5
- meta_subject/migrations/0093_auto_20211117_0352.py +5 -5
- meta_subject/migrations/0095_auto_20220128_1719.py +5 -5
- meta_subject/migrations/0098_auto_20220309_2106.py +5 -5
- meta_subject/migrations/0101_auto_20220316_2147.py +13 -13
- meta_subject/migrations/0115_historicalegfrnotification_egfrnotification.py +5 -13
- meta_subject/migrations/0164_dmreferralfollowup_historicaldmreferralfollowup.py +5 -5
- meta_subject/migrations/0172_remove_historicalbloodresultsglu_action_item_and_more.py +1 -2
- meta_subject/migrations/0177_alter_bloodresultslft_alp_value_and_more.py +1 -2
- meta_subject/migrations/0178_historicalhealtheconomicsupdate_and_more.py +5 -14
- meta_subject/migrations/0186_healtheconomicsupdate_singleton_field_and_more.py +1 -2
- meta_subject/migrations/0187_dmdiagnosis_historicaldmdiagnosis_dmdxresult_and_more.py +5 -14
- meta_subject/migrations/0188_historicaldmdxresult_dmdxresult.py +5 -14
- meta_subject/migrations/0209_remove_historicaldmdxresult_dm_diagnosis_and_more.py +1 -2
- meta_subject/migrations/0216_historicalnextappointment_nextappointment.py +5 -6
- meta_subject/migrations/0220_historicalbloodresultsgludummy_bloodresultsgludummy.py +5 -14
- meta_subject/migrations/0227_alter_followupvitals_waist_circumference_comment_and_more.py +97 -0
- meta_subject/migrations/0228_bloodresultshba1c_hba1c_datetime_and_more.py +9297 -0
- meta_subject/model_mixins/__init__.py +8 -0
- meta_subject/model_mixins/search_slug_model_mixin.py +1 -2
- meta_subject/model_mixins/vitals_fields_model_mixin.py +1 -1
- meta_subject/models/__init__.py +48 -0
- meta_subject/models/birth_outcomes.py +3 -3
- meta_subject/models/blood_results/__init__.py +11 -0
- meta_subject/models/delivery.py +3 -3
- meta_subject/models/diabetes/__init__.py +2 -0
- meta_subject/models/diabetes/dm_endpoint.py +4 -4
- meta_subject/models/diabetes/dm_followup.py +3 -4
- meta_subject/models/diet_and_lifestyle.py +2 -2
- meta_subject/models/followup_examination.py +11 -11
- meta_subject/models/glucose.py +4 -4
- meta_subject/models/glucose_fbg.py +2 -3
- meta_subject/models/health_economics/__init__.py +2 -0
- meta_subject/models/health_economics/health_economics.py +7 -7
- meta_subject/models/health_economics/health_economics_update.py +2 -1
- meta_subject/models/hepatitis_test.py +2 -2
- meta_subject/models/other_arv_regimens_detail.py +1 -1
- meta_subject/models/patient_history.py +5 -6
- meta_subject/models/physical_exam.py +2 -2
- meta_subject/models/pregnancy_update.py +1 -1
- meta_subject/models/signals.py +14 -12
- meta_subject/models/subject_visit.py +1 -1
- meta_subject/models/urine_dipstick_test.py +1 -1
- meta_subject/models/urine_pregnancy.py +1 -1
- meta_visit_schedule/visit_schedules/__init__.py +2 -0
- meta_visit_schedule/visit_schedules/phase_three/__init__.py +2 -0
- meta_visit_schedule/visit_schedules/phase_three/schedule.py +2 -2
- meta_visit_schedule/visit_schedules/phase_three/schedule_dm_referral.py +1 -2
- meta_visit_schedule/visit_schedules/phase_three/schedule_pregnancy.py +1 -2
- meta_ae/tests/holidays.csv +0 -15
- meta_ae/tests/tests/test_actions.py +0 -126
- meta_ae/tests/urls.py +0 -10
- meta_analytics/dataframes/glucose_endpoints/utils.py +0 -0
- meta_analytics/notebooks/anu.ipynb +0 -95
- meta_analytics/notebooks/appointment_planning.ipynb +0 -329
- meta_analytics/notebooks/arvs.ipynb +0 -103
- meta_analytics/notebooks/cleaning/__init__.py +0 -0
- meta_analytics/notebooks/cleaning/consent_v1_ext.ipynb +0 -227
- meta_analytics/notebooks/cleaning/offschedule_eos.ipynb +0 -353
- meta_analytics/notebooks/dsmc/renal_dysfunction.ipynb +0 -435
- meta_analytics/notebooks/endpoints/meta_endpoints_by_date.ipynb +0 -656
- meta_analytics/notebooks/followup_examination.ipynb +0 -141
- meta_analytics/notebooks/hba1c.ipynb +0 -136
- meta_analytics/notebooks/hiv_regimens.ipynb +0 -429
- meta_analytics/notebooks/incidence.ipynb +0 -232
- meta_analytics/notebooks/liver.ipynb +0 -389
- meta_analytics/notebooks/magreth.ipynb +0 -645
- meta_analytics/notebooks/monitoring_report.ipynb +0 -1834
- meta_analytics/notebooks/pharmacy.ipynb +0 -1061
- meta_analytics/notebooks/pharmacy_stock_202410.ipynb +0 -306
- meta_analytics/notebooks/qa.ipynb +0 -273
- meta_analytics/notebooks/steering.ipynb +0 -61
- meta_analytics/notebooks/undiagnosed/meta3_screening_consort_chart.ipynb +0 -1176
- meta_analytics/notebooks/undiagnosed/meta3_screening_undiagnosed.ipynb +0 -519
- meta_analytics/notebooks/undiagnosed/meta_screening_table2.ipynb +0 -964
- meta_analytics/notebooks/undiagnosed/screen_undiagnosed_or.ipynb +0 -296
- meta_analytics/notebooks/undiagnosed/screening.ipynb +0 -273
- meta_analytics/notebooks/undiagnosed/screening2.ipynb +0 -958
- meta_analytics/notebooks/undiagnosed/screening_undiagnosed_20241002.ipynb +0 -958
- meta_analytics/notebooks/ven.ipynb +0 -191
- meta_analytics/notebooks/vitals.ipynb +0 -263
- meta_analytics/tests/__init__.py +0 -0
- meta_analytics/tests/test_endpoints_by_date.py +0 -94
- meta_consent/tests/__init__.py +0 -0
- meta_consent/tests/holidays.csv +0 -15
- meta_consent/tests/tests/__init__.py +0 -0
- meta_consent/tests/tests/test_form_validators.py +0 -110
- meta_consent/tests/tests/test_subject_consent.py +0 -10
- meta_consent/tests/urls.py +0 -17
- meta_dashboard/tests/__init__.py +0 -0
- meta_dashboard/tests/admin.py +0 -22
- meta_dashboard/tests/holidays.csv +0 -15
- meta_dashboard/tests/tests/__init__.py +0 -0
- meta_dashboard/tests/urls.py +0 -55
- meta_edc/tests/__init__.py +0 -0
- meta_edc/tests/tests/__init__.py +0 -0
- meta_edc/tests/tests/test_endpoints.py +0 -555
- meta_edc-1.1.8.dist-info/METADATA +0 -767
- meta_edc-1.1.8.dist-info/WHEEL +0 -5
- meta_edc-1.1.8.dist-info/licenses/AUTHORS.rst +0 -8
- meta_edc-1.1.8.dist-info/top_level.txt +0 -20
- meta_labs/tests/__init__.py +0 -0
- meta_labs/tests/test_labs.py +0 -27
- meta_labs/tests/test_reportables.py +0 -70
- meta_labs/tests/urls.py +0 -4
- meta_lists/tests/__init__.py +0 -0
- meta_lists/tests/test_lists.py +0 -8
- meta_pharmacy/notebooks/pharmacy.ipynb +0 -41
- meta_prn/tests/__init__.py +0 -0
- meta_prn/tests/tests/__init__.py +0 -0
- meta_prn/tests/tests/test_actions.py +0 -97
- meta_prn/tests/tests/test_dm_referral.py +0 -203
- meta_prn/tests/tests/test_eos_events.py +0 -134
- meta_prn/tests/tests/test_manager_order.py +0 -14
- meta_prn/tests/tests/test_pregnancy_notification.py +0 -93
- meta_prn/tests/urls.py +0 -10
- meta_rando/tests/__init__.py +0 -0
- meta_rando/tests/tests/__init__.py +0 -0
- meta_rando/tests/tests/test_randomizers.py +0 -57
- meta_reports/tests/__init__.py +0 -0
- meta_reports/tests/test_reports.py +0 -35
- meta_reports/tests/test_sql_gen.py +0 -5
- meta_reports/tests/urls.py +0 -4
- meta_screening/offline_models.py +0 -3
- meta_screening/tests/__init__.py +0 -0
- meta_screening/tests/holidays.csv +0 -15
- meta_screening/tests/meta_test_case_mixin.py +0 -234
- meta_screening/tests/options.py +0 -127
- meta_screening/tests/tests/__init__.py +0 -0
- meta_screening/tests/tests/test_forms.py +0 -404
- meta_screening/tests/tests/test_screening_part_one.py +0 -108
- meta_screening/tests/tests/test_screening_part_three.py +0 -433
- meta_screening/tests/tests/test_screening_part_two.py +0 -84
- meta_sites/tests/__init__.py +0 -0
- meta_sites/tests/test_sites.py +0 -12
- meta_sites/tests/urls.py +0 -4
- meta_stats/__init__.py +0 -0
- meta_stats/incidence.py +0 -16
- meta_stats/models.py +0 -0
- meta_stats/tests/__init__.py +0 -0
- meta_stats/tests/tests/__init__.py +0 -0
- meta_stats/tests/tests/test_incidence.py +0 -10
- meta_subject/tests/__init__.py +0 -0
- meta_subject/tests/holidays.csv +0 -15
- meta_subject/tests/tests/__init__.py +0 -0
- meta_subject/tests/tests/test_egfr.py +0 -234
- meta_subject/tests/tests/test_fixes.py +0 -64
- meta_subject/tests/tests/test_followup.py +0 -52
- meta_subject/tests/tests/test_manager_order.py +0 -11
- meta_subject/tests/tests/test_medication_adherence.py +0 -79
- meta_subject/tests/tests/test_metadata_rules.py +0 -135
- meta_subject/tests/tests/test_mnsi.py +0 -341
- meta_subject/tests/tests/test_next_appointment.py +0 -231
- meta_subject/tests/tests/test_patient_history_form.py +0 -74
- meta_subject/tests/tests/test_physical_exam.py +0 -84
- meta_subject/tests/tests/test_sf12.py +0 -161
- meta_subject/tests/tests/test_study_medication.py +0 -229
- meta_subject/tests/urls.py +0 -24
- meta_visit_schedule/tests/__init__.py +0 -0
- meta_visit_schedule/tests/tests/__init__.py +0 -0
- meta_visit_schedule/tests/tests/test_schedule.py +0 -181
- meta_visit_schedule/tests/urls.py +0 -4
- tests/__init__.py +0 -0
- tests/etc/randomization_list.csv +0 -241
- tests/etc/randomization_list_phase_three.csv +0 -241
- tests/etc/user-aes-local.key +0 -0
- tests/etc/user-aes-restricted.key +0 -1
- tests/etc/user-rsa-local-private.pem +0 -27
- tests/etc/user-rsa-local-public.pem +0 -9
- tests/etc/user-rsa-restricted-private.pem +0 -27
- tests/etc/user-rsa-restricted-public.pem +0 -9
- tests/etc/user-salt-local.key +0 -0
- tests/etc/user-salt-restricted.key +0 -0
- tests/holidays.csv +0 -15
- tests/test_settings.py +0 -185
- {meta_edc-1.1.8.dist-info → meta_edc-1.1.12.dist-info}/licenses/LICENSE +0 -0
- /meta_ae/tests/__init__.py → /meta_subject/management/__init__py.py +0 -0
- /meta_ae/tests/tests/__init__.py → /meta_subject/management/commands/__init__py.py +0 -0
|
@@ -1,1834 +0,0 @@
|
|
|
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
|
-
"from pathlib import Path\n",
|
|
13
|
-
"\n",
|
|
14
|
-
"import pandas as pd\n",
|
|
15
|
-
"from dj_notebook import activate\n",
|
|
16
|
-
"import numpy as np\n",
|
|
17
|
-
"from django_pandas.io import read_frame\n",
|
|
18
|
-
"\n",
|
|
19
|
-
"env_file = os.environ[\"META_ENV\"]\n",
|
|
20
|
-
"reports_folder = Path(os.environ[\"META_REPORTS_FOLDER\"])\n",
|
|
21
|
-
"analysis_folder = Path(os.environ[\"META_ANALYSIS_FOLDER\"])\n",
|
|
22
|
-
"pharmacy_folder = Path(os.environ[\"META_PHARMACY_FOLDER\"])\n",
|
|
23
|
-
"plus = activate(dotenv_file=env_file)\n",
|
|
24
|
-
"pd.set_option('future.no_silent_downcasting', True)"
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"cell_type": "code",
|
|
29
|
-
"execution_count": null,
|
|
30
|
-
"id": "1",
|
|
31
|
-
"metadata": {},
|
|
32
|
-
"outputs": [],
|
|
33
|
-
"source": [
|
|
34
|
-
"import pdfkit\n",
|
|
35
|
-
"from typing import Callable\n",
|
|
36
|
-
"from datetime import date\n",
|
|
37
|
-
"from edc_pdutils.dataframes import get_subject_visit\n",
|
|
38
|
-
"from meta_visit_schedule.constants import MONTH15, MONTH18, MONTH21, MONTH27, MONTH30, MONTH33, MONTH39\n",
|
|
39
|
-
"from meta_analytics.dataframes import GlucoseEndpointsByDate\n",
|
|
40
|
-
"from scipy.stats import chi2\n",
|
|
41
|
-
"from great_tables import loc, style, md\n",
|
|
42
|
-
"from meta_analytics.dataframes import get_eos_df\n",
|
|
43
|
-
"from meta_analytics.utils import df_as_great_table, df_as_great_table2\n",
|
|
44
|
-
"from meta_prn.models import LossToFollowup\n",
|
|
45
|
-
"from edc_visit_schedule.models import SubjectScheduleHistory\n",
|
|
46
|
-
"from edc_appointment.analytics import get_appointment_df\n",
|
|
47
|
-
"from edc_appointment.constants import NEW_APPT, CANCELLED_APPT, ONTIME_APPT, MISSED_APPT\n",
|
|
48
|
-
"from meta_consent.models import SubjectConsentV1Ext\n",
|
|
49
|
-
"from meta_analytics.dataframes import get_glucose_df, get_screening_df\n",
|
|
50
|
-
"\n",
|
|
51
|
-
"from edc_appointment.constants import SCHEDULED_APPT, UNSCHEDULED_APPT # noqa\n",
|
|
52
|
-
"from edc_constants.constants import YES # noqa"
|
|
53
|
-
]
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
"cell_type": "code",
|
|
57
|
-
"execution_count": null,
|
|
58
|
-
"id": "2",
|
|
59
|
-
"metadata": {},
|
|
60
|
-
"outputs": [],
|
|
61
|
-
"source": [
|
|
62
|
-
"html_data = []\n",
|
|
63
|
-
"data_download_date = date(2025, 6, 30)\n",
|
|
64
|
-
"cutoff_date = date(2025, 6, 30)\n",
|
|
65
|
-
"end_of_trial_date = date(2026, 7, 1)\n",
|
|
66
|
-
"document_title = f\"<h2>Monitoring Report: {cutoff_date.strftime('%B %Y')}</h2><h5>Data Download: {data_download_date.strftime('%d %B %Y')}</h5>\"\n",
|
|
67
|
-
"study_title = 'META3 - Metformin treatment for diabetes prevention in Africa'\n",
|
|
68
|
-
"pdf_filename = f\"monitoring_report_{cutoff_date.strftime('%Y%m%d')}.pdf\"\n"
|
|
69
|
-
]
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
"cell_type": "code",
|
|
73
|
-
"execution_count": null,
|
|
74
|
-
"id": "3",
|
|
75
|
-
"metadata": {},
|
|
76
|
-
"outputs": [],
|
|
77
|
-
"source": [
|
|
78
|
-
"# 105-30-0288-5 should also be late excluded based on the haemoglobin 4.8 presented at baseline\n",
|
|
79
|
-
"\n",
|
|
80
|
-
"df_visit = get_subject_visit(\"meta_subject.subjectvisit\")\n",
|
|
81
|
-
"df_visit_1691 = df_visit.copy()\n",
|
|
82
|
-
"\n",
|
|
83
|
-
"late_exlusion_offstudy_reasons = [\n",
|
|
84
|
-
" 'Patient fulfilled late exclusion criteria (due to abnormal blood values or raised blood pressure at enrolment']\n",
|
|
85
|
-
"df_eos = get_eos_df()\n",
|
|
86
|
-
"df_eos_1691 = df_eos.copy()\n",
|
|
87
|
-
"df_eos_excluded = (\n",
|
|
88
|
-
" df_eos\n",
|
|
89
|
-
" .query(\"offstudy_reason.isin(@late_exlusion_offstudy_reasons)\")\n",
|
|
90
|
-
" .copy()\n",
|
|
91
|
-
" .reset_index()\n",
|
|
92
|
-
")\n",
|
|
93
|
-
"df_visit = (\n",
|
|
94
|
-
" df_visit\n",
|
|
95
|
-
" .merge(df_eos_excluded[[\"subject_identifier\", \"offstudy_datetime\", \"offstudy_reason\"]], on=\"subject_identifier\",\n",
|
|
96
|
-
" how=\"left\", indicator=True)\n",
|
|
97
|
-
" .query(\"_merge=='left_only'\")\n",
|
|
98
|
-
" .drop(columns=[\"_merge\"])\n",
|
|
99
|
-
")\n",
|
|
100
|
-
"\n",
|
|
101
|
-
"df_visit = df_visit[df_visit.appt_datetime.dt.date <= cutoff_date]\n",
|
|
102
|
-
"\n",
|
|
103
|
-
"df_appointments = get_appointment_df()\n",
|
|
104
|
-
"df_appointments[\"site_id\"] = df_appointments.site_id.astype(str)\n",
|
|
105
|
-
"df_appointments_1691 = df_appointments.copy()\n",
|
|
106
|
-
"df_appointments = (\n",
|
|
107
|
-
" df_appointments\n",
|
|
108
|
-
" .merge(df_eos_excluded[[\"subject_identifier\", \"offstudy_datetime\", \"offstudy_reason\"]], on=\"subject_identifier\",\n",
|
|
109
|
-
" how=\"left\", indicator=True)\n",
|
|
110
|
-
" .query(\"_merge=='left_only'\")\n",
|
|
111
|
-
" .drop(columns=[\"_merge\"])\n",
|
|
112
|
-
")\n",
|
|
113
|
-
"\n",
|
|
114
|
-
"cls = GlucoseEndpointsByDate()\n",
|
|
115
|
-
"cls.run()\n",
|
|
116
|
-
"df_endpoint = cls.endpoint_only_df.copy()\n",
|
|
117
|
-
"df_glucose = get_glucose_df()\n",
|
|
118
|
-
"# df_glucose_fbg = get_glucose_fbg_df()\n",
|
|
119
|
-
"# df_glucose = pd.concat([df_glucose, df_glucose_fbg])\n",
|
|
120
|
-
"\n",
|
|
121
|
-
"\n",
|
|
122
|
-
"enrolled = df_visit.copy()\n",
|
|
123
|
-
"enrolled[\"site_id\"] = enrolled[\"site_id\"].astype(str)\n",
|
|
124
|
-
"enrolled_pivot = (\n",
|
|
125
|
-
" enrolled\n",
|
|
126
|
-
" .query(\"visit_code==1000.0\").groupby([\"site_id\"])\n",
|
|
127
|
-
" .size()\n",
|
|
128
|
-
" .reset_index()\n",
|
|
129
|
-
" .pivot_table(columns=\"site_id\", values=0, observed=True)\n",
|
|
130
|
-
")\n",
|
|
131
|
-
"enrolled_pivot.columns.name = \"\"\n",
|
|
132
|
-
"enrolled_pivot[\"total\"] = enrolled_pivot[[\"10\", \"20\", \"30\", \"40\", \"60\"]].sum(axis=1)"
|
|
133
|
-
]
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
"cell_type": "code",
|
|
137
|
-
"execution_count": null,
|
|
138
|
-
"id": "4",
|
|
139
|
-
"metadata": {},
|
|
140
|
-
"outputs": [],
|
|
141
|
-
"source": [
|
|
142
|
-
"# before late exclusion\n",
|
|
143
|
-
"df_visit_orig = df_visit_1691[df_visit_1691.appt_datetime.dt.date <= cutoff_date]\n",
|
|
144
|
-
"enrolled_1691 = df_visit_1691.copy()\n",
|
|
145
|
-
"enrolled_1691[\"site_id\"] = enrolled_1691[\"site_id\"].astype(str)\n",
|
|
146
|
-
"enrolled_1691_pivot = (\n",
|
|
147
|
-
" enrolled_1691\n",
|
|
148
|
-
" .query(\"visit_code==1000.0\").groupby([\"site_id\"])\n",
|
|
149
|
-
" .size()\n",
|
|
150
|
-
" .reset_index()\n",
|
|
151
|
-
" .pivot_table(columns=\"site_id\", values=0, observed=True)\n",
|
|
152
|
-
")\n",
|
|
153
|
-
"enrolled_1691_pivot.columns.name = \"\"\n",
|
|
154
|
-
"enrolled_1691_pivot[\"total\"] = enrolled_1691_pivot[[\"10\", \"20\", \"30\", \"40\", \"60\"]].sum(axis=1)\n",
|
|
155
|
-
"\n",
|
|
156
|
-
"# df_eos_1691\n",
|
|
157
|
-
"# df_appointments_1691\n",
|
|
158
|
-
"\n"
|
|
159
|
-
]
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
"cell_type": "code",
|
|
163
|
-
"execution_count": null,
|
|
164
|
-
"id": "5",
|
|
165
|
-
"metadata": {},
|
|
166
|
-
"outputs": [],
|
|
167
|
-
"source": [
|
|
168
|
-
"column_headers = {\"label\": \"Label\", \"visit_code\": \"Visit code\", \"10\": \"Hindu Mandal\", \"20\": \"Amana\", \"30\": \"Temeke\",\n",
|
|
169
|
-
" \"40\": \"Mwananyamala\", \"60\": \"Mnazi Moja\", \"total\": \"Total\"}\n",
|
|
170
|
-
"column_headers_with_str = {\"label\": \"Label\", \"10_str\": \"Hindu Mandal\", \"20_str\": \"Amana\", \"30_str\": \"Temeke\",\n",
|
|
171
|
-
" \"40_str\": \"Mwananyamala\", \"60_str\": \"Mnazi Moja\", \"total_str\": \"Total\"}"
|
|
172
|
-
]
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
"cell_type": "code",
|
|
176
|
-
"execution_count": null,
|
|
177
|
-
"id": "6",
|
|
178
|
-
"metadata": {},
|
|
179
|
-
"outputs": [],
|
|
180
|
-
"source": [
|
|
181
|
-
"# Table 1a Visits completed to date\n",
|
|
182
|
-
"\n",
|
|
183
|
-
"df_tbl1 = df_visit[(df_visit.visit_code_sequence == 0) & (df_visit.appt_timing == ONTIME_APPT) & ~(\n",
|
|
184
|
-
" df_visit.appt_status.isin([NEW_APPT, CANCELLED_APPT]))].groupby(\n",
|
|
185
|
-
" by=[\"visit_code\", \"site_id\"]).size().to_frame().reset_index()\n",
|
|
186
|
-
"\n",
|
|
187
|
-
"df_tbl1.columns = [\"visit_code\", \"site_id\", \"visits\"]\n",
|
|
188
|
-
"df1 = df_tbl1.pivot(index=\"visit_code\", columns=\"site_id\", values=\"visits\").reset_index()\n",
|
|
189
|
-
"df1.columns.name = None\n",
|
|
190
|
-
"df1.columns = ['visit_code', \"10\", \"20\", \"30\", \"40\", \"60\"]\n",
|
|
191
|
-
"df1['total'] = df1[['10', '20', '30', '40', '60']].sum(axis=1)\n",
|
|
192
|
-
"df1.fillna(0, inplace=True)\n",
|
|
193
|
-
"df_attended = df1.copy().reset_index(drop=True)\n",
|
|
194
|
-
"df_attended = df_attended.fillna(0.0)"
|
|
195
|
-
]
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
"cell_type": "code",
|
|
199
|
-
"execution_count": null,
|
|
200
|
-
"id": "7",
|
|
201
|
-
"metadata": {},
|
|
202
|
-
"outputs": [],
|
|
203
|
-
"source": [
|
|
204
|
-
"gt = df_as_great_table(\n",
|
|
205
|
-
" df_attended[[\"visit_code\", \"10\", \"20\", \"30\", \"40\", \"60\", \"total\"]],\n",
|
|
206
|
-
" title=\"Table 1a: Visits completed to date\"\n",
|
|
207
|
-
")\n",
|
|
208
|
-
"gt = (\n",
|
|
209
|
-
" gt\n",
|
|
210
|
-
" .cols_label({k: v for k, v in column_headers.items() if k != \"label\"})\n",
|
|
211
|
-
" .cols_align(align=\"center\", columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"])\n",
|
|
212
|
-
" .cols_align(align=\"left\", columns=[\"visit_code\"])\n",
|
|
213
|
-
" .data_color(\n",
|
|
214
|
-
" columns=[\"visit_code\"],\n",
|
|
215
|
-
" palette=[\"lavender\", \"thistle\"],\n",
|
|
216
|
-
" domain=[2000, 5000],\n",
|
|
217
|
-
" na_color=\"white\"\n",
|
|
218
|
-
" )\n",
|
|
219
|
-
" .tab_source_note(\n",
|
|
220
|
-
" source_note=f\"Excludes visit reports submitted for participants eventually withdrawn on late exclusion criteria.\")\n",
|
|
221
|
-
")\n",
|
|
222
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
223
|
-
"gt.show()"
|
|
224
|
-
]
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
"cell_type": "code",
|
|
228
|
-
"execution_count": null,
|
|
229
|
-
"id": "8",
|
|
230
|
-
"metadata": {},
|
|
231
|
-
"outputs": [],
|
|
232
|
-
"source": [
|
|
233
|
-
"# Table 1b Total scheduled appointments\n",
|
|
234
|
-
"df_appt_pivot = (\n",
|
|
235
|
-
" df_appointments.query(\"appt_reason==@SCHEDULED_APPT\")\n",
|
|
236
|
-
" .merge(df_eos_excluded[[\"subject_identifier\"]], on=\"subject_identifier\", how=\"left\", indicator=True)\n",
|
|
237
|
-
" .query(\"_merge=='left_only'\")\n",
|
|
238
|
-
" .drop(columns=[\"_merge\"])\n",
|
|
239
|
-
" .reset_index(drop=True)\n",
|
|
240
|
-
" .groupby([\"visit_code\", \"site_id\"])\n",
|
|
241
|
-
" .size()\n",
|
|
242
|
-
" .to_frame()\n",
|
|
243
|
-
" .reset_index()\n",
|
|
244
|
-
" .pivot(index=\"visit_code\", columns=\"site_id\", values=0)\n",
|
|
245
|
-
" .reset_index()\n",
|
|
246
|
-
" .fillna(0)\n",
|
|
247
|
-
")\n",
|
|
248
|
-
"\n",
|
|
249
|
-
"df_appt_pivot[\"total\"] = df_appt_pivot.iloc[:, 1:].sum(axis=1)\n",
|
|
250
|
-
"df_appt_pivot.columns.name = None\n",
|
|
251
|
-
"gt = df_as_great_table(\n",
|
|
252
|
-
" df_appt_pivot,\n",
|
|
253
|
-
" title=\"Table 1b: Total appointments\",\n",
|
|
254
|
-
" subtitle=\"Total possible appointments not including unscheduled appointments\"\n",
|
|
255
|
-
"\n",
|
|
256
|
-
")\n",
|
|
257
|
-
"gt = (\n",
|
|
258
|
-
" gt\n",
|
|
259
|
-
" .cols_label({k: v for k, v in column_headers.items() if k != \"label\"})\n",
|
|
260
|
-
" .cols_align(align=\"center\", columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"])\n",
|
|
261
|
-
" .cols_align(align=\"left\", columns=[\"visit_code\"])\n",
|
|
262
|
-
" .data_color(\n",
|
|
263
|
-
" columns=[\"visit_code\"],\n",
|
|
264
|
-
" palette=[\"lavender\", \"thistle\"],\n",
|
|
265
|
-
" domain=[2000, 5000],\n",
|
|
266
|
-
" na_color=\"white\"\n",
|
|
267
|
-
" )\n",
|
|
268
|
-
")\n",
|
|
269
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
270
|
-
"gt.show()"
|
|
271
|
-
]
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
"cell_type": "code",
|
|
275
|
-
"execution_count": null,
|
|
276
|
-
"id": "9",
|
|
277
|
-
"metadata": {},
|
|
278
|
-
"outputs": [],
|
|
279
|
-
"source": [
|
|
280
|
-
"# Table 1c Past scheduled appointments -- no information provided\n",
|
|
281
|
-
"df_appt_pivot = (\n",
|
|
282
|
-
" df_appointments.query(\n",
|
|
283
|
-
" \"appt_datetime<@cutoff_date and appt_reason==@SCHEDULED_APPT and appt_timing==@ONTIME_APPT and appt_status.isin([@NEW_APPT])\")\n",
|
|
284
|
-
" .merge(df_eos_excluded[[\"subject_identifier\"]], on=\"subject_identifier\", how=\"left\", indicator=True)\n",
|
|
285
|
-
" .query(\"_merge=='left_only'\")\n",
|
|
286
|
-
" .drop(columns=[\"_merge\"])\n",
|
|
287
|
-
" .reset_index(drop=True)\n",
|
|
288
|
-
" .groupby([\"visit_code\", \"site_id\"])\n",
|
|
289
|
-
" .size()\n",
|
|
290
|
-
" .to_frame()\n",
|
|
291
|
-
" .reset_index()\n",
|
|
292
|
-
" .pivot(index=\"visit_code\", columns=\"site_id\", values=0)\n",
|
|
293
|
-
" .reset_index()\n",
|
|
294
|
-
" .fillna(0)\n",
|
|
295
|
-
")\n",
|
|
296
|
-
"df_appt_pivot[\"total\"] = df_appt_pivot.iloc[:, 1:].sum(axis=1)\n",
|
|
297
|
-
"df_appt_pivot.columns.name = None\n",
|
|
298
|
-
"gt = df_as_great_table(\n",
|
|
299
|
-
" df_appt_pivot,\n",
|
|
300
|
-
" title=\"Table 1c: Past appointments not attended/not reported\",\n",
|
|
301
|
-
" subtitle=\"Expected by now but no information provided by site\",\n",
|
|
302
|
-
")\n",
|
|
303
|
-
"gt = (\n",
|
|
304
|
-
" gt\n",
|
|
305
|
-
" .cols_label({k: v for k, v in column_headers.items() if k != \"label\"})\n",
|
|
306
|
-
" .cols_align(align=\"center\", columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"])\n",
|
|
307
|
-
" .cols_align(align=\"left\", columns=[\"visit_code\"])\n",
|
|
308
|
-
" .data_color(\n",
|
|
309
|
-
" columns=[\"visit_code\"],\n",
|
|
310
|
-
" palette=[\"lavender\", \"thistle\"],\n",
|
|
311
|
-
" domain=[2000, 5000],\n",
|
|
312
|
-
" na_color=\"white\"\n",
|
|
313
|
-
" )\n",
|
|
314
|
-
" .tab_source_note(source_note=f\"Scheduled appointment date is before {cutoff_date.strftime('%d %B %Y')}.\")\n",
|
|
315
|
-
")\n",
|
|
316
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
317
|
-
"gt.show()"
|
|
318
|
-
]
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
"cell_type": "code",
|
|
322
|
-
"execution_count": null,
|
|
323
|
-
"id": "10",
|
|
324
|
-
"metadata": {},
|
|
325
|
-
"outputs": [],
|
|
326
|
-
"source": [
|
|
327
|
-
"# Table 1d Unscheduled appointments\n",
|
|
328
|
-
"df_appt = (\n",
|
|
329
|
-
" df_appointments.query(\"appt_reason==@UNSCHEDULED_APPT and appt_timing==@ONTIME_APPT and appt_status!=@NEW_APPT\")\n",
|
|
330
|
-
" .merge(df_eos_excluded[[\"subject_identifier\"]], on=\"subject_identifier\", how=\"left\", indicator=True)\n",
|
|
331
|
-
" .query(\"_merge=='left_only'\")\n",
|
|
332
|
-
" .drop(columns=[\"_merge\"])\n",
|
|
333
|
-
" .reset_index(drop=True)\n",
|
|
334
|
-
" .copy()\n",
|
|
335
|
-
" .reset_index(drop=True)\n",
|
|
336
|
-
")\n",
|
|
337
|
-
"df_appt['visit_code'] = df_appt['visit_code'].astype(int)\n",
|
|
338
|
-
"df_appt['visit_code'] = df_appt['visit_code'].astype(str)\n",
|
|
339
|
-
"\n",
|
|
340
|
-
"subjects_with_unscheduled = df_appt.subject_identifier.nunique()\n",
|
|
341
|
-
"\n",
|
|
342
|
-
"df_appt_pivot = (\n",
|
|
343
|
-
" df_appt\n",
|
|
344
|
-
" .groupby([\"visit_code\", \"site_id\"])\n",
|
|
345
|
-
" .size()\n",
|
|
346
|
-
" .to_frame()\n",
|
|
347
|
-
" .reset_index()\n",
|
|
348
|
-
" .pivot(index=\"visit_code\", columns=\"site_id\", values=0)\n",
|
|
349
|
-
" .reset_index()\n",
|
|
350
|
-
" .fillna(0)\n",
|
|
351
|
-
")\n",
|
|
352
|
-
"df_appt_pivot[\"total\"] = df_appt_pivot.iloc[:, 1:].sum(axis=1)\n",
|
|
353
|
-
"df_appt_pivot.columns.name = None\n",
|
|
354
|
-
"df_appt_pivot[[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"]] = df_appt_pivot[[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"]].astype(\n",
|
|
355
|
-
" 'float64')\n",
|
|
356
|
-
"\n",
|
|
357
|
-
"# add totals row\n",
|
|
358
|
-
"sum_row = df_appt_pivot.select_dtypes(include='float64').sum()\n",
|
|
359
|
-
"sum_row['visit_code'] = 'Total'\n",
|
|
360
|
-
"sum_row_df = pd.DataFrame(sum_row).T\n",
|
|
361
|
-
"df_appt_pivot = pd.concat([df_appt_pivot, sum_row_df], axis=0).reset_index(drop=True)\n",
|
|
362
|
-
"\n",
|
|
363
|
-
"gt = df_as_great_table(\n",
|
|
364
|
-
" df_appt_pivot,\n",
|
|
365
|
-
" title=\"Table 1d: Unscheduled appointments\",\n",
|
|
366
|
-
" subtitle=\"Appointments with sequence>0 grouped by visit code\",\n",
|
|
367
|
-
")\n",
|
|
368
|
-
"gt = (\n",
|
|
369
|
-
" gt\n",
|
|
370
|
-
" .cols_label({k: v for k, v in column_headers.items() if k != \"label\"})\n",
|
|
371
|
-
" .cols_align(align=\"center\", columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"])\n",
|
|
372
|
-
" .cols_align(align=\"left\", columns=[\"visit_code\"])\n",
|
|
373
|
-
" .data_color(\n",
|
|
374
|
-
" columns=[\"visit_code\"],\n",
|
|
375
|
-
" palette=[\"lavender\", \"thistle\"],\n",
|
|
376
|
-
" domain=[2000, 5000],\n",
|
|
377
|
-
" na_color=\"white\"\n",
|
|
378
|
-
" )\n",
|
|
379
|
-
" .fmt_number(columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"], decimals=0)\n",
|
|
380
|
-
" .tab_source_note(source_note=f\"{subjects_with_unscheduled} participants had at least one unscheduled appointment.\")\n",
|
|
381
|
-
")\n",
|
|
382
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
383
|
-
"gt.show()"
|
|
384
|
-
]
|
|
385
|
-
},
|
|
386
|
-
{
|
|
387
|
-
"cell_type": "code",
|
|
388
|
-
"execution_count": null,
|
|
389
|
-
"id": "11",
|
|
390
|
-
"metadata": {},
|
|
391
|
-
"outputs": [],
|
|
392
|
-
"source": [
|
|
393
|
-
"# Table 1e Future scheduled appointments\n",
|
|
394
|
-
"df_appt_pivot = (\n",
|
|
395
|
-
" df_appointments.query(\n",
|
|
396
|
-
" \"@cutoff_date<=appt_datetime<@end_of_trial_date and appt_reason==@SCHEDULED_APPT and appt_timing==@ONTIME_APPT and appt_status.isin([@NEW_APPT])\")\n",
|
|
397
|
-
" .merge(df_eos_excluded[[\"subject_identifier\"]], on=\"subject_identifier\", how=\"left\", indicator=True)\n",
|
|
398
|
-
" .query(\"_merge=='left_only'\")\n",
|
|
399
|
-
" .drop(columns=[\"_merge\"])\n",
|
|
400
|
-
" .reset_index(drop=True)\n",
|
|
401
|
-
" .groupby([\"visit_code\", \"site_id\"])\n",
|
|
402
|
-
" .size()\n",
|
|
403
|
-
" .to_frame()\n",
|
|
404
|
-
" .reset_index()\n",
|
|
405
|
-
" .pivot(index=\"visit_code\", columns=\"site_id\", values=0)\n",
|
|
406
|
-
" .reset_index()\n",
|
|
407
|
-
" .fillna(0)\n",
|
|
408
|
-
")\n",
|
|
409
|
-
"df_appt_pivot[\"total\"] = df_appt_pivot.iloc[:, 1:].sum(axis=1)\n",
|
|
410
|
-
"df_appt_pivot.columns.name = None\n",
|
|
411
|
-
"gt = df_as_great_table(\n",
|
|
412
|
-
" df_appt_pivot,\n",
|
|
413
|
-
" title=\"Table 1e: Future appointments\",\n",
|
|
414
|
-
")\n",
|
|
415
|
-
"gt = (\n",
|
|
416
|
-
" gt\n",
|
|
417
|
-
" .cols_label({k: v for k, v in column_headers.items() if k != \"label\"})\n",
|
|
418
|
-
" .cols_align(align=\"center\", columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"])\n",
|
|
419
|
-
" .cols_align(align=\"left\", columns=[\"visit_code\"])\n",
|
|
420
|
-
" .data_color(\n",
|
|
421
|
-
" columns=[\"visit_code\"],\n",
|
|
422
|
-
" palette=[\"lavender\", \"thistle\"],\n",
|
|
423
|
-
" domain=[2000, 5000],\n",
|
|
424
|
-
" na_color=\"white\"\n",
|
|
425
|
-
" )\n",
|
|
426
|
-
" .fmt_number(columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"], decimals=0)\n",
|
|
427
|
-
" .tab_source_note(\n",
|
|
428
|
-
" source_note=f\"Scheduled appointment date is on or after {cutoff_date.strftime('%d %B %Y')} and before {end_of_trial_date.strftime('%d %B %Y')}.\")\n",
|
|
429
|
-
")\n",
|
|
430
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
431
|
-
"gt.show()"
|
|
432
|
-
]
|
|
433
|
-
},
|
|
434
|
-
{
|
|
435
|
-
"cell_type": "code",
|
|
436
|
-
"execution_count": null,
|
|
437
|
-
"id": "12",
|
|
438
|
-
"metadata": {},
|
|
439
|
-
"outputs": [],
|
|
440
|
-
"source": [
|
|
441
|
-
"# Table 2 Visits Missed to Date as % of Visits Attended + Visits Missed\n",
|
|
442
|
-
"subject_count = (\n",
|
|
443
|
-
" df_visit\n",
|
|
444
|
-
" .merge(df_eos_excluded[[\"subject_identifier\"]], on=\"subject_identifier\", how=\"left\", indicator=True)\n",
|
|
445
|
-
" .query(\"_merge=='left_only'\")\n",
|
|
446
|
-
" .drop(columns=[\"_merge\"])\n",
|
|
447
|
-
" .reset_index(drop=True)\n",
|
|
448
|
-
" .query(\"visit_code_sequence==0 and appt_timing==@MISSED_APPT and ~appt_status.isin([@NEW_APPT, @CANCELLED_APPT])\")\n",
|
|
449
|
-
").subject_identifier.nunique()\n",
|
|
450
|
-
"df_tbl = (\n",
|
|
451
|
-
" df_visit[(df_visit.visit_code_sequence == 0) & (df_visit.appt_timing == MISSED_APPT) & ~(\n",
|
|
452
|
-
" df_visit.appt_status.isin([NEW_APPT, CANCELLED_APPT]))]\n",
|
|
453
|
-
" .merge(df_eos_excluded[[\"subject_identifier\"]], on=\"subject_identifier\", how=\"left\", indicator=True)\n",
|
|
454
|
-
" .query(\"_merge=='left_only'\")\n",
|
|
455
|
-
" .drop(columns=[\"_merge\"])\n",
|
|
456
|
-
" .reset_index(drop=True)\n",
|
|
457
|
-
" .groupby(by=[\"visit_code\", \"site_id\"])\n",
|
|
458
|
-
" .size()\n",
|
|
459
|
-
" .to_frame()\n",
|
|
460
|
-
" .reset_index()\n",
|
|
461
|
-
")\n",
|
|
462
|
-
"df_tbl.columns = [\"visit_code\", \"site_id\", \"visits\"]\n",
|
|
463
|
-
"df_tbl_pivot = df_tbl.pivot(index=\"visit_code\", columns=\"site_id\", values=\"visits\").reset_index()\n",
|
|
464
|
-
"df_tbl_pivot.columns.name = None\n",
|
|
465
|
-
"df_tbl_pivot.columns = ['visit_code', \"10\", \"20\", \"30\", \"40\", \"60\"]\n",
|
|
466
|
-
"df_tbl_pivot['total'] = df_tbl_pivot[['10', '20', '30', '40', '60']].sum(axis=1)\n",
|
|
467
|
-
"df_missed = (\n",
|
|
468
|
-
" df_tbl_pivot\n",
|
|
469
|
-
" .fillna(0)\n",
|
|
470
|
-
" .copy()\n",
|
|
471
|
-
" .set_index([\"visit_code\"])\n",
|
|
472
|
-
")\n",
|
|
473
|
-
"\n",
|
|
474
|
-
"df_attended_display = df_attended.copy()\n",
|
|
475
|
-
"df_attended_display = (\n",
|
|
476
|
-
" df_attended_display\n",
|
|
477
|
-
" .set_index([\"visit_code\"])\n",
|
|
478
|
-
")\n",
|
|
479
|
-
"\n",
|
|
480
|
-
"attended_and_missed = df_attended_display + df_missed\n",
|
|
481
|
-
"attended_and_missed = (\n",
|
|
482
|
-
" attended_and_missed\n",
|
|
483
|
-
" .fillna(0)\n",
|
|
484
|
-
" .reset_index()\n",
|
|
485
|
-
" .set_index([\"visit_code\"])\n",
|
|
486
|
-
")\n",
|
|
487
|
-
"\n",
|
|
488
|
-
"attended_and_missed_perc = df_missed / attended_and_missed\n",
|
|
489
|
-
"attended_and_missed_perc = (\n",
|
|
490
|
-
" attended_and_missed_perc\n",
|
|
491
|
-
" .fillna(0)\n",
|
|
492
|
-
" .reset_index()\n",
|
|
493
|
-
" .set_index([\"visit_code\"])\n",
|
|
494
|
-
")\n",
|
|
495
|
-
"\n",
|
|
496
|
-
"df_result = df_missed.merge(attended_and_missed_perc, on=[\"visit_code\"], suffixes=(\"\", \"_perc\"))\n",
|
|
497
|
-
"for col in [\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"]:\n",
|
|
498
|
-
" col_perc = f\"{col}_perc\"\n",
|
|
499
|
-
" df_result[col] = df_result.apply(lambda x: f\"{x[col]} ({x[col_perc] * 100:.2f})\", axis=1)\n",
|
|
500
|
-
"df_result = df_result.reset_index().sort_values(by=[\"visit_code\"], ascending=True)\n",
|
|
501
|
-
"df_result = df_result.fillna(0.0)"
|
|
502
|
-
]
|
|
503
|
-
},
|
|
504
|
-
{
|
|
505
|
-
"cell_type": "code",
|
|
506
|
-
"execution_count": null,
|
|
507
|
-
"id": "13",
|
|
508
|
-
"metadata": {},
|
|
509
|
-
"outputs": [],
|
|
510
|
-
"source": [
|
|
511
|
-
"df_table = df_result[[\"visit_code\", \"10\", \"20\", \"30\", \"40\", \"60\", \"total\"]].copy()\n",
|
|
512
|
-
"gt = df_as_great_table(\n",
|
|
513
|
-
" df_table,\n",
|
|
514
|
-
" title=\"Table 2a: Visits Missed to Date\",\n",
|
|
515
|
-
" subtitle=\"as % of Visits Attended + Visits Missed\"\n",
|
|
516
|
-
")\n",
|
|
517
|
-
"gt = (\n",
|
|
518
|
-
" gt\n",
|
|
519
|
-
" .cols_label({k: v for k, v in column_headers.items() if k != \"label\"})\n",
|
|
520
|
-
" .cols_align(align=\"center\", columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"])\n",
|
|
521
|
-
" .cols_align(align=\"left\", columns=[\"visit_code\", \"label\"])\n",
|
|
522
|
-
" .tab_style(\n",
|
|
523
|
-
" style=[style.fill(color=\"snow\"), style.text(color=\"black\")],\n",
|
|
524
|
-
" locations=loc.body(\n",
|
|
525
|
-
" columns=[0],\n",
|
|
526
|
-
" rows=list(range(0, len(df_table))),\n",
|
|
527
|
-
" ),\n",
|
|
528
|
-
" )\n",
|
|
529
|
-
" .tab_source_note(source_note=f\"{subject_count} participants had at least one missed visit.\")\n",
|
|
530
|
-
"\n",
|
|
531
|
-
")\n",
|
|
532
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
533
|
-
"gt.show()\n"
|
|
534
|
-
]
|
|
535
|
-
},
|
|
536
|
-
{
|
|
537
|
-
"cell_type": "code",
|
|
538
|
-
"execution_count": null,
|
|
539
|
-
"id": "14",
|
|
540
|
-
"metadata": {},
|
|
541
|
-
"outputs": [],
|
|
542
|
-
"source": [
|
|
543
|
-
"# Table 2b: Number of missed visits by participant\n",
|
|
544
|
-
"subject_count = (\n",
|
|
545
|
-
" df_visit\n",
|
|
546
|
-
" .merge(df_eos_excluded[[\"subject_identifier\"]], on=\"subject_identifier\", how=\"left\", indicator=True)\n",
|
|
547
|
-
" .query(\"_merge=='left_only'\")\n",
|
|
548
|
-
" .drop(columns=[\"_merge\"])\n",
|
|
549
|
-
" .reset_index(drop=True)\n",
|
|
550
|
-
" .query(\"visit_code_sequence==0 and appt_timing==@MISSED_APPT and ~appt_status.isin([@NEW_APPT, @CANCELLED_APPT])\")\n",
|
|
551
|
-
").subject_identifier.nunique()\n",
|
|
552
|
-
"df_tbl = (\n",
|
|
553
|
-
" df_visit[(df_visit.visit_code_sequence == 0) & (df_visit.appt_timing == MISSED_APPT) & ~(\n",
|
|
554
|
-
" df_visit.appt_status.isin([NEW_APPT, CANCELLED_APPT]))]\n",
|
|
555
|
-
" .merge(df_eos_excluded[[\"subject_identifier\"]], on=\"subject_identifier\", how=\"left\", indicator=True)\n",
|
|
556
|
-
" .query(\"_merge=='left_only'\")\n",
|
|
557
|
-
" .drop(columns=[\"_merge\"])\n",
|
|
558
|
-
" .reset_index(drop=True)\n",
|
|
559
|
-
" .groupby(by=[\"subject_identifier\", \"site_id\"])\n",
|
|
560
|
-
" .size()\n",
|
|
561
|
-
" .to_frame()\n",
|
|
562
|
-
" .reset_index()\n",
|
|
563
|
-
")\n",
|
|
564
|
-
"df_tbl.columns = [\"subject_identifier\", \"site_id\", \"missed_count\"]\n",
|
|
565
|
-
"df_tbl[\"category\"] = pd.cut(df_tbl[\"missed_count\"], bins=[0, 1, 3, 5, 7, 100],\n",
|
|
566
|
-
" labels=[\"Missed at least 1\", \"2 to 3\", \"4 to 5\", \"6 to 7\", \"missed more than 7\"])\n",
|
|
567
|
-
"df_tbl_pivot = df_tbl.pivot_table(index=\"category\", columns=\"site_id\", values=\"missed_count\", observed=False,\n",
|
|
568
|
-
" aggfunc=\"count\").reset_index()\n",
|
|
569
|
-
"\n",
|
|
570
|
-
"df_tbl_pivot['total'] = df_tbl_pivot.select_dtypes(include='int').sum(axis=1, skipna=True)\n",
|
|
571
|
-
"\n",
|
|
572
|
-
"sum_row = df_tbl_pivot.select_dtypes(include='int64').sum()\n",
|
|
573
|
-
"sum_row['category'] = 'Total'\n",
|
|
574
|
-
"\n",
|
|
575
|
-
"df_tbl_pivot = (\n",
|
|
576
|
-
" pd.concat([df_tbl_pivot, sum_row.to_frame().T], axis=0)\n",
|
|
577
|
-
" .rename(columns={10: \"10\", 20: \"20\", 30: \"30\", 40: \"40\", 60: \"60\"})\n",
|
|
578
|
-
")\n",
|
|
579
|
-
"\n",
|
|
580
|
-
"gt = df_as_great_table(\n",
|
|
581
|
-
" df_tbl_pivot,\n",
|
|
582
|
-
" title=\"Table 2b: Number of participants who missed one or more visits\",\n",
|
|
583
|
-
")\n",
|
|
584
|
-
"gt = (\n",
|
|
585
|
-
" gt\n",
|
|
586
|
-
" .cols_label(\n",
|
|
587
|
-
" {\"category\": \"Category\", **{k: v for k, v in column_headers.items() if k not in [\"visit_code\", \"label\"]}})\n",
|
|
588
|
-
" .cols_align(align=\"center\", columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"])\n",
|
|
589
|
-
" .cols_align(align=\"left\", columns=[\"category\"])\n",
|
|
590
|
-
" .tab_style(\n",
|
|
591
|
-
" style=[style.fill(color=\"snow\"), style.text(color=\"black\")],\n",
|
|
592
|
-
" locations=loc.body(\n",
|
|
593
|
-
" columns=[0],\n",
|
|
594
|
-
" rows=list(range(0, len(df_table))),\n",
|
|
595
|
-
" ),\n",
|
|
596
|
-
" )\n",
|
|
597
|
-
")\n",
|
|
598
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
599
|
-
"gt.show()\n",
|
|
600
|
-
"\n"
|
|
601
|
-
]
|
|
602
|
-
},
|
|
603
|
-
{
|
|
604
|
-
"cell_type": "code",
|
|
605
|
-
"execution_count": null,
|
|
606
|
-
"id": "15",
|
|
607
|
-
"metadata": {},
|
|
608
|
-
"outputs": [],
|
|
609
|
-
"source": [
|
|
610
|
-
"# func for tables 3,4,5\n",
|
|
611
|
-
"def get_row_df(row_df: pd.DataFrame, label: str = None, **kwargs) -> pd.DataFrame:\n",
|
|
612
|
-
" row_df = row_df.groupby(by=[\"site_id\"]).site_id.count().to_frame(name=\"n\")\n",
|
|
613
|
-
" row_df[\"label\"] = label\n",
|
|
614
|
-
" row_df = row_df.reset_index()\n",
|
|
615
|
-
" row_df = row_df.pivot(index=\"label\", values=\"n\", columns=\"site_id\").reset_index()\n",
|
|
616
|
-
" row_df.columns.name = \"\"\n",
|
|
617
|
-
" all_sites = [10, 20, 30, 40, 60]\n",
|
|
618
|
-
" for site in all_sites:\n",
|
|
619
|
-
" if site not in row_df.columns:\n",
|
|
620
|
-
" row_df[site] = None\n",
|
|
621
|
-
" row_df = row_df.reset_index(drop=True)\n",
|
|
622
|
-
" return row_df\n",
|
|
623
|
-
"\n",
|
|
624
|
-
"\n",
|
|
625
|
-
"def get_table_df(\n",
|
|
626
|
-
" df_source: pd.DataFrame,\n",
|
|
627
|
-
" visit_code: float | None = None,\n",
|
|
628
|
-
" month_label: str | None = None,\n",
|
|
629
|
-
" visit_codes: list[float] | None = None,\n",
|
|
630
|
-
" get_row_func: Callable | None = None,\n",
|
|
631
|
-
" category_labels: list[str] | None = None,\n",
|
|
632
|
-
") -> pd.DataFrame:\n",
|
|
633
|
-
" get_row_df_func = get_row_func or get_row_df\n",
|
|
634
|
-
" if visit_code:\n",
|
|
635
|
-
" df_month = df_source[df_source.visit_code == visit_code].copy()\n",
|
|
636
|
-
" elif visit_codes:\n",
|
|
637
|
-
" df_month = df_source[df_source.visit_code.isin(visit_codes)].copy()\n",
|
|
638
|
-
" elif month_label:\n",
|
|
639
|
-
" df_month = df_source.copy()\n",
|
|
640
|
-
"\n",
|
|
641
|
-
" row_df = df_month.copy()\n",
|
|
642
|
-
" table_df = get_row_df_func(row_df, \"Total (n)\", category_labels=category_labels)\n",
|
|
643
|
-
"\n",
|
|
644
|
-
" row_df = df_month.query(\"ogtt_value<7.8 and fbg_value<6.1\").copy()\n",
|
|
645
|
-
" table_df = pd.concat([table_df, get_row_df_func(row_df, \"OGTT <7.8; FBG <6.1\", category_labels=category_labels)])\n",
|
|
646
|
-
"\n",
|
|
647
|
-
" row_df = df_month[(df_month.ogtt_value < 7.8) & (df_month.fbg_value >= 6.1) & (df_month.fbg_value < 7.0)].copy()\n",
|
|
648
|
-
" table_df = pd.concat(\n",
|
|
649
|
-
" [table_df, get_row_df_func(row_df, \"OGTT <7.8; FBG >=6.1 <7.0\", category_labels=category_labels)])\n",
|
|
650
|
-
"\n",
|
|
651
|
-
" row_df = df_month[(df_month.ogtt_value < 7.8) & (df_month.fbg_value >= 7.0)].copy()\n",
|
|
652
|
-
" table_df = pd.concat([table_df, get_row_df_func(row_df, \"OGTT <7.8; FBG >=7.0\", category_labels=category_labels)])\n",
|
|
653
|
-
"\n",
|
|
654
|
-
" row_df = df_month[(df_month.ogtt_value >= 7.8) & (df_month.ogtt_value < 11.1) & (df_month.fbg_value < 6.1)].copy()\n",
|
|
655
|
-
" table_df = pd.concat(\n",
|
|
656
|
-
" [table_df, get_row_df_func(row_df, \"OGTT ≥7.8 to <11.1; FBG <6.1\", category_labels=category_labels)])\n",
|
|
657
|
-
"\n",
|
|
658
|
-
" row_df = df_month[(df_month.ogtt_value >= 7.8) & (df_month.ogtt_value < 11.1) & (df_month.fbg_value >= 6.1) & (\n",
|
|
659
|
-
" df_month.fbg_value < 7.0)].copy()\n",
|
|
660
|
-
" table_df = pd.concat(\n",
|
|
661
|
-
" [table_df, get_row_df_func(row_df, \"OGTT ≥7.8 to <11.1; FBG >=6.1 <7.0\", category_labels=category_labels)])\n",
|
|
662
|
-
"\n",
|
|
663
|
-
" row_df = df_month[(df_month.ogtt_value >= 7.8) & (df_month.ogtt_value < 11.1) & (df_month.fbg_value >= 7.0)].copy()\n",
|
|
664
|
-
" table_df = pd.concat(\n",
|
|
665
|
-
" [table_df, get_row_df_func(row_df, \"OGTT ≥7.8 to <11.1; FBG >=7.0\", category_labels=category_labels)])\n",
|
|
666
|
-
"\n",
|
|
667
|
-
" row_df = df_month[(df_month.ogtt_value >= 11.1) & (df_month.fbg_value < 6.1)].copy()\n",
|
|
668
|
-
" table_df = pd.concat([table_df, get_row_df_func(row_df, \"OGTT ≥11.1; FBG <6.1\", category_labels=category_labels)])\n",
|
|
669
|
-
"\n",
|
|
670
|
-
" row_df = df_month[(df_month.ogtt_value >= 11.1) & (df_month.fbg_value >= 6.1) & (df_month.fbg_value < 7.0)].copy()\n",
|
|
671
|
-
" table_df = pd.concat(\n",
|
|
672
|
-
" [table_df, get_row_df_func(row_df, \"OGTT ≥11.1; FBG >=6.1 <7.0\", category_labels=category_labels)])\n",
|
|
673
|
-
"\n",
|
|
674
|
-
" row_df = df_month[(df_month.ogtt_value >= 11.1) & (df_month.fbg_value >= 7.0)].copy()\n",
|
|
675
|
-
" table_df = pd.concat([table_df, get_row_df_func(row_df, \"OGTT ≥11.1; FBG >=7.0\", category_labels=category_labels)])\n",
|
|
676
|
-
"\n",
|
|
677
|
-
" row_df = df_month[(df_month.ogtt_value.isna())].copy()\n",
|
|
678
|
-
" table_df = pd.concat([table_df, get_row_df_func(row_df, \"Missing OGTT\", category_labels=category_labels)])\n",
|
|
679
|
-
" return table_df\n",
|
|
680
|
-
"\n",
|
|
681
|
-
"\n",
|
|
682
|
-
"def format_table_df(tbl_df, add_totals: bool | None = None):\n",
|
|
683
|
-
" \"\"\"Pivot on site\"\"\"\n",
|
|
684
|
-
" add_totals = True if add_totals is None else add_totals\n",
|
|
685
|
-
" tbl_df = tbl_df.fillna(0.0)\n",
|
|
686
|
-
" tbl_df[\"total\"] = tbl_df.iloc[:, 1:].sum(axis=1)\n",
|
|
687
|
-
" tbl_df = tbl_df.reset_index(drop=True)\n",
|
|
688
|
-
"\n",
|
|
689
|
-
" if add_totals:\n",
|
|
690
|
-
" df_last = tbl_df[1:].sum().to_frame()\n",
|
|
691
|
-
" df_last.loc[\"label\"] = np.nan\n",
|
|
692
|
-
" df_last = df_last.reset_index()\n",
|
|
693
|
-
" df_last.columns = [\"label\", \"value\"]\n",
|
|
694
|
-
" df_last = df_last.pivot_table(columns=\"label\", values=\"value\").reset_index(drop=True)\n",
|
|
695
|
-
" df_last.columns.name = \"\"\n",
|
|
696
|
-
" df_last[\"label\"] = \"Totals\"\n",
|
|
697
|
-
"\n",
|
|
698
|
-
" tbl_df = pd.concat([tbl_df, df_last])\n",
|
|
699
|
-
" tbl_df = tbl_df.reset_index(drop=True)\n",
|
|
700
|
-
"\n",
|
|
701
|
-
" tbl_df.columns = [\"label\", \"10\", \"20\", \"30\", \"40\", \"60\", \"total\"]\n",
|
|
702
|
-
"\n",
|
|
703
|
-
" for site in [\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"]:\n",
|
|
704
|
-
" tbl_df[f\"{site}_perc\"] = (tbl_df[site] / tbl_df.iloc[0][site]) * 100 if tbl_df.iloc[0][site] > 0 else 0\n",
|
|
705
|
-
" tbl_df[f\"{site}_perc_str\"] = tbl_df[f\"{site}_perc\"].map('{:.1f}'.format)\n",
|
|
706
|
-
"\n",
|
|
707
|
-
" for site in [\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"]:\n",
|
|
708
|
-
" tbl_df[f\"{site}_str\"] = tbl_df[[f\"{site}\", f\"{site}_perc_str\"]].apply(lambda x: ' ('.join(x.astype(str)),\n",
|
|
709
|
-
" axis=1)\n",
|
|
710
|
-
" tbl_df[f\"{site}_str\"] = tbl_df[f\"{site}_str\"] + \")\"\n",
|
|
711
|
-
"\n",
|
|
712
|
-
" cols = [\"label\", *[f\"{site}_str\" for site in [\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"]]]\n",
|
|
713
|
-
" tbl_df1 = tbl_df[cols]\n",
|
|
714
|
-
" tbl_df1.loc[tbl_df.label == \"Total (n)\"] = tbl_df.iloc[0][\n",
|
|
715
|
-
" [\"label\", \"10\", \"20\", \"30\", \"40\", \"60\", \"total\"]].to_list()\n",
|
|
716
|
-
" return tbl_df1\n",
|
|
717
|
-
"\n",
|
|
718
|
-
"\n",
|
|
719
|
-
"def format_table_with_bmi_df(tbl_df, add_totals: bool | None = None, category_labels: list[str] = None):\n",
|
|
720
|
-
" \"\"\"Pivot on BMI categories\"\"\"\n",
|
|
721
|
-
"\n",
|
|
722
|
-
" add_totals = True if add_totals is None else add_totals\n",
|
|
723
|
-
" tbl_df = tbl_df.fillna(0.0)\n",
|
|
724
|
-
" tbl_df[\"total\"] = tbl_df.iloc[:, 1:].sum(axis=1)\n",
|
|
725
|
-
" tbl_df = tbl_df.reset_index(drop=True)\n",
|
|
726
|
-
"\n",
|
|
727
|
-
" if add_totals:\n",
|
|
728
|
-
" df_last = tbl_df[1:].sum().to_frame()\n",
|
|
729
|
-
" df_last.loc[\"label\"] = np.nan\n",
|
|
730
|
-
" df_last = df_last.reset_index()\n",
|
|
731
|
-
" df_last.columns = [\"label\", \"value\"]\n",
|
|
732
|
-
" df_last = df_last.pivot_table(columns=\"label\", values=\"value\").reset_index(drop=True)\n",
|
|
733
|
-
" df_last.columns.name = \"\"\n",
|
|
734
|
-
" df_last[\"label\"] = \"Totals\"\n",
|
|
735
|
-
"\n",
|
|
736
|
-
" tbl_df = pd.concat([tbl_df, df_last])\n",
|
|
737
|
-
" tbl_df = tbl_df.reset_index(drop=True)\n",
|
|
738
|
-
"\n",
|
|
739
|
-
" tbl_df.columns = [\"label\", *category_labels, \"total\"]\n",
|
|
740
|
-
"\n",
|
|
741
|
-
" for label in [*category_labels, \"total\"]:\n",
|
|
742
|
-
" tbl_df[f\"{label}_perc\"] = (tbl_df[label] / tbl_df.iloc[0][label]) * 100 if tbl_df.iloc[0][label] > 0 else 0\n",
|
|
743
|
-
" tbl_df[f\"{label}_perc_str\"] = tbl_df[f\"{label}_perc\"].map('{:.1f}'.format)\n",
|
|
744
|
-
"\n",
|
|
745
|
-
" for cat in [*category_labels, \"total\"]:\n",
|
|
746
|
-
" tbl_df[f\"{label}_str\"] = tbl_df[[f\"{label}\", f\"{label}_perc_str\"]].apply(lambda x: ' ('.join(x.astype(str)),\n",
|
|
747
|
-
" axis=1)\n",
|
|
748
|
-
" tbl_df[f\"{label}_str\"] = tbl_df[f\"{label}_str\"] + \")\"\n",
|
|
749
|
-
"\n",
|
|
750
|
-
" cols = [\"label\", *[f\"{label}_str\" for label in [*category_labels, \"total\"]]]\n",
|
|
751
|
-
" tbl_df1 = tbl_df[cols]\n",
|
|
752
|
-
" tbl_df1.loc[tbl_df.label == \"Total (n)\"] = tbl_df.iloc[0][[\"label\", *category_labels, \"total\"]].to_list()\n",
|
|
753
|
-
" return tbl_df1\n",
|
|
754
|
-
"\n",
|
|
755
|
-
"\n",
|
|
756
|
-
"def get_row_by_df(row_df: pd.DataFrame, label: str, category_labels: list[str]) -> pd.DataFrame:\n",
|
|
757
|
-
" # if label not in category_labels:\n",
|
|
758
|
-
" # raise ValueError(f\"Invalid label. Expected one of {category_labels}. Got {label}.\")\n",
|
|
759
|
-
" row_df = row_df.groupby(by=[\"site_id\"]).site_id.count().to_frame(name=\"n\")\n",
|
|
760
|
-
" row_df[\"label\"] = label\n",
|
|
761
|
-
" row_df = row_df.reset_index()\n",
|
|
762
|
-
" row_df = row_df.pivot(index=\"label\", values=\"n\", columns=\"site_id\").reset_index()\n",
|
|
763
|
-
" row_df.columns.name = \"\"\n",
|
|
764
|
-
"\n",
|
|
765
|
-
" for label in category_labels:\n",
|
|
766
|
-
" if label not in row_df.columns:\n",
|
|
767
|
-
" row_df[label] = None\n",
|
|
768
|
-
" row_df = row_df.reset_index(drop=True)\n",
|
|
769
|
-
" return row_df"
|
|
770
|
-
]
|
|
771
|
-
},
|
|
772
|
-
{
|
|
773
|
-
"cell_type": "code",
|
|
774
|
-
"execution_count": null,
|
|
775
|
-
"id": "16",
|
|
776
|
-
"metadata": {},
|
|
777
|
-
"outputs": [],
|
|
778
|
-
"source": [
|
|
779
|
-
"def get_fbg_value(r):\n",
|
|
780
|
-
" if not pd.isna(r[\"converted_fbg2_value\"]):\n",
|
|
781
|
-
" return r[\"converted_fbg2_value\"]\n",
|
|
782
|
-
" return r[\"converted_fbg_value\"]\n",
|
|
783
|
-
"\n",
|
|
784
|
-
"\n",
|
|
785
|
-
"def get_ogtt_value(r):\n",
|
|
786
|
-
" if not pd.isna(r[\"converted_ogtt2_value\"]):\n",
|
|
787
|
-
" return r[\"converted_ogtt2_value\"]\n",
|
|
788
|
-
" return r[\"converted_ogtt_value\"]\n"
|
|
789
|
-
]
|
|
790
|
-
},
|
|
791
|
-
{
|
|
792
|
-
"cell_type": "code",
|
|
793
|
-
"execution_count": null,
|
|
794
|
-
"id": "17",
|
|
795
|
-
"metadata": {},
|
|
796
|
-
"outputs": [],
|
|
797
|
-
"source": [
|
|
798
|
-
"# Table 3: OGTT and FBG at Enrolment\n",
|
|
799
|
-
"\n",
|
|
800
|
-
"subjects = df_visit.subject_identifier.unique()\n",
|
|
801
|
-
"df_screening = get_screening_df().query(\"consented==True and subject_identifier.isin(@subjects)\")\n",
|
|
802
|
-
"df_screening[\"visit_code\"] = \"Enrol\"\n",
|
|
803
|
-
"df_screening[\"fbg_value\"] = df_screening.apply(get_fbg_value, axis=1)\n",
|
|
804
|
-
"df_screening[\"ogtt_value\"] = df_screening.apply(get_ogtt_value, axis=1)\n",
|
|
805
|
-
"df_screening[\"site_id\"] = df_screening.site.astype(int)\n",
|
|
806
|
-
"df_screening = df_screening.drop(columns=[\"site\"])\n",
|
|
807
|
-
"df_table3 = get_table_df(df_screening, month_label=\"enrol\")\n",
|
|
808
|
-
"df_table3 = format_table_df(df_table3)\n",
|
|
809
|
-
"df_table3 = df_table3.fillna(0.0)\n",
|
|
810
|
-
"gt = df_as_great_table(df_table3, title=\"Table 3a: OGTT and FBG at Screening / Enrolment\")\n",
|
|
811
|
-
"\n",
|
|
812
|
-
"column_headers_enrol = {k: v for k, v in column_headers_with_str.items() if k not in \"visit_code\"}\n",
|
|
813
|
-
"gt = (\n",
|
|
814
|
-
" gt\n",
|
|
815
|
-
" .cols_label(column_headers_enrol)\n",
|
|
816
|
-
" .cols_align(align=\"center\", columns=[\"10_str\", \"20_str\", \"30_str\", \"40_str\", \"60_str\", \"total_str\"])\n",
|
|
817
|
-
" .cols_align(align=\"left\", columns=[\"label\"])\n",
|
|
818
|
-
" .cols_width(cases={\"label\": \"35%\"})\n",
|
|
819
|
-
" .tab_source_note(source_note=\"Excluding patients eventually withdrawn for `late exclusion` criteria\")\n",
|
|
820
|
-
")\n",
|
|
821
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
822
|
-
"gt.show()\n"
|
|
823
|
-
]
|
|
824
|
-
},
|
|
825
|
-
{
|
|
826
|
-
"cell_type": "code",
|
|
827
|
-
"execution_count": null,
|
|
828
|
-
"id": "18",
|
|
829
|
-
"metadata": {},
|
|
830
|
-
"outputs": [],
|
|
831
|
-
"source": [
|
|
832
|
-
"# bmi_categories:\n",
|
|
833
|
-
"# 1 calculated_bmi_value<25\n",
|
|
834
|
-
"# 2 calculated_bmi_value>=25 & calculated_bmi_value<30\n",
|
|
835
|
-
"# 3 calculated_bmi_value>=30\n",
|
|
836
|
-
"\n",
|
|
837
|
-
"\n",
|
|
838
|
-
"# subjects = df_visit.subject_identifier.unique()\n",
|
|
839
|
-
"# df_screening = get_screening_df().query(\"consented==True and subject_identifier.isin(@subjects)\")\n",
|
|
840
|
-
"# df_screening[\"visit_code\"] = \"Enrol\"\n",
|
|
841
|
-
"# df_screening[\"fbg_value\"] = df_screening.apply(get_fbg_value, axis=1)\n",
|
|
842
|
-
"# df_screening[\"ogtt_value\"] = df_screening.apply(get_ogtt_value, axis=1)\n",
|
|
843
|
-
"# df_screening[\"site_id\"] = df_screening.site.astype(int)\n",
|
|
844
|
-
"# df_screening = df_screening.drop(columns=[\"site\"])\n",
|
|
845
|
-
"# df_screening[\"bmi\"] = pd.NA\n",
|
|
846
|
-
"# df_screening.loc[df_screening[\"calculated_bmi_value\"] < 25.0, \"bmi\"] = \"bmi<25\"\n",
|
|
847
|
-
"# df_screening.loc[(df_screening[\"calculated_bmi_value\"]>=25.0) & (df_screening[\"calculated_bmi_value\"] < 30.0), \"bmi\"] = \"25<=bmi<30\"\n",
|
|
848
|
-
"# df_screening.loc[df_screening[\"calculated_bmi_value\"] > 30.0, \"bmi\"] = \"bmi>30\"\n",
|
|
849
|
-
"#\n",
|
|
850
|
-
"# category_labels = [ \"bmi<25\", \"25<=bmi<30\", \"bmi>=30\", \"Total (n)\"]\n",
|
|
851
|
-
"# df_table3 = get_table_df(df_screening, month_label=\"enrol\", get_row_func=get_row_by_df, category_labels=category_labels)\n",
|
|
852
|
-
"# df_table3 = format_table_with_bmi_df(df_table3, category_labels=category_labels)\n",
|
|
853
|
-
"# df_table3 = df_table3.fillna(0.0)\n",
|
|
854
|
-
"# gt = df_as_great_table(df_table3, title=\"Table 3b: OGTT/FBG by BMI at Screening / Enrolment\")\n",
|
|
855
|
-
"# column_headers_enrol = {\"bmi<25_str\":\"bmi<25\", \"25<=bmi<30_str\":\"25<=bmi<30\", \"bmi>30_str\":\"bmi>30\", \"total_str\": \"total\"}\n",
|
|
856
|
-
"# gt = (\n",
|
|
857
|
-
"# gt\n",
|
|
858
|
-
"# .cols_label(column_headers_enrol)\n",
|
|
859
|
-
"# .cols_align(align=\"center\", columns=[\"bmi<25_str\", \"25<=bmi<30_str\", \"bmi>30_str\", \"total_str\"])\n",
|
|
860
|
-
"# .cols_align(align=\"left\", columns=[\"label\"])\n",
|
|
861
|
-
"# .cols_width(cases={\"label\": \"35%\"})\n",
|
|
862
|
-
"# .tab_source_note(source_note=\"Excluding patients eventually withdrawn for `late exclusion` criteria\")\n",
|
|
863
|
-
"# )\n",
|
|
864
|
-
"# html_data.append(gt.as_raw_html())\n",
|
|
865
|
-
"# gt.show()\n",
|
|
866
|
-
"\n"
|
|
867
|
-
]
|
|
868
|
-
},
|
|
869
|
-
{
|
|
870
|
-
"cell_type": "code",
|
|
871
|
-
"execution_count": null,
|
|
872
|
-
"id": "19",
|
|
873
|
-
"metadata": {},
|
|
874
|
-
"outputs": [],
|
|
875
|
-
"source": [
|
|
876
|
-
"[col for col in df_screening.columns if \"bmi\" in col]"
|
|
877
|
-
]
|
|
878
|
-
},
|
|
879
|
-
{
|
|
880
|
-
"cell_type": "code",
|
|
881
|
-
"execution_count": null,
|
|
882
|
-
"id": "20",
|
|
883
|
-
"metadata": {},
|
|
884
|
-
"outputs": [],
|
|
885
|
-
"source": [
|
|
886
|
-
"# Table 4: OGTT and FBG at 12-month visit\n",
|
|
887
|
-
"df_table3 = get_table_df(df_glucose, visit_codes=[1120.0])\n",
|
|
888
|
-
"df_table3 = format_table_df(df_table3)\n",
|
|
889
|
-
"df_table3 = df_table3.fillna(0.0)\n",
|
|
890
|
-
"gt = df_as_great_table(df_table3, title=\"Table 4: OGTT and FBG at 12-month visit\")\n",
|
|
891
|
-
"gt = (\n",
|
|
892
|
-
" gt\n",
|
|
893
|
-
" .cols_label(column_headers_with_str)\n",
|
|
894
|
-
" .cols_align(align=\"center\", columns=[\"10_str\", \"20_str\", \"30_str\", \"40_str\", \"60_str\", \"total_str\"])\n",
|
|
895
|
-
" .cols_align(align=\"left\", columns=[\"label\"])\n",
|
|
896
|
-
" .cols_width(cases={\"label\": \"35%\"})\n",
|
|
897
|
-
")\n",
|
|
898
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
899
|
-
"gt.show()\n"
|
|
900
|
-
]
|
|
901
|
-
},
|
|
902
|
-
{
|
|
903
|
-
"cell_type": "code",
|
|
904
|
-
"execution_count": null,
|
|
905
|
-
"id": "21",
|
|
906
|
-
"metadata": {},
|
|
907
|
-
"outputs": [],
|
|
908
|
-
"source": [
|
|
909
|
-
"# Table 5: OGTT and FBG at 24-month visit\n",
|
|
910
|
-
"df_table4 = get_table_df(df_glucose, 1240.0)\n",
|
|
911
|
-
"df_table4 = format_table_df(df_table4)\n",
|
|
912
|
-
"df_table4 = df_table4.fillna(0.0)\n",
|
|
913
|
-
"gt = df_as_great_table(df_table4, title=\"Table 5: OGTT and FBG at 24-month visit\")\n",
|
|
914
|
-
"gt = (\n",
|
|
915
|
-
" gt\n",
|
|
916
|
-
" .cols_label(column_headers_with_str)\n",
|
|
917
|
-
" .cols_align(align=\"center\", columns=[\"10_str\", \"20_str\", \"30_str\", \"40_str\", \"60_str\", \"total_str\"])\n",
|
|
918
|
-
" .cols_align(align=\"left\", columns=[\"label\"])\n",
|
|
919
|
-
" .cols_width(cases={\"label\": \"35%\"})\n",
|
|
920
|
-
")\n",
|
|
921
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
922
|
-
"gt.show()"
|
|
923
|
-
]
|
|
924
|
-
},
|
|
925
|
-
{
|
|
926
|
-
"cell_type": "code",
|
|
927
|
-
"execution_count": null,
|
|
928
|
-
"id": "22",
|
|
929
|
-
"metadata": {},
|
|
930
|
-
"outputs": [],
|
|
931
|
-
"source": [
|
|
932
|
-
"# Table 6: OGTT and FBG at 36-month visit\n",
|
|
933
|
-
"df_table5 = get_table_df(df_glucose, 1360.0)\n",
|
|
934
|
-
"df_table5 = format_table_df(df_table5)\n",
|
|
935
|
-
"df_table5 = df_table5.fillna(0.0)\n",
|
|
936
|
-
"gt = df_as_great_table(df_table5, title=\"Table 6: OGTT and FBG at 36-month visit\")\n",
|
|
937
|
-
"gt = (\n",
|
|
938
|
-
" gt\n",
|
|
939
|
-
" .cols_label(column_headers_with_str)\n",
|
|
940
|
-
" .cols_align(align=\"center\", columns=[\"10_str\", \"20_str\", \"30_str\", \"40_str\", \"60_str\", \"total_str\"])\n",
|
|
941
|
-
" .cols_align(align=\"left\", columns=[\"label\"])\n",
|
|
942
|
-
" .cols_width(cases={\"label\": \"35%\"})\n",
|
|
943
|
-
")\n",
|
|
944
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
945
|
-
"gt.show()"
|
|
946
|
-
]
|
|
947
|
-
},
|
|
948
|
-
{
|
|
949
|
-
"cell_type": "code",
|
|
950
|
-
"execution_count": null,
|
|
951
|
-
"id": "23",
|
|
952
|
-
"metadata": {},
|
|
953
|
-
"outputs": [],
|
|
954
|
-
"source": [
|
|
955
|
-
"# Table 7: Any OGTT>11.1 ever\n",
|
|
956
|
-
"row_df = df_glucose[df_glucose.ogtt_value >= 11.1].copy()\n",
|
|
957
|
-
"table_df = get_row_df(row_df, \"Total (n)\")\n",
|
|
958
|
-
"df_table6 = format_table_df(table_df)\n",
|
|
959
|
-
"df_table = df_table6[:1].fillna(0.0).copy().reset_index(drop=True)\n",
|
|
960
|
-
"gt = df_as_great_table(df_table, title=\"Table 7: Any OGTT>11.1 ever\")\n",
|
|
961
|
-
"gt = (\n",
|
|
962
|
-
" gt\n",
|
|
963
|
-
" .cols_label(column_headers_with_str)\n",
|
|
964
|
-
" .cols_align(align=\"center\", columns=[\"10_str\", \"20_str\", \"30_str\", \"40_str\", \"60_str\", \"total_str\"])\n",
|
|
965
|
-
" .cols_align(align=\"left\", columns=[\"label\"])\n",
|
|
966
|
-
" .cols_width(cases={\"label\": \"35%\"})\n",
|
|
967
|
-
")\n",
|
|
968
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
969
|
-
"gt.show()"
|
|
970
|
-
]
|
|
971
|
-
},
|
|
972
|
-
{
|
|
973
|
-
"cell_type": "code",
|
|
974
|
-
"execution_count": null,
|
|
975
|
-
"id": "24",
|
|
976
|
-
"metadata": {},
|
|
977
|
-
"outputs": [],
|
|
978
|
-
"source": [
|
|
979
|
-
"# func for table 7\n",
|
|
980
|
-
"def get_table7_df(df_source: pd.DataFrame, visit_code: float) -> pd.DataFrame:\n",
|
|
981
|
-
" df_month = df_source[(df_source.visit_code >= visit_code) & (df_source.visit_code <= visit_code + 0.9)].copy()\n",
|
|
982
|
-
"\n",
|
|
983
|
-
" row_df = df_month.copy()\n",
|
|
984
|
-
" table_df = get_row_df(row_df, \"Total (n)\")\n",
|
|
985
|
-
"\n",
|
|
986
|
-
" row_df = df_month[(df_month.fbg_value < 6.1)].copy()\n",
|
|
987
|
-
" table_df = pd.concat([table_df, get_row_df(row_df, \"FBG <6.1\")])\n",
|
|
988
|
-
"\n",
|
|
989
|
-
" row_df = df_month[(df_month.fbg_value >= 6.1) & (df_month.fbg_value < 7.0)].copy()\n",
|
|
990
|
-
" table_df = pd.concat([table_df, get_row_df(row_df, \"FBG >=6.1 <7.0\")])\n",
|
|
991
|
-
"\n",
|
|
992
|
-
" row_df = df_month[(df_month.fbg_value >= 7.0)].copy()\n",
|
|
993
|
-
" table_df = pd.concat([table_df, get_row_df(row_df, \"FBG >=7.0\")])\n",
|
|
994
|
-
" return table_df"
|
|
995
|
-
]
|
|
996
|
-
},
|
|
997
|
-
{
|
|
998
|
-
"cell_type": "code",
|
|
999
|
-
"execution_count": null,
|
|
1000
|
-
"id": "25",
|
|
1001
|
-
"metadata": {},
|
|
1002
|
-
"outputs": [],
|
|
1003
|
-
"source": [
|
|
1004
|
-
"# Table 8: Interim FBG results\n",
|
|
1005
|
-
"df_table7 = get_table7_df(df_glucose, 1150.0)\n",
|
|
1006
|
-
"df_table7 = format_table_df(df_table7, add_totals=False)\n",
|
|
1007
|
-
"df_table7[\"visit_code\"] = MONTH15\n",
|
|
1008
|
-
"\n",
|
|
1009
|
-
"df_table71 = get_table7_df(df_glucose, 1180.0)\n",
|
|
1010
|
-
"df_table71 = format_table_df(df_table71, add_totals=False)\n",
|
|
1011
|
-
"df_table71[\"visit_code\"] = MONTH18\n",
|
|
1012
|
-
"\n",
|
|
1013
|
-
"df_table72 = get_table7_df(df_glucose, 1210.0)\n",
|
|
1014
|
-
"df_table72 = format_table_df(df_table72, add_totals=False)\n",
|
|
1015
|
-
"df_table72[\"visit_code\"] = MONTH21\n",
|
|
1016
|
-
"\n",
|
|
1017
|
-
"df_table73 = get_table7_df(df_glucose, 1270.0)\n",
|
|
1018
|
-
"df_table73 = format_table_df(df_table73, add_totals=False)\n",
|
|
1019
|
-
"df_table73[\"visit_code\"] = MONTH27\n",
|
|
1020
|
-
"\n",
|
|
1021
|
-
"df_table74 = get_table7_df(df_glucose, 1300.0)\n",
|
|
1022
|
-
"df_table74 = format_table_df(df_table74, add_totals=False)\n",
|
|
1023
|
-
"df_table74[\"visit_code\"] = MONTH30\n",
|
|
1024
|
-
"\n",
|
|
1025
|
-
"df_table75 = get_table7_df(df_glucose, 1330.0)\n",
|
|
1026
|
-
"df_table75 = format_table_df(df_table75, add_totals=False)\n",
|
|
1027
|
-
"df_table75[\"visit_code\"] = MONTH33\n",
|
|
1028
|
-
"\n",
|
|
1029
|
-
"df_table76 = get_table7_df(df_glucose, 1390.0)\n",
|
|
1030
|
-
"df_table76 = format_table_df(df_table76, add_totals=False)\n",
|
|
1031
|
-
"df_table76[\"visit_code\"] = MONTH39\n",
|
|
1032
|
-
"\n",
|
|
1033
|
-
"df_table = pd.concat([df_table7, df_table71, df_table72, df_table73, df_table74, df_table75, df_table76])\n",
|
|
1034
|
-
"df_table = df_table.reset_index(drop=True)\n",
|
|
1035
|
-
"df_table = df_table.fillna(0.0)"
|
|
1036
|
-
]
|
|
1037
|
-
},
|
|
1038
|
-
{
|
|
1039
|
-
"cell_type": "code",
|
|
1040
|
-
"execution_count": null,
|
|
1041
|
-
"id": "26",
|
|
1042
|
-
"metadata": {},
|
|
1043
|
-
"outputs": [],
|
|
1044
|
-
"source": [
|
|
1045
|
-
"column_headers_with_str = {\"visit_code\": \"Visit Code\", **column_headers_with_str}\n",
|
|
1046
|
-
"gt = df_as_great_table2(df_table, title=\"Table 8: Interim FBG results\")\n",
|
|
1047
|
-
"gt = (\n",
|
|
1048
|
-
" gt\n",
|
|
1049
|
-
" .cols_label(column_headers_with_str)\n",
|
|
1050
|
-
" .cols_move_to_start(columns=\"visit_code\")\n",
|
|
1051
|
-
" .cols_align(align=\"center\", columns=[\"10_str\", \"20_str\", \"30_str\", \"40_str\", \"60_str\", \"total_str\"])\n",
|
|
1052
|
-
" .cols_align(align=\"left\", columns=[\"visit_code\", \"label\"])\n",
|
|
1053
|
-
" .cols_width(cases={\"label\": \"15%\"})\n",
|
|
1054
|
-
" .tab_style(\n",
|
|
1055
|
-
" style=[\n",
|
|
1056
|
-
" style.text(color=\"black\", weight=\"bold\"),\n",
|
|
1057
|
-
" style.fill(color=\"lightgray\")\n",
|
|
1058
|
-
" ],\n",
|
|
1059
|
-
" locations=loc.row_groups()\n",
|
|
1060
|
-
" )\n",
|
|
1061
|
-
")\n",
|
|
1062
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
1063
|
-
"gt.show()"
|
|
1064
|
-
]
|
|
1065
|
-
},
|
|
1066
|
-
{
|
|
1067
|
-
"cell_type": "code",
|
|
1068
|
-
"execution_count": null,
|
|
1069
|
-
"id": "27",
|
|
1070
|
-
"metadata": {},
|
|
1071
|
-
"outputs": [],
|
|
1072
|
-
"source": [
|
|
1073
|
-
"# Table 9: Primary Endpoint met\n",
|
|
1074
|
-
"df_endpoint_grp = df_endpoint.groupby(by=[\"site_id\", \"endpoint_label\"]).size().to_frame().reset_index()\n",
|
|
1075
|
-
"df_endpoint_grp.columns = [\"site_id\", \"label\", \"endpoints\"]\n",
|
|
1076
|
-
"df_endpoint_pivot = df_endpoint_grp.pivot_table(index=\"label\", columns=\"site_id\", values=\"endpoints\").reset_index()\n",
|
|
1077
|
-
"df_endpoint_pivot.columns.name = \"\"\n",
|
|
1078
|
-
"df_endpoint_pivot.columns = ['label', \"10\", \"20\", \"30\", \"40\", \"60\"]\n",
|
|
1079
|
-
"df_endpoint_pivot.loc[len(df_endpoint_pivot)] = df_endpoint_pivot[['10', '20', '30', '40', '60']].sum().to_dict()\n",
|
|
1080
|
-
"df_endpoint_pivot.at[len(df_endpoint_pivot) - 1, 'label'] = 'Total'\n",
|
|
1081
|
-
"df_endpoint_pivot['total'] = df_endpoint_pivot[['10', '20', '30', '40', '60']].sum(axis=1)\n",
|
|
1082
|
-
"df_endpoint_pivot = df_endpoint_pivot.fillna(0.0)\n",
|
|
1083
|
-
"\n",
|
|
1084
|
-
"gt = df_as_great_table(\n",
|
|
1085
|
-
" df_endpoint_pivot,\n",
|
|
1086
|
-
" title=\"Table 9a: Primary Endpoint met\"\n",
|
|
1087
|
-
")\n",
|
|
1088
|
-
"gt = (\n",
|
|
1089
|
-
" gt\n",
|
|
1090
|
-
" .cols_label({k: v for k, v in column_headers.items() if k not in [\"visit_code\"]})\n",
|
|
1091
|
-
" .cols_align(align=\"center\", columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"])\n",
|
|
1092
|
-
" .cols_align(align=\"left\", columns=[\"label\"])\n",
|
|
1093
|
-
" .cols_width(cases={\"label\": \"25%\"})\n",
|
|
1094
|
-
")\n",
|
|
1095
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
1096
|
-
"gt.show()"
|
|
1097
|
-
]
|
|
1098
|
-
},
|
|
1099
|
-
{
|
|
1100
|
-
"cell_type": "code",
|
|
1101
|
-
"execution_count": null,
|
|
1102
|
-
"id": "28",
|
|
1103
|
-
"metadata": {},
|
|
1104
|
-
"outputs": [],
|
|
1105
|
-
"source": [
|
|
1106
|
-
"#read_frame(SubjectScheduleHistory.objects.filter(offschedule_model=\"meta_prn.offschedule\"), verbose=False).rename(columns={\"site\": \"site_id\"})"
|
|
1107
|
-
]
|
|
1108
|
-
},
|
|
1109
|
-
{
|
|
1110
|
-
"cell_type": "code",
|
|
1111
|
-
"execution_count": null,
|
|
1112
|
-
"id": "29",
|
|
1113
|
-
"metadata": {},
|
|
1114
|
-
"outputs": [],
|
|
1115
|
-
"source": [
|
|
1116
|
-
"from great_tables import html\n",
|
|
1117
|
-
"\n",
|
|
1118
|
-
"# Table 9b: Primary Endpoint no EOS or DM Referral\n",
|
|
1119
|
-
"df_subjecthistory = read_frame(\n",
|
|
1120
|
-
" SubjectScheduleHistory.objects.filter(offschedule_model=\"meta_prn.offschedule\", offschedule_datetime__isnull=False),\n",
|
|
1121
|
-
" verbose=False).rename(columns={\"site\": \"site_id\"})\n",
|
|
1122
|
-
"df_subjecthistory[\"site_id\"] = df_subjecthistory[\"site_id\"].astype(str)\n",
|
|
1123
|
-
"df_endpoint_no_off = df_endpoint.merge(df_subjecthistory[[\"subject_identifier\", \"offschedule_datetime\"]],\n",
|
|
1124
|
-
" on=[\"subject_identifier\"], how=\"left\")\n",
|
|
1125
|
-
"df_endpoint_grp = df_endpoint_no_off.query(\"offschedule_datetime.isna()\").groupby(\n",
|
|
1126
|
-
" by=[\"site_id\", \"endpoint_label\"]).size().to_frame().reset_index()\n",
|
|
1127
|
-
"df_endpoint_grp.columns = [\"site_id\", \"label\", \"endpoints\"]\n",
|
|
1128
|
-
"df_endpoint_pivot = df_endpoint_grp.pivot_table(index=\"label\", columns=\"site_id\", values=\"endpoints\").reset_index()\n",
|
|
1129
|
-
"df_endpoint_pivot.columns.name = \"\"\n",
|
|
1130
|
-
"df_endpoint_pivot.columns = ['label', *[str(col) for col in df_endpoint_pivot.columns if col != \"label\"]]\n",
|
|
1131
|
-
"for col in [c for c in ['label', \"10\", \"20\", \"30\", \"40\", \"60\"] if str(c) not in df_endpoint_pivot.columns]:\n",
|
|
1132
|
-
" df_endpoint_pivot[str(col)] = np.nan\n",
|
|
1133
|
-
"df_endpoint_pivot.columns = ['label', \"10\", \"20\", \"30\", \"40\", \"60\"]\n",
|
|
1134
|
-
"df_endpoint_pivot.loc[len(df_endpoint_pivot)] = df_endpoint_pivot[['10', '20', '30', '40', '60']].sum().to_dict()\n",
|
|
1135
|
-
"df_endpoint_pivot.at[len(df_endpoint_pivot) - 1, 'label'] = 'Total'\n",
|
|
1136
|
-
"df_endpoint_pivot['total'] = df_endpoint_pivot[['10', '20', '30', '40', '60']].sum(axis=1)\n",
|
|
1137
|
-
"df_endpoint_pivot = df_endpoint_pivot.fillna(0.0)\n",
|
|
1138
|
-
"subjects = df_endpoint_no_off.query(\"offschedule_datetime.isna()\").subject_identifier.to_list()\n",
|
|
1139
|
-
"\n",
|
|
1140
|
-
"gt = df_as_great_table(\n",
|
|
1141
|
-
" df_endpoint_pivot,\n",
|
|
1142
|
-
" title=\"Table 9b: Primary Endpoint met -- participant not referred\"\n",
|
|
1143
|
-
")\n",
|
|
1144
|
-
"gt = (\n",
|
|
1145
|
-
" gt\n",
|
|
1146
|
-
" .cols_label({k: v for k, v in column_headers.items() if k not in [\"visit_code\"]})\n",
|
|
1147
|
-
" .cols_align(align=\"center\", columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"])\n",
|
|
1148
|
-
" .cols_align(align=\"left\", columns=[\"label\"])\n",
|
|
1149
|
-
" .cols_width(cases={\"label\": \"25%\"})\n",
|
|
1150
|
-
" .tab_source_note(source_note=html(\"<BR>\".join(subjects)))\n",
|
|
1151
|
-
")\n",
|
|
1152
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
1153
|
-
"gt.show()"
|
|
1154
|
-
]
|
|
1155
|
-
},
|
|
1156
|
-
{
|
|
1157
|
-
"cell_type": "code",
|
|
1158
|
-
"execution_count": null,
|
|
1159
|
-
"id": "30",
|
|
1160
|
-
"metadata": {},
|
|
1161
|
-
"outputs": [],
|
|
1162
|
-
"source": []
|
|
1163
|
-
},
|
|
1164
|
-
{
|
|
1165
|
-
"cell_type": "code",
|
|
1166
|
-
"execution_count": null,
|
|
1167
|
-
"id": "31",
|
|
1168
|
-
"metadata": {},
|
|
1169
|
-
"outputs": [],
|
|
1170
|
-
"source": [
|
|
1171
|
-
"# Table 10: Incident Rate per 1000 person years\n",
|
|
1172
|
-
"\n",
|
|
1173
|
-
"def get_df_main(df_visit: pd.DataFrame, lower_days: float | None = None, upper_days: float | None = None):\n",
|
|
1174
|
-
" if not lower_days:\n",
|
|
1175
|
-
" lower_days = -1\n",
|
|
1176
|
-
" cutoff_datetime = df_visit.query(\"@lower_days<followup_days<=@upper_days\").visit_datetime.max()\n",
|
|
1177
|
-
" # exclude subjects for this reason\n",
|
|
1178
|
-
" offstudy_reasons = [\n",
|
|
1179
|
-
" 'Patient fulfilled late exclusion criteria (due to abnormal blood values or raised blood pressure at enrolment']\n",
|
|
1180
|
-
"\n",
|
|
1181
|
-
" df_eos = get_eos_df()\n",
|
|
1182
|
-
" df_eos_excluded = (\n",
|
|
1183
|
-
" df_eos\n",
|
|
1184
|
-
" .query(\"followup_days>@lower_days and followup_days<=@upper_days and offstudy_reason.isin(@offstudy_reasons)\")\n",
|
|
1185
|
-
" .copy()\n",
|
|
1186
|
-
" .reset_index()\n",
|
|
1187
|
-
" )\n",
|
|
1188
|
-
" df_visit_final = (\n",
|
|
1189
|
-
" df_visit.query(\"@lower_days<followup_days<=@upper_days and reason!='missed' and visit_code<2000.0\")\n",
|
|
1190
|
-
" .merge(df_eos_excluded[[\"subject_identifier\"]], on=\"subject_identifier\", how=\"left\", suffixes=(\"\", \"_y\"),\n",
|
|
1191
|
-
" indicator=True)\n",
|
|
1192
|
-
" .query(\"_merge=='left_only'\")\n",
|
|
1193
|
-
" .drop(columns=[\"_merge\"])\n",
|
|
1194
|
-
" )\n",
|
|
1195
|
-
" df_main = (\n",
|
|
1196
|
-
" df_visit_final\n",
|
|
1197
|
-
" .groupby(by=[\"subject_identifier\"])[[\"baseline_datetime\", \"visit_datetime\", \"followup_days\"]]\n",
|
|
1198
|
-
" .max()\n",
|
|
1199
|
-
" .reset_index()\n",
|
|
1200
|
-
" )\n",
|
|
1201
|
-
"\n",
|
|
1202
|
-
" df_main = (\n",
|
|
1203
|
-
" df_main\n",
|
|
1204
|
-
" .merge(\n",
|
|
1205
|
-
" df_endpoint.query(\"days_to_endpoint>@lower_days\")[\n",
|
|
1206
|
-
" [\"subject_identifier\", \"endpoint_label\", \"endpoint_type\", \"days_to_endpoint\"]],\n",
|
|
1207
|
-
" how=\"left\",\n",
|
|
1208
|
-
" on=[\"subject_identifier\"])\n",
|
|
1209
|
-
" .reset_index(drop=True)\n",
|
|
1210
|
-
" )\n",
|
|
1211
|
-
" if lower_days >= 365.25:\n",
|
|
1212
|
-
" df_main[\"followup_days\"] = df_main[\"followup_days\"] - lower_days\n",
|
|
1213
|
-
" df_main[\"followup_years\"] = df_main[\"followup_days\"] / 365.25\n",
|
|
1214
|
-
" return df_main, len(df_main), len(\n",
|
|
1215
|
-
" df_main.query(\"@lower_days<days_to_endpoint<=@upper_days and endpoint_label.notna()\"))\n",
|
|
1216
|
-
"\n",
|
|
1217
|
-
"\n",
|
|
1218
|
-
"def get_rate_and_ci(events, person_years_total):\n",
|
|
1219
|
-
" lower_ci = (chi2.ppf(0.025, 2 * events) / (2 * person_years_total)) * 1000\n",
|
|
1220
|
-
" upper_ci = (chi2.ppf(0.975, 2 * (events + 1)) / (2 * person_years_total)) * 1000\n",
|
|
1221
|
-
" return events / person_years_total * 1000, lower_ci, upper_ci\n",
|
|
1222
|
-
"\n",
|
|
1223
|
-
"\n",
|
|
1224
|
-
"def get_incidence_data(term: str, lower_days: float, upper_days: float):\n",
|
|
1225
|
-
" data = {}\n",
|
|
1226
|
-
" df_main, subjects, events = get_df_main(df_visit, lower_days=lower_days, upper_days=upper_days)\n",
|
|
1227
|
-
" person_years_total = df_main.followup_years.sum()\n",
|
|
1228
|
-
" data.update({term: [person_years_total, subjects, events, *get_rate_and_ci(events, person_years_total)]})\n",
|
|
1229
|
-
" return data"
|
|
1230
|
-
]
|
|
1231
|
-
},
|
|
1232
|
-
{
|
|
1233
|
-
"cell_type": "code",
|
|
1234
|
-
"execution_count": null,
|
|
1235
|
-
"id": "32",
|
|
1236
|
-
"metadata": {},
|
|
1237
|
-
"outputs": [],
|
|
1238
|
-
"source": [
|
|
1239
|
-
"incidence_data = {}\n",
|
|
1240
|
-
"incidence_data.update(get_incidence_data(\"total\", lower_days=-1, upper_days=10000))\n",
|
|
1241
|
-
"incidence_data.update(get_incidence_data(\"0-1 years\", lower_days=-1, upper_days=365.25))\n",
|
|
1242
|
-
"incidence_data.update(get_incidence_data(\"1-2 years\", lower_days=365.25, upper_days=2 * 365.25))\n",
|
|
1243
|
-
"incidence_data.update(get_incidence_data(\"2-3 years\", lower_days=2 * 365.25, upper_days=3 * 365.25))\n",
|
|
1244
|
-
"incidence_data.update(get_incidence_data(\"3+ years\", lower_days=3 * 365.25, upper_days=10 * 365.25))\n",
|
|
1245
|
-
"data = dict(label=[], person_years=[], subjects=[], failures=[], rate=[], lower_ci=[], upper_ci=[])\n",
|
|
1246
|
-
"for k in incidence_data:\n",
|
|
1247
|
-
" data[\"label\"].append(k)\n",
|
|
1248
|
-
"\n",
|
|
1249
|
-
"for v in incidence_data.values():\n",
|
|
1250
|
-
" data[\"person_years\"].append(v[0])\n",
|
|
1251
|
-
" data[\"subjects\"].append(v[1])\n",
|
|
1252
|
-
" data[\"failures\"].append(v[2])\n",
|
|
1253
|
-
" data[\"rate\"].append(v[3])\n",
|
|
1254
|
-
" data[\"lower_ci\"].append(v[4])\n",
|
|
1255
|
-
" data[\"upper_ci\"].append(v[5])\n",
|
|
1256
|
-
"\n",
|
|
1257
|
-
"df_table9 = pd.DataFrame(data={k: v for k, v in data.items() if k != \"subjects\"})"
|
|
1258
|
-
]
|
|
1259
|
-
},
|
|
1260
|
-
{
|
|
1261
|
-
"cell_type": "code",
|
|
1262
|
-
"execution_count": null,
|
|
1263
|
-
"id": "33",
|
|
1264
|
-
"metadata": {},
|
|
1265
|
-
"outputs": [],
|
|
1266
|
-
"source": [
|
|
1267
|
-
"gt = df_as_great_table(\n",
|
|
1268
|
-
" df_table9,\n",
|
|
1269
|
-
" title=\"Table 10: Incident Rate per 1000 person years\",\n",
|
|
1270
|
-
" subtitle=md(\"using randomisation to diabetes/last seen\"),\n",
|
|
1271
|
-
")\n",
|
|
1272
|
-
"gt = gt.fmt_number(columns=[\"person_years\", \"failures\", \"rate\", \"lower_ci\", \"upper_ci\"], decimals=2)\n",
|
|
1273
|
-
"gt = (gt\n",
|
|
1274
|
-
" .cols_label(\n",
|
|
1275
|
-
" {\"label\": \"Label\", \"person_years\": \"Person years\", \"failures\": \"Failures\", \"rate\": \"Rate\", \"lower_ci\": \"Lower\",\n",
|
|
1276
|
-
" \"upper_ci\": \"Upper\"})\n",
|
|
1277
|
-
" .cols_align(align=\"left\", columns=[\"label\"])\n",
|
|
1278
|
-
" .cols_align(align=\"center\", columns=[\"person_years\", \"failures\", \"rate\", \"lower_ci\", \"upper_ci\"])\n",
|
|
1279
|
-
" .tab_spanner(\n",
|
|
1280
|
-
" label=\"95%CI\",\n",
|
|
1281
|
-
" columns=[\"lower_ci\", \"upper_ci\"],\n",
|
|
1282
|
-
")\n",
|
|
1283
|
-
" .tab_source_note(source_note=\"Excluding patients withdrawn for `late exclusion` criteria\")\n",
|
|
1284
|
-
" )\n",
|
|
1285
|
-
"gt.show()\n",
|
|
1286
|
-
"html_data.append(gt.as_raw_html())"
|
|
1287
|
-
]
|
|
1288
|
-
},
|
|
1289
|
-
{
|
|
1290
|
-
"cell_type": "code",
|
|
1291
|
-
"execution_count": null,
|
|
1292
|
-
"id": "34",
|
|
1293
|
-
"metadata": {},
|
|
1294
|
-
"outputs": [],
|
|
1295
|
-
"source": [
|
|
1296
|
-
"# Table 11: Proportion meeting primary endpoint\n",
|
|
1297
|
-
"df_table10 = pd.DataFrame(data=data)\n",
|
|
1298
|
-
"df_table10[\"proportion\"] = df_table10[\"failures\"] / df_table10[\"subjects\"] * 100\n",
|
|
1299
|
-
"gt = df_as_great_table(\n",
|
|
1300
|
-
" df_table10[[\"label\", \"subjects\", 'failures', \"proportion\"]],\n",
|
|
1301
|
-
" title=\"Table 11: Proportion meeting primary endpoint\",\n",
|
|
1302
|
-
")\n",
|
|
1303
|
-
"gt = (\n",
|
|
1304
|
-
" gt\n",
|
|
1305
|
-
" .fmt_number(columns=[\"failures\", \"proportion\"], decimals=2)\n",
|
|
1306
|
-
" .cols_label({\"label\": \"Label\", \"subjects\": \"Participants\", \"failures\": \"Failures\", \"proportion\": \"%\"})\n",
|
|
1307
|
-
" .cols_align(align=\"left\", columns=[\"label\"])\n",
|
|
1308
|
-
" .cols_align(align=\"center\", columns=[\"subjects\", \"failures\", \"proportion\"])\n",
|
|
1309
|
-
" .tab_source_note(source_note=\"Excluding patients withdrawn for `late exclusion` criteria\")\n",
|
|
1310
|
-
")\n",
|
|
1311
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
1312
|
-
"gt.show()\n"
|
|
1313
|
-
]
|
|
1314
|
-
},
|
|
1315
|
-
{
|
|
1316
|
-
"cell_type": "code",
|
|
1317
|
-
"execution_count": null,
|
|
1318
|
-
"id": "35",
|
|
1319
|
-
"metadata": {},
|
|
1320
|
-
"outputs": [],
|
|
1321
|
-
"source": []
|
|
1322
|
-
},
|
|
1323
|
-
{
|
|
1324
|
-
"cell_type": "code",
|
|
1325
|
-
"execution_count": null,
|
|
1326
|
-
"id": "36",
|
|
1327
|
-
"metadata": {},
|
|
1328
|
-
"outputs": [],
|
|
1329
|
-
"source": [
|
|
1330
|
-
"# Table 11a: End of Study Table (for those who have completed an end of study form)\n",
|
|
1331
|
-
"df_eos = get_eos_df()\n",
|
|
1332
|
-
"offstudy_reasons = {\n",
|
|
1333
|
-
" \"Delivered / Completed followup from pregnancy\": \"Pregnancy\",\n",
|
|
1334
|
-
" \"Patient completed 36 months of follow-up\": \"Completed 36m\",\n",
|
|
1335
|
-
" \"Patient developed diabetes\": \"Developed diabetes\",\n",
|
|
1336
|
-
" \"Other reason (specify below)\": \"Other\",\n",
|
|
1337
|
-
" \"Patient fulfilled late exclusion criteria (due to abnormal blood values or raised blood pressure at enrolment\": \"Late exclusion\",\n",
|
|
1338
|
-
" \"Patient has been transferred to another health centre\": \"Transferred out\",\n",
|
|
1339
|
-
" \"Patient is withdrawn on CLINICAL grounds ...\": \"Withdrawal: Clinical grounds\",\n",
|
|
1340
|
-
" \"Patient lost to follow-up\": \"LTFU\",\n",
|
|
1341
|
-
" \"Patient reported/known to have died\": \"Died\",\n",
|
|
1342
|
-
" \"Patient withdrew consent to participate further\": \"Withdrawal: Consent\",\n",
|
|
1343
|
-
"}\n",
|
|
1344
|
-
"df_eos[\"offstudy_reason\"] = df_eos[\"offstudy_reason\"].map(offstudy_reasons)\n",
|
|
1345
|
-
"df_eos[\"offstudy_reason\"] = pd.Categorical(df_eos[\"offstudy_reason\"],\n",
|
|
1346
|
-
" categories=sorted(list(offstudy_reasons.values())), ordered=True)\n",
|
|
1347
|
-
"df_eos[\"site_id\"] = df_eos[\"site_id\"].astype(str)\n",
|
|
1348
|
-
"df_eos_pivot = (\n",
|
|
1349
|
-
" df_eos\n",
|
|
1350
|
-
" .groupby(by=[\"offstudy_reason\", \"site_id\"], observed=True)\n",
|
|
1351
|
-
" .size()\n",
|
|
1352
|
-
" .reset_index()\n",
|
|
1353
|
-
" .pivot_table(index=\"offstudy_reason\", columns=\"site_id\", values=0, observed=True)\n",
|
|
1354
|
-
" .fillna(0)\n",
|
|
1355
|
-
" .astype(int)\n",
|
|
1356
|
-
" .reset_index()\n",
|
|
1357
|
-
")\n",
|
|
1358
|
-
"df_eos_pivot[\"total\"] = df_eos_pivot[[\"10\", \"20\", \"30\", \"40\", \"60\"]].sum(axis=1)\n",
|
|
1359
|
-
"df_eos_pivot.columns.name = \"\"\n",
|
|
1360
|
-
"sum_row = df_eos_pivot.select_dtypes(include='int64').sum()\n",
|
|
1361
|
-
"sum_row['offstudy_reason'] = 'Total'\n",
|
|
1362
|
-
"sum_row_df = pd.DataFrame(sum_row).T\n",
|
|
1363
|
-
"enrolled_1691_pivot[\"offstudy_reason\"] = \"Enrolled\"\n",
|
|
1364
|
-
"enrolled_1691_pivot = enrolled_1691_pivot[[*df_eos_pivot.columns]]\n",
|
|
1365
|
-
"df_eos_pivot = pd.concat([enrolled_1691_pivot, df_eos_pivot, sum_row_df], ignore_index=True)\n",
|
|
1366
|
-
"\n",
|
|
1367
|
-
"gt = df_as_great_table(\n",
|
|
1368
|
-
" df_eos_pivot,\n",
|
|
1369
|
-
" title=\"Table 12a: End of study report\",\n",
|
|
1370
|
-
" subtitle=md(\"for those who have completed an End of study report\"),\n",
|
|
1371
|
-
")\n",
|
|
1372
|
-
"gt = (\n",
|
|
1373
|
-
" gt\n",
|
|
1374
|
-
" .cols_label(\n",
|
|
1375
|
-
" {\"offstudy_reason\": \"Reason\", **{k: v for k, v in column_headers.items() if k not in [\"visit_code\", \"label\"]}})\n",
|
|
1376
|
-
" .cols_align(align=\"left\", columns=[\"offstudy_reason\"])\n",
|
|
1377
|
-
" .cols_align(align=\"center\", columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"])\n",
|
|
1378
|
-
" .tab_style(\n",
|
|
1379
|
-
" style=[style.fill(color=\"snow\"), style.text(color=\"black\")],\n",
|
|
1380
|
-
" locations=loc.body(\n",
|
|
1381
|
-
" columns=[0],\n",
|
|
1382
|
-
" rows=[len(df_eos_pivot) - 1]),\n",
|
|
1383
|
-
" )\n",
|
|
1384
|
-
" .tab_style(\n",
|
|
1385
|
-
" style=[style.fill(color=\"lightblue\"), style.text(color=\"black\")],\n",
|
|
1386
|
-
" locations=loc.body(\n",
|
|
1387
|
-
" columns=[\"10\", \"20\", \"30\", \"40\", \"60\"],\n",
|
|
1388
|
-
" rows=[len(df_eos_pivot) - 1],\n",
|
|
1389
|
-
" ),\n",
|
|
1390
|
-
" )\n",
|
|
1391
|
-
" .tab_style(\n",
|
|
1392
|
-
" style=[style.fill(color=\"lightgreen\"), style.text(color=\"black\")],\n",
|
|
1393
|
-
" locations=loc.body(\n",
|
|
1394
|
-
" columns=[\"total\"],\n",
|
|
1395
|
-
" rows=[len(df_eos_pivot) - 1],\n",
|
|
1396
|
-
" ),\n",
|
|
1397
|
-
" )\n",
|
|
1398
|
-
" .tab_style(\n",
|
|
1399
|
-
" style=[style.fill(color=\"snow\"), style.text(color=\"black\")],\n",
|
|
1400
|
-
" locations=loc.body(\n",
|
|
1401
|
-
" columns=[\"offstudy_reason\"],\n",
|
|
1402
|
-
" rows=[0],\n",
|
|
1403
|
-
" ),\n",
|
|
1404
|
-
" )\n",
|
|
1405
|
-
")\n",
|
|
1406
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
1407
|
-
"gt.show()\n"
|
|
1408
|
-
]
|
|
1409
|
-
},
|
|
1410
|
-
{
|
|
1411
|
-
"cell_type": "code",
|
|
1412
|
-
"execution_count": null,
|
|
1413
|
-
"id": "37",
|
|
1414
|
-
"metadata": {},
|
|
1415
|
-
"outputs": [],
|
|
1416
|
-
"source": []
|
|
1417
|
-
},
|
|
1418
|
-
{
|
|
1419
|
-
"cell_type": "code",
|
|
1420
|
-
"execution_count": null,
|
|
1421
|
-
"id": "38",
|
|
1422
|
-
"metadata": {},
|
|
1423
|
-
"outputs": [],
|
|
1424
|
-
"source": [
|
|
1425
|
-
"# Table 12b: Study status\n",
|
|
1426
|
-
"def get_schedule_df(df_subjecthistory: pd.DataFrame, onschedule_model: str, offschedule_model: str,\n",
|
|
1427
|
-
" mode: str) -> pd.DataFrame:\n",
|
|
1428
|
-
" columns = {k: f\"{k}_{mode}\" for k in [\"10\", \"20\", \"30\", \"40\", \"60\"]}\n",
|
|
1429
|
-
" df_schedule = (\n",
|
|
1430
|
-
" df_subjecthistory\n",
|
|
1431
|
-
" .query(\n",
|
|
1432
|
-
" f\"onschedule_model==@onschedule_model and offschedule_model==@offschedule_model and offschedule_datetime.{'isna' if mode == 'on' else 'notna'}()\")\n",
|
|
1433
|
-
" .groupby(by=[\"onschedule_model\", \"site_id\"])\n",
|
|
1434
|
-
" .size()\n",
|
|
1435
|
-
" .reset_index()\n",
|
|
1436
|
-
" .pivot_table(index=\"onschedule_model\", columns=\"site_id\", values=0, observed=True)\n",
|
|
1437
|
-
" .reset_index()\n",
|
|
1438
|
-
" .rename(columns={\"onschedule_model\": \"schedule\", **columns})\n",
|
|
1439
|
-
" .fillna(0)\n",
|
|
1440
|
-
" .copy()\n",
|
|
1441
|
-
" )\n",
|
|
1442
|
-
" df_schedule.columns.name = \"\"\n",
|
|
1443
|
-
" return df_schedule\n",
|
|
1444
|
-
"\n",
|
|
1445
|
-
"\n",
|
|
1446
|
-
"df_subjecthistory = read_frame(SubjectScheduleHistory.objects.all(), verbose=False).rename(columns={\"site\": \"site_id\"})\n",
|
|
1447
|
-
"df_subjecthistory[\"site_id\"] = df_subjecthistory[\"site_id\"].astype(str)\n",
|
|
1448
|
-
"\n",
|
|
1449
|
-
"df_on = pd.concat([\n",
|
|
1450
|
-
" get_schedule_df(df_subjecthistory, 'meta_prn.onschedule', 'meta_prn.offschedule', \"on\"),\n",
|
|
1451
|
-
" get_schedule_df(df_subjecthistory, 'meta_prn.onscheduledmreferral', 'meta_prn.offscheduledmreferral', \"on\"),\n",
|
|
1452
|
-
" get_schedule_df(df_subjecthistory, 'meta_prn.onschedulepregnancy', 'meta_prn.offschedulepregnancy', \"on\"),\n",
|
|
1453
|
-
"])\n",
|
|
1454
|
-
"\n",
|
|
1455
|
-
"df_on = (\n",
|
|
1456
|
-
" df_on\n",
|
|
1457
|
-
" .fillna(0)\n",
|
|
1458
|
-
" .reset_index(drop=True)\n",
|
|
1459
|
-
")\n",
|
|
1460
|
-
"\n",
|
|
1461
|
-
"df_off = pd.concat([\n",
|
|
1462
|
-
" get_schedule_df(df_subjecthistory, 'meta_prn.onschedule', 'meta_prn.offschedule', \"off\"),\n",
|
|
1463
|
-
" get_schedule_df(df_subjecthistory, 'meta_prn.onscheduledmreferral', 'meta_prn.offscheduledmreferral', \"off\"),\n",
|
|
1464
|
-
" get_schedule_df(df_subjecthistory, 'meta_prn.onschedulepregnancy', 'meta_prn.offschedulepregnancy', \"off\"),\n",
|
|
1465
|
-
"])\n",
|
|
1466
|
-
"df_off = (\n",
|
|
1467
|
-
" df_off\n",
|
|
1468
|
-
" .fillna(0)\n",
|
|
1469
|
-
" .reset_index(drop=True)\n",
|
|
1470
|
-
")\n",
|
|
1471
|
-
"\n",
|
|
1472
|
-
"df_status = pd.merge(df_on, df_off, on=[\"schedule\"], how=\"outer\")\n",
|
|
1473
|
-
"columns = []\n",
|
|
1474
|
-
"for ele in [[f\"{x}_on\", f\"{x}_off\"] for x in [\"10\", \"20\", \"30\", \"40\", \"60\"]]:\n",
|
|
1475
|
-
" columns.extend(ele)\n",
|
|
1476
|
-
"df_status = df_status[[\"schedule\", *columns]]\n",
|
|
1477
|
-
"df_status[\"total_on\"] = df_status[[col for col in columns if \"on\" in col]].sum(axis=1)\n",
|
|
1478
|
-
"df_status[\"total_off\"] = df_status[[col for col in columns if \"off\" in col]].sum(axis=1)\n",
|
|
1479
|
-
"df_status[\"total\"] = df_status[columns].sum(axis=1)\n",
|
|
1480
|
-
"df_status[\"schedule\"] = df_status.schedule.map(\n",
|
|
1481
|
-
" {\"meta_prn.onschedule\": \"Main trial\", \"meta_prn.onscheduledmreferral\": \"Diabetes\",\n",
|
|
1482
|
-
" \"meta_prn.onschedulepregnancy\": \"Pregnancy\"})\n",
|
|
1483
|
-
"\n",
|
|
1484
|
-
"gt = df_as_great_table(\n",
|
|
1485
|
-
" df_status,\n",
|
|
1486
|
-
" title=\"Table 12b: Study status\",\n",
|
|
1487
|
-
" subtitle=md(\"Calculated from Offschedule form; not End of study report\"),\n",
|
|
1488
|
-
")\n",
|
|
1489
|
-
"# gt = gt.fmt_number(columns=[\"person_years\", \"failures\", \"rate\", \"lower_ci\", \"upper_ci\"], decimals=0)\n",
|
|
1490
|
-
"gt = (gt\n",
|
|
1491
|
-
" .tab_source_note(\n",
|
|
1492
|
-
" source_note=(\n",
|
|
1493
|
-
" \"Note: Offschedule form is always submitted before the End of study report. \"\n",
|
|
1494
|
-
" \"When the Offschedule form is submitted, future appointments for the schedule are removed and \"\n",
|
|
1495
|
-
" \"the site staff are actioned to submit the End of study report.\"\n",
|
|
1496
|
-
" )\n",
|
|
1497
|
-
")\n",
|
|
1498
|
-
" .cols_label({\n",
|
|
1499
|
-
" \"10_on\": \"On\", \"10_off\": \"Off\",\n",
|
|
1500
|
-
" \"20_on\": \"On\", \"20_off\": \"Off\",\n",
|
|
1501
|
-
" \"30_on\": \"On\", \"30_off\": \"Off\",\n",
|
|
1502
|
-
" \"40_on\": \"On\", \"40_off\": \"Off\",\n",
|
|
1503
|
-
" \"60_on\": \"On\", \"60_off\": \"Off\",\n",
|
|
1504
|
-
" \"total_on\": \"On\", \"total_off\": \"Off\",\n",
|
|
1505
|
-
" \"schedule\": \"Schedule\", \"total\": \"Total\"})\n",
|
|
1506
|
-
" .cols_align(align=\"center\")\n",
|
|
1507
|
-
" .cols_align(align=\"left\", columns=[\"label\"])\n",
|
|
1508
|
-
" .tab_spanner(\n",
|
|
1509
|
-
" label=\"Hindu mandal\",\n",
|
|
1510
|
-
" columns=[\"10_on\", \"10_off\"],\n",
|
|
1511
|
-
")\n",
|
|
1512
|
-
" .tab_spanner(\n",
|
|
1513
|
-
" label=\"Amana\",\n",
|
|
1514
|
-
" columns=[\"20_on\", \"20_off\"],\n",
|
|
1515
|
-
")\n",
|
|
1516
|
-
" .tab_spanner(\n",
|
|
1517
|
-
" label=\"Temeke\",\n",
|
|
1518
|
-
" columns=[\"30_on\", \"30_off\"],\n",
|
|
1519
|
-
")\n",
|
|
1520
|
-
" .tab_spanner(\n",
|
|
1521
|
-
" label=\"Mwananyamala\",\n",
|
|
1522
|
-
" columns=[\"40_on\", \"40_off\"],\n",
|
|
1523
|
-
")\n",
|
|
1524
|
-
" .tab_spanner(\n",
|
|
1525
|
-
" label=\"Mnazi Moja\",\n",
|
|
1526
|
-
" columns=[\"60_on\", \"60_off\"],\n",
|
|
1527
|
-
")\n",
|
|
1528
|
-
" .tab_spanner(\n",
|
|
1529
|
-
" label=\"Total\",\n",
|
|
1530
|
-
" columns=[\"total_on\", \"total_off\"],\n",
|
|
1531
|
-
")\n",
|
|
1532
|
-
" .tab_style(\n",
|
|
1533
|
-
" style=[style.fill(color=\"lightblue\"), style.text(color=\"black\")],\n",
|
|
1534
|
-
" locations=loc.body(\n",
|
|
1535
|
-
" columns=[\"10_off\", \"20_off\", \"30_off\", \"40_off\", \"60_off\"],\n",
|
|
1536
|
-
" rows=list(range(0, 1)),\n",
|
|
1537
|
-
" ),\n",
|
|
1538
|
-
")\n",
|
|
1539
|
-
" .tab_style(\n",
|
|
1540
|
-
" style=[style.fill(color=\"lightgreen\"), style.text(color=\"black\")],\n",
|
|
1541
|
-
" locations=loc.body(\n",
|
|
1542
|
-
" columns=[\"total_off\"],\n",
|
|
1543
|
-
" rows=list(range(0, 1)),\n",
|
|
1544
|
-
" ),\n",
|
|
1545
|
-
")\n",
|
|
1546
|
-
" .fmt_number(columns=[*[c for c in df_status.columns if c not in [\"schedule\"]]], decimals=0)\n",
|
|
1547
|
-
" )\n",
|
|
1548
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
1549
|
-
"gt.show()"
|
|
1550
|
-
]
|
|
1551
|
-
},
|
|
1552
|
-
{
|
|
1553
|
-
"cell_type": "code",
|
|
1554
|
-
"execution_count": null,
|
|
1555
|
-
"id": "39",
|
|
1556
|
-
"metadata": {},
|
|
1557
|
-
"outputs": [],
|
|
1558
|
-
"source": [
|
|
1559
|
-
"# off schedule no eos\n",
|
|
1560
|
-
"\n",
|
|
1561
|
-
"subjects_preg_dm = df_subjecthistory[~(df_subjecthistory.offschedule_datetime.isna()) & (\n",
|
|
1562
|
-
" df_subjecthistory.schedule_name != \"schedule\")].subject_identifier\n",
|
|
1563
|
-
"\n",
|
|
1564
|
-
"df_subjecthistory[\n",
|
|
1565
|
-
" ~(df_subjecthistory.subject_identifier.isin(df_eos_1691.subject_identifier))].sort_values(\n",
|
|
1566
|
-
" by=[\"subject_identifier\", \"onschedule_datetime\"])"
|
|
1567
|
-
]
|
|
1568
|
-
},
|
|
1569
|
-
{
|
|
1570
|
-
"cell_type": "code",
|
|
1571
|
-
"execution_count": null,
|
|
1572
|
-
"id": "40",
|
|
1573
|
-
"metadata": {},
|
|
1574
|
-
"outputs": [],
|
|
1575
|
-
"source": []
|
|
1576
|
-
},
|
|
1577
|
-
{
|
|
1578
|
-
"cell_type": "code",
|
|
1579
|
-
"execution_count": null,
|
|
1580
|
-
"id": "41",
|
|
1581
|
-
"metadata": {},
|
|
1582
|
-
"outputs": [],
|
|
1583
|
-
"source": [
|
|
1584
|
-
"# Table 13: Loss to Follow Up\n",
|
|
1585
|
-
"df_ltfu = read_frame(LossToFollowup.objects.all(), verbose=False).rename(columns={\"site\": \"site_id\"})\n",
|
|
1586
|
-
"df_ltfu_pivot = (\n",
|
|
1587
|
-
" df_ltfu\n",
|
|
1588
|
-
" .groupby(by=[\"loss_category\", \"site_id\"], observed=True, dropna=False)\n",
|
|
1589
|
-
" .size()\n",
|
|
1590
|
-
" .reset_index()\n",
|
|
1591
|
-
" .pivot_table(index=\"loss_category\", columns=\"site_id\", values=0, observed=True, dropna=False)\n",
|
|
1592
|
-
" .fillna(0)\n",
|
|
1593
|
-
" .astype(int)\n",
|
|
1594
|
-
" .reset_index()\n",
|
|
1595
|
-
")\n",
|
|
1596
|
-
"df_ltfu_pivot[\"total\"] = df_eos_pivot[[\"10\", \"20\", \"30\", \"40\", \"60\"]].sum(axis=1)\n",
|
|
1597
|
-
"df_ltfu_pivot.columns.name = \"\"\n",
|
|
1598
|
-
"sum_row = df_ltfu_pivot.select_dtypes(include='int64').sum()\n",
|
|
1599
|
-
"sum_row['loss_category'] = 'Total'\n",
|
|
1600
|
-
"sum_row_df = pd.DataFrame(sum_row).T\n",
|
|
1601
|
-
"df_ltfu_pivot = pd.concat([df_ltfu_pivot, sum_row_df], ignore_index=True)\n",
|
|
1602
|
-
"df_ltfu_pivot\n"
|
|
1603
|
-
]
|
|
1604
|
-
},
|
|
1605
|
-
{
|
|
1606
|
-
"cell_type": "code",
|
|
1607
|
-
"execution_count": null,
|
|
1608
|
-
"id": "42",
|
|
1609
|
-
"metadata": {},
|
|
1610
|
-
"outputs": [],
|
|
1611
|
-
"source": [
|
|
1612
|
-
"# Table 13c: End of study report not submitted\n",
|
|
1613
|
-
"\n",
|
|
1614
|
-
"df1 = (\n",
|
|
1615
|
-
" df_status\n",
|
|
1616
|
-
" .query(\"schedule=='Main trial'\")[[col for col in columns if \"off\" in col]]\n",
|
|
1617
|
-
" .rename(columns=dict(zip([col for col in columns if \"off\" in col], [\"10\", \"20\", \"30\", \"40\", \"60\"])))\n",
|
|
1618
|
-
" .reset_index(drop=True)\n",
|
|
1619
|
-
")\n",
|
|
1620
|
-
"df2 = (\n",
|
|
1621
|
-
" df_eos_pivot\n",
|
|
1622
|
-
" .query(\"offstudy_reason=='Total'\")[[\"10\", \"20\", \"30\", \"40\", \"60\"]]\n",
|
|
1623
|
-
" .reset_index(drop=True)\n",
|
|
1624
|
-
")\n",
|
|
1625
|
-
"\n",
|
|
1626
|
-
"df_eos_not_reported = df1 - df2\n",
|
|
1627
|
-
"df_eos_not_reported[\"schedule\"] = 'Main trial'\n",
|
|
1628
|
-
"df_eos_not_reported[\"total\"] = df_eos_not_reported[[\"10\", \"20\", \"30\", \"40\", \"60\"]].sum(axis=1)\n",
|
|
1629
|
-
"df_eos_not_reported = df_eos_not_reported[[\"schedule\", \"10\", \"20\", \"30\", \"40\", \"60\", \"total\"]]\n",
|
|
1630
|
-
"\n",
|
|
1631
|
-
"gt = df_as_great_table(\n",
|
|
1632
|
-
" df_eos_not_reported,\n",
|
|
1633
|
-
" title=\"Table 13c: End of study report not submitted\",\n",
|
|
1634
|
-
" subtitle=md(\"End of study report expected based on Offschedule form\"),\n",
|
|
1635
|
-
")\n",
|
|
1636
|
-
"gt = (\n",
|
|
1637
|
-
" gt\n",
|
|
1638
|
-
" .cols_label(\n",
|
|
1639
|
-
" {\"schedule\": \"Schedule\", **{k: v for k, v in column_headers.items() if k not in [\"visit_code\", \"label\"]}})\n",
|
|
1640
|
-
" .cols_align(align=\"left\", columns=[\"schedule\"])\n",
|
|
1641
|
-
" .cols_align(align=\"center\", columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"])\n",
|
|
1642
|
-
" .tab_style(\n",
|
|
1643
|
-
" style=[style.fill(color=\"snow\"), style.text(color=\"black\")],\n",
|
|
1644
|
-
" locations=loc.body(\n",
|
|
1645
|
-
" columns=[0],\n",
|
|
1646
|
-
" rows=[len(df_eos_pivot) - 1]),\n",
|
|
1647
|
-
" )\n",
|
|
1648
|
-
" .tab_style(\n",
|
|
1649
|
-
" style=[style.fill(color=\"lightblue\"), style.text(color=\"black\")],\n",
|
|
1650
|
-
" locations=loc.body(\n",
|
|
1651
|
-
" columns=[\"10\", \"20\", \"30\", \"40\", \"60\"],\n",
|
|
1652
|
-
" rows=[len(df_eos_pivot) - 1],\n",
|
|
1653
|
-
" ),\n",
|
|
1654
|
-
" )\n",
|
|
1655
|
-
" .tab_style(\n",
|
|
1656
|
-
" style=[style.fill(color=\"lightgreen\"), style.text(color=\"black\")],\n",
|
|
1657
|
-
" locations=loc.body(\n",
|
|
1658
|
-
" columns=[\"total\"],\n",
|
|
1659
|
-
" rows=[len(df_eos_pivot) - 1],\n",
|
|
1660
|
-
" ),\n",
|
|
1661
|
-
" )\n",
|
|
1662
|
-
")\n",
|
|
1663
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
1664
|
-
"gt.show()\n"
|
|
1665
|
-
]
|
|
1666
|
-
},
|
|
1667
|
-
{
|
|
1668
|
-
"cell_type": "code",
|
|
1669
|
-
"execution_count": null,
|
|
1670
|
-
"id": "43",
|
|
1671
|
-
"metadata": {},
|
|
1672
|
-
"outputs": [],
|
|
1673
|
-
"source": [
|
|
1674
|
-
"# Table 14: Baseline Sample"
|
|
1675
|
-
]
|
|
1676
|
-
},
|
|
1677
|
-
{
|
|
1678
|
-
"cell_type": "code",
|
|
1679
|
-
"execution_count": null,
|
|
1680
|
-
"id": "44",
|
|
1681
|
-
"metadata": {},
|
|
1682
|
-
"outputs": [],
|
|
1683
|
-
"source": [
|
|
1684
|
-
"# Table 15: Consented to extended followup\n",
|
|
1685
|
-
"df_consented = (\n",
|
|
1686
|
-
" read_frame(SubjectConsentV1Ext.objects.all(), verbose=False)\n",
|
|
1687
|
-
" .query(\"agrees_to_extension==@YES\")\n",
|
|
1688
|
-
" .rename(columns={\"site\": \"site_id\"})\n",
|
|
1689
|
-
")\n",
|
|
1690
|
-
"df_consented[\"site_id\"] = df_consented.site_id.astype(str)\n",
|
|
1691
|
-
"df_consented[\"month\"] = df_consented.report_datetime.dt.strftime(\"%m\")\n",
|
|
1692
|
-
"df_consented[\"year\"] = df_consented.report_datetime.dt.strftime(\"%Y\")\n",
|
|
1693
|
-
"df_consented_grp = (\n",
|
|
1694
|
-
" df_consented.groupby(by=[\"site_id\", \"year\", \"month\"]).\n",
|
|
1695
|
-
" size()\n",
|
|
1696
|
-
" .reset_index()\n",
|
|
1697
|
-
" .sort_values(by=[\"site_id\", \"year\", \"month\"], ascending=True)\n",
|
|
1698
|
-
" .reset_index(drop=True)\n",
|
|
1699
|
-
")\n",
|
|
1700
|
-
"df_consented_pivot = (\n",
|
|
1701
|
-
" df_consented_grp\n",
|
|
1702
|
-
" .pivot_table(index=[\"year\", \"month\"], columns=\"site_id\", values=0, aggfunc=\"sum\")\n",
|
|
1703
|
-
" .reset_index()\n",
|
|
1704
|
-
" .fillna(0)\n",
|
|
1705
|
-
")\n",
|
|
1706
|
-
"if \"60\" not in df_consented_pivot.columns:\n",
|
|
1707
|
-
" df_consented_pivot[\"60\"] = 0.0 * len(df_consented_pivot)\n",
|
|
1708
|
-
"df_consented_pivot.columns.name = \"\"\n",
|
|
1709
|
-
"df_consented_pivot[\"year\"] = df_consented_pivot[\"year\"].astype(str)\n",
|
|
1710
|
-
"df_consented_pivot[\"month\"] = df_consented_pivot[\"month\"].astype(str)\n",
|
|
1711
|
-
"\n",
|
|
1712
|
-
"sum_row = df_consented_pivot[[\"10\", \"20\", \"30\", \"40\", \"60\"]].sum()\n",
|
|
1713
|
-
"sum_row['year'] = \"Total\"\n",
|
|
1714
|
-
"sum_row['month'] = \"\"\n",
|
|
1715
|
-
"df_consented_pivot = pd.concat([df_consented_pivot, sum_row.to_frame().T], ignore_index=True)\n",
|
|
1716
|
-
"df_consented_pivot[\"total\"] = df_consented_pivot[[\"10\", \"20\", \"30\", \"40\", \"60\"]].sum(axis=1).astype(int)\n",
|
|
1717
|
-
"df_consented_pivot[[\"10\", \"20\", \"30\", \"40\", \"60\"]] = df_consented_pivot[[\"10\", \"20\", \"30\", \"40\", \"60\"]].astype(int)\n",
|
|
1718
|
-
"gt = df_as_great_table2(\n",
|
|
1719
|
-
" df_consented_pivot,\n",
|
|
1720
|
-
" title=\"Table 15: Consented to extended followup\",\n",
|
|
1721
|
-
" rowname_col=\"month\",\n",
|
|
1722
|
-
" groupname_col=\"year\",\n",
|
|
1723
|
-
")\n",
|
|
1724
|
-
"gt = (\n",
|
|
1725
|
-
" gt\n",
|
|
1726
|
-
" .cols_label({\"year\": \"Year\", \"month\": \"Month\",\n",
|
|
1727
|
-
" **{k: v for k, v in column_headers.items() if k not in [\"visit_code\", \"label\"]}})\n",
|
|
1728
|
-
" .cols_align(align=\"center\")\n",
|
|
1729
|
-
" .fmt_number(columns=[\"10\", \"20\", \"30\", \"40\", \"60\", \"total\"], decimals=0)\n",
|
|
1730
|
-
" .tab_stubhead(label=\"Consented\")\n",
|
|
1731
|
-
" .tab_style(\n",
|
|
1732
|
-
" style=[\n",
|
|
1733
|
-
" style.text(color=\"black\", weight=\"bold\"),\n",
|
|
1734
|
-
" style.fill(color=\"lightgray\")\n",
|
|
1735
|
-
" ],\n",
|
|
1736
|
-
" locations=loc.row_groups()\n",
|
|
1737
|
-
" )\n",
|
|
1738
|
-
")\n",
|
|
1739
|
-
"html_data.append(gt.as_raw_html())\n",
|
|
1740
|
-
"gt.show()"
|
|
1741
|
-
]
|
|
1742
|
-
},
|
|
1743
|
-
{
|
|
1744
|
-
"cell_type": "code",
|
|
1745
|
-
"execution_count": null,
|
|
1746
|
-
"id": "45",
|
|
1747
|
-
"metadata": {},
|
|
1748
|
-
"outputs": [],
|
|
1749
|
-
"source": []
|
|
1750
|
-
},
|
|
1751
|
-
{
|
|
1752
|
-
"cell_type": "code",
|
|
1753
|
-
"execution_count": null,
|
|
1754
|
-
"id": "46",
|
|
1755
|
-
"metadata": {},
|
|
1756
|
-
"outputs": [],
|
|
1757
|
-
"source": [
|
|
1758
|
-
"# gather raw html\n",
|
|
1759
|
-
"raw_html = [f'<div class=\"page-break\">{s}</div>' for s in html_data]\n",
|
|
1760
|
-
"style_css = \"\"\"\n",
|
|
1761
|
-
"<style>\n",
|
|
1762
|
-
" .page-break {\n",
|
|
1763
|
-
" page-break-inside: avoid; /* Always add page break before this element */\n",
|
|
1764
|
-
" }\n",
|
|
1765
|
-
" .table-header {\n",
|
|
1766
|
-
" font-weight: bold;\n",
|
|
1767
|
-
" font-size: 18px;\n",
|
|
1768
|
-
" text-align: center;\n",
|
|
1769
|
-
" border-bottom: None;\n",
|
|
1770
|
-
" }\n",
|
|
1771
|
-
"</style>\n",
|
|
1772
|
-
"\"\"\"\n",
|
|
1773
|
-
"raw_html = ''.join(raw_html)\n",
|
|
1774
|
-
"raw_html = f'<!DOCTYPE html>\\n<html lang=\"en\">\\n{style_css}\\n<head>\\n<meta charset=\"utf-8\"/>\\n</head>\\n<body>\\n' + document_title + raw_html + '\\n</body>\\n</html>\\n'"
|
|
1775
|
-
]
|
|
1776
|
-
},
|
|
1777
|
-
{
|
|
1778
|
-
"cell_type": "code",
|
|
1779
|
-
"execution_count": null,
|
|
1780
|
-
"id": "47",
|
|
1781
|
-
"metadata": {},
|
|
1782
|
-
"outputs": [],
|
|
1783
|
-
"source": [
|
|
1784
|
-
"# render html to PDF\n",
|
|
1785
|
-
"pdfkit.from_string(raw_html, str(analysis_folder / pdf_filename),\n",
|
|
1786
|
-
" options={\n",
|
|
1787
|
-
" 'footer-center': 'Page [page] of [topage]',\n",
|
|
1788
|
-
" 'footer-font-size': '8',\n",
|
|
1789
|
-
" 'footer-spacing': '5',\n",
|
|
1790
|
-
" 'encoding': \"UTF-8\",\n",
|
|
1791
|
-
" 'margin-top': '10mm',\n",
|
|
1792
|
-
" 'margin-right': '15mm',\n",
|
|
1793
|
-
" 'margin-bottom': '15mm',\n",
|
|
1794
|
-
" 'margin-left': '15mm',\n",
|
|
1795
|
-
" 'header-center': study_title,\n",
|
|
1796
|
-
" 'header-font-size': '6',\n",
|
|
1797
|
-
" 'header-spacing': '0',\n",
|
|
1798
|
-
" 'disable-javascript': None,\n",
|
|
1799
|
-
" 'no-outline': None,\n",
|
|
1800
|
-
" },\n",
|
|
1801
|
-
" verbose=True)"
|
|
1802
|
-
]
|
|
1803
|
-
},
|
|
1804
|
-
{
|
|
1805
|
-
"cell_type": "code",
|
|
1806
|
-
"execution_count": null,
|
|
1807
|
-
"id": "48",
|
|
1808
|
-
"metadata": {},
|
|
1809
|
-
"outputs": [],
|
|
1810
|
-
"source": []
|
|
1811
|
-
}
|
|
1812
|
-
],
|
|
1813
|
-
"metadata": {
|
|
1814
|
-
"kernelspec": {
|
|
1815
|
-
"display_name": "Python 3 (ipykernel)",
|
|
1816
|
-
"language": "python",
|
|
1817
|
-
"name": "python3"
|
|
1818
|
-
},
|
|
1819
|
-
"language_info": {
|
|
1820
|
-
"codemirror_mode": {
|
|
1821
|
-
"name": "ipython",
|
|
1822
|
-
"version": 3
|
|
1823
|
-
},
|
|
1824
|
-
"file_extension": ".py",
|
|
1825
|
-
"mimetype": "text/x-python",
|
|
1826
|
-
"name": "python",
|
|
1827
|
-
"nbconvert_exporter": "python",
|
|
1828
|
-
"pygments_lexer": "ipython3",
|
|
1829
|
-
"version": "3.12.4"
|
|
1830
|
-
}
|
|
1831
|
-
},
|
|
1832
|
-
"nbformat": 4,
|
|
1833
|
-
"nbformat_minor": 5
|
|
1834
|
-
}
|