diff --git a/redcap/project.py b/redcap/project.py index 96d460f..9f96db6 100755 --- a/redcap/project.py +++ b/redcap/project.py @@ -192,6 +192,46 @@ def export_fem(self, arms=None, format='json', df_kwargs=None): return self.read_csv(StringIO(response), **df_kwargs) + def export_field_names(self, field=None, format='json', df_kwargs=None): + """ + Export the project's export field names + + Parameters + ---------- + fields : str + Limit exported field name to this field (only single field supported). + When not provided, all fields returned. + format : (``'json'``), ``'csv'``, ``'xml'``, ``'df'`` + Return the metadata in native objects, csv or xml. + ``'df'`` will return a ``pandas.DataFrame``. + df_kwargs : dict + Passed to ``pandas.read_csv`` to control construction of + returned DataFrame. + by default ``{'index_col': 'original_field_name'}`` + + Returns + ------- + metadata : list, str, ``pandas.DataFrame`` + metadata structure for the project. + """ + ret_format = format + if format == 'df': + ret_format = 'csv' + + pl = self.__basepl('exportFieldNames', format=ret_format) + + if field: + pl['field'] = field + + response, _ = self._call_api(pl, 'exp_field_names') + + if format in ('json', 'csv', 'xml'): + return response + elif format == 'df': + if not df_kwargs: + df_kwargs = {'index_col': 'original_field_name'} + return self.read_csv(StringIO(response), **df_kwargs) + def export_metadata(self, fields=None, forms=None, format='json', df_kwargs=None): """ diff --git a/redcap/request.py b/redcap/request.py index bf6cce4..f5e9714 100644 --- a/redcap/request.py +++ b/redcap/request.py @@ -69,6 +69,8 @@ def validate(self): valid_data = { 'exp_record': (['type', 'format'], 'record', 'Exporting record but content is not record'), + 'exp_field_names': (['format'], 'exportFieldNames', + 'Exporting field names, but content is not exportFieldNames'), 'del_record': (['format'], 'record', 'Deleting record but content is not record'), 'imp_record': (['type', 'overwriteBehavior', 'data', 'format'],