Announcement

Collapse
No announcement yet.

Getting XML when trying to read a field

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

  • 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.
    I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
    http://www.linkedin.com/pub/david-rothbauer/5/923/518
    codeismydrug.wordpress.com
    hl7coders.wordpress.com

    Test all my code suggestions prior to implementation

  • #2
    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

    Comment


    • #3
      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?

      Comment


      • #4
        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;

        Comment

        Working...
        X