欢乐连接:javascript阅读器和bytea

时间:2012-12-04 15:59:39

标签: mirth

我需要从数据库中读取一个blob字段,在频道阅读器中,然后通过TCP发送它。

我可以使用数据库阅读器轻松完成此操作,除非我有Blob字段,所以我尝试使用JavaScript阅读器:

var dbConn = DatabaseConnectionFactory.createDatabaseConnection('org.postgresql.Driver','jdbc:postgresql://127.0.0.1:5432/ris','postgres','postgres');
// You may access this result below with $('column_name')
var resultQuery = "select mensajehl7, p.ip, p.port from turnohl7 h7 join pacs p on p.idpacs=h7.idpacs where h7.estado='NW'";
var qryResult = dbConn.executeCachedQuery(resultQuery);

var result = new Packages.java.util.ArrayList();

while(qryResult.next())
{ 
  var columna = new Array();
  columna['hl7'] = qryResult.getBytes(1);
  result.add(columna);
}

dbConn.close();
return result;

似乎结果需要是XML,因为堆栈跟踪建议:

[2012-12-04 12:56:29,227]  ERROR (org.mule.impl.DefaultComponentExceptionStrategy:95): Caught exception in Exception Strategy for: f4a3cccb-902e-4504-86f5-0bfa473ad144: org.mule.umo.routing.RoutingException: Failed to transform message before applying the filter. Failed to route event via endpoint: ImmutableMuleEndpoint{connector=com.mirth.connect.connectors.js.JavaScriptConnector@379cf50c, endpointUri=js://sink, transformer=Transformer{name='ResultMapToXML', returnClass=false, returnClass=false, sourceTypes=[interface java.util.Map, class java.lang.String]}, name='_jsEndpoint#-1389160782', type='receiver', properties={}, transactionConfig=org.mule.impl.MuleTransactionConfig@44adab2d, filter=null, deleteUnacceptedMessages=false, initialised=true, securityFilter=null, synchronous=true, initialState=started, createConnector=0}. Message payload is of type: java.lang.String
org.mule.umo.routing.RoutingException: Failed to transform message before applying the filter. Failed to route event via endpoint: ImmutableMuleEndpoint{connector=com.mirth.connect.connectors.js.JavaScriptConnector@379cf50c, endpointUri=js://sink, transformer=Transformer{name='ResultMapToXML', returnClass=false, returnClass=false, sourceTypes=[interface java.util.Map, class java.lang.String]}, name='_jsEndpoint#-1389160782', type='receiver', properties={}, transactionConfig=org.mule.impl.MuleTransactionConfig@44adab2d, filter=null, deleteUnacceptedMessages=false, initialised=true, securityFilter=null, synchronous=true, initialState=started, createConnector=0}. Message payload is of type: java.lang.String
    at org.mule.routing.inbound.SelectiveConsumer.isMatch(SelectiveConsumer.java:64)
    at org.mule.routing.inbound.InboundMessageRouter.route(InboundMessageRouter.java:79)
    at org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:487)
    at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:266)
    at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:225)
    at com.mirth.connect.connectors.js.JavaScriptMessageReceiver.processMessage(JavaScriptMessageReceiver.java:101)
    at com.mirth.connect.connectors.js.JavaScriptMessageReceiver.poll(JavaScriptMessageReceiver.java:82)
    at org.mule.providers.PollingMessageReceiver.run(PollingMessageReceiver.java:97)
    at org.mule.impl.work.WorkerContext.run(WorkerContext.java:290)
    at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
    at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
    at java.lang.Thread.run(Unknown Source)Caused by: org.mule.umo.transformer.TransformerException: java.lang.StringIndexOutOfBoundsException: String index out of range: -2 (com.mirth.connect.server.mule.adaptors.AdaptorException)
    at com.mirth.connect.server.mule.transformers.JavaScriptTransformer.transform(JavaScriptTransformer.java:285)
    at org.mule.transformers.AbstractEventAwareTransformer.doTransform(AbstractEventAwareTransformer.java:48)
    at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:197)
    at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:200)
    at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:200)

如何在变压器中使用我的bytea字段?

2 个答案:

答案 0 :(得分:2)

这个答案不是直接的,但希望它会有所帮助。

我将讨论两个方面:

1。从数据库获取HL7数据

我做了类似的事情,除了在我的情况下,HL7数据以varchar(max)存储在SQL Server中,我调用存储过程而不是传递完整查询。

当返回数据表时,我们将hl7数据提取为clob(而不是blob),如下所示

// the hl7 data is returned as a CLOB, not a string
var hl7MsgClob  = dataTable.getClob("HL7");
var clobLength = hl7MsgClob.length();

// clobs have a starting index of 1, and the getSubString is inclusive on both ends of the range
var hl7Msg = hl7MsgClob.getSubString(1,clobLength);

// This is a code template that decodes characters we escaped prior to writing to SQL Server
var cleanHL7 = Util_DecodeTextFromSQLStorage(hl7Msg);

// convert the message to an XML format
var HL7AsXML = SerializerFactory.getHL7Serializer(false,false,true).toXML(cleanHL7);

2。在Mirth中传递数据

从Javascript阅读器返回的数据类型必须与通道源的数据类型匹配。我不知道更新的Mirth版本,但在版本1.8.2中,这是在标记为“Incoming Data”的下拉列表的Summary选项卡上配置的。

如果您将此设置为HL7 v2.x,则所需的数据类型MIGHT实际上是HL7 v.2.x的XML变体 - 而不是更熟悉的管道分隔格式。如果您的hl7采用管道分隔格式,要进行实验,您可以使用我在上面发布的最后一行代码将其转换为xML格式。

答案 1 :(得分:0)

从数据库中获取blob的简单方法是在select语句中使用强制转换很简单。

CAST(<Field Name> AS CHAR(10000) CHARACTER SET utf8) AS '<FieldName>'