Extra CR at end of message

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Extra CR at end of message

  • Creator
    Topic
  • #51051
    Gary Atkinson
    Participant

    Has anyone had an issue where hl7 data was coming into the engine with an extra 0d on the last segment.  Here is an example:

    Code:

    message           : ‘MSH:;~&:SPC:N:IM:N:200907020101:41:ADT;A04:9838707:D:2.2:9838707::AL::x0dEVN:A04:200907020101::x0dPID::01013071:1119123;;;N:118450;N198670:CONTROL;BARE;LEEIN;::19450918:F::2:1219 ANTABUSE DR;;GLEN BURNIE;MD;21061;US;C;02:02:(410)455-1236:(410)787-4000X7856:ENGLISH;E;:M:;:918300001;;;N:006-23-1236:x0dPD1::::271;SHERMAN;EDWARD;N::::::::N:x0dNK1:1:CONTROL;RELATIVE:H;;:1219 ANTABUSE DR;;GLEN BURNIE;MD;21061;US:(410)455-1236:x0dPV1::O:;;;N;;;:3:::477;YORK;JAMES;J;;;MD::””:PHT:::0918100001;;;N:1:::477;YORK;JAMES;J;;;MD:OPS;;N:0918300001;;;N:S:::::::::::::::::::N:::::200907020001:::::x0dAL1:::;:::x0dDG1:0:I9::ADM DIAG::ADMITTING::::::::x0dDG1:99:I9::ADM DIAG::WORKING::::::::x0dGT1:1:118450:CONTROL;BARE;LEEIN;::1219 ANTABUSE DR;;GLEN BURNIE;MD;21061;US;C;02:(410)455-1236::19450918:F::S:006-23-1236:::1:BALT/WASH MED CNTR;BWMC:301 HOSPITAL DRIVE;;GLEN BURNIE;MD;21061;US;;02:(410)787-4000X7856::1x0dIN1:1:::::::::::::::;;:::::::::::::::::::::::::::::x0dACC:””::x0dUB1:1:::::::::::::::11;20090604~;~;~;~;:::::::x0dZCA:::;;;x0dZCV:2::***::::::::PHT:x0dZCD::N:::;;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::x0dZCE:16;NURSE;:””:BWMC;BALT/WASH MED CNTR;N:301 HOSPITAL DRIVE;;GLEN BURNIE;MD;21061;US;;02::::1::x0dZCI:1:::S:::N:::::::::::::::::::::::::::x0dZCM:N::::::::::::::::::::::271;SHERMAN;EDWARD;N:N:x0dx0d’


    I am sending this data Raw; std mlp; from the sending system.  The receiving vendor can not handle this “extra” 0d and ends up sending the ack terminating with 0d 0d.  First, I going to sending system and telling them to fix the “extra” 0d.  If that does not go well, how can I fix this in the engine?  Also, I find this odd that I have never had any other vendor complain of this and we have about 20 adt feeds; one of which is a raw feed  ðŸ˜•

