dicom

Quick and dirty JavaScript DICOMweb UID generator

I thought I’d share this tidbit code, to create UIDs (Study Instance UID, SOP Insuance UID, etc) using Javascript, primarily for use with standards like DICOMweb STOW-RS and UPS-RS.

WARNING: This is not a proper implementation, and could result in UID collisions in your repositories. Do not use in production – you should use proper UID management procedures defined in  DICOM PS3.5 B.1.

var dicomUID = '2.25.xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
   var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
   return v.toString(10);
});

I put a functional example on jsFiddle.

See DICOM PS3.5 B.2 for the specification reference. The JavaScript inspiration came from an answer on StackOverflow.