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

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 07-14-2010, 07: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


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

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

What I'd like is:

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?

Reply With Quote
Old 07-14-2010, 12:14 PM
mourisj mourisj is offline
Mirth Guru
Join Date: Feb 2007
Location: Luxembourg
Posts: 407
mourisj is an unknown quantity at this point

You have to do

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
Reply With Quote
Old 12-05-2010, 12:45 AM
mnowlin mnowlin is offline
OBX.3 Kenobi
Join Date: Sep 2006
Posts: 142
mnowlin is an unknown quantity at this point


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
Old 12-05-2010, 11:24 AM
leaflet leaflet is offline
OBX.1 Kenobi
Join Date: Sep 2010
Posts: 32
leaflet is on a distinguished road

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"/>^");
str_xmldata.indexOf("<") > -)
start str_xmldata.indexOf("<");
end str_xmldata.indexOf(">");
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'');

Reply With Quote

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:03 AM.

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