发布于 2019-09-19 15:22:12
基于@AmitJoshi的其他答案;我现在可以回答我的问题:
下面是JavaScript函数:
function GenerateUidFromGuid(){
var guid = uuid.v4(); //Generate UUID using node-uuid *) package or some other similar package
var guidBytes = `0${guid.replace(/-/g, "")}`; //add prefix 0 and remove `-`
var bigInteger = bigInt(guidBytes,16); //As big integer are not still in all browser supported I use BigInteger **) packaged to parse the integer with base 16 from uuid string
return `2.25.${bigInteger.toString()}`; //Output the previus parsed integer as string by adding `2.25.` as prefix
}以下是参考资料:
发布于 2019-09-19 13:05:57
我知道您正在寻找JavaScript示例;但是下面是一个c#代码。看看能不能把它翻译成JavaScript。变量名称和数据类型是自我解释的,这可能有助于您翻译。
下面的代码是基于@VictorDerks的这答案的。答案中甚至解释了一个更快的方法,请看。
public string GenerateUidFromGuid()
{
Guid guid = Guid.NewGuid();
string strTemp = "";
StringBuilder uid = new StringBuilder(64, 64);
uid.Append("2.25.");
//This code block is important------------------------------------------------
string guidBytes = string.Format("0{0:N}", guid);
BigInteger bigInteger = BigInteger.Parse(guidBytes, NumberStyles.HexNumber);
strTemp = string.Format(CultureInfo.InvariantCulture, "{0}", bigInteger);
uid.Append(strTemp);
//This code block is important------------------------------------------------
return uid.ToString();
}Guid guid看起来像f254934a-1cf5-47e7-913b-84431ba05b86。
string.Format("0{0:N}", guid)返回0f254934a1cf547e7913b84431ba05b86。格式被移除并以零作为前缀。
BigInteger.Parse(guidBytes....返回322112315302124436275117686874389371782。BigInteger.Parse将将字符串转换/解析为大整数数据类型。NumberStyles决定如何设置格式。
发布于 2020-10-29 12:09:59
为了防止您想要达到相同目的的库,可以使用由dicomuid.js ( 桑杜斯 (StackOverflow配置文件)编写的)库。
这不需要组织根前缀;这使用“2.25”。作为前缀。这使用了通用唯一标识符(UUID)。它将UUID转换为单个大小数。
下面是从github复制的代码
// Create new DICOM UID.
// Result will be like 2.25.176371623884904210764200284661930180516
var uid1 = DICOMUID.create();
// Create DICOM UID from a RFC4122 v4 UUID.
// Result for line below is 2.25.329800735698586629295641978511506172918
var uid2 = DICOMUID.create("f81d4fae-7dec-11d0-a765-00a0c91e6bf6");https://stackoverflow.com/questions/58009141
复制相似问题