I define a javascript transformer now, but always tip failure when transformation, the code is as follows:
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;
and Exceptions are as follows:
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]
The problem in your above code starts with
createSegment
code. Until then it works fine.In your outbound transformer create a dummy message template as follows: This is just a namesake template, that you're defining to create a HL7 segment scope.
Considering you receive JSON something like this:
I dont think this syntax is correct
createSegment('MSH', msg, i++);
I have modified the code you provided above:You can also increment counter in the HL7 message in your suggested way no wrong. refer counter : Adding Multiple NTE segments to HL7 message with Mirth