Skip to main content

Parse EU FMD compliant GS1 & PPN Datamatrix barcodes

Project description

pharma_datamatrix package

The package allow users to pass the string produced by the 2D barcode scanners and parse the string into GTIN, EXPIRY, SERIAL, BATCH and NHRN. Optionally, user can pass validation=True, to validate the GTIN and Expiry date.

Files

pharma_datamatrix.py: Primary file with the parsing logic. Is the string is valid, it will return a dict of the values. Otherwise return invalid string.

expiry_date_validation.py: This files contains the logic that validates the Expiry date. This file checks if the YYMMDD contains valid digits. Ex: MM to be between 01 & 12. And if the expiry date greater than the date of the scan: i.e. not is valid past date.

gs1_gtin_validation.py: This file contains the logic that validates the GS1 - GTIN(14).

Installation

To install the package please run the below command: pip install pharma_datamatrix

Usage

The function pharma_datamatrix(barcode: str, Validation: bool = False) takes two parameters: The first parameter 'barcode' is of 'string' type and its mandatory. The string should contain the seperator as per GS1 guidelines. The second parameter 'validation' is of bool type and default to 'False'. Users can pass 'True' for the package to perform validation on GTIN and Expiry Date.

Initial Import: from pharma_datamatrix import pharma_datamatrix

Example 1: Usage without validation (Expiry date is invalid but no validation is performed) pharma_datamatrix('01085860077038511724113110HB5R121587E4QA11R') Output: {'NHRN': None, 'GTIN': '08586007703851', 'EXPIRY': '241131', 'BATCH': 'HB5R1', 'SERIAL': '21587E4QA11R'}

Example 2: Usage without validation (Invalid barcode) pharma_datamatrix('085860077038511724113110HB5R21587E4QA11R') Output: INVALID BARCODE

Example 3: Usage with validation (valid barcode) pharma_datamatrix('01085860077038511724123110HB5R21587E4QA11R', True) Output: {'NHRN': None, 'GTIN': '08586007703851', 'EXPIRY': '241231', 'BATCH': 'HB5R1', 'SERIAL': '21587E4QA11R'}

Example 4: Usage with validation (valid barcode format but Invalid expiry date (31 Nov 24)) pharma_datamatrix('01085860077038511724113110HB5R21587E4QA11R', True) Output: INVALID EXPIRY DATE

Example 5: Usage with validation (valid barcode format but Invalid GTIN) pharma_datamatrix('01083860077038511724113110HB5R21587E4QA11R', True) Output: INVALID GTIN

Source

Github link: https://github.com/PinchofLogic/pharma_datamatrix

Project details


Download files

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

Source Distribution

pharma_datamatrix-1.2.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file pharma_datamatrix-1.2.tar.gz.

File metadata

  • Download URL: pharma_datamatrix-1.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for pharma_datamatrix-1.2.tar.gz
Algorithm Hash digest
SHA256 157ac1bed1051fdf4f6f8df65e0618d350ca0bfedb847fe4cabb1a5d225f9037
MD5 7b38f224147330ae40db6c39b1324e00
BLAKE2b-256 f720c072edfdb1fe78ed8376cce198347ad8f68d0ddea14a8a5f3221f5dd05aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page