• Iguana 6
  • Previous Versions
  • API
  • Sample Code
  • Training
  • Create a Ticket
iNTERFACEWARE Help Center
  • Iguana 6
  • Previous Versions
  • API
  • Sample Code
  • Training
  • Create a Ticket

Code Repository

Home›Code Repository›codemap.lua
Modules

codemap.lua

Verified Featured
Added by iNTERFACEWARE

This module is used to map one set of codes to another set of codes, or to validate code membership in a set

Source Code
-- This code map library has a number of useful helper routines for doing mapping and checking codes etc.
 
local codemap = {}
 
-- Make a set
-- MySet = codemap.set{"Fred", "Bruce", "Jim"}
-- if MySet[Msg.PID[3][1][1]] then print('One of our three amigos') end
function codemap.set(a)
   local m = {}
   for _,v in ipairs(a) do m[v] = true end
   return codemap.map(m, false)
end
 
-- Create a map the advantage of this function is that it will take a tree node without
-- needing to convert it to a string. Example of usage
-- SexMap = codemap.map({'M'='Male', 'm'='Male', 'F'='Female', 'f'='Female'},'defaultValue')
function codemap.map(m, default)
   return setmetatable(m, {
         __index = function(m,k)
            if type(k) ~= 'string' then
               local v = rawget(m, tostring(k))
               if v ~= nil then return v end
            end
            return default
         end})
end

local codemap_map = {
   Title="codemap.map";
   Usage="codemap.map({codemap} [, default])",
   SummaryLine="Create a codemap table to map one set of codes to another",
   Desc=[[Create a codemap table to map one set of codes to another.
   <p>You can add a default value to the codeset to match unknown values, 
   if no default is used then <b>nil</b> is returned.
   <br><br><b>Note</b>: This function uses Lua metatables - but you do not need to 
   understand this to use it.
   ]];
   ParameterTable= true,
   Parameters= {
      {codemap= {Desc='Table containing the code mappings <u>table</u>.'}},
      {default= {Desc='Default return if no match is found <u>string</u>.', Opt = true}},
   };
   Returns = {
      {Desc="Returns a codeset table for mapping codes <u>table</u>."},
   };
   Examples={
      [[   -- using a default codemap value
   local SexCodeMap = codemap.map({
      M='Male',
      m='Male',
      F='Female',
      f='Female'
   }, 'Other')    -- default = 'Other'

   -- use the map you created to convert codes
   trace(SexCodeMap['M']) --> 'Male'
   trace(SexCodeMap['W']) --> 'Other'
   ]],
      [[   -- without a default codemap value
   local SexCodeMap = codemap.map({
      M='Male',
      m='Male',
      F='Female',
      f='Female'
   })             -- no default

   -- use the map you created to convert codes
   trace(SexCodeMap['M']) --> 'Male'
   trace(SexCodeMap['W']) --> nil
   ]],
   };
   SeeAlso={
      {
         Title="codemap.lua - in our code repository",
         Link="http://help.interfaceware.com/code/details/codemap-lua"
      },
      {
         Title="Codemap example",
         Link="http://help.interfaceware.com/v6/codemap-example"
      }
   }
}

help.set{input_function=codemap.map, help_data=codemap_map}

local codemap_set = {
   Title="codemap.set";
   Usage="codemap.set{codemap}",
   SummaryLine="Create a codemap table to use for membership checking",
   Desc=[[Create a codemap table to use for membership checking.<p> The codemap.set()
   function uses codemap.map() to create a codemap table with known 
   values set to <b>true</b> and a default of <b>false</b> for unknown
   values.
   ]];
   ParameterTable= true,
   Parameters= {
      {codeset= {Desc='Set of valid codes to use for membership checking <u>table</u>.'}},
   };
   Returns = {
      {Desc="Returns a mapping table for membership checking <u>table</u>."},
   };
   Examples={
      [[   local AmigoSet = codemap.set{"Fred", "Jim", "Harry"}

   -- Check for set membership
   trace(AmigoSet['Fred']) --> true
   trace(AmigoSet['Mary']) --> false
   ]],
   };
   SeeAlso={
      {
         Title="codemap.lua - in our code repository",
         Link="http://help.interfaceware.com/code/details/codemap-lua"
      },
      {
         Title="Codemap example",
         Link="http://help.interfaceware.com/v6/codemap-example"
      }
   }
}

help.set{input_function=codemap.set, help_data=codemap_set}

return codemap
Description
This module is used to map one set of codes to another set of codes, or to validate code membership in a set
Attachments
codemap_basic.zip
codemap_advanced.zip
Usage Details

This code simply maps one set of codes to another set of codes. You just need to create the mapping table and then use it to map your codes. An optional default value for mapping unrecognized codes can be included.

How to use codemap.lua:

  • Add it to your shared modules in any Translator project
  • Add local codemap = require 'codemap' at the top of your script
  • Use the codemap.map() function to create and return the mapping table
  • Use the returned mapping table to translate code values
  • Use the codemap.set() function to create and return a table for membership checking
  • Use the returned table for checking code membership

Here is a basic example using the codemap module:

codemap = require 'codemap'
-- The codemap module is a helpful example showing how 
-- easy it is to map common fields from one value to another.
-- https://help.interfaceware.com/code/details/codemap-lua

-- We set up the code map
local SexCodeMap = codemap.map({
      M='Male',
      m='Male',
      F='Female',
      f='Female',
   },'Other')

local function MapCodes()
   -- This shows mapping functionality
   local V = 'M'
   local W = 'W'
   local A = SexCodeMap[V]
   local B = SexCodeMap[W]
   trace(A)
   trace(B)
end

