Skip to content

Commit

Permalink
research_protocol_config
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 26, 2024
1 parent 7fea412 commit a56dbbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions edc_identifier/research_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, Optional

from django.apps import apps as django_apps
from edc_protocol import Protocol
from edc_protocol.research_protocol_config import ResearchProtocolConfig

from .checkdigit_mixins import LuhnMixin
from .exceptions import IdentifierError
Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(
self.template = template or self.template
app_config = django_apps.get_app_config("edc_device")
self.device_id = device_id or app_config.device_id
self.protocol_number = protocol_number or Protocol().protocol_number
self.protocol_number = protocol_number or ResearchProtocolConfig().protocol_number
self.site = site or django_apps.get_model("sites.site").objects.get_current()
if identifier:
# load an existing identifier
Expand Down
8 changes: 5 additions & 3 deletions edc_identifier/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import secrets

from edc_protocol import Protocol
from edc_protocol.research_protocol_config import ResearchProtocolConfig

from .exceptions import SubjectIdentifierError

Expand All @@ -15,14 +15,16 @@ def is_subject_identifier_or_raise(subject_identifier, reference_obj=None, raise
`raise_on_none` is `True`.
"""
if subject_identifier or raise_on_none:
if not re.match(Protocol().subject_identifier_pattern, subject_identifier or ""):
if not re.match(
ResearchProtocolConfig().subject_identifier_pattern, subject_identifier or ""
):
reference_msg = ""
if reference_obj:
reference_msg = f"See {repr(reference_obj)}. "
raise SubjectIdentifierError(
f"Invalid format for subject identifier. {reference_msg}"
f"Got `{subject_identifier or ''}`. "
f"Expected pattern `{Protocol().subject_identifier_pattern}`"
f"Expected pattern `{ResearchProtocolConfig().subject_identifier_pattern}`"
)
return subject_identifier

Expand Down

0 comments on commit a56dbbe

Please sign in to comment.