如何在 Mirth 中加载静态数据,避免多次往返数据库

发布于 2024-07-18 22:22:10 字数 387 浏览 10 评论 0原文

Mirth 是一个帮助医疗保健应用程序 HL7 消息集成的代理。

我的问题是,每次您想要查找 HL7 中包含的某些数据时,您都可以省去访问自己的数据存储的麻烦。

设想: 对于通道收到的每条消息,我想找到该设施的助记符/代码/ID 并获取该设施的全名。 不幸的是,我无法要求 HL7 消息的发送者将其在消息中一起发送给我。 所以我必须编写自己的数据库访问代码来调用存储过程,传入 ID 并接收全名。

关于如何在 Mirth 中创建数据缓存以便您可以从任何通道、源、目标、转换器或过滤器访问查找,您有什么想法吗?

Mirth is a broker to help with healthcare application HL7 message integration.

My question is about saving yourself the trouble of hitting your own datastore everytime you want to do a lookup on some data contained within the HL7.

Scenario:
for each message received by the channel, I want to find the facility's mnemonic/code/ID and get the full name of the facility. Unfortunately I cannot ask the sender of the HL7 message to send it along in the message for me. So I have to write my own DB access code to call a stored procedure, pass in the ID, and receive the full name.

Any idea on how to create a cache of data in Mirth so that you can access the lookup from any channel, source, destination, transformer or filter?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不弃不离 2024-07-25 22:22:10

在我们的例子中,我们必须从数据库加载查找值,我们按如下方式解决了这个问题:

  1. 使用一个通道部署脚本,在将通道部署到全局地图时加载查找值。
  2. 有一个全局模板函数,允许您从此全局映射中查找值。
  3. 在过滤器和翻译中使用全局模板函数。

注意:在我们的例子中,每个键可以有两个与之关联的值。 如果我们不使用两者,我们只需在数据库查询中将第二个设置为 null。

要加载全局地图,请将其放入频道的部署脚本中(根据需要自定义):

// This script executes once when the mule engine is started
// You only have access to the globalMap here to persist data 

var sqlDBDriver   = 'net.sourceforge.jtds.jdbc.Driver';
var sqlDBName     = 'jdbc:jtds:sqlserver://databaseserver/databasename';
var sqlDBDUser    = 'username';
var sqlDBPassword = 'password';

function PopulateLookup ( sqlQuery, globalMapName )
{
    logger.info('Loading lookup table values in the deploy script: ' + globalMapName);

    var dbConn = DatabaseConnectionFactory.createDatabaseConnection( sqlDBDriver, sqlDBName, sqlDBDUser, sqlDBPassword );
    var rs = dbConn.executeCachedQuery( sqlQuery );
    dbConn.close();

    var arr = new Array();
    while(rs.next())
    {
        var obj = new Object();
        obj.LeftValue   = rs.getString('LeftValue');
        obj.RightValue1 = rs.getString('RightValue1');
        obj.RightValue2   = rs.getString('RightValue2');
        arr.push(obj);
    } 
    globalMap.put( globalMapName, arr );
}

PopulateLookup( 'SELECT keyColumn as LeftValue, Value1 as RightValue1, Value2 as RightValue2 FROM tableName', 'GlobalMapName' );

// Repeat above line as needed for each lookup you need

return;

为了访问这些值,您可以使用以下函数作为全局模板。

function FindLookupValueWithDefault ( LookupGlobalMapName, LeftValue, DefaultValue1, DefaultValue2 ){
    /***********************************************************************************************
    DESCRIPTION: Retrieves lookup table values from the global map and uses the input values to return output values

     PARAMETERS:
       LookupGlobalMapName - name of the lookup table in the Global Map
       LeftValue - The value to look up
       DefaultValue1 - the first default value if a match was not found
       DefaultValue2 - the second default value if a match was not found

    RETURNS:
       An object containing the replacement value and associated OID if applicable

    REMARKS: 
    ************************************************************************************************/
        // Retrieve the previously matched item from the globalmap
        //    We do this to save time and not look through a huge lookup table tons of times
        //    unless we absolutely have to
        var prevItem = globalMap.get(LookupGlobalMapName + '-Previous');

        // This is the same item requested for this globalmap name - just return the previous value
        if ( prevItem != null && prevItem.LeftValue == LeftValue) {
            return prevItem;
        }

        //
        // If we reach this point the previous item either did not exist or did not match 
        //

        // Retrieve the array with lookup objects from the globalmap and search for the matching value
        var arr = globalMap.get(LookupGlobalMapName);
        var obj = new Object();
        obj.LeftValue = LeftValue;
        obj.RightValue1 = DefaultValue1;
        obj.RightValue2   = DefaultValue2; 
        for each ( item in arr )
        {
            var pattern=new RegExp("^" + item.LeftValue + "$");
            var result = pattern.test(LeftValue );

            if ( pattern.test(LeftValue ) )
            {
                obj = item;
                break;
            } 
        }

        // Store the previous value in the globalmap
        globalMap.put( LookupGlobalMapName + '-Previous', obj );

        // Return the object we found or created
        return obj;
    }

