Skip to content

Commit

Permalink
Merge branch 'release/0.2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Dec 7, 2018
2 parents 9ea4ee2 + ebef1c7 commit f6249c4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.18
0.2.19
18 changes: 13 additions & 5 deletions edc_registration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def natural_key(self):
return (self.subject_identifier_as_pk, )

def __str__(self):
return self.mask_subject_identifier()
return self.masked_subject_identifier
natural_key.dependencies = ['sites.Site']

def update_subject_identifier_on_save(self):
Expand All @@ -191,12 +191,20 @@ def update_subject_identifier_on_save(self):
def make_new_identifier(self):
return self.subject_identifier_as_pk.hex

def mask_subject_identifier(self):
if not self.subject_identifier_is_set():
@property
def masked_subject_identifier(self):
"""Returns the subject identifier, if set, otherwise
the string '<identifier not set>'.
"""
if not self.subject_identifier_is_set:
return '<identifier not set>'
return self.subject_identifier

@property
def subject_identifier_is_set(self):
"""Returns True if subject identifier has been set to a
subject identifier; that is, no longer the default UUID.
"""
obj = self.__class__.objects.get(pk=self.id)
if re.match(UUID_PATTERN, obj.subject_identifier):
return False
Expand All @@ -207,7 +215,7 @@ def raise_on_changed_subject_identifier(self):
the subject identifier for an existing instance if the subject
identifier is already set.
"""
if self.id and self.subject_identifier_is_set():
if self.id and self.subject_identifier_is_set:
with transaction.atomic():
obj = self.__class__.objects.get(pk=self.id)
if obj.subject_identifier != self.subject_identifier_as_pk.hex:
Expand All @@ -233,7 +241,7 @@ def raise_on_duplicate(self, attrname):
if not self.id:
raise RegisteredSubjectError(
error_msg.format(action='insert'))
elif self.subject_identifier_is_set() and obj.id != self.id:
elif self.subject_identifier_is_set and obj.id != self.id:
raise RegisteredSubjectError(
error_msg.format(action='update'))
else:
Expand Down
2 changes: 1 addition & 1 deletion edc_registration/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_subject_identifier_as_uuid(self):
screening_identifier='12345')
rs = RegisteredSubject.objects.get(
registration_identifier=obj.to_string(obj.registration_identifier))
self.assertFalse(rs.subject_identifier_is_set())
self.assertFalse(rs.subject_identifier_is_set)

def test_masks_if_not_set(self):
obj = SubjectModelOne.objects.create(
Expand Down

0 comments on commit f6249c4

Please sign in to comment.