How to convert UUID/GUID to OID/DICOM UID in JavaScript?

前端 未结 3 781
梦毁少年i
梦毁少年i 2021-01-21 09:33

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.17450698773882054

3条回答
  •  北海茫月
    2021-01-21 10:08

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

    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
    }
    

    Following are the references:

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

    jsfiddle

提交回复
热议问题