2009-04-27 71 views
3

Mirth是一个代理商,可以帮助医疗应用HL7消息集成。如何在Mirth中加载静态数据,避免很多往返数据库

我的问题是关于每当你想查看HL7中包含的一些数据时,自己保存打自己的数据存储区的麻烦。

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

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

回答

2

你可以尝试写一个全局脚本有两个功能:

1)填充的Java hastable或类似的结构与您正在寻找

2中的数据)使用参数你传递的关键到散列表并返回散列表中包含的对应于该键的数据。

链接到欢乐使用Java(link

+0

谢谢杰森;我从你的博客文章中学到了很多东西。发布技巧的荣誉!我有实施,我会尽可能在问题中发布。再次感谢! – 2009-05-30 01:42:13

5

在我们的情况下,我们不得不从数据库加载查找值,我们解决了这个如下:

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

您的里程可能会有所不同......但现在这已经为我们带来最多。

谢谢, Frans de Wet