2

我现在定义了一个javascript转换器,但是转换的时候总是提示失败,代码如下:

var input = JSON.parse(connectorMessage.getRawData());
var patienId = input.PATIENT_ID;
var patientName = input.PATIENT_NAME;
var idCard = input.ID_NO;
var i = 1;
createSegment("MSH", msg, i++);
msg['MSH']['MSH.1']['MSH.1.1'] = '|';
msg['MSH']['MSH.2']['MSH.2.1'] = '^~\\&';
msg['MSH']['MSH.3']['MSH.3.1'] = patienId;
msg['MSH']['MSH.4']['MSH.4.2'] = patientName;
msg['MSH']['MSH.5']['MSH.5.1'] = idCard;

例外情况如下:

Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransformerException: 
CHANNEL:    WsToHttpTest
CONNECTOR:  sourceConnector
SCRIPT SOURCE:  TRANSFORMER
LINE NUMBER:    31
 DETAILS:   TypeError: Cannot set property "1" of undefined to ""
    at f4645dbe-9637-415e-ae39-f3dce72d6eaa:31 (createSegment)
    at f4645dbe-9637-415e-ae39-f3dce72d6eaa:53 (doTransform)
    at f4645dbe-9637-415e-ae39-f3dce72d6eaa:80 (doScript)
    at f4645dbe-9637-415e-ae39-f3dce72d6eaa:82
    at                       com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.doCall(JavaScriptFilterTransformer.java:154)
at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.doCall(JavaScriptFilterTransformer.java:119)
at com.mirth.connect.server.util.javascript.JavaScriptTask.call(JavaScriptTask.java:113)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

[enter image description here][1]
4

1 回答 1

3

上面代码中的问题始于createSegment代码。在那之前它工作正常。

在您的出站转换器中创建一个虚拟消息模板,如下所示:这只是一个同名模板,您定义它以创建一个 HL7 段范围。

MSH|^~\&|||||||||||
PID||||||||||||||||||||
PD1|||||

考虑到您收到的 JSON 是这样的:

{
    "PATIENT_ID": "XXXX",
    "PATIENT_NAME": "John",
    "ID_NO": "454141541"
}

我认为这种语法不正确createSegment('MSH', msg, i++); 我已经修改了您上面提供的代码:

var input = JSON.parse(connectorMessage.getRawData());
var patienId = input.PATIENT_ID;
var patientName = input.PATIENT_NAME;
var idCard = input.ID_NO;
msg=tmp;
createSegment('MSH', msg);
msg['MSH']['MSH.1']= "|";
msg['MSH']['MSH.2']= "^~\\&";
msg['MSH']['MSH.3']= patienId;
msg['MSH']['MSH.4']= patientName;
msg['MSH']['MSH.5']= idCard;

您还可以按照您建议的方式增加 HL7 消息中的计数器,没有错。参考计数器:使用 Mirth 将多个 NTE 段添加到 HL7 消息

在此处输入图像描述

于 2016-08-16T06:40:38.137 回答