web stats
Getting XML when trying to read a field - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-14-2010, 06:20 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default Getting XML when trying to read a field

Hi;

I'm trying to read PV1.3 into a variable which is subsequently written into a database.

I'm using
Code:
 var PtLocation = msg['PV1']['PV1.3'].toString();
What I'm getting is this:

Code:
<PV1.3><PV1.3.1>1NSY</PV1.3.1><PV1.3.2>E2.TNSY</PV1.3.2><PV1.3.3>01</PV1.3.3>
What I'd like is:

Code:
1NSY^E2.TNSY^01
This is causing a data truncation error.

The problem is that I have to write this data back into an HL7 2.x message that will be generated later in the day.

I've had this happen to me sporadically in the past. Sometimes using the format I'm using works, other times it doesn't.

Can anyone help?

Thanks.
Reply With Quote
  #2  
Old 07-14-2010, 11:14 AM
mourisj mourisj is offline
Mirth Guru
 
Join Date: Feb 2007
Location: Luxembourg
Posts: 407
mourisj is an unknown quantity at this point
Default

You have to do

Code:
var PtLocation1 = msg['PV1']['PV1.3']['PV1.3.1'].toString();
var PtLocation2 = msg['PV1']['PV1.3']['PV1.3.2'].toString();
var PtLocation3 = msg['PV1']['PV1.3']['PV1.3.3'].toString();
and then concatenate to the string you want to submit to your database.
__________________
JJ Mouris
FFE Luxembourg
IT-Department
Reply With Quote
  #3  
Old 12-04-2010, 11:45 PM
mnowlin mnowlin is offline
OBX.3 Kenobi
 
Join Date: Sep 2006
Posts: 142
mnowlin is an unknown quantity at this point
Default

Bump....

I'm trying to do the same thing, but the string I'm looking at can contain anywhere from 1-25 elements. Sure, I can write the code (although ugly), but is there a better way?
Reply With Quote
  #4  
Old 12-05-2010, 10:24 AM
leaflet leaflet is offline
OBX.1 Kenobi
 
Join Date: Sep 2010
Posts: 32
leaflet is on a distinguished road
Default

Add the function xml_strip() to your destination and use it as follows:

HTML Code:
var strPV1_3 = msg['PV1']['PV1.3'].toString();
logger.info("Incoming Data:" + strPV1_3);
strPV1_3 = xml_strip(strPV1_3);

PHP Code:
function xml_strip(str_xmldata) {
      
// syed:xml stripping function
    // This function removes XML tags and characters and returns a string
    // Incoming data: <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>
    // Outgoing data: 2000^2012^01
    // Usage: 
    //        var strPV1_3 = msg['PV1']['PV1.3'].toString();
    //        logger.info("Incoming Data:" + strPV1_3);
    //        strPV1_3 = xml_strip(strPV1_3);

    
str_xmldata str_xmldata.replace( /<\//g, "^</");
    
str_xmldata str_xmldata.replace( /\/>/g"/>^");
    while( 
str_xmldata.indexOf("<") > -)
    {
        var 
start str_xmldata.indexOf("<");
        var 
end str_xmldata.indexOf(">");
        var 
sub str_xmldata.substringstartend+);
        
str_xmldata str_xmldata.replacesub"" );
    }    

    
//removes all "^" from end
    
str_xmldata str_xmldata.replace(/^\^+|\^+$/g'');

    
//removes all "~" from end
    
str_xmldata str_xmldata.replace(/^\~+|\~+$/g'');
    return 
str_xmldata;

Reply With Quote
Reply

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 11:15 AM.


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