web stats
need some looping help - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
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:

Code:
<ClinicalDocument>
    <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.10.20.19.1"/>
    <id domain="AcumenEHR" extension="116158717"/>
    <noteStatus value="E"/>
    <hie_outbound_reason_revised>too early in the month</hie_outbound_reason_revised>
    <ReasonReversed/>
    <custodian>
        <assignedcustodian>1271</assignedcustodian>
    </custodian>
    <noteType>CDE_ProvImpComp</noteType>
    <effectiveDateTime value="2018-01-02 11:15:00.0"/>
    <languageCode code="en-us"/>
    <recordTarget>
        <patientRole>
            <id assigningAuthorityName="AcumenEHR" extension="DFQA_5000305594" root=""/>
            <id assigningAuthorityName="AcumenEHR" extension="AIN_134706" root=""/>
            <id assigningAuthorityName="Fresenius" extension="5000305594" root=""/>
            <addr>
                <streetAddressLine>32 Hartwell Ave</streetAddressLine>
                <city>Lexington</city>
                <state>MA</state>
                <postalCode>02421</postalCode>
                <country/>
            </addr>
            <telecom value=""/>
            <patient>
                <name>
                    <prefix/>
                    <given>TESTPA1</given>
                    <family>EGATEORD</family>
                </name>
                <administrativeGenderCode code="F" codeSystem="2.16.840.1.113883.5.1"/>
                <birthTime value="1961-12-03"/>
                <id extension="SSN"/>
            </patient>
            <id extension="DFQA_5000305594"/>
            <patientschedule>null</patientschedule>
            <patientshift>null</patientshift>
        </patientRole>
    </recordTarget>
</ClinicalDocument>

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.

Thanks
Reply With Quote
  #2  
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
Default

Hi,

Your'e close : for (i=0;i<msg['recordTarget']['patientRole']['id'].length();i++)
__________________
Tom
Reply With Quote
  #3  
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
Default

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.

Code:
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.

Code:
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
Reply

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