Append file to HL7 message

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Append file to HL7 message

  • Creator
    Topic
  • #53029
    Jerry Magrann
    Participant

      Hello All – need some TCL help here. I have a file with HL7 segments created in it that I need to add to the end of certain ADT messages coming through one of my threads. I also have to make some changes to the ADT message.

      1. Do I make 2 diff procs, one to make changes to the ADT then one to open the file and append it to the ADT?

      2. Running 5.8 on Redhat, and I’m having trouble even opening the file with the switch patterns in my TCL program.  

      Comments / suggestions? Every time I search “file open” or “file” on the forum here, a million topics come up not even close to what I’m looking for.

      Thanks in advance! – Jerry

    Viewing 4 reply threads
    • Author
      Replies
      • #76294
        Jeff Dinsmore
        Participant

          I’m assuming you’re new to Tcl – so I’ll start with basic info. If you need more, I’ll be happy to elaborate.

          You shouldn’t need two procs.

          to open a file in read mode:

           set infile [open r]

          read the whole file:

           set wholeFile [read $infile]

          close the file:

           close $infile

          It’s usually a good idea to check that the file exists before attempting to open it.

           if { [file exists ] } {

             # do cool stuff here

           } else {

             # do less cool stuff here

           }

          There’s a wealth of Tcl info/documentation on the Tcl Developer Exchange

          http://www.tcl.tk/man

          You can also load Tcl/Tk from ActiveState on your desktop PC and play with Tcl outside of Cloverleaf as well. There’s complete Tcl/Tk documentation with that distribution.

          Jeff Dinsmore
          Chesapeake Regional Healthcare

        • #76295
          Charlie Bursell
          Participant

            I would just make one suggestion Jeff.

            When you read in a whole file, whether with read or read_file, it is a good idea to ignore the final linefeed.  Otherwise, something like [split $wholeFile n] will always give you an empty string at the end.

            read -nonewline $infile

            or

            read_file -nonewline

            Be careful with read_file, or write_file.  If HL7 data it tries to be your “friend” and convert CR to LF.  As with all things I have a fix   😉

            Edit the file $HCIROOT/tcl/lib/tclx8.4/stringfile.tcl

            In both the read_file and write_file procs right after:

                  set fp [open $fileName]

            Add this line:

                   fconfigure $fp -translation lf

            And just save the file

            I hope it helps

          • #76296
            Jerry Magrann
            Participant

              Charlie, you got it right – I got the file open, the data extracted, but friendly LFs instead of the HL7 necessary CRs after each segment. Without editing the tcl library like you suggested, to do it in coding, use a split to append the CR?

            • #76297
              Charlie Bursell
              Participant

                I should have mentioned you can read by opening the file as Jeff suggested but if HL7 data tou have to configure it to not change CR to LF

                Do this

                set fd [file open ]

                fconfigure $fd -translation lf

                set data [read_file -nonewline $fd]

                close $fd

              • #76298
                Jeff Dinsmore
                Participant

                  Correct.

                  When reading/writing HL7 from files, you need to be cognizant of end-of-line translations.

                  Because I’m a control freak, I generally use “fconfigure $infile -translation binary” to avoid any unpleasant surprises – and to know exactly what I’m getting – then split on n and r and explicitly ignore any empty strings.

                  Jeff Dinsmore
                  Chesapeake Regional Healthcare

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