Viewing 17 reply threads
  • Author
    Replies
    • #68584

      You could write a little tcl proc that will remove the trailing carriage returns?

      Something like this maybe?

        regsub — {rr$} $msg {r} match msg

      (Note: I didn’t test that code.)

      -- Max Drown (Infor)

    • #68585
      Jim Kosloskey
      Participant

      Why not ask the sending vendor to correct that?

      If they won’t, you can still use Tcl.

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #68586
      Jim Kosloskey
      Participant

      Why not ask the sending vendor to correct that?

      If they won’t, you can still use Tcl.

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #68587
      Gary Atkinson
      Participant

      In this tcl code what is the “match” for?  Also, since the rr is occuring in the very last segment how do I adjust for end of message characters?

    • #68588

      Code:

      set msg “hello, world!x0dblahblahblahx0dfoobarx0dx0d”
      # regsub ?switches? exp string subSpec ?varName?
      regsub — {rr$} $msg “r” msg
      puts $msg

      Here is some test code that works. The “$” means match on the end of the line, so “rr$” would only match on two carriage returns at the end of the line.

      -- Max Drown (Infor)

    • #68589
      Gary Atkinson
      Participant

      Got ya. Thx!

    • #68590
      Tom Rioux
      Participant

      Max,

      Just thinking, but suppose the message for some crazy reason had 3 carriage returns at the end.   If you ran that code against it, wouldn’t it still have double carriage returns?   Wouldn’t something like this work if you just wanted to be sure to return a single carriage return?

      regsub — {[r]+$} $msg “r” msg

      Here is what I did using just a 0d and not an actual carriage return:

      hcitcl>set msg “hello,world!0dblahblahblah0dfoobar0d0d0d”

      hello,world!0dblahblahblah0dfoobar0d0d0d

      hcitcl>regsub — {[0d]+$} $msg “0d” msg

      1

      hcitcl>echo $msg

      hello,world!0dblahblahblah0dfoobar0d

      What do you think???

      Tom Rioux

    • #68591
      Michael Hertel
      Participant

      Or, for those of us regsub challenged:

      set msg [string trimright $msg r]r  ðŸ˜€

    • #68592

      Yup, if you expect to have more than 2 trailing carriage returns, you would need to account for that somehow. You could use the tcl string trim commands, too.

      regsub — {r{2,}$} $msg “r” msg

      — or —

      regsub — {r+$} $msg “r” msg

      — or —

      set msg [string trim $msg r]

      set msg “$msgr”

      -- Max Drown (Infor)

    • #68593
      Tom Rioux
      Participant

      Good one Michael!  I try to use the string commands whenever possible and sometimes forget about doing stuff like this with the “trim” or “map” string commands.

      Later…Tom

    • #68594
      David Barr
      Participant

      Gary Atkinson wrote:

      In this tcl code what is the “match” for?

      Match is just a variable name for an unused parameter to the regexp function (I think that Max was confusing regsub and regexp) .

    • #68595

      Yup. In my first post I was just typing some code out by memory. I corrected it in a later post after I actually tested the code.  ðŸ˜€

      -- Max Drown (Infor)

    • #68596
      Gary Atkinson
      Participant

      Thanks all for the code…it works great.  This is a much easier route than trying to get the vendor to comply.  ðŸ˜€

    • #68597
      Gary Atkinson
      Participant

      Well, I spoke to soon on this.  After doing some more investigation it appears the “extra” r is being added in by the engine (or some tcl code).  The following two procs touch all the ADT messages, so I am thinking one of them may be the issue.  Unfortunately, I don’t see anything, but I am no tcl pro and these procs were written years ago.  At any rate I am posting both procs here in the hopes someone “sees” something.

      Code:


      #####################################################################
      # Name: tps_adt_normalize
      # Purpose: Normalizes HBOC HL7 message by removing 2nd subfield
      # from message type. And removes the leading zeros from Med. Rec.# and
      #       ACCT.#.  Proc will also KILL message if “acct_ln” (PID:18) is true (temp number),
      #                which is not a valid account number
      #  
      # UPoC type: sms_ib_data
      #             Insert proc after acknowledge procedure
      # ARGS:     {ACCTLN number} :  Default number is 6.
      #                              Length of PID:18, account number field
      #           {DEBUG value}   :  0= off
      #                              1= on
      # Returns: CONTINUE modified message if acct_ln is not true, else KILL message
      #
      # Usage:
      # STAR sends HL7 messages with 3 subfields in the message
      # type, ie., ADT^A01^05.  Cloverleaf cannot handle this.  This
      # proc removes the 2nd subfield and stores it in field 7
      # (Security, unused) of the MSH segment.  This can be undone using
      # the unnormalize.tcl proc I could not find this procedure on the
      # server, but leaving this comment for historical purposes.
      #
      #  VERSION HISTORY: 10/16/2008 Gary Atkinson
      #                   Added check for invalid account number length
      #                   Added in some echos (module and msg) and debug option
      #

      proc tps_adt_normalize { args } {
         global HciConnName

         if ![info exists HciConnName] { set HciConnName UNKNOWN }
         set module “(tps_adt_normalize/$HciConnName)” ;# For error reorting
         
         keylget args MODE mode ;# What mode
         keylget args CONTEXT context ;# What context
         
         keylget args ARGS uargs   ;# Get User Args and set defaults if not defined
         set acctln 6       ; keylget uargs ACCTLN acctln
         set debug 0         ; keylget uargs DEBUG debug
         
         set dispList {} ;#Nothning to return
         
         switch -exact — $mode {
             start {
         echo “$module: Using settings – ACCTLN = $acctln, DEBUG = $debug”
         return “” ;# Nothing specific
             }

             run {
         keylget args MSGID mh ;# Get message handle
         set msg [msgget $mh] ;# Get message
      #
      # Validate context
      #
         if ![cequal $context sms_ib_data] {
      echo “$module: Called with Invalid Context. S/B sms_ib_data is $context!”
      echo “Continuing message – No action taken”
      lappend dispList “CONTINUE $mh”
         }

      #
      # Split the message and get fields to check
      # First set up some constants
      #
         set sep [csubstr $msg 3 1] ;# HL7 field separator    
         set sub [csubstr $msg 4 1] ;# HL7 subfield separator    
         set segments [split $msg r] ;# Get segments
         set outbuf “” ;# Holds outbound message
      #
      # LOOP through and make changes
      #
         foreach seg $segments {

      set segtype [csubstr $seg 0 3] ;# segment type

      if [cequal $segtype MSH] { ;# MSH?
         set fields [split $seg $sep] ;# Fields
         set type [lindex $fields 8] ;# Version
         set subfields [split $type $sub] ;# subfields
         set newtype [lindex $subfields 0]$sub[lindex $subfields 1]
         set xtrig [lindex $subfields 2] ;# Extra trigger
         set fields [lreplace $fields 7 8 $xtrig $newtype]
         set seg [join $fields $sep]
      }
                         if [cequal $segtype PID] {
                             set fields [split $seg $sep]
                             set pid3 [lindex $fields 3]
                             set pid18 [lindex $fields 18]
                             #puts “This is the before account#: $pid18”
                             set new_pid3 [string trimleft $pid3 0]
                             set new_pid18 [string trimleft $pid18 0]
                             #puts “This is the after account#: $new_pid18”
                             set new_pid18_ln [ string length [ lindex [ split $new_pid18 $sub ] 0] ]
                             #puts “This is the new PID:18 length: $new_pid18_ln”
                             set fields [lreplace $fields 3 3 $new_pid3]
                             set fields [lreplace $fields 18 18 $new_pid18]
                             set seg [join $fields $sep]
                         }    
               append outbuf ${seg}r
         }
      #
      # Put modified message in message handle and KILL msg if acctln is less or equal to PID:18
      #
        msgset $mh $outbuf
        if {$new_pid18_ln <= $acctln && $new_pid18_ln != 0} {
                     lappend dispList "KILL $mh"
                     if {$debug} {
                        echo "The following message contained an invalid account number, which length is $new_pid18_ln"
                        echo [msgget $mh]n
                     }
                  } else {
                     lappend dispList "CONTINUE $mh"
                  }
               }

      shutdown {
         # Doing some clean-up work
      }
               default {
                 error "Unknown mode '$mode' in $module"
               }
         }
         return $dispList
      }

      ######################################################################
      # Name: nah_char_reformat
      # Purpose: North Arundel Hospital.
      # The messages contain the character "&" in the several fields.
      # The "&" character in HL7 is used to denote sub-components.  Therefore,
      # Cloverleaf will treat the "&" segments as if it denoting a sub-component.
      # A table is read to obtain the Segment and the number of the field(s) within
      # the segment to check.  The field numbers must be separated by a dash.
      # The specified field is checked, all occurrences of & are replaced with +.
      # The new message is then created, the original message killed,
      # and the new message is continued.
      #
      # Written By: Donna Snider, Park City Solutions
      # Date: 02/26/2003
      #
      # UPoC type: tps     Must be used/entered in TSP Inbound Data
      # on Inbound Thread
      # Args: tps keyed list containing the following keys:
      #       MODE    run mode ("start", "run" or "time")
      #       MSGID   message handle
      #       ARGS
      #      name of table used:  
      # {SEGMENTBL CIS_TABLE}
      #
      # Returns: tps disposition list:
      # If the message contains any & (except encoding characters in MSH)
      #                     A new reformattted messages is created.
      #    The new (copied)  message is CONTINUE.
      #    The original message is KILL.
      # Otherwise
      #    The origianl message is CONTINUE.

      ########################################
      proc nah_char_reformat { args } {
         keylget args MODE mode               ;# Fetch mode

         set dispList {} ;# Nothing to return

         switch -exact — $mode {
             start {
        return {}
             }

             run {
                 set datList [datlist]
                 set mh [keylget args MSGID]
                 set segtable [keylget args ARGS.SEGMENTBL]
                 set msg [msgget $mh]
            #  Create a copy of the message omitting the encoding characters and check
            #    Do any & exist in the remaining  message  – if yes, reformat else continue msg
                 set chkmsg [crange $msg 9 end]
                  if {[regexp "&" $chkmsg] == 1} {
            # Get field separator from MSH segment
                    set fieldSeparator [crange $msg 3 3]
            # Split message into segments  
                   set segmentList [split $msg r]
                   set newSegmentList ""
            # Search table for each Segment
            # When match on Segment ID, field numbers to check are returned
                   foreach segment $segmentList {
                          set tblfieldlist 0
                          set segmentID [crange $segment 0 2]
                          set tblfieldlist [tbllookup $segtable $segmentID]
                          if {$tblfieldlist != 0} {
                                 set fieldIDlist [split $tblfieldlist "-"]
                                 set fieldList [split $segment $fieldSeparator]
                                 foreach fieldID $fieldIDlist {
                                      set oldfield ""
                                      set oldfield [lindex $fieldList $fieldID]
       if {$oldfield != ""} {  
       regsub -all — "&" $oldfield "+" newfield
                                      set fieldList [lreplace $fieldList $fieldID $fieldID $newfield]
          }
        }
                             set segment [join $fieldList $fieldSeparator]
                           }      
                    set newSegmentList [lappend newSegmentList $segment]
                  }
                  set newMsg [join $newSegmentList r]
                  set mhNew [msgcopy $mh]
                  msgset $mhNew $newMsg
                  lappend dispList "KILL $mh"
                  lappend dispList "CONTINUE $mhNew"
           } else {
                  lappend dispList "CONTINUE $mh"
           }
      }

      shutdown {
         # Doing some clean-up work
      }

             default {
         error "Unknown mode '$mode' in nah_char_reformat"
             }
      }

         return $dispList
      }

    • #68598
      Gary Atkinson
      Participant

      Eureka I found the bug.  Duh  ðŸ˜³

    • #68599
      Russ Ross
      Participant

      Based on what you are telling us my first suspicion is to investigate the following code you posted as a possible cause of haveing rr after the last segment:

      Code:

                  append outbuf ${seg}r
            }
      #
      # Put modified message in message handle and KILL msg if acctln is less or equal to PID:18
      #
           msgset $mh $outbuf

      You could either remove the appending of r to outbuf or either do the triming of rr that you’ve become familiar with just before doing the msgset.

      I don’t have enough spare time to copy your code and do a test.

      Russ Ross
      RussRoss318@gmail.com

    • #68600
      Russ Ross
      Participant

      Since you found the bug ignore my previous post.

      I did not see you found the bug until I submitted my posted and page 2 showed up.

      Russ Ross
      RussRoss318@gmail.com

    • #68601
      Gary Atkinson
      Participant

      That was culprit Ross.  I did not write this proc, so I took it apart an re-wrote it.  Thanks for taking the time to look over it, that is all I needed  8)

Viewing 17 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,127
Forums
28
Topics
9,300
Replies
34,445
Topic Tags
288
Empty Topic Tags
10