ЕСОЗ - публічна документація

Human readable Medication request number

It should satisfy the below requirements

  1. must be unique
  2. not a sequence - so no-one can generate new ID based on knowledge of the existing one
  3. Medication request number is a reason for the pharmacist to ship the drugs to any person who knows the number
  4. should be easy to read and pass a number to other person via any channel: orally, phone, sms.

Solutions

Solution 1

ID with the below structure

XXXX-1234-5678-9012-345-C

where

XXXX - series, can be used to split ID's between the groups based on the way how it was generated. Or we can just use it to increase number of combinations and decrease the collision probability

initially we can should generate all the ids within the same series.

Options for the series:

  1. all the latin letters - 810,000 combinations
  2. numbers and only some letters that looks the same in Cyrillic and Latin alphabet and can be entered via the phone keypad: A, E, H, K, M, P, T, X - 104,976 combinations
  3. numbers - 10,000 combinations

It is proposed to go with option 2 with the possibility to extend to option 1 if needed in future


1234-5678-9012-345 - randomly generated numbers

Number of combinations - 100,000,000,000,000

Options for numbers:

  1. just random numbers
  2. random and some salt like timestamp
  3. hash on some personal data like birthday or phone number

It is proposed to start with option 2. And later we can change this decision and start generating new ID's in other manner using new series.

C - checksum to minimize the probability of human mistakes. Should be calculated using the Damn algorithm or  Verhoeff algorithm.

There is no difference between these algorithms in terms of error detection. So we should chose the one based on what is easier to implement.


The proposed solution means that after new ID was generated we should check that it is unique in the DB. The probability of collisions is not low enough to avoid that.

Total number of possible combinations excluding series will be:

51,200,000,000,000,000

Probability of collisions: 0.01% probability in the range of around 5.5 millions.



Probability of collisions including series: 0.0001% probability in the range of around 24 millions.


Solution 2 - TO GO!

The same as solution1, but 

XXXX-12E4-52A8-P01-3

XXXX-12E4-52A8-P01 - randomly generated numbers and letters A, E, H, K, M, P, T, X.

In this case:

Probability of collisions: 0.01% probability in the range of around 343 millions.

In this case we might not check if ID is unique. 

This number is shorter but not so convenient for human to work with.


collision probability
from math import log1p, sqrt

def birthday(probability_exponent, bits):
    probability = 10. ** probability_exponent
    outputs     =  2. ** bits
    return sqrt(2. * outputs * -log1p(-probability))

print birthday(-6, 68)

ЕСОЗ - публічна документація