Announcement

Collapse
No announcement yet.

e4x for each in javascript transformer step

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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);
    }

    Comment


    • #3
      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());
      	}
      Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

      Nicholas Rupley
      Work: 949-237-6069
      Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


      - How do I foo?
      - You just bar.

      Comment


      • #4
        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.......

        Comment

        Working...
        X