Summary
Functions
Extracts the barcode prefix from a collection UUID. The barcode prefix is the last 12 characters of the UUID (the final block).
Generate a compact barcode string from an item_code.
Generates a unique collection UUID that doesn't collide with existing barcode prefixes. Takes a function that checks if a barcode prefix exists and generates new UUIDs until a unique one is found.
Functions
Extracts the barcode prefix from a collection UUID. The barcode prefix is the last 12 characters of the UUID (the final block).
Examples
iex> extract_barcode_prefix("b371e6aa-3fb1-48cf-8439-90373dfcd91a")
"90373dfcd91a"
iex> extract_barcode_prefix("invalid")
nil
Generate a compact barcode string from an item_code.
New Format (preferred for new items)
Combines unix timestamp (milliseconds) + collection UUID segment + item index.
Example: 17738990974338c87c8d23358001
1773899097433= unix timestamp in milliseconds8c87c8d23358= last 12 chars of collection UUID001= item index (padded to 3 digits)
Old Format (backward compatibility)
Falls back to extracting UUID last block + sequence for older item_codes.
Example: 8c87c8d23358001
Item Code Format
Expected: unit-type-collection_uuid-timestamp-index
Example: curatorian-book-c1fcfbee-8674-4ee1-bc30-8c87c8d23358-1773899097433-000
Generates a unique collection UUID that doesn't collide with existing barcode prefixes. Takes a function that checks if a barcode prefix exists and generates new UUIDs until a unique one is found.
Parameters
- check_exists_fn: A function that takes a barcode prefix and returns true if it exists
- max_attempts: Maximum number of attempts (default: 100)
Returns
- - A unique UUID
- - If unable to find unique UUID after max attempts