Announcement

Collapse
No announcement yet.

Loop through XML to HL7

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

  • Loop through XML to HL7

    I've tried a number of options. What appears below does NOT work, but nothing else has so far either.
    The code below it only iterates once, no matter what I have done. This is in the source transformer side.

    I have incoming (test data, no HIPPA violation)

    Code:
        <Insurances>
            <Insurance>
                <id>P</id>
                <co_name>Blue Cross Blue Sheild</co_name>
                <co_strt/>
                <co_city>Washington</co_city>
                <co_state>DC</co_state>
                <co_zip>DC</co_zip>
                <co_phone>(   )   -</co_phone>
                <co_attn>Claims</co_attn>
                <neiccode>-</neiccode>
                <ins_last>Adams</ins_last>
                <ins_first>Michelle</ins_first>
                <ins_strt>345 Shoreline Drive</ins_strt>
                <ins_city>Westlake Village</ins_city>
                <ins_stat>CA</ins_stat>
                <ins_zip>91362</ins_zip>
                <ins_phon>(818)987-4455</ins_phon>
                <ins_dob>4/4/1992</ins_dob>
                <ins_sex>F</ins_sex>
                <ins_num>777669999</ins_num>
                <ins_grp/>
                <ins_gpnm/>
                <ins_emp/>
                <ins_local/>
            </Insurance>
            <Insurance>
                <id>P</id>
                <co_name>Medicare</co_name>
                <co_strt>12345 Your Town</co_strt>
                <co_city>Westside</co_city>
                <co_state>US</co_state>
                <co_zip>99999</co_zip>
                <co_phone>(123)123-1234</co_phone>
                <co_attn/>
                <neiccode>-</neiccode>
                <ins_last>Adams</ins_last>
                <ins_first>Michelle</ins_first>
                <ins_strt>345 Shoreline Drive East</ins_strt>
                <ins_city>Westlake Village</ins_city>
                <ins_stat>CA</ins_stat>
                <ins_zip>91362</ins_zip>
                <ins_phon>(818)987-4455</ins_phon>
                <ins_dob>4/4/1992</ins_dob>
                <ins_sex>M</ins_sex>
                <ins_num/>
                <ins_grp/>
                <ins_gpnm/>
                <ins_emp/>
                <ins_local/>
            </Insurance>
            <Insurance>
                <id>2</id>
                <co_name>AARP Grp Health Ins Program</co_name>
                <co_strt>PO Box 1011</co_strt>
                <co_city>Montgomeryville</co_city>
                <co_state>PA</co_state>
                <co_zip>189361011</co_zip>
                <co_phone>(201)   -</co_phone>
                <co_attn>AARP Claim Unit</co_attn>
                <neiccode>NEIC</neiccode>
                <ins_last>Adams</ins_last>
                <ins_first>Michelle</ins_first>
                <ins_strt>24 Union Avenue</ins_strt>
                <ins_city>Westlake Village</ins_city>
                <ins_stat>CA</ins_stat>
                <ins_zip>91362</ins_zip>
                <ins_phon>(818)987-4455</ins_phon>
                <ins_dob>4/4/1947</ins_dob>
                <ins_sex>M</ins_sex>
                <ins_num>777669999</ins_num>
                <ins_grp/>
                <ins_gpnm/>
                <ins_emp/>
                <ins_local/>
            </Insurance>
        </Insurances>
    The code for parsing the XML out to IN1 segments that I have looks like the following. And I know each line is parsed differently. I was trying to find out what works.
    Nothing so far. I know it's me, but I need to get over this hump. Thanks.
    Code:
    var counter = 0;
    var IN1i = <IN1><IN1.1><IN1.1.1></IN1.1.1></IN1.1><IN1.2><IN1.2.1></IN1.2.1><IN1.2.2></IN1.2.2><IN1.2.3></IN1.2.3></IN1.2><IN1.3><IN1.3.1></IN1.3.1></IN1.3> <IN1.4><IN1.4.1></IN1.4.1></IN1.4><IN1.5><IN1.5.1></IN1.5.1></IN1.5><IN1.6><IN1.6.1></IN1.6.1></IN1.6></IN1>;
    for each (msg['Insurance'] in msg){
        tmp['IN1'][counter] = IN1i;
        tmp['IN1'][counter]['IN1.1']['IN1.1.1'] = counter + 1;
        tmp['IN1'][counter]['IN1.2']['IN1.2.1'] =  ['INS_NUM'].toString();
        tmp['IN1'][counter]['IN1.2']['IN1.2.2'] =  msg['Insurance']['INS_GRP'].toString();
        tmp['IN1'][counter]['IN1.2']['IN1.2.3'] = 'CMP_DEMO';
        tmp['IN1'][counter]['IN1.3']['IN1.3.1']= 'INS_ID';
        tmp['IN1'][counter]['IN1.4']['IN1.4.1'] =  msg['Insurances']['Insurance']['CO_NAME'].toString();
        counter++;
        channelMap.put("HighCounter",counter.toString());
    }
    HighCounter was used to see if it was going past 1. It hasn't.
    The result is here
    Code:
    MSH|^~\&|ADT_COMPULINK|COMPULINK1|IFASYSTEMS|HELLS_HOSPITAL|||ADT^A04|1303106|P|2.3.1||||||||
    IN1|1|INS_NUM^^CMP_DEMO|INS_ID|||
    Post edited by: dugjohnson, at: 10/09/2007 13:29

  • #2
    Re:Loop through XML to HL7

    I see the first problem, sorry:
    Code:
    for each (insurance in msg['Insurance']){
       //here you can access insurance as a var, like insurance['INS_GRP'];
    
    }
    Alternatively, you can try doing a direct for loop:

    Code:
    for (var i = 0; i < msg['Insurance'].length; i++){
       var insurance = msg['Insurance'][i];
    
    }
    Chris Lang

    Comment


    • #3
      Re:Loop through XML to HL7

      The following per your idea
      Code:
      var counter = 0;
      var IN1i = <IN1><IN1.1><IN1.1.1></IN1.1.1></IN1.1><IN1.2><IN1.2.1></IN1.2.1><IN1.2.2></IN1.2.2><IN1.2.3></IN1.2.3></IN1.2><IN1.3><IN1.3.1></IN1.3.1></IN1.3> <IN1.4><IN1.4.1></IN1.4.1></IN1.4><IN1.5><IN1.5.1></IN1.5.1></IN1.5><IN1.6><IN1.6.1></IN1.6.1></IN1.6></IN1>;
      for each (insurance in msg['Insurance']){
          tmp['IN1'][counter] = IN1i;
          tmp['IN1'][counter]['IN1.1']['IN1.1.1'] = counter + 1;
          tmp['IN1'][counter]['IN1.2']['IN1.2.1'] =  insurance['INS_NUM'].toString();
          tmp['IN1'][counter]['IN1.2']['IN1.2.2'] =  insurance['INS_GRP'].toString();
          tmp['IN1'][counter]['IN1.2']['IN1.2.3'] = 'CMP_DEMO';
          tmp['IN1'][counter]['IN1.3']['IN1.3.1']= 'INS_ID';
          tmp['IN1'][counter]['IN1.4']['IN1.4.1'] =  insurance['CO_NAME'].toString();
          counter++;
          channelMap.put("HighCounter",counter.toString());
      }
      produces
      Code:
      MSH|^~\&|ADT_COMPULINK|COMPULINK1|IFASYSTEMS|HELLS_HOSPITAL|||ADT^A04|1303106|P|2.3.1||||||||
      Yeah, I know. No IN1s.
      This
      Code:
      var counter = 0;
      var IN1i = <IN1><IN1.1><IN1.1.1></IN1.1.1></IN1.1><IN1.2><IN1.2.1></IN1.2.1><IN1.2.2></IN1.2.2><IN1.2.3></IN1.2.3></IN1.2><IN1.3><IN1.3.1></IN1.3.1></IN1.3> <IN1.4><IN1.4.1></IN1.4.1></IN1.4><IN1.5><IN1.5.1></IN1.5.1></IN1.5><IN1.6><IN1.6.1></IN1.6.1></IN1.6></IN1>;
      for each (insurance in msg..Insurance){
          tmp['IN1'][counter] = IN1i;
          tmp['IN1'][counter]['IN1.1']['IN1.1.1'] = counter + 1;
          tmp['IN1'][counter]['IN1.2']['IN1.2.1'] =  insurance['INS_NUM'].toString();
          tmp['IN1'][counter]['IN1.2']['IN1.2.2'] =  insurance['INS_GRP'].toString();
          tmp['IN1'][counter]['IN1.2']['IN1.2.3'] = 'CMP_DEMO';
          tmp['IN1'][counter]['IN1.3']['IN1.3.1']= 'INS_ID';
          tmp['IN1'][counter]['IN1.4']['IN1.4.1'] =  insurance['CO_NAME'].toString();
          counter++;
          channelMap.put("HighCounter",counter.toString());
      }
      produces this
      Code:
      MSH|^~\&|ADT_COMPULINK|COMPULINK1|IFASYSTEMS|HELLS_HOSPITAL|||ADT^A04|1303106|P|2.3.1||||||||
      IN1|1|^^CMP_DEMO|INS_ID|||
      IN1|2|^^CMP_DEMO|INS_ID|||
      IN1|3|^^CMP_DEMO|INS_ID|||
      Better, the right number of records, but still no data.
      And, yes, I'm looking at the ECMA Stuff.

      Comment


      • #4
        Re:Loop through XML to HL7

        Try lower-case strings

        'INS_NUM', "INS_GRP' should be 'ins_num' and 'ins_grp'
        Chris Lang

        Comment


        • #5
          Re:Loop through XML to HL7

          The following gives an Error
          Code:
          var counter = 0;
          var IN1i = <IN1><IN1.1><IN1.1.1></IN1.1.1></IN1.1><IN1.2><IN1.2.1></IN1.2.1><IN1.2.2></IN1.2.2><IN1.2.3></IN1.2.3></IN1.2><IN1.3><IN1.3.1></IN1.3.1></IN1.3> <IN1.4><IN1.4.1></IN1.4.1></IN1.4><IN1.5><IN1.5.1></IN1.5.1></IN1.5><IN1.6><IN1.6.1></IN1.6.1></IN1.6></IN1>;
          for each (insurance in msg..Insurance){
              tmp['IN1'][counter] = IN1i;
              tmp['IN1'][counter]['IN1.1']['IN1.1.1'] = counter + 1;
              tmp['IN1'][counter]['IN1.2']['IN1.2.1'] =  insurance['ins_num'];
              tmp['IN1'][counter]['IN1.2']['IN1.2.2'] =  insurance['ins_grp'];
              tmp['IN1'][counter]['IN1.2']['IN1.2.3'] = 'CMP_DEMO';
              tmp['IN1'][counter]['IN1.3']['IN1.3.1']= 'INS_ID';
              tmp['IN1'][counter]['IN1.4']['IN1.4.1'] =  insurance['co_name'];
              counter++;
              channelMap.put("HighCounter",counter.toString());
          }
          Error
          Code:
          ERROR-300: Transformer error
          ERROR MESSAGE:	Error evaluating transformer
          com.webreach.mirth.model.converters.SerializerException: java.lang.ArrayIndexOutOfBoundsException: 2
          	at com.webreach.mirth.model.converters.ER7Serializer.fromXML(ER7Serializer.java:168)
          	at com.webreach.mirth.model.converters.ER7Serializer.fromXML(ER7Serializer.java:50)
          	at com.webreach.mirth.server.mule.transformers.JavaScriptTransformer.evaluateTransformerScript(JavaScriptTransformer.java:406)
          	at com.webreach.mirth.server.mule.transformers.JavaScriptTransformer.transform(JavaScriptTransformer.java:286)
          	at org.mule.transformers.AbstractEventAwareTransformer.doTransform(AbstractEventAwareTransformer.java:48)
          	at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:197)
          	at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:200)
          	at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:200)
          	at org.mule.impl.MuleEvent.getTransformedMessage(MuleEvent.java:251)
          	at org.mule.routing.inbound.SelectiveConsumer.isMatch(SelectiveConsumer.java:61)
          	at org.mule.routing.inbound.InboundMessageRouter.route(InboundMessageRouter.java:79)
          	at org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:492)
          	at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:271)
          	at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:230)
          	at com.webreach.mirth.connectors.file.FileMessageReceiver.processFile(FileMessageReceiver.java:208)
          	at com.webreach.mirth.connectors.file.FileMessageReceiver.poll(FileMessageReceiver.java:130)
          	at org.mule.providers.PollingMessageReceiver.run(PollingMessageReceiver.java:118)
          	at org.mule.impl.work.WorkerContext.run(WorkerContext.java:290)
          	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
          	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
          	at java.lang.Thread.run(Unknown Source)
          Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
          	at com.webreach.mirth.model.converters.ER7XMLHandler.startElement(ER7XMLHandler.java:130)
          	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
          	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
          	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
          	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
          	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
          	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
          	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
          	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
          	at com.webreach.mirth.model.converters.ER7Serializer.fromXML(ER7Serializer.java:163)
          	... 20 more
          The following does not
          Code:
          var counter = 0;
          var IN1i = <IN1><IN1.1><IN1.1.1></IN1.1.1></IN1.1><IN1.2><IN1.2.1></IN1.2.1><IN1.2.2></IN1.2.2><IN1.2.3></IN1.2.3></IN1.2><IN1.3><IN1.3.1></IN1.3.1></IN1.3> <IN1.4><IN1.4.1></IN1.4.1></IN1.4><IN1.5><IN1.5.1></IN1.5.1></IN1.5><IN1.6><IN1.6.1></IN1.6.1></IN1.6></IN1>;
          for each (insurance in msg..Insurance){
              tmp['IN1'][counter] = IN1i;
              tmp['IN1'][counter]['IN1.1']['IN1.1.1'] = counter + 1;
              tmp['IN1'][counter]['IN1.2']['IN1.2.1'] =  insurance['INS_NUM'];
              tmp['IN1'][counter]['IN1.2']['IN1.2.2'] =  insurance['INS_GRP'];
              tmp['IN1'][counter]['IN1.2']['IN1.2.3'] = 'CMP_DEMO';
              tmp['IN1'][counter]['IN1.3']['IN1.3.1']= 'INS_ID';
              tmp['IN1'][counter]['IN1.4']['IN1.4.1'] =  insurance['CO_NAME'];
              counter++;
              channelMap.put("HighCounter",counter.toString());
          }
          producing
          Code:
          MSH|^~\&|ADT_COMPULINK|COMPULINK1|IFASYSTEMS|HELLS_HOSPITAL|||ADT^A04|1303106|P|2.3.1||||||||
          IN1|1|^^CMP_DEMO|INS_ID|||
          IN1|2|^^CMP_DEMO|INS_ID|||
          IN1|3|^^CMP_DEMO|INS_ID|||
          I was under the impression that XML was case sensitive and that is the code that I am producing for the XML as I extract from my tables. I didn't design the fields, I just extract them. Do I need to lowercase the names to make this work? Everything else has worked so far, but I do need to iterate.

          Comment


          • #6
            Re:Loop through XML to HL7

            In your xml you pasted it was lowercase - it is case sensitive.
            Chris Lang

            Comment


            • #7
              Re:Loop through XML to HL7

              Interesting. I hadn't noticed that. The XML that I pasted came from the Raw Message tab. The original XML that I am modeling with is upper case. The code that is currently being produced is a mix of upper AND lower case, which would, obviously cause a problem.
              Don't know when it changed, amidst this furious programming session.

              Good catch. I'll let you know how it goes.

              Comment

              Working...
              X