Converting alphanumeric

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Converting alphanumeric

  • Creator
    Topic
  • #49492
    Richard Hart
    Participant

      We have a requirement to convert from an alphanumeric 6 character value to a unique 5 character value.

      Any ideas?

    Viewing 8 reply threads
    • Author
      Replies
      • #62200
        Tom Rioux
        Participant

          What does the inbound field look like?  Is it “A12345” or “A1234B”, etc?  Quite frankly, I think that this is something that should not be the responsibility of the interface engine.  There is no totally certain and secure way of knowing that number the IE may genearate will be a “unique” number on the receiving system.  It should be left up to either the sending or receiving system to generate this number.

          Just my opinion….

          Tom Rioux

        • #62201
          Richard Hart
          Participant

            Thomas.

            Thanks for the reply, there is no definite format for this field.

            I didn’t think there was a solution without using the complete character set, but my boss was keen to investigate the possibility for a mathmatical solution.

            >It should be left up to either the sending or receiving system to generate this number.

            Probably, we’ve requested a patch, as the database field is large enough and it is the applications HL7 processing that is performing the truncation.

            I won’t hold my breathe as this vendor hasn’t released a version that was usuable for an upgrade in the last 4 years!

            I’ve coded the work-around with a simple gdbm database.

          • #62202
            David Barr
            Participant

              Richard Hart wrote:

              I didn’t think there was a solution without using the complete character set, but my boss was keen to investigate the possibility for a mathmatical solution.

              I depends on which characters are used in the input and which characters are allowed in the output.  If you have base-16 input (0-9, A-F), it should be pretty easy to save a character or two by converting to base 64 output.  There are functions in Tcllib for dealing with base 64 encoding.  Here’s an example:

              Code:

              #!/hci/qdx5.4.1/integrator/bin/hcitcl

              package require base64

              proc convert { hex } {
                 scan $hex “%x” dec
                 set str “”
                 while { $dec } {
                     set str [format “%c” [expr $dec%256]]$str
                     set dec [expr $dec/256]
                 }
                 return [::base64::encode $str]
              }

              puts [convert abc123]

              It won’t be quite this simple if you have more than 16 possible input characters, but it’s not difficult, either.

            • #62203
              Richard Hart
              Participant

                David.

                Thanks for the suggestion, unfortunately the range is 0-9 and A-Z.

                A base64 conversion works size wise, ie 6 characters to 5, but then gets into binary data which is non-standard and may have issues with HL7 message characters.

                I’ve used a base 32 conversion (0-9, A-Z without similar looking letters) to change a 6 digit to 4 alhanumeric.

              • #62204
                Charlie Bursell
                Participant

                  FYI, you do not need the base64 package to do base64 conversions in Cloverleaf.  The commands encode and decode are availabel for that

                  encode charlie

                     =>   Y2hhcmxpZQ==

                  decode Y2hhcmxpZQ==

                     =>  charlie

                • #62205
                  David Barr
                  Participant

                    Richard Hart wrote:

                    David.

                    Thanks for the suggestion, unfortunately the range is 0-9 and A-Z.

                    Ok, so you wouldn’t be able to use “scan” like I did.  You’d have to use something else.

                    Quote:

                    A base64 conversion works size wise, ie 6 characters to 5, but then gets into binary data which is non-standard and may have issues with HL7 message characters.

                    Base64 output is not binary and doesn’t use any special HL7 characters.  It uses A-Z, a-z, 0-9, +, / and =.

                  • #62206
                    Dennis Pfeifer
                    Participant

                      My suggestion would be to expand your number range to include lower case values ..

                      convert your current ‘base 36’ number system that includes 0-9 and A-Z into a ‘base 62’ number system that includes 0-9, A-Z and a-z

                      how you assign them is totally up to you ..

                      0 -> 0

                      1 -> 1

                      .

                      .

                      .

                      A -> 10 (decimal)

                      B -> 11 (decimal)

                      .

                      .

                      Z -> 35 (decimal)

                      a -> 36 (decimal)

                      b -> 37 (decimal)

                      .

                      .

                      z -> 61 (decimal)

                      I’d convert your current base 36 number to a base 10 number (because I and computers like them ..) and then convert the base 10 number to a base 62 number ..

                      Dennis

                    • #62207
                      Richard Hart
                      Participant

                        Guys.

                        Thanks for the responses:

                        tcl>puts “‘[::base64::encode ZZZZZZ]'”

                        ‘WlpaWlpa’

                        tcl>puts “‘[::base64::decode ZZZZZZ]'”

                        ‘eY’ [with a ‘silent’ 226 extend ASCII character in between]

                        I was using the decode to reduce the number of characters and this contained binary data.

                        There was some concern with using lower case as the application displayed the information with an uppercase translation.

                      • #62208
                        Dennis Pfeifer
                        Participant

                          Thanks ..

                          I’ve slightly miss led you ..

                          in essance .. you need to get your base 36 number to a base 74 system ..

                          if you wish to fit your ‘number’ from a six digit value into a five digit value, you will need to find a base 74 representation ..

                          you need

                          36 ^ 6 = X ^ 5

                          where X is the base of your destination number system …

                          .. then round X up to the whole digit ..

                          your base will need to be 74 or greater to represent a six digit base 36 number into a five digit number ..

                          You will need to choose an additional 38 characters to represent your number as a five digit number system

                          Dennis

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