Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build/
docs/_build/
_site/
.idea/
*.swp
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
HISTORY
-------

1.0.1 (2016-10-05)
+++++++++++++++++

* Add a ``Project`` method to export the survey participant list.
* Update author email.

1.0 (2014-05-16)
++++++++++++++++

Expand Down
4 changes: 2 additions & 2 deletions fabfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'Scott Burns <scott.s.burns@vanderbilt.edu>'
__author__ = 'Scott Burns <scott.s.burns@gmail.com>'
__license__ = 'MIT'
__copyright__ = '2014, Vanderbilt University'

Expand Down Expand Up @@ -30,7 +30,7 @@ def clean():


def test():
local('nosetests -v -w test/')
local('nosetests -sv -w test/')

def doc():
with lcd('docs'):
Expand Down
2 changes: 1 addition & 1 deletion redcap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'Scott Burns <scott.s.burns@vanderbilt.edu>'
__author__ = 'Scott Burns <scott.s.burns@gmail.com>'
__license__ = 'MIT'
__copyright__ = '2014, Vanderbilt University'

Expand Down
26 changes: 24 additions & 2 deletions redcap/project.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'Scott Burns <scott.s.burns@vanderbilt.edu>'
__author__ = 'Scott Burns <scott.s.burnsgmail.com>'
__license__ = 'MIT'
__copyright__ = '2014, Vanderbilt University'

Expand Down Expand Up @@ -74,7 +74,7 @@ def configure(self):
events = tuple([])
else:
events = ev_data

if isinstance(arm_data, dict) and ('error' in arm_data.keys()):
arm_nums = tuple([])
arm_names = tuple([])
Expand Down Expand Up @@ -656,3 +656,25 @@ def export_users(self, format='json'):
"""
pl = self.__basepl(content='user', format=format)
return self._call_api(pl, 'exp_user')[0]

def export_survey_participant_list(self, instrument, event=None, format='json'):
""" Export the Survey Participant List

Notes
----
The passed instrument must be set up as a survey instrument.

Parameters
---------
instrument: str
Name of instrument as seen in second column of Data Dictionary.
event: str
Unique event name, only used in longitudinal projects
format: (json, xml, csv), json by default
Format of returned data
"""
pl = self.__basepl(content='participantList', format=format)
pl['instrument'] = instrumenet
if event:
pl['event'] = event
return self._call_api(pl, 'exp_survey_participant_list')
8 changes: 5 additions & 3 deletions redcap/request.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'Scott Burns <scott.s.burns@vanderbilt.edu>'
__author__ = 'Scott Burns <scott.s.burns@gmail.com>'
__license__ = 'MIT'
__copyright__ = '2014, Vanderbilt University'

Expand Down Expand Up @@ -85,7 +85,9 @@ def validate(self):
'Exporting form-event mappings but content != formEventMapping'),
'exp_user': (['format'], 'user',
'Exporting users but content is not user'),
'version': (['format'], 'version',
'exp_survey_participant_list': (['instrument'], 'participantList',
'Exporting Survey Participant List but content != participantList'),
'version': (['format'], 'version',
'Requesting version but content != version')
}
extra, req_content, err_msg = valid_data[self.type]
Expand All @@ -94,7 +96,7 @@ def validate(self):
pl_keys = set(self.payload.keys())
# if req is not subset of payload keys, this call is wrong
if not set(required) <= pl_keys:
#what is not in pl_keys?
# what is not in pl_keys?
not_pre = required - pl_keys
raise RCAPIError("Required keys: %s" % ', '.join(not_pre))
# Check content, raise with err_msg if not good
Expand Down
4 changes: 2 additions & 2 deletions redcap/version.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'Scott Burns <scott.s.burns@vanderbilt.edu>'
__author__ = 'Scott Burns <scott.s.burns@gmail.com>'
__license__ = 'MIT'
__copyright__ = '2014, Vanderbilt University'

VERSION = '1.0'
VERSION = '1.0.1'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'Scott Burns <scott.s.burns@vanderbilt.edu>'
__author__ = 'Scott Burns <scott.s.burns@gmail.com>'
__license__ = 'MIT'
__copyright__ = '2014, Vanderbilt University'

Expand Down
17 changes: 17 additions & 0 deletions test/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,20 @@ def test_bad_md(self):
r = RCRequest(*args).execute()
self.assertTrue(r is not None)
self.assertTrue(len(r) > 0)

def test_survey_participant_list_type(self):
payload = {
'token': 'foobar',
'content': 'participantList',
'format': 'json',
'instrument': 'bar',
}
url = 'https://foobarbat.com'
typee = 'exp_survey_participant_list'
# This should not raise
RCRequest(url, payload, typee)

# This should raise because of a different content
payload['content'] = 'foobar'
with self.assertRaises(RCAPIError):
RCRequest(url, payload, typee)