web stats
need some looping help - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 03-20-2018, 04:37 AM
rutledj rutledj is offline
Mirth Guru
Join Date: Nov 2010
Location: North Carolina
Posts: 399
rutledj is on a distinguished road
Default need some looping help

Given this xml:

    <templateId root="2.16.840.1.113883.10.20.3"/>
    <typeId extension="POCD_HD000040" root="2.16.840.1.113883.1.3"/>
    <templateId root="2.16.840.1.113883."/>
    <id domain="AcumenEHR" extension="116158717"/>
    <noteStatus value="E"/>
    <hie_outbound_reason_revised>too early in the month</hie_outbound_reason_revised>
    <effectiveDateTime value="2018-01-02 11:15:00.0"/>
    <languageCode code="en-us"/>
            <id assigningAuthorityName="AcumenEHR" extension="DFQA_5000305594" root=""/>
            <id assigningAuthorityName="AcumenEHR" extension="AIN_134706" root=""/>
            <id assigningAuthorityName="Fresenius" extension="5000305594" root=""/>
                <streetAddressLine>32 Hartwell Ave</streetAddressLine>
            <telecom value=""/>
                <administrativeGenderCode code="F" codeSystem="2.16.840.1.113883.5.1"/>
                <birthTime value="1961-12-03"/>
                <id extension="SSN"/>
            <id extension="DFQA_5000305594"/>

how, in a source transformer step, do you loop through the id's under the <patientRole> tag?

I tried for (i=0;i<msg['recordTarget']['patientRole']['id'].length;i++)
but this does not work. It doesn't see a length here.

Reply With Quote
Old 03-20-2018, 04:56 AM
aTom aTom is offline
OBX.3 Kenobi
Join Date: Feb 2016
Location: Lake Geneva Area
Posts: 115
aTom is on a distinguished road


Your'e close : for (i=0;i<msg['recordTarget']['patientRole']['id'].length();i++)
Reply With Quote
Old 03-20-2018, 08:45 AM
agermano agermano is offline
Mirth Guru
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,176
agermano is on a distinguished road

aTom is correct that for e4x objects, length is a function, not a property.

It's usually a little cleaner to use a for each..in loop instead of a for loop unless the index value is important to know. You can also use the dot notation with generic xml. It doesn't work for HL7 because the element names contain dots.

for each (var id in msg.recordTarget.patientRole.id) {
  extension = id.@extension.toString();
If you are looking for a particular id, you can also use filtering and skip the loop entirely.

msg.recordTarget.patientRole.id.(@extension.match(/^AIN/) != null).@extension.toString()
// returns 'AIN_134706'

msg.recordTarget.patientRole.id.(@assigningAuthorityName == 'Fresenius').@extension.toString();
// returns '5000305594'

Last edited by agermano; 03-20-2018 at 08:48 AM.
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 02:53 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation