Package: edc-pdutils
edc-pdutilsUse pandas with the EdcUsing the management command to export to CSV and STATATheexport_modelsmanagement command requires you to log in with an account that has export permissions.The basic command requires an app_label (-a) and a path to the export folder (-p)By default, the export format is CSV but delimited using the pipe delimiter,|.Export one or more modulespythonmanage.pyexport_models-aambition_subject-p/ambition/exportThe-aexcepts more than one app_labelpythonmanage.pyexport_models-aambition_subject,ambition_prn,ambition_ae-p/ambition/exportExport data in CSV format or STATA formatTo export as CSV where the delimiter is|pythonmanage.pyexport_models-aambition_subject-p/ambition/exportTo export as STATAdtause option-fstatapythonmanage.pyexport_models-aambition_subject-p/ambition/export-fstataExport encrypted dataTo export encrypted fields include option--decrypt:pythonmanage.pyexport_models-aambition_subject-p/ambition/export--decryptNote:If using the--decryptoption, the user account will needPII_EXPORTpermissionsExport with a simple file nameTo export using a simpler filename that drops the tablename app_label prefix and does not include a datestamp suffix.Add option--use_simple_filename.pythonmanage.pyexport_models-aambition_subject-p/ambition/export--use_simple_filenameExport for a country onlyAdd option--country.pythonmanage.pyexport_models-aambition_subject-p/ambition/export--country="uganda"Export manuallyTo export Crf data, for example:fromedc_pdutils.df_exportersimportCsvCrfTablesExporterfromedc_pdutils.df_handlersimportCrfDfHandlerapp_label='ambition_subject'csv_path='/Users/erikvw/Documents/ambition/export/'date_format='%Y-%m-%d'sep='|'exclude_history_tables=TrueclassMyDfHandler(CrfDfHandler):visit_tbl=f'{app_label}_subjectvisit'exclude_columns=['form_as_json','survival_status','last_alive_date','screening_age_in_years','registration_datetime','subject_type']classMyCsvCrfTablesExporter(CsvCrfTablesExporter):visit_column='subject_visit_id'datetime_fields=['randomization_datetime']df_handler_cls=MyDfHandlerapp_label=app_labelexport_folder=csv_pathsys.stdout.write('\n')exporter=MyCsvCrfTablesExporter(export_folder=csv_path,exclude_history_tables=exclude_history_tables)exporter.to_csv(date_format=date_format,delimiter=sep)To export INLINE data for any CRF configured with an inline, for example:classMyDfHandler(CrfDfHandler):visit_tbl='ambition_subject_subjectvisit'exclude_columns=['form_as_json','survival_status','last_alive_date','screening_age_in_years','registration_datetime','subject_type']classMyCsvCrfInlineTablesExporter(CsvCrfInlineTablesExporter):visit_columns=['subject_visit_id']df_handler_cls=MyDfHandlerapp_label='ambition_subject'export_folder=csv_pathexclude_inline_tables=['ambition_subject_radiology_abnormal_results_reason','ambition_subject_radiology_cxr_type']sys.stdout.write('\n')exporter=MyCsvCrfInlineTablesExporter()exporter.to_csv(date_format=date_format,delimiter=sep)Usingmodel_to_dataframefromedc_pdutils.model_to_dataframeimportModelToDataframefromedc_pdutils.utilsimportget_model_namesfromedc_pdutils.df_exporters.csv_exporterimportCsvExporterapp_label='ambition_subject'csv_path='/Users/erikvw/Documents/ambition/export/'date_format='%Y-%m-%d'sep='|'formodel_nameinget_model_names(app_label=app_label,# with_columns=with_columns,# without_columns=without_columns,):m=ModelToDataframe(model=model_name)exporter=CsvExporter(data_label=model_name,date_format=date_format,delimiter=sep,export_folder=csv_path,)exported=exporter.to_csv(dataframe=m.dataframe)SettingsEXPORT_FILENAME_TIMESTAMP_FORMAT: True/False (Default: False)By default a timestamp of the current date is added as a suffix to CSV export filenames.By default a timestamp of format%Y%m%d%H%M%Sis added.EXPORT_FILENAME_TIMESTAMP_FORMATmay be set to an empty string or a valid format forstrftime.IfEXPORT_FILENAME_TIMESTAMP_FORMATis set to an empty string, “”, a suffix is not added.For example:# defaultregistered_subject_20190203112555.csv# EXPORT_FILENAME_TIMESTAMP_FORMAT = "%Y%m%d"registered_subject_20190203.csv# EXPORT_FILENAME_TIMESTAMP_FORMAT = ""registered_subject.csv