用于访问这些值的代码示例:

var myObject = FindLookupValueWithDefault('GlobalMapName', 'LookupValue', 'DefaultValue1', 'DefaultValue2');

if ( myObject != null )
{

      var value1 = myObject.RightValue1;
      var value2 = myObject.RightValue2;
}

您的里程可能会有所不同......但这对我们来说到目前为止一直有效。

谢谢,
弗朗斯·德·韦特

In our case, where we had to load lookup values from a database, we solved this as follows:

  1. Have a channel deploy script that loads lookup values when the channel is deployed into the global map.
  2. Have a global template function that allows you to lookup values from this global map.
  3. Use the global template function in filters and translates.

Note: In our case, each key could have two values associated with it. If we did not use both we just set the second to null in the query from the database.

To load the global map place this in your deploy script of your channel (customize as needed):

// This script executes once when the mule engine is started
// You only have access to the globalMap here to persist data 

var sqlDBDriver   = 'net.sourceforge.jtds.jdbc.Driver';
var sqlDBName     = 'jdbc:jtds:sqlserver://databaseserver/databasename';
var sqlDBDUser    = 'username';
var sqlDBPassword = 'password';

function PopulateLookup ( sqlQuery, globalMapName )
{
    logger.info('Loading lookup table values in the deploy script: ' + globalMapName);

    var dbConn = DatabaseConnectionFactory.createDatabaseConnection( sqlDBDriver, sqlDBName, sqlDBDUser, sqlDBPassword );
    var rs = dbConn.executeCachedQuery( sqlQuery );
    dbConn.close();

    var arr = new Array();
    while(rs.next())
    {
        var obj = new Object();
        obj.LeftValue   = rs.getString('LeftValue');
        obj.RightValue1 = rs.getString('RightValue1');
        obj.RightValue2   = rs.getString('RightValue2');
        arr.push(obj);
    } 
    globalMap.put( globalMapName, arr );
}

PopulateLookup( 'SELECT keyColumn as LeftValue, Value1 as RightValue1, Value2 as RightValue2 FROM tableName', 'GlobalMapName' );

// Repeat above line as needed for each lookup you need

return;

In order to access these values you use the following function as a global template.

function FindLookupValueWithDefault ( LookupGlobalMapName, LeftValue, DefaultValue1, DefaultValue2 ){
    /***********************************************************************************************
    DESCRIPTION: Retrieves lookup table values from the global map and uses the input values to return output values

     PARAMETERS:
       LookupGlobalMapName - name of the lookup table in the Global Map
       LeftValue - The value to look up
       DefaultValue1 - the first default value if a match was not found
       DefaultValue2 - the second default value if a match was not found

    RETURNS:
       An object containing the replacement value and associated OID if applicable

    REMARKS: 
    ************************************************************************************************/
        // Retrieve the previously matched item from the globalmap
        //    We do this to save time and not look through a huge lookup table tons of times
        //    unless we absolutely have to
        var prevItem = globalMap.get(LookupGlobalMapName + '-Previous');

        // This is the same item requested for this globalmap name - just return the previous value
        if ( prevItem != null && prevItem.LeftValue == LeftValue) {
            return prevItem;
        }

        //
        // If we reach this point the previous item either did not exist or did not match 
        //

        // Retrieve the array with lookup objects from the globalmap and search for the matching value
        var arr = globalMap.get(LookupGlobalMapName);
        var obj = new Object();
        obj.LeftValue = LeftValue;
        obj.RightValue1 = DefaultValue1;
        obj.RightValue2   = DefaultValue2; 
        for each ( item in arr )
        {
            var pattern=new RegExp("^" + item.LeftValue + "$");
            var result = pattern.test(LeftValue );

            if ( pattern.test(LeftValue ) )
            {
                obj = item;
                break;
            } 
        }

        // Store the previous value in the globalmap
        globalMap.put( LookupGlobalMapName + '-Previous', obj );

        // Return the object we found or created
        return obj;
    }

A sample of code to access the values:

var myObject = FindLookupValueWithDefault('GlobalMapName', 'LookupValue', 'DefaultValue1', 'DefaultValue2');

if ( myObject != null )
{

      var value1 = myObject.RightValue1;
      var value2 = myObject.RightValue2;
}

Your mileage may vary ... but this has worked for us up to now.

Thanks,
Frans de Wet

初与友歌 2024-07-25 22:22:10

您可以尝试编写具有两个函数的全局脚本:

1)使用您要查找的数据填充Java哈希表或类似的构造

2)使用您传入的参数作为哈希表的键,并返回相应哈希表中包含的数据到这个键。

在 Mirth 中使用 Java 的链接 (链接

You could try writing a global script with two functions:

1) Populate a Java hastable or similar construct with the data you are looking for

2) Use the parameter you pass in as the key to the hashtable and return the data contained in the hashtable corresponding to this key.

Link to using Java in Mirth (link)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文