Adding <CR> <LF>

  • Creator
    Topic
  • #49163
    Krishna Kumar
    Participant

    I am getting a Radilogy charge in HL7  (2.2v) as a flat file. I noticed that this file does not have separating messages. Only it has at the end of each segment. Hence when I pass it through Cloverleaf I am getting errors like

    The # 5 segment encountered ‘MSH’ is out of order for message type ‘DFT_P03’

    The # 5 segment encountered ‘EV1’ is out of order for message type ‘DFT_P03’

    The # 5 segment encountered ‘PID’ is out of order for message type ‘DFT_P03’

    The # 5 segment encountered ‘PV1H’ is out of order for message type ‘DFT_P03’

    How can I format this file ? Anybody any suggetions ?

    Krishna Kumar

    UT Medicine

Viewing 4 reply threads
  • Author
    Replies
    • #60940
      David Barr
      Participant

      To convert the file in a script (or on the command line) try this:

      Code:

      perl -pe ‘s/rMSH/rnMSH/g’ < inputfile > outputfile

      If you want to fix it in the engine, write a TCL proc to split the message (using split, append, etc) and do a msgcopy, msgset and CONTINUE to create individual messages.  The proc should run in the inbound data context.

    • #60941
      David Dillard
      Participant

      Hi,

      You can also substitute a CR-LF for every CR in the message using the regsub command

      Code:

      regsub -all “r” $msg “rn” msg

      Like David said, run this on the inbound data before any other formatting or translations take place.

      Here is a sample proc to get you started

      Code:

      proc Add_LF { args } {
         keylget args MODE mode                  ;# Fetch mode
         set dispList {}             ;# Nothing to return

         switch -exact — $mode {
             start {
                 # Perform special init functions
             # N.B.: there may or may not be a MSGID key in args
             }

             run {
                 # ‘run’ mode always has a MSGID; fetch and process it
                 keylget args MSGID mh
                 set msg [msgget $mh]
                 # substitute all with
                 regsub -all “r” $msg “rn” msg
                 msgset $mh $msg
                 lappend dispList “CONTINUE $mh”
             }

             time {
                 # Timer-based processing
             # N.B.: there may or may not be a MSGID key in args
             }
             
             shutdown {
             # Doing some clean-up work
         }
         }

         return $dispList
      }

    • #60942
      Krishna Kumar
      Participant

      Thanks for the reply. But I need this replacement after FT1 segment only. Not on all segments and this is where one message is separated from other message in the file.

      Any further explanation welcome.

      Thanks

      Krishna Kumar

    • #60943
      David Barr
      Participant

      If you’re going to write a TCL proc, just use the “split” command to split your original message on r characters.  This gives you a list of all the segments.  Do a “foreach” loop over this list.  Append each segment to the current message (initially blank).  Every time you process an MSH segment, save your current message using msgcopy, msgset, and lappend it to your dispList, and replace the current message with what’s in the MSH segment.

      And when you are done, don’t forget to KILL your original message.

    • #60944
      David Dillard
      Participant

      😳

      Sorry for the confusion

      — I did not read your question close enough and my mind took off on it’s own tangent.

      I plead caffeine deficiency

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

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,292
Replies
34,435
Topic Tags
286
Empty Topic Tags
10