CSV preproc

  • Creator
    Topic
  • #51807
    Mike Campbell
    Participant

    Does anyone have any experience or examples of a tcl preproc that

    parses a csv file to allow different xlt’s based on a value in a specific field?  

    I’m getting better at the HL/7 procs, but this is a new animal for us.

    Thanks.

    Mike C.

Viewing 7 reply threads
  • Author
    Replies
    • #71811
      Charlie Bursell
      Participant

      I’m not sure I understand the problem.  You seem to mixing apples and oranges.

      Is the message coming in an HL7 and you wish to use the CSV file as a lookup table to determine how to route the message?

      If so, you will probably need a TRXID proc that will make use of dynamic tables (Since this is a CSV file I assume it is dynamic)

      Take a look at the CSV package provided under $HCIROOT/tcl/lib/tcllib1.xx

      A plug:

      You can attend the UG in Sept.  I will discussing this particular issue  ðŸ˜€

    • #71812
      Mike Campbell
      Participant

      Charlie,

        I’ve already mentioned the UG to the management.  Hopefully someone from here will get to go.

      Actually, this will be a csv file to a vrl type of xlate.  Not the usual HL/7.  Think I have the parsing figured out now.  Found the correct lindex and split combination.  Thanks, and hopefully I’ll get down to the UG.  

      I’ll check out the example you listed as well.

      Thanks Charlie.

    • #71813
      Connie Kraska
      Participant

      Hi Mike, Charlie knows more than me so he will probably solve your problem.  But I did want to send you a preprocessing proc we used years ago to determine how to route an order to either Lab or Radiology.  The incoming layout was FRL from an old clinical orders system, CCS.  This may be an antiquated way of doing this but you might get it to work:

      ######################################################################

      # Name: CCS_orders_OMFALOIE_routing

      # Purpose: This procedure parses the incoming CCS OMFALOIE

      # (which is the order modification/additional criteria)

      # It examines the ordering_dept field to determine

      # whether the order is meant for FlexiRad or FlexiLab.

      # Once this has been done it chooses the appropriate

      # translation and destination thread.

      # UPoC type: tps

      # Args: tps keyedlist containing the following keys:

      #       MODE    run mode (“start”, “run” or “time”)

      #       MSGID   message handle

      #       ARGS    user-supplied arguments:

      #              

      #

      # Returns: tps disposition list:

      #          

      #

      ########### CHANGE HISTORY ############################################

      # Date Task Pgmr Description

      # 01/11/01      4471    CEK     Modified code to process RESP orderes

      #######################################################################

      proc CCS_orders_OMFALOIE_routing { args } {

         keylget args MODE mode               ;# Fetch mode

         set dispList {} ;# Nothing to return

         set DatList [datlist]

         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 GRMin [grmcreate -msg $mh frl CCS.order.OMFALOIE.frl]

         set OrderingDept [datget [grmfetch $GRMin ordering_dept] VALUE]

         if { [cequal $OrderingDept XRAY] || [cequal $OrderingDept PROC] } {

      keylset detail

         PREPROCS.ARGS {}      

         PREPROCS.PROCS {}      

         DEST flexirad_out      

         POSTPROCS.ARGS {}      

         POSTPROCS.PROCS {}    

         TYPE xlate    

         XLATE CCS.orders.OMFALOIE.to.FlexiRad.ORM_O01.xlt

      lappend xrayRouting $detail

      msgrouteset $mh $xrayRouting

      lappend dispList “CONTINUE $mh”

         } elseif { [cequal $OrderingDept LAB] } {

      keylset detail

         PREPROCS.ARGS {}      

         PREPROCS.PROCS {}      

         DEST flexilab_out      

         POSTPROCS.ARGS {}      

         POSTPROCS.PROCS {}    

         TYPE xlate    

         XLATE CCS.orders.OMFALOIE.to.FlexiLab.ORM_O01.xlt

      lappend labRouting $detail

      msgrouteset $mh $labRouting

      lappend dispList “CONTINUE $mh”

         } elseif { [cequal $OrderingDept RESP] } {

      keylset detail

         PREPROCS.ARGS {}      

         PREPROCS.PROCS {}      

         DEST clinivision_out      

         POSTPROCS.ARGS {}      

         POSTPROCS.PROCS {}    

         TYPE xlate    

         XLATE CCS.orders.OMFALOIE.to.Clinivision.ORM_O01.xlt

      lappend respRouting $detail

      msgrouteset $mh $respRouting

      lappend dispList “CONTINUE $mh”

         } else {

      lappend dispList “KILL $mh”

      error “CCS Order Mod sent for unknown destination -[set OrderingDept]-“

         }

         hcidatlistreset $DatList

         grmdestroy $GRMin

             }

             time {

                 # Timer-based processing

         # N.B.: there may or may not be a MSGID key in args

             }

      shutdown {

         # Doing some clean-up work

      }

             default {

         error “Unknown mode ‘$mode’ in CCS_orders_routing”

             }

         }

         return $dispList

    • #71814
      Mike Campbell
      Participant

      So, here is a snippet of the code.  I’m trying to either pass or fail the

      message based on the location.

      Basically, I get the location desired, but the check of that against the PROFIT list is always true.  Probably something really simple but I haven’t been able to see it yet!


        set PROFIT

           lappend PROFIT {West Avon Rd.} {South Street}

         proc parseCSV {msg} {

               variable SEGMENTS {}          ;# List of Segments

        variable DEBUG ;# Debug flag

               variable PATREC                ;# List of patient records locations

               variable PROFIT                ;# List of Cerner ProFit locations

        variable myName ;# Procedure name

        # Set field separator

        set fldSep ,

         

                  if {$DEBUG} {

             echo nStarting FNB-CSV pre-proc

           }

        # List of Segments

               set SEGMENTS [split $msg $fldSep]

           

        set LOCATION [split [lindex $SEGMENTS 5] $fldSep]  

                echo “Location found is: ” $LOCATION  

             

                 if {[lsearch -exact $PROFIT $LOCATION] < 0} {

                    echo found

                    echo $PROFIT

                 }

        # Message OK

        return 1

           }

        }

    • #71815
      Charlie Bursell
      Participant

      What if your CSV contains embedded commas or control characters

      In the startup portion of your proc:

                       package require csv

      Replace  set SEGMENTS [split $msg $fldSep]

       with

                    set SEGMENTS [csv::split $msg]

      I don’t know about the rest of the proc

    • #71816
      Mike Campbell
      Participant

      Sorry for the dumb questions:

       is the required csv package a built-in for tcl?  

      When I try to test the proc, it returns:

       invalid command name “csv::split”

    • #71817
      Charlie Bursell
      Participant

      It is part of the supplied tcllib package

    • #71818
      Michael Hertel
      Participant

      Code:

            set SEGMENTS [split $msg $fldSep]
         
      set LOCATION [split [lindex $SEGMENTS 5] $fldSep]  

      You are splitting twice with the same separators.

      Also, are you removing double quotes?

      Simsbury and “Simsbury” are not the same.

Viewing 7 reply threads
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,129
Forums
28
Topics
9,301
Replies
34,447
Topic Tags
288
Empty Topic Tags
10