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
5 changes: 5 additions & 0 deletions bin/dm_redcap_scan_completed.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ def parse_id(subject_id):
# KCNI site and study fields match the datman fields.
return ident

# Avoid modifying the ID if the study happens to match the destination
# study, otherwise duplicate records may be made
if 'Study' in id_map and ident.study in id_map['Study'].values():
return ident

return datman.scanid.parse(subject_id, settings=id_map)


Expand Down
39 changes: 39 additions & 0 deletions tests/test_dm_redcap_scan_completed.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,45 @@ def test_bad_id_raises_parse_exception(self, config):
with pytest.raises(ParseException):
rc.parse_id(bad_id)

def test_sites_dont_get_modified_if_study_field_unchanged(self, config):
def mock_get_key(key):
if key != 'IdMap':
raise datman.config.UndefinedSetting
settings = {
'Study': {
'SPN31': 'SPN30'
},
'Site': {
'CMH': 'CMP'
}
}
return settings
config.get_key.side_effect = mock_get_key
rc.cfg = config

parsed = rc.parse_id('SPN30_CMH_0001_01_SE01_MR')
assert str(parsed) == 'SPN30_CMH_0001_01_01'

def test_sites_do_get_modified_when_study_code_is_not_matched(self, config):
def mock_get_key(key):
if key != 'IdMap':
raise datman.config.UndefinedSetting
settings = {
'Study': {
'XYZ02': 'ABC01'
},
'Site': {
'CMH': 'CMP'
}
}
return settings
config.get_key.side_effect = mock_get_key
rc.cfg = config

parsed = rc.parse_id('XYZ03_CMH_0001_01_SE01_MR')

assert str(parsed) == 'XYZ03_CMP_0001_01_01'

@pytest.fixture
def config(self):
conf = Mock(spec=datman.config.config)
Expand Down