且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在JavaScript中将UUID/GUID转换为OID/DICOM UID?

更新时间:2023-02-04 18:27:56

基于@AmitJoshi的其他答案;我现在可以回答我的问题:

Based on other answer from @AmitJoshi; I can now answer my question:

这是JavaScript函数:

Here is the JavaScript function:

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
}

以下是参考文献:

  • https://github.com/kelektiv/node-uuid
  • https://github.com/peterolson/BigInteger.js

jsfiddle