Announcement

Collapse
No announcement yet.

E4X syntax help please

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

  • E4X syntax help please

    I can do this:

    Code:
    msg.Assignments.Assignment.(Primary_Assignment == 1).Assignment_Start_Date.toString().replace('-','')+"000000";
    just fine, but cannot do this:

    Code:
    msg['Assignments']['Assignment'](Primary_Assignment == 1)['Assignment_Start_Date'].toString().replace('-','')+"000000";
    How do I filter when using the square brackets?

    Simon

  • #2
    You can't, because the square bracket notation is meant for string literals (or expressions that evaluate to such), that are then used to look up the property name. It's not even part of E4X, it's part of the overarching ECMAScript standard.
    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


    • #3
      Have you tried the following?

      Code:
      msg['Assignments']['Assignment'][(Primary_Assignment == 1).toString()]['Assignment_Start_Date'].toString().replace('-','')+"000000";
      All node references and subscripts need to be enclosed in brackets, even when values are calculated or concatenated and, as Mr. Rupley wisely stated, they must be text.
      Last edited by Jon Blanchard; 07-25-2014, 08:20 AM.
      Thanks.

      Jon

      Comment


      • #4
        Originally posted by Jon Blanchard View Post
        Have you tried the following?

        Code:
        msg['Assignments']['Assignment'][(Primary_Assignment == 1).toString()]['Assignment_Start_Date'].toString().replace('-','')+"000000";
        All node references and subscripts need to be enclosed in brackets, even when values are calculated or concatenated.
        Unfortunately that won't quite work either, because it's going to try to reference "Primary_Assignment". If that is an externally defined variable then that would be fine, but if it's a child node then it won't work, because at that point you're not working with the E4X construct anymore. Also, property references of objects don't necessarily need to be enclosed in brackets. For example, this:

        Code:
        msg.MSH
        is equivalent to this:

        Code:
        msg['MSH']
        The bracket notation is only needed when you're doing something more complex like referring to a property name which has non-identifier characters in it (like "." or "-"), or when you want to use an expression to evaluate the property name. For example, this will work:

        Code:
        msg.MSH['MSH.1']
        But this will not:

        Code:
        msg.MSH.MSH.1
        Hopefully it's obvious why: In the first example you're referencing the "MSH.1" property of the "MSH" object. The second example would just throw a syntax error at runtime (or fail to compile through Rhino) because "1" is an invalid identifier. Even if it was correct syntax it still wouldn't work because now you're referencing the "1" property of the "MSH" property of the "MSH" parent object (I mean, unless that really is how the inheritance tree is structured).

        The same holds true even for native arrays. You can reference an element like array[1], and even array['1'], but you can't reference it with array.1.

        Again, everything I've described doesn't even have to do with E4X at all, it's just a part of ECMA-262.
        Last edited by narupley; 07-25-2014, 08:26 AM.
        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


        • #5
          Thanks for the clarification. I can use

          Code:
          msg.Assignments.Assignment.(Primary_Assignment == 1).Assignment_Start_Date.toString()
          I was just asking because drag and drop from a message template gives you the square brackets by default even when it does not need to.

          Thank you both for your input,
          Simon

          Comment


          • #6
            I assumed that seaston would understand, and therefore didn't mention, that Primary_Assignment will have to be a variable in order for my version to work. Otherwise, s/he would have to expound even further to absolutely identify the value at node Primary_Assignment, then apply the .toString() method. I am not trying to invalidate anything narupley has said, but state that I believe it is possible, but much more cumbersome.

            Without an example XML document that the statement is applied to, a more definitive answer is fleeting.
            Thanks.

            Jon

            Comment


            • #7
              This does rather leave me wondering if it is at all possible to use that filtering method on say one of the PID.3 values in this fictitious message or indeed any XML with dots present in the tags:


              Code:
              <HL7Message>
                  <MSH>
                      <MSH.1>|</MSH.1>
                      <MSH.2>^~\&amp;</MSH.2>
                      <MSH.3>
                          <MSH.3.1>ADT1</MSH.3.1>
                      </MSH.3>
                      <MSH.4>
                          <MSH.4.1>SHM</MSH.4.1>
                      </MSH.4>
                      <MSH.5>
                          <MSH.5.1>SHMADT</MSH.5.1>
                      </MSH.5>
                      <MSH.6>
                          <MSH.6.1>SHM</MSH.6.1>
                      </MSH.6>
                      <MSH.7>
                          <MSH.7.1>200812091126</MSH.7.1>
                      </MSH.7>
                      <MSH.8>
                          <MSH.8.1>SECURITY</MSH.8.1>
                      </MSH.8>
                      <MSH.9>
                          <MSH.9.1>ADT</MSH.9.1>
                          <MSH.9.2>A01</MSH.9.2>
                          <MSH.9.3>ADT_A01</MSH.9.3>
                      </MSH.9>
                      <MSH.10>
                          <MSH.10.1>MSG00001</MSH.10.1>
                      </MSH.10>
                      <MSH.11>
                          <MSH.11.1>P</MSH.11.1>
                      </MSH.11>
                      <MSH.12>
                          <MSH.12.1>2.5</MSH.12.1>
                      </MSH.12>
                      <MSH.13/>
                  </MSH>
                  <EVN>
                      <EVN.1>
                          <EVN.1.1>A01</EVN.1.1>
                      </EVN.1>
                      <EVN.2>
                          <EVN.2.1>200812091126</EVN.2.1>
                      </EVN.2>
                      <EVN.3/>
                      <EVN.4/>
                  </EVN>
                  <PID>
                      <PID.1>
                          <PID.1.1>1</PID.1.1>
                      </PID.1>
                      <PID.2>
                          <PID.2.1>1001</PID.2.1>
                      </PID.2>
                      <PID.3>
                          <PID.3.1>1001</PID.3.1>
                          <PID.3.2>5</PID.3.2>
                          <PID.3.3>M11</PID.3.3>
                          <PID.3.4>ADT1</PID.3.4>
                          <PID.3.5>MR</PID.3.5>
                          <PID.3.6>SHM</PID.3.6>
                      </PID.3>
                      <PID.3>
                          <PID.3.1>123456789</PID.3.1>
                          <PID.3.2/>
                          <PID.3.3/>
                          <PID.3.4>USSSA</PID.3.4>
                          <PID.3.5>SS</PID.3.5>
                      </PID.3>
                      <PID.4/>
                      <PID.5>
                          <PID.5.1>OHALLAHAN</PID.5.1>
                          <PID.5.2>COLLEEN</PID.5.2>
                          <PID.5.3/>
                          <PID.5.4/>
                      </PID.5>
                      <PID.6/>
                      <PID.7>
                          <PID.7.1>19850704</PID.7.1>
                      </PID.7>
                      <PID.8>
                          <PID.8.1>F</PID.8.1>
                      </PID.8>
                      <PID.9/>
                      <PID.10>
                          <PID.10.1>2106-3</PID.10.1>
                      </PID.10>
                      <PID.11>
                          <PID.11.1>1200 N ELM STREET</PID.11.1>
                          <PID.11.2/>
                          <PID.11.3>NEWPORT BEACH</PID.11.3>
                          <PID.11.4>CA</PID.11.4>
                          <PID.11.5>92660-1020</PID.11.5>
                          <PID.11.6>US</PID.11.6>
                          <PID.11.7>H</PID.11.7>
                      </PID.11>
                      <PID.12>
                          <PID.12.1>OC</PID.12.1>
                      </PID.12>
                      <PID.13>
                          <PID.13.1>(949) 555-1234</PID.13.1>
                      </PID.13>
                      <PID.14>
                          <PID.14.1>(949) 555-5678</PID.14.1>
                      </PID.14>
                      <PID.15/>
                      <PID.16>
                          <PID.16.1>S</PID.16.1>
                      </PID.16>
                      <PID.17/>
                      <PID.18>
                          <PID.18.1>PATID1001</PID.18.1>
                          <PID.18.2>2</PID.18.2>
                          <PID.18.3>M10</PID.18.3>
                          <PID.18.4>ADT1</PID.18.4>
                          <PID.18.5>AN</PID.18.5>
                          <PID.18.6>A</PID.18.6>
                      </PID.18>
                      <PID.19>
                          <PID.19.1>123456789</PID.19.1>
                      </PID.19>
                      <PID.20>
                          <PID.20.1>U1234567</PID.20.1>
                          <PID.20.2>CA</PID.20.2>
                      </PID.20>
                      <PID.21/>
                  </PID>
                  <NK1>
                      <NK1.1>
                          <NK1.1.1>1</NK1.1.1>
                      </NK1.1>
                      <NK1.2>
                          <NK1.2.1>OHALLAHAN</NK1.2.1>
                          <NK1.2.2>BRITTANY</NK1.2.2>
                          <NK1.2.3>M</NK1.2.3>
                      </NK1.2>
                      <NK1.3>
                          <NK1.3.1>SIS</NK1.3.1>
                          <NK1.3.2>SISTER</NK1.3.2>
                      </NK1.3>
                      <NK1.4/>
                      <NK1.5/>
                      <NK1.6/>
                      <NK1.7>
                          <NK1.7.1>N</NK1.7.1>
                          <NK1.7.2>NEXT-OF-KIN</NK1.7.2>
                      </NK1.7>
                  </NK1>
                  <PV1>
                      <PV1.1>
                          <PV1.1.1>1</PV1.1.1>
                      </PV1.1>
                      <PV1.2>
                          <PV1.2.1>I</PV1.2.1>
                      </PV1.2>
                      <PV1.3>
                          <PV1.3.1>2000</PV1.3.1>
                          <PV1.3.2>2012</PV1.3.2>
                          <PV1.3.3>01</PV1.3.3>
                      </PV1.3>
                      <PV1.4/>
                      <PV1.5/>
                      <PV1.6/>
                      <PV1.7>
                          <PV1.7.1>001122</PV1.7.1>
                          <PV1.7.2>ZOIDBERG</PV1.7.2>
                          <PV1.7.3>JOHN</PV1.7.3>
                          <PV1.7.4/>
                      </PV1.7>
                      <PV1.8/>
                      <PV1.9/>
                      <PV1.10>
                          <PV1.10.1>SUR</PV1.10.1>
                      </PV1.10>
                      <PV1.11/>
                      <PV1.12/>
                      <PV1.13/>
                      <PV1.14>
                          <PV1.14.1>1</PV1.14.1>
                      </PV1.14>
                      <PV1.15>
                          <PV1.15.1>A0</PV1.15.1>
                      </PV1.15>
                      <PV1.16/>
                  </PV1>
              </HL7Message>
              Simon

              Comment


              • #8
                It is possible, but the syntax is a bit more complicated:

                Code:
                msg.PID['PID.3'].(function(){return XML(this)['PID.3.1']=='1001'}())
                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

                Working...
                X