我看过Pixelmed文档中的getNewSOPInstanceUID方法,但我不熟悉Pixelmed源代码。我需要一个算法或Python源代码。
在DICOM中创建UID有两种方式。一种是基于注册的UID根,另一种是基于UUID。后一种方法是在2012年通过CP-1156添加到DICOM标准中的。例如Study UID、Series UID和SOP Instance UID等的UID可以通过将UUID转换为DICOM UID来创建。
大多数编程语言都内置了创建UUID的支持。下面的示例代码基于GUID值在C#中创建一个有效的DICOM UID。
public static string GuidToUidStringUsingStringAndParse(Guid value)
{
var guidBytes = string.Format("0{0:N}", value);
var bigInteger = BigInteger.Parse(guidBytes, NumberStyles.HexNumber);
return string.Format(CultureInfo.InvariantCulture, "2.25.{0}", bigInteger);
}
以下方法执行相同操作,但速度快约5倍:public static string ConvertGuidToUuidInteger(ref Guid value)
{
// ISO/IEC 9834-8, paragraph 6.3 (referenced by DICOM PS 3.5, B.2) defines how
// to convert a UUID to a single integer value that can be converted back into a UUID.
// The Guid.ToByteArray Method returns the array in a strange order (see .NET docs),
// BigInteger expects the input array in little endian order.
// The last byte controls the sign, add an additional zero to ensure
// the array is parsed as a positive number.
var octets = value.ToByteArray();
var littleEndianOrder = new byte[]
{ octets[15], octets[14], octets[13], octets[12], octets[11], octets[10], octets[9], octets[8],
octets[6], octets[7], octets[4], octets[5], octets[0], octets[1], octets[2], octets[3], 0 };
return "2.25." + new BigInteger(littleEndianOrder).ToString(CultureInfo.InvariantCulture);
}
1.2.840.xxxxx.30.152.99999.235.20.100.yyyyMMddHHmmss.zzzzzz
具体含义:
1.2.840.xxxxx: 组织根
30: 应用程序ID
152: 应用程序版本
99999: 安装/位置ID
235: 研究ID
20: 系列号
100: 图像号
yyyyMMddHHmmss: 日期时间
zzzzzz: 线程安全计数器/随机数
问题:
D] 基于UUID的UID [建议使用]
UID可以由根"2.25."后跟通用唯一标识符(UUID)的十进制表示形式生成。
问题:
YOUR_ORGROOT.Year.Month.Day.Hour.Minute.Second.Milliseconds.StaticCounter
注意,限制为64个字符!我真的建议你不要自己实现它。现在大多数语言都提供了UUID库,不要重复造轮子。特别是如果你要编写提取MAC地址的代码,这可能非常复杂,需要用可移植的C语言编写。
UUID并不完全符合DICOM定义,因此您需要注册自己的组织根UID,然后只需使用生成的UUID填充即可满足空间和时间唯一性条件。
YOUR_ORG_ROOT.CONVERTED_UUID
请注意,您在Value Representation UI中有64个字节的存储空间(已经足够了,请参见这里):
([0-9.]+)
Org Root
\0
(0二进制)进行填充。最后,由于您正在使用Python,请使用uuid库python-uuid。
上述内容应被视为标准中官方定义的替代实现:
当直接将UUID转换为UID时,必须使用“2.25.”根。