Skip to content

Instantly share code, notes, and snippets.

@aclud
Created February 29, 2024 20:41
Show Gist options
  • Save aclud/f3c532cfbd861edca3d91e7de2369681 to your computer and use it in GitHub Desktop.
Save aclud/f3c532cfbd861edca3d91e7de2369681 to your computer and use it in GitHub Desktop.
Javascript DICOM UID append and route
// Rule::Evaluate()
function Rule::Evaluate()
{
//note - UID length not validated for conformance to standards, use case specific and short-term
//change these lines to suit your needs
var strLog = "c:\\temp\\data.txt"; //log path must exist
var strDestinationUID = "1.2.528.1.1001.300.17.5477.3229.31222759877014.20110126194948796"; //use GetDestinationUID.vbs to obtain UID to send to
var strAdd = ".1"; // string to add to the end of every UID
//create logging object
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile(strLog, 8, true, 0);
//create variables from DICOM file
var strStudyUid = dcmsetImage.GetValue(0x0020000D);
var strSeriesUid = dcmsetImage.GetValue(0x0020000E);
var strImageUid = dcmsetImage.GetValue(0x00080018);
//change the DICOM data
dcmsetRepair.SetValue(0x0020000D, strStudyUid + strAdd);
dcmsetRepair.SetValue(0x0020000E, strSeriesUid + strAdd);
dcmsetRepair.SetValue(0x00080018, strImageUid + strAdd);
//write to the log file and close it
file.WriteLine(fnTime() + ";" + strStudyUid + ";" + strSeriesUid + ";" + strImageUid);
//log.info("---> " + strStudyUid + " changed to " + strStudyUid + strAdd + " <---"); //log additional info to connect.log if needed
file.Close();
//submit send job
var objCN = new ActiveXObject("***REMOVED***");
var objPS = new ActiveXObject("***REMOVED***");
objPS.Clear();
objPS.SetProperty("StudyUID", strStudyUid + strAdd);
objPS.SetProperty("DestinationUID", strDestinationUID);
objCN.SubmitSendJob(objPS.asString);
return true;
};
function fnTime()
{
var newDate = new Date;
while ((new Date()) - newDate <= 1) {} ;
var yyyy = newDate.getFullYear() ;
var mo = pad(newDate.getMonth() + 1, 2);
var dd = pad(newDate.getDate(), 2) ;
var hh = pad(newDate.getHours(), 2) ;
var mm = pad(newDate.getMinutes(), 2) ;
var ss = pad(newDate.getSeconds(), 2) ;
var ms = pad(newDate.getMilliseconds(), 3) ;
return yyyy + "-" + mo + "-" + dd + " " + hh + ":" + mm + ":" + ss + "." + ms
};
function pad(number, length)
{
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment