tcl procs and table data

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf tcl procs and table data

  • Creator
    Topic
  • #49282
    Anonymous
    Participant

      I prefer to use tcl to do about all of my work in engine, but I am limited in some of the things I want to do because I just don’t have the knowledge.

      My first question deals with translation tables.  Is there a way to read in a translation file into memory so that it is available each time the tcl proc is called?  I don’t want to do a bunch of I/O in a tcl proc considering the message traffic so I would like to load it into memory on startup and keep it available.

      My second question is with tcl procs.  I am new to the hospital setting since I worked for a GE Healthcare for years.  At this hospital they do not use common functions and would like to implement a common tcl procs library for everyone to use, but I don’t want these tcl procs to show in the list in the engine.  I would compare what I want to a DLL where I can package common code in a library so others can share.  

      Thanks.

    Viewing 3 reply threads
    • Author
      Replies
      • #61364
        Jonathan Hamilton
        Participant

          For your first question, in Tcl just use ‘tbllookup tablename value’.

          As far as your second question goes your are looking for a Tcl package.  Any good Tcl book will have details on how to create and access them.  I use them heavily for the same scenario you describe.

          The 5 second intro to packages:

             Create a file with the procs you want in the library.  Use an extension other than .tcl, I use .pkg.  I typically store the package file either in the $HCIROOT/tclprocs or $HCIROOT/tcl/lib/ directory so all sites can access the same library.

             At the top of the file add the line ‘package provide 1.0′.

             From cmd line go to the location of the package file and type ‘pkg_mkindex . *.pkg’.  This should create a pkgIndex.tcl file.

             From any Tcl code (proc, script, etc.) simply add ‘package require ‘.  Now you can use your library procs without them showing in the NetConfig UPoC lists.

          Depending on what your building you may also want to explore namespaces which can take packages to the next level, although at the expense of complexity.[/list]

        • #61365
          Jonathan Hamilton
          Participant

            Oops, should be pkg_mkIndex.

          • #61366
            Richard Hart
            Participant

              Doc.

              We use TCL translations in most of our interfaces and use ‘tables’ extensively.  We use a TCL array …

              proc QryTableTop {aCode} {

                     # make the array global, so it is always available

                 global QryTableTopArray

                     #

                     # if the array requires initialisation, do this now

                     #

                 if {[array exists QryTableTopArray] == 0} {

                     set QryTableTopArray(A)  AKHS

                     set QryTableTopArray(X)  3811

                     set QryTableTopArray(Z)  3812

                 }

                     # set the return variable to the default value

                 set myData $aCode

                     # make sure we don’t fall over if there is NO data!

                 catch {set myData $QryTableTopArray($aCode)}

                     # return the data from the array

                 return $myData

              }

              We also have a library of common functions that we use and the library code and common functions exist in a ‘LIB’ directory, which is referenced from a site tclIndex

              eg

              # Tcl autoload index file, version 2.0

              # This file is generated by the “auto_mkindex” command

              # and sourced to set up indexing information for one or

              # more commands.  Typically each line is a command that

              # sets an element in the auto_index array, where the

              # element name is the name of a command and the value is

              # a script that loads the command.

              set auto_index(ccm_xlate_ris)

                ]

                set auto_index(ccm_xlate_cap)

                  ]

                  set auto_index(ccm_xlate_ult)

                    ]

                    set auto_index(ccm_xlate_rad)

                      ]

                      set auto_index(ccm_xlate_sud)

                        ]

                        set auto_index(MakeMrn)

                          ]

                          set auto_index(MakeAcct)

                            ]

                            set auto_index(MakePtType)

                              ]

                              set auto_index(MakeLabHospitalService)

                                ]

                                set auto_index(MakeCtrlId)

                                  ]

                                  set auto_index(MapHexChars)

                                    ]

                                    set auto_index(TranEncChars)

                                      ]

                                      set auto_index(gen_code_resend)

                                        ]

                                        set auto_index(gen_code_printmsg)

                                          ]

                                          set auto_index(gen_code_splitter)

                                            ]

                                            set auto_index(gen_code_mkreply)

                                              ]

                                              set auto_index(Print)

                                                ]

                                                set auto_index(RetRepeat)

                                                  ]

                                                  set auto_index(RetComp)

                                                    ]

                                                    set auto_index(ChangeField)

                                                      ]

                                                      set auto_index(SourceTablesFile)

                                                        ]

                                                        We run on Unix, so we use ‘make’ and CVS to create the TCL files and tclIndex. We also use Unix links to keep one copy of the source and provide a simple method of managing code changes.

                                                      1. #61367
                                                        Chris Williams
                                                        Participant

                                                          Question #2:

                                                          I’m sure this will horrify the purists, but one fast, down and dirty way to make those procs available in unix without having to go the package route is to put them into filename then add a line inside …/integrator/tcl/lib/localInit.tcl that says something like

                                                          source $env(HCIROOT)/…/filename

                                                          Chris

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