如何在JavaScript中将UUID/GUID转换为OID/DICOM UID? [英] How to convert UUID/GUID to OID/DICOM UID in JavaScript?

查看:300
本文介绍了如何在JavaScript中将UUID/GUID转换为OID/DICOM UID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何转换类似8348d2c5-0a65-4560-bb24-f4f6bcba601d的UUID/GUID值(我用 uuid生成了 v4)像2.25.174506987738820548334170905323706671133一样转换为OID/DICOM UID吗?我希望使用JavaScript解决方案.参见维基百科).

How can I convert an UUID/GUID value like 8348d2c5-0a65-4560-bb24-f4f6bcba601d (that I genreated with uuid v4) in to OID/DICOM UID like 2.25.174506987738820548334170905323706671133? I would prefer the solution in JavaScript. See wikipedia).

我使用在线生成器转换的示例.

The example I converted with this online generator.

推荐答案

基于@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

这篇关于如何在JavaScript中将UUID/GUID转换为OID/DICOM UID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