Skip to main content

Manage identifiers in the Edc

Project description

pypi travis coverage


Add research subject identifiers and other useful identifiers to your project


Add to settings:


Identifiers for research subjects

Create subject identifiers.

from edc_identifier.subject_identifier import SubjectIdentifier

subject_identifier = SubjectIdentifier(
>>> subject_identifier.identifier

Maternal and Infant Identifiers

See also, edc_pregnancy model mixins DeliveryMixin, BirthMixin.

For example:

from edc_identifier.maternal_identifier import MaternalIdentifier

maternal_identifier = MaternalIdentifier(

>>> maternal_identifier.identifier

Add infants

>>> maternal_identifier.deliver(2, model='edc_example.maternallabdel')
>>> [infant.identifier for infant in maternal_identifier.infants]
['000-40990001-6-25', '000-40990001-6-26']

maternal_identifier.infants is a list of InfantIdentifier instances

Reload class:

>>> maternal_identifier = MaternalIdentifier(identifier='000-40990001-6')
>>> maternal_identifier.identifier
>>> [infant.identifier for infant in maternal_identifier.infants]
['000-40990001-6-25', '000-40990001-6-26']

Only allocate an identifier to one infant of twins:

>>> maternal_identifier.deliver(2, model='edc_example.maternallabdel', birth_orders='2')
>>> [infant.identifier for infant in maternal_identifier.infants]
[None, '000-40990001-6-26']

Of triplets, allocate identifiers to the 2nd and 3rd infants only:

>>> maternal_identifier.deliver(3, model='edc_example.maternallabdel', birth_orders='2,3')
>>> [infant.identifier for infant in maternal_identifier.infants]
[None, '000-40990001-6-37', '000-40990001-6-38']

Research subject identifier classes can create a Registered Subject instance

See also edc_registration

SubjectIdentifier by default does not create a RegisteredSubject instance unless create_registration=True.

By default, MaternalIdentifier and InfantIdentifier create RegisteredSubject instances that can be updated with full details later with the Delivery and Birth models. Continuing from above:

maternal_identifier = MaternalIdentifier(identifier='000-40990001-6')
maternal_identifier.deliver(1, model='edc_example.maternallabdel', create_registration=True)

# mother
>>> RegisteredSubject.objects.get(subject_identifier='000-40990001-6')
<RegisteredSubject '000-40990001-6'>

# infant is linked to the mother
>>> RegisteredSubject.objects.get(linked_identifier='000-40990001-6')
<RegisteredSubject '000-40990001-6-10'>

# infant
>>> obj = RegisteredSubject.objects.get(subject_identifier='000-40990001-6-10')
>>> obj.first_name
'Baby1Carter'  ## generates a temp name until Birth form is added with complete information.
>>> obj.relative_identifier

Subject type “Caps” are enforced by the research subject identifier classes

See also edc_protocol

Limits on the number of identifiers that can be allocated per subject type are enforced when identifiers are created. edc_identifier reads the “caps” from edc_protocol.apps.AppConfig linking the subject type, e.g. subject, or maternal or infant, to the relevant cap and not allowing the number of allocated identifiers to exceed the cap.

(Subject type “Caps” still working? needs to be verified)

Numeric Identifiers

The numeric identifier uses a check-digit and may have a separator if specified.

from edc_identifier import NumericIdentifier

class MyIdentifier(NumericIdentifier):

>>> id = MyIdentifier(None)
>>> id
>>> next(id)
>>> next(id)

# add a separator
class MyIdentifier(NumericIdentifier):
identifier_pattern = r'^[0-9]{4}\-[0-9]{4}\-[0-9]{4}$'
checkdigit_pattern = r'^\-[0-9]{1}$'
separator = '-'
seed = ['3200-0000-0000']

>>> id = MyIdentifier(None)
>>> id
>>> next(id)
>>> next(id)

# start from the last identifier, increment is immediate and automatic
>>> id = MyIdentifier('3200-0000-3222-0')
>>> id

Alphanumeric Identifiers

from edc_identifier import AlphanumericIdentifier

class MyIdentifier(AlphanumericIdentifier):
        alpha_pattern = r'^[A-Z]{3}$'
        numeric_pattern = r'^[0-9]{4}$'
        seed = ['AAA', '0000']

>>> id = MyIdentifier(None)
>>> id

Your identifier will starts with ‘AAA0001’ plus the checkdigit “5”. Subsequent calls to next increment like this:

>>> print(next(id))
>>> print(next(id))
>>> print(next(id))

The identifier increments on the numeric sequence then the alpha:

>>> id = MyIdentifier('AAA99991)
>>> id

>>> next(id)
>>> next(id)
>>> next(id)

>>> id = MyIdentifier('AAB99999')
>>> id

See getresults-receive for sample usage with settings and a History model.

Short Identifiers

Creates a small identifier that is almost unique, for example, across 25 Edc devices in a community. We use these as sample requisition identifiers that are transcribed manually onto a tube from the Edc screen in a household. Once the sample is received at the local lab it is allocated a laboratory-wide unique specimen identifier.

from edc_identifier import ShortIdentifier

>>> ShortIdentifier()

Add a static prefix – prefix(2) + identifier(5):

    from edc_identifier import ShortIdentifier

    class MyIdentifier(ShortIdentifier):
    prefix_pattern = r'^[0-9]{2}$'

>>> options = {'prefix': 22}
>>> id = MyIdentifier(options=options)
    >>> id
    >>> next(id)

Add a checkdigit – prefix(2) + identifier(5) + checkdigit(1):

    from edc_identifier import ShortIdentifier

    class MyIdentifier(ShortIdentifier):
    prefix_pattern = r'^[0-9]{2}$'
    checkdigit_pattern = r'^[0-9]{1}$'

>>> options = {'prefix': 22}
>>> id = MyIdentifier(options=options)
    >>> id
    >>> next(id)

We use this in edc-quota to get a confirmation code:

from edc_identifier import ShortIdentifier

class ConfirmationCode(ShortIdentifier):

    identifier_type = 'confirmation'
    prefix_pattern = ''

>>> code = ConfirmationCode()
>>> print(code)
>>> next(code)

Add more to the prefix, such as device code and community code.

    from edc_identifier.short_identifier import ShortIdentifier

    class RequisitionIdentifier(ShortIdentifier):

            identifier_type = 'requisition'
            prefix_pattern = r'^[0-9]{4}$'
            template = '{device_id}{community_id}{random_string}'

            def options(self):
                    if 'prefix' not in self._options:
                                    {'prefix': str(self._options.get('device_id')) + str(self._options.get('community_id'))})
                    return self._options

>>> options = {'device_id': 22, 'community_id': '12'}
>>> id = RequisitionIdentifier(options=options)
    >>> id
    >>> next(id)

… if you prefer not to use the IdentifierHistory model, for example, if you are filling in a model field on save():

from my_app.models import Requisition

class RequisitionIdentifier(ShortIdentifier):

    identifier_type = 'requisition'
    requisition_model = Requisition

    def is_duplicate(self, identifier):
            return True
        except self.requisition_model.DoesNotExist:
        return False

        def update_history(self):

Batch Identifier

To have an identifier prefixed by the current date stamp:

from edc_identifier.batch_identifier import BatchIdentifier

>>> id = BatchIdentifier()
>>> id
>>> next(id)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
edc-identifier-0.2.14.macosx-10.13-x86_64.tar.gz (53.8 kB) Copy SHA256 hash SHA256 Source None Aug 9, 2018
edc_identifier-0.2.14-py3-none-any.whl (41.2 kB) Copy SHA256 hash SHA256 Wheel py3 Aug 9, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page