Testing for number vs alpha

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Testing for number vs alpha

  • Creator
    Topic
  • #53386
    Tom Arrowsmith
    Participant

      I need to determine if the PV1-7.1 has a physician ID number as opposed to a physician name. I realize that even if a number is present, it may be in the “text” format.

      Is there a bit of tcl code I can call from the xlate that would accomplish this for me? for example, distinguish between the value “123” as opposed to the value “SMITH”?

      If I see the value to be a text name, I want to instead insert the ID “1” (which stands for “Doctor, NotOnFile”)

      Or is there another way to accomplish this?

      Would prefer a some tcl code that can be called from the xlate – as I am not a very accomplished tcl programmer.

      Thanks!

      Tom

    Viewing 3 reply threads
    • Author
      Replies
      • #77524
        Paul Bishop
        Participant

          you can do this with an inline tcl fragment:


          lassign $xlateInVals docIn

          if {[string is digit -strict $docIn]} {

            set docOut $docIn

          } else {

            set docOUt “1”

          }

          set xlateOutVals


          the Source would be your PV1-7.1 field, and Destination would be whatever you are moving to.  The “-strict” will cause empty fields to test false.

          Paul Bishop
          Carle Foundation Hospital
          Urbana, IL

        • #77525
          Gene Salay
          Participant

            Tom,

            Most systems will be consistent and always put the ID in PV1-7.1 and the name in PV1-7.2

            That aside, if you’re trying to determine if a field is numeric or alpha, you can use the tcl command “string is…”.

            In Xlate, you could do something like this:

            set inFld [lindex $xlateInVals 0]

            set outFld $inFld

            if [string is alpha $inFld] {set outFld 1}

            set xlateOutVals

          • #77526
            Paul Bishop
            Participant

              I hit submit too soon – the “set docOUt $docIn” should be “set docOut $docIn”.

              Paul Bishop
              Carle Foundation Hospital
              Urbana, IL

            • #77527
              Jeff Dinsmore
              Participant

                Gene – testing for digit with the -strict option is the better way to go.

                If the tested string has any non-alpha characters – like “abc1def”, “string is alpha” will test false – effectively causing it to be treated as an integer.

                Jeff Dinsmore
                Chesapeake Regional Healthcare

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