Skip to content

Latest commit

 

History

History
73 lines (50 loc) · 1.4 KB

README.md

File metadata and controls

73 lines (50 loc) · 1.4 KB

subject-id-validator

Python scripts to check subject IDs

ID Schema

A well-formed ID is 7 characters long, sequentially consisting of:

  • 2 uppercase letters (Site ID)
  • 4 digits
  • 1 digit (check digit)
Details for the check digit algorithm

The check digit must correctly evaluate to the following:

{
  (ASCII value of 1st character * 1) +
  (ASCII value of 2nd character * 2) +
  (1st digit * 3) +
  (2nd digit * 4) +
  (3rd digit * 5) +
  (4th digit * 6)
} % 10

Validator scripts

Requirements

Python 3

Installation

No installation required, just clone the git repo or download the code.

git clone https://github.com/PREDICT-DPACC/subject-id-validator.git

Usage

python check.py [-h] --id ID

Where ID is the Subject ID to validate.

You may also import the module directly in the Python interpreter or your own scripts.

>>> from idvalidator import validate
>>> validate('ME00011') # A valid ID
True
>>> validate('ME00012') # An invalid ID (wrong check digit)
False

The validate function will return True for valid IDs and False for invalid IDs.

Note: This validator accepts lowercase letters for the Site ID but will print a warning.

Tests

You may run our test suite with the following command:

python test.py -b

This may also give you ideas for how to test your own implementation.