Extracting information from a scanned GS1-type barcode

I am developing an application in Android Studio to get the expiration date of items when scanning a barcode.

I don't want the user to install the ZXing barcode app separately, so I entered the ZXing code into my project. By doing this, I was able to get the product ID.

I also want to get product information such as description, production date and expiration date using the scanned barcode data. How can i do this?

+1


source to share


3 answers


There are two processes involved in obtaining information represented by a GS1 barcode that stores data in the standard GS1 Application ID format.

  1. Retrieves data fields (called Application IDs) contained in GS1 Structured Data obtained by scanning a symbol. This always includes the unique identifier for the GTIN-14 and may include additional information such as expiration date, LOT number, etc. This process can be performed by a stand-alone application.
  2. Search the retrieved GTIN in a database, locally for your application or through some public API, to provide a text representation of the country of origin, manufacturer, and possibly a product description. To complete this process, the application requires access to external resources.

Prerequisites: GS1 Application Identifier Standard Format

GS1 data consists of a concatenated list of Application Identifiers (AI) and values ​​starting with AI (01), which represents the GTIN.

For example, the data "(01) 95012345678903 (10) 000123 (17) 150801" represents the following information:

GTIN:             95012345678903
BATCH/LOT:        000123
USE BY OR EXPIRY: 1st August 2015

      

Section 3: GS1 Application ID. The GS1 Generic Specification definitions provide the meaning of each of the Application Identifiers and furthermore also indicate whether the AI ​​values ​​are by definition variable length or fixed length, in which case the mandatory length is provided.

GS1 barcodes use a special character without data (FNC1) to indicate that the data conforms to the GS1 Application Identifier standard and delimit the end of a variable length data field from the next AI. For example, the above data can be encoded in a code {FNC1}019501234567890310000123{FNC1}17150801

character 128 to produce the following GS1-128 character:

GS1-128: (01) 95012345678903 (10) 000123 (17) 150801

When this character is read by a barcode scanner, it is decoded as follows: [†] :

019501234567890310000123{GS}17150801

      

Note that the original non-data character FNC1 was discarded, and FNC1, used as a variable length AI delimiter, was represented by the GS character (ASCII value 29).

Extraction (and optional verification)



Extracting the GTIN and any additional information can be done directly by your application.

Extracting the raw application ID data from decoded GS1 symbol data from a barcode scanner requires your application to contain a data structure that we will call AI-TABLE

matching AI templates with their values ​​derived from the data provided in the GS1 general specifications section above:

AI     | N (value length)
-------------------------
(00)   | 18
(01)   | 14
(10)   | variable
(17)   | 6
(240)  | variable
(310n) | 6
(37)   | variable
...

      

With this tool, you can continue extracting AI values ​​from scanned barcode data as follows:

while more data:
    AI,N = Entry from AI-TABLE matching a prefix of the data, otherwise FAIL.

    if N is fixed-length:
        VALUE = next N characters
    else N is variable length:
        VALUE = characters until "GS" or end of data

    emit: (AI) VALUE

      

In practice, you can include AI-TABLE

more data from the generic specifications in yours so that your application can perform extended validation for each type and length VALUE

. However, the above is sufficient to retrieve data such as AI (17) representing the expiration date you are looking for.

Respect

To get the rest of the data you are interested in (which is not directly encoded in the barcode), such as the item name and manufacturer details, it is necessary that you search for the extracted GTIN using external resources such as a local product database or one of the publicly available UPC APIs.

The GTIN itself contains the country of origin (in fact it is the national GS1 member organization with which the manufacturer is registered, so not exactly the country of origin), the manufacturer ID - together they are called the GS1 prefix, are variable in length and assigned by GS1, and the rest of the digits are a product code that is arbitrarily assigned by the manufacturer.

Given the GTIN, some UPC databases will only contain details related to the GS1 prefix, such as the textual representation of the GS1 member organization and manufacturer. Others try to keep records of individual GTIN assignments for common elements, but this data will always be somewhat incomplete and outdated as there is no mandatory real-time GTIN job register.

Examples of free information platforms are provided in the answers to this question .

[†] Actually you can see ]C1019501234567890310000123{GS}17150801

in this case the main symbol identifier for GS1-128 ]C1

can be dropped.

+8


source


This is a client-specific Javascript solution, needs more work to generalize:



//define AI's, parameter name and, optionally, transformation functions
SapApplicationIdentifiers= [
    { ai: '00', regex: /^00(\d{18})/,         parameter: 'SSCC'},
    { ai: '01', regex: /^01(\d{14})/,         parameter: 'EAN'},
    { ai: '02', regex: /^02(\d{14})/,         parameter: 'EAN'},
    { ai: '10', regex: /^10([^\u001D]{1,20})/,  parameter: 'LOTE'},
    { ai: '13', regex: /^13(\d{6})/},
    { ai: '15', regex: /^15(\d{6})/,        parameter: 'F_CONS', transform: function(match){ return '20'+match[1].substr(0,2)+'-'+match[1].substr(2,2)+'-'+match[1].substr(4,2);}},
    { ai: '17', regex: /^17(\d{6})/,        parameter: 'F_CONS', transform: function(match){ return '20'+match[1].substr(0,2)+'-'+match[1].substr(2,2)+'-'+match[1].substr(4,2);}},
    { ai: '19', regex: /^19(\d{6})/,        parameter: 'F_CONS', transform: function(match){ return '20'+match[1].substr(0,2)+'-'+match[1].substr(2,2)+'-'+match[1].substr(4,2);}},
    { ai: '21', regex: /^21([\d\w]{1,20})/},                       //numero de serie
    { ai: '30', regex: /^30(\d{1,8})/},
    { ai: '310', regex: /^310(\d)(\d{6})/, parameter: 'NTGEW', transform: function(match){ return parseInt( match[2] ) / Math.pow( 10,parseInt( match[1] ) )}},
    { ai: '320', regex: /^320(\d)(\d{6})/, parameter: 'NTGEW', transform: function(match){ return parseInt( match[2] ) / Math.pow( 10,parseInt( match[1] ) )}},
    { ai: '330', regex: /^330(\d)(\d{6})/},
    { ai: '37', regex: /^37(\d{1,8})/,        parameter: 'CANT'}
  ];

 //walks through the code, removing recognized fields
 function parseAiByAi(code, mercancia, onError ){
    var match;

    if(!code)
      return;

    SapApplicationIdentifiers.forEach(function(AI){
      if(code.indexOf(AI.ai)==0 && AI.regex.test(code)){
        match= AI.regex.exec( code );
        if(AI.parameter){
          if(angular.isFunction(AI.transform)){
            mercancia[AI.parameter] = AI.transform(match);
          }else
            mercancia[AI.parameter]= match[1];
          if(AI.parameter=="NTGEW"){
            mercancia.NTGEW_IA= AI.ai;
          }
        }

        code= code.replace(match[0],'').replace(/^[\0\u001D]/,'');
        parseAiByAi(code, mercancia, onError);
      }

    });
  }

  parseAiByAi(code, mercancia, onError);

      

0


source


You can try using the UPC Database API . They have no guarantee of uptime and they limit 1000 requests per day. I was also able to find this API that charges 1/1000 calls. Good luck!

-1


source







All Articles