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

2024/2/27 7:32:41

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.


I am aware you are looking for JavaScript sample; but following is a c# code. See if you can translate it to JavaScript. The variable names and data types are self explainer which may help you while translation.

The code below is based on this answer from @VictorDerks. There is even a faster method explained in that answer; have a look.

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();

The Guid guid looks like f254934a-1cf5-47e7-913b-84431ba05b86.

The string.Format("0{0:N}", guid) returns 0f254934a1cf547e7913b84431ba05b86. Formatting is removed and prefixed with zero.

The BigInteger.Parse(guidBytes.... returns 322112315302124436275117686874389371782. The BigInteger.Parse will convert/parse the string to big-integer data type. The NumberStyles determine how to format.

Looking at the question, I think you are already aware about details explained here and here.

Related Q&A

JavaScript Depth-first search

I am trying to implement DFS in JavaScript but I am having a little problem. Here is my Algorithm class:"use strict";define([], function () {return function () {var that = this; = …

Differences between`[.]` vs `.` in regex

The following expressions are not the same: /[.]*/ and /.*/. Why is that, and how exactly are they different? What is the interaction between the [] and special characters in regular expressions?Than…

Javascripts sort is unstable - how do I get around this?

According to the MDN spec, Javascripts sort() function is unstable (does not maintain input order for identical elements).Ironically, it seems that Firefox currently doesnt implement this - but Chrome …

contenteditable div loses selection when another input focuses

I have a problem with contenteditable div. When i want to execute a simple command (like bold or italic) on it, i do the following:memorize the div (since it will lose focus after i click on bold butto…

Web Audio API analyser node getByteFrequencyData returning blank array

Im trying to access FFT data from the analyser node using analyser.getByteFrequencyData(array) but it seems to return a blank array:var array = new Uint8Array(analyser.frequencyBinCount); analyser.getB…

insert at cursor in react

I need to insert text at caret (current cursor position) in the React-controlled textarea (like autocomplete).For vanilla textarea I used this code:insertAtCursor: function (myField, myValue) {// IEif …

How to get all objects that are visible on the camera in Three.js

I need lazy load textures to my meshes, and load only those that are visible to the camera. how i can do this without million vectors in Raycaster?

Passing Value Including Spaces on Ajax Call

Trying to pass spaces along with ajax call.word is been passed the same as word i believe so.On the other hand two words need to be send completely with call.word second but not the same as word secon…

How to render a react component from a string name

I want to dynamically render a react component from its string-name. Here is what I have done, but it does not work. Can this be done ? An example would really help.string_name is the name of the comp…

Using Google Tag Manager with Google Analytics to track a Chrome Extension (2020)

I am working on a chrome extension, and I would like to be able to track metrics with google analytics. I believe the easiest way to do that would be through tag manager, and I have found this tutorial…