Skip to main content

Codemap Library

The codemap library is a helpful library for mapping or validating codes that belong in a set. Otherwise known as a “dictionary” or “code lookup“.

Use the codemap.map() function to create and return a mapping table to translate code values. A second argument can be included to return a default value if there is no matching code.

local SexMap = codemap.map({F=’Female’,  M=’male’, W=’Female’, U=’Unknown’},’other’)   

-- Example: mapping an HL7 message
PID[8][1] = SexMap[PID[8][1]] -- maps to ’Female’

Use codemap.set{} to create and return a mapping table to use for membership checking (checking if a code matches a given set of codes). This function will return true if a code exists in the set or false if not.

local AmigoSet = codemap.set{’Fred’, ’Jim’, ’Harry’}   
local isMember = AmigoSet[’Harry’] -- true
local isMember = AmigoSet[’William’] -- false

Import the codemap library into one of your Translator projects. You can find the source code here: https://bitbucket.org/interfaceware/codemap_library/src/main/?search_id=4347f796-0e3c-4c6e-a13c-1a56be064efa