Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, June 22, 2017 4:00:10 PM(UTC)
Nick Villalobos

Groups: Registered
Posts: 119

Was thanked: 4 time(s) in 4 post(s)

Below you will find a code snippet that demonstrates how you can create your own SOPInstanceUID (Unique Identifier) as well as add it into your Dicom DataSet.

  • Unique Identifiers (UIDs) provide the capability to uniquely identify a wide variety of items. They guarantee uniqueness across multiple countries, sites, vendors and equipment. Different classes of objects, instance of objects and information entities can be distinguished from one another across the DICOM universe of discourse irrespective of any semantic context.

  • For example the same UID value cannot be used to identify both a study instance (Study Instance UID) and a series instance (Series Instance UID) within that study or a different study. Implementers also need to be cautioned against building new UID values by derivation (for example by adding a suffix) from a UID assigned by another implementation.

  • Each UID is composed of two parts, an <org root> and a <suffix>:

    UID = <org root>.<suffix>

  • The <org root> "1.2.840.10008" is reserved for DICOM defined items (such as DICOM Transfer Syntaxes) and shall not be used for privately defined items (such as an Image Instance).


To read more about Dicom Unique Identifiers you can visit this page here.

How to generate a Unique Identifier:
Code:

private string GenerateNewUid(string orgroot)
{
   //Gets date/time
   var now = DateTime.Now;

   //Gets numeric date info without year...exact military time
   string zeroDate = now.Month.ToString() + now.Day.ToString() + "." + now.Hour.ToString() + now.Minute.ToString() + now.Second.ToString() + now.Millisecond.ToString();

   //Globally Unique Identifier
   string guid = new string(Guid.NewGuid().ToString().Where(char.IsDigit).ToArray());

   //Combines the strings
   string sopUid = $"{orgroot}.{zeroDate}.{guid}";

   //check the length of the string to see if it's over 64 characters long, if it is, then make a substring of it that is 64 chars long starting at char index 0
   //otherwise, use the original string
   sopUid = sopUid.Length > 64 ? sopUid.Substring(0, 64) : sopUid;
   return sopUid;
}


How to add the SOPInstanceUID (Unique Identifier) to your Dicom DataSet :
Code:

//reserved org root for DICOM
string orgnum = "1.2.840.10008";

//Generate a new unique Identifier
string uid = GenerateNewUid(orgnum);

//Now add the Unique Identifier to your Dicom DataSet

//Start Dicom engine
DicomEngine.Startup();

DicomDataSet ds = new DicomDataSet();

//Removes all the items from the Data Set
ds.Reset();

//Creates the Data Set object, inserting the appropriate elements for the specified class.
ds.Initialize(DicomClassType.SCImageStorage, DicomDataSetInitializeFlags.AddMandatoryElementsOnly | DicomDataSetInitializeFlags.ExplicitVR);

//Finds or inserts (if not found) an element in the data set and sets the value of the element
ds.InsertElementAndSetValue(DicomTag.SOPInstanceUID, uid);
 

Edited by moderator Wednesday, September 5, 2018 9:06:11 AM(UTC)  | Reason: Removed duplicate call to GenerateNewUid

Nick Villalobos
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.046 seconds.