2009-04-27 68 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