mtoloo mtoloo - 1 year ago 128
Python Question

How to generate SOPInstance UID for DICOM file?

I am developing a system which is able to create structured report for a PACS. Obviously in order to create a DICOM file (containing Report data), I need three UIDs for Study, Series and file. StudyUID and SeriesUID must be the same as the study and series that report is created for it, but for SOPInstanceUID I need to generate a UID.
I have seen a method in Pixelmed documentation (getNewSOPInstanceUID), but I am not familiar with the Pixelmed source. I need an algorithm or Python source.

Answer Source

I would really suggest you go away from implementing it yourself. Most language do provide a UUID library these days, do not reinvent the wheel. Esp. if you are going to write code to extract MAC adress, this can be very complex writing it in portable C.

UUID do not exactly fit the DICOM definition, so you need to register your own Organisation Root UID, then simply pad with a generated UUID which bring spatial and time uniqueness condition.


Pay attention that you have 64 bytes (that's plenty already, see here) for storage in Value Representation UI:

  • Convert Hexadecimal notation of UUID to VR: UI definition ([0-9.]+)
  • Trim with extreme care (you may introduce redundancy during this operation)
  • Choose a short Org Root
  • Pad with \0 (0 binary) if needed.

Finally since you are using python, use uuid lib python-uuid.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download