I have an issue with the trandformation og an HL7 message to XML in Mrth.
The problem I have is that the message segment has two instances in it which I now need to to seperate into two xml tage.
so the HL7 segement looks like this:
PID|1|16^^^MEDAVIS^PI|||MyTest^TEST 2^T^^MISS~Test2^^^^^^B|00MemberCode|19921106|M|||MANNING ROAD^^DURBAN^^4001^ZA||0313017352~072363395^^CP~^NET^Internet^[email protected]|0313017352~072363395^^CP~^NET^Internet^[email protected]|||||123456PatDepCode|||||||ZA||||N
So the issue is with the PID segment where there are multiple tags in segement 5 (name) and then also in segment
The transformation I have been using with a different vendor feeding information to our system only used one tage in the segment and looked like this:
tmp['Patient']['Name']= msg['PID']['PID.5']['PID.5.2'].toString();
tmp['Patient']['Surname'] = msg['PID']['PID.5']['PID.5.1'].toString();
The problem is that with the two segments in the code I end up with this mess
<Name><PID.5.2>TEST 2</PID.5.2><PID.5.2/></Name>
<Surname><PID.5.1>TEST G4M Nachname</PID.5.1><PID.5.1>NameOfBirth</PID.5.1></Surname>
How do I alter the ransform so the forst segment would be something likename 1 and surname1 and the second segment name2 and surname2
UPDATE: I have updated the transform code and it gives the right result but their is still an error message, despite it producing the reuslt using the code with the error.
<PID.5> <PID.5.1>TEST G4M Nachname</PID.5.1> <PID.5.2>TEST 2</PID.5.2> <PID.5.3>T</PID.5.3> <PID.5.4/> <PID.5.5>MISS</PID.5.5> </PID.5> <PID.5> <PID.5.1>NameOfBirth</PID.5.1> <PID.5.2/> <PID.5.3/> <PID.5.4/> <PID.5.5/> <PID.5.6/> <PID.5.7>B</PID.5.7> </PID.5>
So the adjusted transform looks like:
/*patient name seperation*/
var segmentlength = msg['PID']['PID.5']['PID.5.2'].toString().length;
var tildeappears = msg['PID']['PID.5']['PID.5.2'].toString().indexof('~');
tmp['Patient']['Name'] = msg['PID']['PID.5']['PID.5.1'].toString().substring(0,tildeappears-1);
tmp['Patient']['Name1']= msg['PID']['PID.5']['PID.5.1'].toString().substring(tildeappears+1,segmentlength)
But when run Mirth returns this error:
Transformer error ERROR MESSAGE: Error evaluating transformer com.mirth.connect.server.MirthJavascriptTransformerException: CHANNEL: AGFA_DFT_PayloadBuilderV3 CONNECTOR: OutputLog SCRIPT SOURCE: TRANSFORMER SOURCE CODE: 604: tmp['Patient']['MRN'] = msg['PID']['PID.3']['PID.3.1'].toString(); 605: 606: /patient name seperation/ 607: 608: var segmentlength = msg['PID']['PID.5']['PID.5.2'].toString().length; 609: tildeappears = msg['PID']['PID.5']['PID.5.2'].toString().indexof('~'); 610: tmp['Patient']['Name'] = msg['PID']['PID.5']['PID.5.2'].toString().substring(0,tildeappears-1); 611: tmp['Patient']['Name1']= msg['PID']['PID.5']['PID.5.2'].toString().substring(tildeappears+1,segmentlength); 612: tmp['Patient']['Surname'] = msg['PID']['PID.5']['PID.5.1'].toString(); 613: LINE NUMBER: 609 DETAILS: TypeError: Cannot find function indexof in object TEST 2. at 40699b8f-7c07-4eaf-8d54-e6f423be853b:609 (doTransform) at 40699b8f-7c07-4eaf-8d54-e6f423be853b:792 (doScript) at 40699b8f-7c07-4eaf-8d54-e6f423be853b:794 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(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)