web stats
Mirth Community - View Single Post - Mirth Tools: User defined functions
View Single Post
  #53  
Old 03-19-2018, 05:50 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 841
siddharth is on a distinguished road
Default configMap Resolver

If not already known, then there is a Mirth feature called configuration Map available from Settings->ConfigurationMap, where you can store your sensitive Credentials information like DB Credentials, API Credentials and values that are stored can be pulled by just doing configurationMap.get('key'), just like with channel Map.

However, you cannot update details to the configMap from channels or code templates, in a way that configurationMap.put('key') is not possible. It is a read only static Map.

Configuration Map Resolver
This function returns a credentials object thereby fetching values from the configurationMap. All that is necessary is to settle for a "pattern" while storing information in configurationMap.

Let's say that you have stored DB credentials to an EMR database with customerID as ABCD, so I would name the keys as.

ABCD-DB_URL
ABCD-DB_UserName
ABCD-DB_Password

Now, I will call the resolver function like

configMapResolver('ABCD','DB');

and this will return a credentials object with the information.

Code:
function configMapResolver(customerID,type) {

sPattern=customerID+'-'+type+'_';

oCredentials=new Object();
oCredentials.Type=type;
oCredentials.URL=configurationMap.get(sPattern+'URL');
oCredentials.UserName=configurationMap.get(sPattern+'UserName');
oCredentials.Password=configurationMap.get(sPattern+'Password');

return oCredentials;
}

You can add more flags like version or environment to it.

We use this method for all purpose, DB as well as API credentials (differentiated by the type variable)
__________________
HL7v2.7 Certified Control Specialist!

Last edited by siddharth; 03-19-2018 at 05:52 AM. Reason: fix
Reply With Quote