web stats
e4x for each in javascript transformer step - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-13-2012, 01:09 PM
johnvoigt johnvoigt is offline
OBX.1 Kenobi
 
Join Date: Jun 2011
Posts: 26
johnvoigt is on a distinguished road
Default e4x for each in javascript transformer step

I have an xml javascript element x-

<PatientOrder>
<MSH_LocationID>1107</MSH_LocationID>
<MPS_PatientID>1071</MPS_PatientID>
<PID_AdmissionNumber>werwer</PID_AdmissionNumber>
<PID_FirstName>TEST</PID_FirstName>
<PID_LastName>MMI</PID_LastName>
<PID_DateOfBirth>1986-05-05T00:00:00</PID_DateOfBirth>
<PID_Sex>M</PID_Sex>
<ORC_Control>NW</ORC_Control>
<ORC_PharmacyOrderID>81050</ORC_PharmacyOrderID>
<ORC_EffectiveDate>20110927120000</ORC_EffectiveDate>
<RXO_DrugID>11000010002105</RXO_DrugID>
<RXO_UsesGPI>1</RXO_UsesGPI>
<RXO_DrugName>CMP Amphotericin B 15mg/10ml D5W</RXO_DrugName>
<RXO_GiveAmount>1.0000000e+000</RXO_GiveAmount>
<RXO_GiveUnits>amp(s)</RXO_GiveUnits>
<RXO_DrugForm>amp(s)</RXO_DrugForm>
<RXO_AdministrationInstructions>*3 Times a Day 8AM,12PM,4PM</RXO_AdministrationInstructions>
<RXO_Route>BOTH EYES (Ophthalmic)</RXO_Route>
<RXO_SpecialInstructions />
<RXE_SubstitutionFlag>N</RXE_SubstitutionFlag>
<RXC>
<CompoundItem>
<RXC_Code>80100020002015</RXC_Code>
<RXC_Strength>5</RXC_Strength>
<RXC_StrengthUnits>%</RXC_StrengthUnits>
<RXC_Amount>1.0000000e+001</RXC_Amount>
</CompoundItem>
<CompoundItem>
<RXC_Code>76567567658</RXC_Code>
<RXC_Strength>6</RXC_Strength>
<RXC_StrengthUnits>%</RXC_StrengthUnits>
<RXC_Amount>4.0000000e+001</RXC_Amount>
</CompoundItem>
</RXC>
<RXE_Route>BOTH EYES (Ophthalmic)</RXE_Route>
<ORC_EnteredBy>erichermps</ORC_EnteredBy>
<ORC_PharmacyCallbackPhone>1-866-GO-MPSRx</ORC_PharmacyCallbackPhone>
<RXO_PhysicianDEANumber>11111</RXO_PhysicianDEANumber>
</PatientOrder>

I am trying to loop through the coumpound items

I am trying to loop through each of the <CompoundItem>
children and do something with the values in each of the children's items.

I have the following
for each (seg in x..CompoundItem)
{
logger.error('NEW CHild SEGMENT found');
}
but i get an error like The content of elements must consist of well-formed character data or markup.

How would i parse though to read those child values into hl7 segements?

THanks
Reply With Quote
  #2  
Old 02-13-2012, 01:32 PM
upstart33 upstart33 is offline
Mirth Guru
 
Join Date: Dec 2010
Location: Chicago, IL.
Posts: 461
upstart33 is on a distinguished road
Default

Try this to see if it gets you started;

Code:
msg = new XML(msg.toString().replace(/ns[0-9]\:/g,''));

for each (var seg in msg['CompoundItem']) {
logger.error(seg);
}

or
msg = new XML(msg.toString().replace(/ns[0-9]\:/g,''));

for each (var seg in msg.getChildren()) {
logger.error(seg);
}
Reply With Quote
  #3  
Old 02-13-2012, 02:18 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

In the stacktrace, does it show what line the error occurred at?

Given the XML structure you posted and assuming a variable "x" contains said XML, you would loop through the CompoundItem elements like so:

Code:
for each (rxc in x.RXC)
	for each (compoundItem in rxc['CompoundItem']) {
		// Do something
		logger.info('RXC Code: '+compoundItem['RXC_Code'].toString());
		logger.info('RXC Strength: '+compoundItem['RXC_Strength'].toString());
		logger.info('RXC StrengthUnits: '+compoundItem['RXC_StrengthUnits'].toString());
		logger.info('RXC Amount: '+compoundItem['RXC_Amount'].toString());
	}
Reply With Quote
  #4  
Old 02-14-2012, 05:55 AM
johnvoigt johnvoigt is offline
OBX.1 Kenobi
 
Join Date: Jun 2011
Posts: 26
johnvoigt is on a distinguished road
Default

Thanks for your help. Based on the above I actually figured out what i needed to do. Since i wanted to drill down 2 levels i put something like this
for each (seg in x['RXC'].CompoundItem)
{
logger.error(seg.CompoundItem.RXC_Code);
etc.......
Reply With Quote
Reply

Tags
e4x, javascript, xml child segments

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 01:43 PM.


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