› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Converting alphanumeric
Any ideas?
Just my opinion….
Tom Rioux
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.
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:
#!/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.
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.
encode charlie
=> Y2hhcmxpZQ==
decode Y2hhcmxpZQ==
=> charlie
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.
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 =.
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
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.
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