Varatharaj Gopal
Varatharaj Gopal

Reputation: 1

Mirth -> HL7 into XML conversion Ques

I'm new to the Mirth Connect When I tried to convert HL7 into XML I 'm struggling.Suppose my HL7 messages have repeat segments like ORC in ORM Messages how to iterate that. below is my code:

tmp['Messages']['orderList']['order'][count]['provider']=msg['ORC'][count]['ORC.10']['ORC.10.1'].toString();

but it is throwing an error:

`TypeError: Cannot read property "provider"` from undefined.

please help me to proceed further.

Upvotes: 0

Views: 1018

Answers (1)

agermano
agermano

Reputation: 1729

It's failing because your count is higher than the number of elements returned by tmp['Messages']['orderList']['order'], so it is returning undefined. The short answer is that you need to add another order node to tmp['Messages']['orderList'] before you can access it. It's hard to say how best to do that without seeing more of your code, requirements, outbound template, etc... Most frequently I build the node first, and then use appendChild to add it.

A simple example would be:

var tmp = <xml>
    <Messages>
        <orderList />
    </Messages>
</xml>;

var prov = 12345;
var nextOrder = <order>
    <provider>{prov}</provider>
</order>;

tmp.Messages.orderList.appendChild(nextOrder);

After which, tmp will look like:

<xml>
    <Messages>
        <orderList>
            <order>
                <provider>12345</provider>
            </order>
        </orderList>
    </Messages>
</xml>

The technology you are using to work with xml is called e4x, and it's running on the Mozilla Rhino Javascript engine. Here are a couple resources that might help you.

https://web.archive.org/web/20181120184304/https://wso2.com/project/mashup/0.2/docs/e4xquickstart.html

https://developer.mozilla.org/en-US/docs/Archive/Web/E4X/Processing_XML_with_E4X

Upvotes: 1

Related Questions