Newsletter: February 2006
Project Corner - Unique IDs
Every interface project seems to need a unique ID somewhere in its solution.
Below is a snippet of Python code that uses/populates a field in the message header (MSH) to build a unique ID. It's built from the current date/time and stored into MSH.7 in YYYYMMDDHHMMSS form and the Message Control ID MSH.10 which is an ID for the message itself. A random number is tacked on to the tail just to be sure it is unique.
The result may be something like "12342005082612512169" with 20050826 as the embedded date at 12:51:21 and a random bit 69. This snippet is in a form that passthru scripting might use.
def init_MSH():
import time
import random
# set MSH constants required
# Date/Time of Message - 7
iterator.field(7).value = time.strftime("%Y%m%d%H%M%S")
# Message Control ID - 10
MSH10 = iterator.field(10).value
random.seed()
MessageID = MSH10 + time.strftime("%Y%m%d%H%M%S")
+ str(random.randint(10000,99999))
if len(MessageID) > 20:
MessageID = MessageID[:20]
iterator.field(10).value = MessageID
# Processing ID - 11
iterator.field(11).value = "P"
# Version ID - 12
iterator.field(12).value = "2.3"
# Accept Acknowledgement - 15
#iterator.field(15).value = "AL"
return
The method would be similar if it were included in the Chameleon VMD "In Equation" for the MSH segment for field 10-Message Control ID. This sets a global Python variable MessageID as well as setting the value into the field.
import time
import random
random.seed()
MessageID = value + time.strftime("%Y%m%d%H%M%S")
+ str(random.randint(10000,99999))
if len(MessageID) > 20:
MessageID = MessageID[:20]
value = MessageID
Why is this important?
The MessageID value comes in handy to make sure that newer processing of the same message re-submitted is ordered first in first out. For troubleshooting, the ID tells you the ID from the HL7 source and the date/time of processing. In databases unique keys are nice to have to tie things together. Even if the above isn't exactly what you need the technigue may be a useful template for future needs.

