Skip to content

Utzel-Butzel/bmp-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bmp-reader

bmp-reader scanner payload decoding banner

JS decoder for scanner payloads from the German Bundeseinheitlicher Medikationsplan (BMP).

The package does not scan camera input or images. BMP printouts use a DataMatrix 2D barcode whose payload is compact ISO-8859-1 XML; this package starts after a scanner has already returned that payload text or bytes.

This package is part of the AvatarMediKI project. More project context is available at anabox-smart.de/ki.

Install

Install bmp-reader from npm with npm install:

npm install bmp-reader

Requires Node.js 20 or newer.

Usage

import { decodeBmp, decodeBmpPages } from "bmp-reader";

const plan = decodeBmp(scannerText);

console.log(plan.patient.firstName);
console.log(plan.medications);

const combined = decodeBmpPages([page1ScannerText, page2ScannerText]);
console.log(combined.sections);

decodeBmp() accepts a string, Uint8Array, or ArrayBuffer. Byte inputs are decoded with exact Latin-1 byte mapping.

Online Demo

The static demo in docs/ can be served directly by GitHub Pages:

The demo accepts pasted BMP payload XML, reads DataMatrix barcodes from webcam or image files with zxing-wasm, includes anonymized sample payloads, assembles multi-page examples, and shows the decoded plan as overview cards, medication rows, section items, warnings, JSON, and formatted XML.

Scanner Integration

Use a scanner or barcode library that can read DataMatrix codes and preserve the BMP payload as ISO-8859-1/Latin-1 data. BMP payloads are compact XML, but they are not UTF-8; German characters such as ä, ö, ü, ß, or Ü must survive as Latin-1 bytes.

Recommended scanner handoff:

  • Prefer passing raw scanner bytes to decodeBmp() as Uint8Array or ArrayBuffer.
  • If your scanner returns text, make sure it maps each byte directly to the same JavaScript character code (0x00 to 0xff) instead of transcoding from UTF-8.
  • For multi-page BMP printouts, scan each DataMatrix separately and pass the page payloads to decodeBmpPages().
  • Keep camera, image, PDF, or hardware scanning code in your application; this package intentionally only decodes the returned BMP XML payload.

Recommended scanner/decoder tools:

  • Hardware scanners: use a 2D imager that explicitly supports DataMatrix ECC200. Configure it as USB HID keyboard wedge, USB serial, or native serial depending on your app, and verify that it does not transcode Latin-1 payload bytes as UTF-8.
  • Browser or Node image decoding: zxing-wasm is a good JS option because it supports DataMatrix and can read from browser image data or Node buffers.
  • CLI or CI checks: dmtxread from libdmtx is useful for DataMatrix-only fixture validation.
  • Native browser scanning: the BarcodeDetector API can be useful where available, but feature-detect BarcodeDetector.getSupportedFormats() and only use it for BMP when data_matrix is supported in your target browsers.

BMP Version Support

Version support refers to the XML MP.v attribute in the scanner payload.

BMP version Default status Notes
028 / v2.8 Supported Included in the default supportedVersions; covered by official/public fixtures.
027 / v2.7 Supported Included in the default supportedVersions; covered by specification examples.
026 / v2.6 Opt-in compatibility Not supported by default. Historical XML fixtures parse with allowUnknownVersion: true, but this is not claimed as full support.
023 / v2.3 Opt-in compatibility Not supported by default. Historical XML fixtures parse with allowUnknownVersion: true, but this is not claimed as full support.
Other XML versions Not supported by default decodeBmp() throws UNSUPPORTED_VERSION unless allowUnknownVersion or a custom supportedVersions list is provided.
Pipe-delimited MP|020|... Not supported This older non-XML carrier format is intentionally rejected.

API

decodeBmp(input, options?)

Decodes one BMP carrier XML payload.

Options:

  • allowUnknownVersion: return data with a warning instead of throwing for unknown BMP versions.
  • supportedVersions: defaults to ["027", "028"].

decodeBmpPages(inputs, options?)

Decodes and assembles all pages of a multi-page BMP. It validates that pages share the same instance ID and version, detects missing or duplicate pages, sorts pages, and merges adjacent sections with the same heading.

BmpDecodeError

Thrown errors expose a stable code and a details object.

Known error codes include:

  • MALFORMED_XML
  • WRONG_ROOT
  • UNSUPPORTED_VERSION
  • MISSING_REQUIRED_ROOT_FIELD
  • MISSING_REQUIRED_FIELD
  • MISSING_PAGE
  • DUPLICATE_PAGE
  • INVALID_PAGE_ASSEMBLY
  • INVALID_INPUT

Notes

The decoder preserves raw attributes and unknown attributes. It does not resolve PZN values or access an Arzneimitteldatenbank; PZN-only medication entries are returned with warnings because display data may need an external drug database.

Help Improve Test Fixtures

Real-world BMP payloads help catch edge cases that official examples and synthetic fixtures miss. If you can share an anonymized Medikationsplan payload, please open an issue or pull request with the scanner text/bytes or compact XML plus the BMP version if you know it.

Please only share data that is fully anonymized. Do not send real patient data, names, birth dates, insurance numbers, addresses, doctor or practice names, IDs, or identifying free-text notes. When in doubt, replace values with synthetic data while keeping the same XML structure.

Development

The library is authored in TypeScript and compiled to dist/.

npm run typecheck
npm run build
npm test

The test suite includes official/public fixtures from the v2.8 BMP_Beispieldateien_V2.8.zip sample and the v2.7 barcode-content example printed in the BMP specification. It also keeps historical v2.6 and v2.3 specification examples as permissive-version fixtures, plus synthetic fixtures for multi-page and edge-case behavior. Barcode, generated-PDF, downloaded public-PDF, and downloaded public-image scanning tests are test-only and are not exported by the package; one public image fixture covers the older pipe-delimited MP|020|... carrier format as an intentionally rejected non-XML payload.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors