-
-
Save goeblr/816e9cef0c1ca7f71238a131a03d9bba to your computer and use it in GitHub Desktop.
Dicom UUID-derived UID generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A port from javascript: https://hcintegrations.ca/2014/05/14/quick-and-dirty-javascript-dicomweb-uid-generator/ | |
public static string NewUID_dirty() | |
{ | |
var r = new System.Random(); | |
var uid = System.Text.RegularExpressions.Regex.Replace("2.25.xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx", "x", m => (r.Next()%16).ToString() ); | |
return System.Text.RegularExpressions.Regex.Replace(uid, "y", m => (r.Next()&3|8).ToString()); | |
} | |
// Trying to strictly follow the Dicom spec: ftp://medical.nema.org/medical/dicom/2013/output/html/part05.html#sect_B.2 | |
// More details at: ISO/IEC 9834-8 / ITU-T X.667, Section 6.3 | |
public static string NewUID() | |
{ | |
var guid = new System.Guid().ToByteArray(); | |
var bigint = new System.Numerics.BigInteger(guid); | |
return "2.25." + bigint.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment