Skip to main content

pypi actions coverage

edc-identifier

Add research subject identifiers and other useful identifiers to your project

Installation

Add to settings:

INSTALLED_APPS = [
    ...
    'edc_identifier.apps.AppConfig',
    ...
]

Identifiers for research subjects

Create subject identifiers.

from edc_identifier.subject_identifier import SubjectIdentifier

subject_identifier = SubjectIdentifier(
    subject_type_name='subject',
    model='edc_example.enrollment',
    protocol='000',
    device_id='99',
    study_site='40')
>>> subject_identifier.identifier
'000-40990001-6'

Maternal and Infant Identifiers

See also, edc_pregnancy model mixins DeliveryMixin, BirthMixin.

For example:

from edc_identifier.maternal_identifier import MaternalIdentifier

maternal_identifier = MaternalIdentifier(
    subject_type_name='maternal',
    model='edc_example.enrollment',
    study_site='40',
    last_name='Carter')

>>> maternal_identifier.identifier
'000-40990001-6'

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
'000-40990001-6'
>>> [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
'000-40990001-6'

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):
        pass

>>> id = MyIdentifier(None)
>>> id
MyIdentifier('00000000018')
>>> next(id)
'00000000026'
>>> next(id)
'00000000034'


# 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
MyIdentifier('3200-0000-0001-1')
>>> next(id)
'3200-0000-0002-9'
>>> next(id)
'3200-0000-0003-7'

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

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
MyIdentifier('AAA00015')

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

>>> print(next(id))
AAA00023
>>> print(next(id))
AAA00031
>>> print(next(id))
AAA00049

The identifier increments on the numeric sequence then the alpha:

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

>>> next(id)
'AAB00021'
>>> next(id)
'AAB00039'
>>> next(id)
'AAB00047'

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

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()
ShortIdentifier('46ZZ2')

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
    MyIdentifier('22UYMBT')
    >>> next(id)
    '22KM84G'

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
    MyIdentifier('223GF8A3')
    >>> next(id)
    '22DXVW23'

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)
CAT33
>>> next(code)
3FU7D

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}'

            @property
            def options(self):
                    if 'prefix' not in self._options:
                            self._options.update(
                                    {'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
    RequisitionIdentifier('22126MZXD')
    >>> next(id)
    '2212Y899C'

… 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):
        try:
            self.requisition_model.get(requisition_identifier=identifier)
            return True
        except self.requisition_model.DoesNotExist:
            pass
        return False

        def update_history(self):
                pass

Batch Identifier

To have an identifier prefixed by the current date stamp:

from edc_identifier.batch_identifier import BatchIdentifier

>>> datetime.today().strftime('%Y%m%d)
20150817
>>> id = BatchIdentifier()
>>> id
BatchIdentifier('201508170001')
>>> next(id)
'201508170002'

Metadata

Release files for edc-identifier 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for edc-identifier 1.0.0
File Size Uploaded
edc_identifier-1.0.0.tar.gz 42.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for edc-identifier 1.0.0
File Interpreter ABI Platform
edc_identifier-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 98.9 kB

Release files / edc_identifier-1.0.0.tar.gz

Download URL edc_identifier-1.0.0.tar.gz
Size 42.3 kB
Tags Source
SHA-256 checksum
How to use checksums
bbaf7be0ba7c58de1b31a61a4145e579dba8d65d4e18b8f21aad0b343c504eea
BLAKE2b-256 checksum
How to use checksums
a149960d85dc74fdddafc5ecb33de1c39992cba7ceaf78b8b70dc8e3ea533900
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.4

Release files / edc_identifier-1.0.0-py3-none-any.whl

Download URL edc_identifier-1.0.0-py3-none-any.whl
Size 56.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
575fecb555a104cbd6448bc334b97006dff4a80588210fe9a89ba1170235fe6d
BLAKE2b-256 checksum
How to use checksums
fa0e43e7c38c13b65887cb3f3cc2447029d926f1c9a72d579c7bf231cbb3279a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.3.39

2 release files

0.3.38

2 release files

0.3.37

2 release files

0.3.36

2 release files

0.3.35

2 release files

0.3.34

2 release files

0.3.33

2 release files

0.3.32

2 release files

0.3.30

2 release files

0.3.27

2 release files

0.3.26

2 release files

0.3.24

2 release files

0.3.23

2 release files

0.3.18

2 release files

0.3.17

2 release files

0.3.16

2 release files

0.3.15

2 release files

0.3.13

2 release files

0.3.12

2 release files

0.3.11

2 release files

0.3.9

2 release files

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.44

1 release file

0.2.43

1 release file

0.2.42

1 release file

0.2.41

1 release file

0.2.40

1 release file

0.2.39

1 release file

0.2.38

1 release file

0.2.36

1 release file

0.2.35

1 release file

0.2.34

1 release file

0.2.33

1 release file

0.2.32

1 release file

0.2.31

1 release file

0.2.30

1 release file

0.2.29

1 release file

0.2.28

1 release file

0.2.27

1 release file

0.2.26

1 release file

0.2.25

1 release file

0.2.24

1 release file

0.2.23

1 release file

0.2.22

1 release file

0.2.21

1 release file

0.2.20

1 release file

0.2.19

1 release file

0.2.18

1 release file

0.2.17

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page