【问题标题】:How to load static data in Mirth, avoid many roundtrips to a database如何在 Mirth 中加载静态数据,避免多次往返数据库
【发布时间】:2010-10-22 04:21:04
【问题描述】:

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

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

场景: 对于频道收到的每条消息,我想找到设施的助记符/代码/ID 并获取设施的全名。不幸的是,我不能要求 HL7 消息的发件人在消息中为我发送它。所以我得自己写DB访问代码来调用存储过程,传入ID,接收全名。

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

【问题讨论】:

    标签: shortcuts hl7 mirth


    【解决方案1】:

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

    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;
    }
    

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

    谢谢, 弗兰斯·德韦特

    【讨论】:

      【解决方案2】:

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

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

      2) 使用你传入的参数作为哈希表的key,返回这个key对应的哈希表中包含的数据。

      链接到在 Mirth 中使用 Java (link)

      【讨论】:

      • 谢谢杰森;我实际上从你的博文中学到了很多。感谢发布操作方法!我有实现,我会尽可能在问题中发布。再次感谢!
      • 很高兴为您提供帮助 - 我很想知道解决方案是否有效!
      猜你喜欢
      • 2012-07-20
      • 2016-03-24
      • 2013-08-07
      • 1970-01-01
      • 2015-11-11
      • 2011-04-07
      • 1970-01-01
      • 2023-03-12
      • 2021-12-16
      相关资源
      最近更新 更多