-- Here we set up a set which we can use to test to see
-- if something is a member of it.
local AmigoSet = codemap.set{"Fred", "Jim", "Harry"}

local function CheckSets()
   local Name1 = "Fred"
   local Name2 = "Mary"
   if (AmigoSet[Name1]) then
      trace(Name1 .. " is one of the three amigos!")
   end

   if (not AmigoSet[Name2]) then
      trace(Name2 .. " is not one the three amigos!")
   end   
end

function main()
   MapCodes()
   CheckSets()
end

Note: The code makes use of an advanced Lua feature called metatables. However, it’s not necessary to understand metatables to use the module.

More Information
• Map one codeset to another
• HL7 Conformance
Bookmark
  • Reviews
  • Related Listings
Filter
Sort by: Oldest First
  • Newest First
  • Rating
  • Helpfulness
Write a Review
Rating
Keyword
Filter
Sort by: Oldest First
  • Newest First
  • Title
  • Most Reviews
  • Highest Rated
Rating
iNTERFACEWARE
custom_merge.lua
Added by iNTERFACEWARE
Modules
A customizable database merge method for Iguana 5.5.1 and up.
dateparse.lua
Added by iNTERFACEWARE
Modules
A fuzzy date/time parser that is very useful for automatically translating a wide variety of date/time formats.
hl7.findSegment.lua
Added by iNTERFACEWARE
Modules
A utility for finding any HL7 segment in a parsed HL7 message node tree.
iguanaServer.lua
Added by iNTERFACEWARE
Modules
Provides programmatic access to various operations that can be performed on Iguana channels.
mime.lua
Added by iNTERFACEWARE
Modules
Sends MIME-encoded email attachments using the SMTP protocol. A wrapper around net.smtp.send.
retry.lua
Added by iNTERFACEWARE
Modules
A module for retrying operations which might periodically fail like database operations.
sha1.lua
Added by iNTERFACEWARE
Modules
A pure Lua-based implementation of the popular SHA-1 hashing function.
store.lua
Added by iNTERFACEWARE
Modules
The "original" store module: Allows you to store key/value pairs in a persistent storage mechanism. We recommend using the new store2 module instead.
stringutil.lua
Added by iNTERFACEWARE
Modules
A library of helpful extensions to the standard Lua string library.
dup.lua
Added by iNTERFACEWARE
Modules
Duplicate message filter.
xml.lua
Added by iNTERFACEWARE
Modules
A collection of helpful XML node functions.
urlcode.lua
Added by iNTERFACEWARE
Modules
A module for parsing URL encoded GET/POST sequences
csv_parse.lua
Added by iNTERFACEWARE
Modules
A module for parsing well-formed CSV files.
scrub.lua
Added by iNTERFACEWARE
Modules
The “scrub” module given below redacts sensitive information from HL7 messages.
throttleDB.lua
Added by iNTERFACEWARE
Modules
Throttle database access by reducing the number of inserts during peak hours
rtf.lua
Added by iNTERFACEWARE
Modules
A module for converting a RTF file to plain text.
resubmit.lua
Added by iNTERFACEWARE
Modules
Resubmit a logged message to an Iguana channel using the unique reference number (refmsgid).
throttle.lua
Added by iNTERFACEWARE
Modules
Throttle a process during peak hours, by slowing down the code.
validate.lua
Added by iNTERFACEWARE
Modules
A template module for testing HL7 message conformance, you will need to extend it to match your requirements
scheduler.lua
Added by iNTERFACEWARE
Modules
Schedule jobs to run at a specified time of day, very useful for batch processing
Showing 1 - 20 of 31 results
«12»

Topics

  • expandGetting Started
  • expandAdministration
    • expandInstallation
    • expandLicensing
    • expandUpgrades
    • expandDeployment
    • expandConfiguration Management
      • expandCustom Configuration
    • expandBackup and Restore
    • expandSecurity
      • expandHIPAA Compliance
    • expandTroubleshooting
  • expandDeveloping Interfaces
    • expandArchitecture
    • expandInterfaces
      • expandHL7
      • expandDatabase
        • expandConnect
      • expandWeb Services
      • expandCDA
      • expandX12
      • expandOther Interfaces
      • expandUtilities
    • expandRepositories
      • expandBuiltin Repositories
        • expandIguana Upgrade
        • expandIguana Tutorials
        • expandIguana Tools
        • expandIguana Protocols
        • expandIguana Files
        • expandIguana Date/Time
        • expandIguana Webservices
        • expandIguana Excel
      • expandRemote Repositories
      • expandCS Team Repositories
        • expandIguana Channels
    • expandSample Code
      • expandModules
      • expandUsing built-in functions
      • expandWorking with XML
    • expandLua Programming
    • expandPerformance
  • expandFAQs and TIPs
    • expandFrequently Asked Questions
      • expandInstalls and Upgrades
      • expandWeb Services
      • expandConfiguration
      • expandChannels
      • expandTranslator
      • expandOther
      • expandDatabase
      • expandAdministration
      • expandLogs
      • expandChameleon
    • expandTips
      • expandChannels
      • expandChameleon
      • expandWeb Services
      • expandSecurity
      • expandProgramming
      • expandOther
      • expandAdministration
  • expandReference
    • expandIguana Enterprise and Professional
    • expandProgram Settings
    • expandChannel Settings
    • expandDashboard
    • expandChannels
    • expandTranslator
    • expandLogs
      • expandLog Encryption
    • expandHTTP API
    • expandCDA API
    • expandError Messages
    • expandChameleon
    • expandIguana Change Log

Other Links

  • Training Center
  • News & Announcements
  • iNTERFACEWARE Blog
  • Older Documention (IGUANA v4 & Chameleon)
Copyright © iNTERFACEWARE Inc.