Come caricare i dati statici in Mirth, evitare molti andata e ritorno a un database

StackOverflow https://stackoverflow.com/questions/795462

  •  18-09-2019
  •  | 
  •  

Domanda

Mirth è un broker per aiutare con l'integrazione delle applicazioni di assistenza sanitaria messaggio HL7.

La mia domanda riguarda il risparmio la fatica di colpire il proprio archivio dati ogni volta che si vuole fare una ricerca su alcuni dei dati contenuti all'interno del HL7.

Scenario: per ogni messaggio ricevuto dal canale, voglio trovare l'impianto mnemonico / codice / ID e ottenere il nome completo della struttura. Purtroppo non posso chiedere al mittente del messaggio HL7 per inviarlo insieme nel messaggio per me. Quindi devo scrivere il mio codice di accesso DB per chiamare una stored procedure, passare l'ID, e ricevere il nome completo.

Qualche idea su come creare una cache di dati in Mirth in modo che sia possibile accedere alla ricerca da qualsiasi canale, origine, destinazione, trasformatore o filtrare?

È stato utile?

Soluzione

Si potrebbe provare a scrivere uno script globale con due funzioni:

1) Compilare un hastable Java o costrutto simile con i dati che si sta cercando

2) Utilizzare il parametro si passa come la chiave per la tabella hash e restituire i dati contenuti nella tabella hash corrispondente a questa chiave.

Link utilizzando Java in Mirth ( link )

Altri suggerimenti

Nel nostro caso, dove abbiamo dovuto caricare i valori di ricerca da un database, abbiamo risolto in questo modo:

  1. Dai script deploy canale che carica valori di ricerca quando il canale viene distribuito nella mappa globale.
  2. Avere una funzione di modello globale che permette di ricercare i valori da questa mappa globale.
  3. Utilizzare la funzione di modello globale nei filtri e traduce.

Nota: Nel nostro caso, ogni tasto può avere due valori ad esso associati. Se non abbiamo usato entrambi abbiamo appena impostato il secondo a null nella query dal database.

Per caricare il posto mappa globale presente nel vostro script deploy del tuo canale (personalizzare in base alle esigenze):

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

Per poter accedere a questi valori si utilizza la seguente funzione di un modello globale.

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

Un campione di codice per accedere ai valori:

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

if ( myObject != null )
{

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

La vostra situazione potrebbe essere diversa ... ma questo ha lavorato per noi fino ad oggi.

Grazie, Frans de Wet

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top