Announcement

Collapse
No announcement yet.

How to create a repeating field (without template)

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

  • How to create a repeating field (without template)

    Need helps on how to create the repeating field without using templates.
    I need to have the followings:
    tmp['PID']['PID.3'][0] = msg['PID']['PID.3']
    tmp['PID']['PID.3'][1] = msg['PID']['PID.2']

    I cannot use the inbound/outbound templates. Here is what I did:
    var tmp = msg.copy();
    tmp['PID']['PID.3'][1] = tmp['PID']['PID.3'];
    tmp['PID']['PID.3'][1]['PID.3.1'] = msg['PID']['PID.2']['PID.2.1'].toString();
    However I got an error message:
    TypeError: Cannot set property "PID.3.1" of undefined to "1212121212"

    I tried the way indicated in:
    http://www.mirthcorp.com/community/f...ead.php?t=4271
    It did not really add it as the repeating field. Instead it appends the followings to the end of the entire PID segment:
    <PID.3><PID.3.1>......

    I struggled whole day without any success. Please help. Thanks.

    John Chen
    ==========

  • #2
    Hi john. I had the same problem one year ago and I found no way to do this "directly". The only way that worked for me was this:

    Code:
    var pid3_template = <PID.3>
                	<PID.3.1></PID.3.1>
                	<PID.3.2></PID.3.2>
    				<PID.3.3></PID.3.3>
    				<PID.3.4></PID.3.4>
            	</PID.3>
                     
                     pid3_template['PID.3.1'] = 'something'
    		 pid3_template['PID.3.4'] = 'something else'
    
    //supposing to have yet instance [0], add the [1] to the message:
     
                     tmp['PID']['PID.3'][1] += pid3_template
    I know that it is not the best solution, but I get struggled with this also, so I kept this.
    Hope this helps

    Alessandro
    Last edited by asulis; 06-11-2012, 02:38 AM.

    Comment


    • #3
      If you don't want to use an outbound template, you could do this:

      Code:
      msg.PID['PID.3'] += renameField(msg.PID['PID.2'],'PID.3');
      The code for renameField can be found here. Cheers!
      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 replies.
        However each time I use:
        tmp['PID']['PID.3'][1] += pid3_template;
        It always appends to the end of the PID segment as a value of PID.26.1.
        I am using version 2.2.1.5861. Not sure if it is a bug.

        John Chen
        =======

        Comment


        • #5
          I have the same problem, it is putting them at the end.
          Mirth Connect Server 3.8.0
          Built on May 22, 2019
          Java version: 1.8.0_181

          Comment


          • #6
            If you're not using templates, how come you have tmp in all your code? We had a system that required very little info so what we did was grab what we wanted from the PID values, delete the PID and just create it again - seemed easier...

            Code:
            ..loop over PID and grab data first (patNum/patVar)
            
            
            delete msg['PID'];
            
            	createSegmentAfter('PID', msg['MSH']);
            	msg['PID']['PID.3']['PID.3.1'] = "001" +patNum;
            	msg['PID']['PID.3']['PID.3.4'] = "NAN";
            	msg['PID']['PID.3']['PID.3.5'] = "MR";
            
            	if (patVar > 0)
            	{
            		var newPID = <PID.3/>;
            		newPID['PID.3.1'] = "PID";
            		msg['PID']['PID.3'] += newPID;
            		msg['PID']['PID.3'][1]['PID.3.1'] = patVar;
            		msg['PID']['PID.3'][1]['PID.3.4'] = "002";
            		msg['PID']['PID.3'][1]['PID.3.5'] = "GB";
            	}

            Comment


            • #7
              Originally posted by jchen View Post
              Thanks for your replies.
              However each time I use:
              tmp['PID']['PID.3'][1] += pid3_template;
              It always appends to the end of the PID segment as a value of PID.26.1.
              I am using version 2.2.1.5861. Not sure if it is a bug.

              John Chen
              =======
              Something like this should work:

              var pid3 = new XML('<PID.3 />');
              pid3['PID.3.1']='12345';
              pid3['PID.3.4']='A';
              pid3['PID.3.5']='MR';

              tmp.PID.insertChildBefore(tmp['PID']['PID.3'][0], pid3);

              Comment


              • #8
                I got mine to work by doing a function and then calling it....

                function getNewPID13() {
                var field = new XML();
                field = <PID.13><PID.13.1></PID.13.1>
                <PID.13.2></PID.13.2>
                <PID.13.3></PID.13.3>
                <PID.13.5></PID.13.5>
                <PID.13.6></PID.13.6>
                <PID.13.7></PID.13.7>
                <PID.13.8></PID.13.8>
                <PID.13.9></PID.13.9>
                </PID.13>;
                return field;
                }

                for(i=0;..........{
                var pid13=(i>0?getNewPID13():tmp['PID'][0]['PID.13']);

                ...other assignment code here...
                }
                if(i>0) { tmp['PID'][0]['PID.13'].appendChild(pid13); }
                Last edited by StickyBandit; 02-14-2020, 05:25 AM.

                Comment

                Working...
                X