Tuesday, January 15, 2019

PowerShell DICOM Scripting

Disclosure: This post is purely technical!
Assumption: you know your way around PowerShell or how to get there and a bit of DICOM and our RZDCX API.

If your system is x64 (probably) than make sure to regsvr32 radix.dll the x64 version.

Let's PowerShell!!!

# download rzdcx
Invoke-WebRequest -Uri http://downloads.roniza.com/rzdcx/2.0.8.7/RZDCX_2087.zip -OutFile ./rzdcx.zip

# unzip it
Expand-Archive ./rzdcx.zip -DestinationPath ./rzdcx

# regsvr32 win32 version
$rzdcx32 = Resolve-Path .\rzdcx\win32\rzdcx.dll
Start-Process regsvr32 -verb runAs -argumentlist $rzdcx32

$rzdcx64 = Resolve-Path .\rzdcx\x64\rzdcx.dll
Start-Process regsvr32 -verb runAs -argumentlist $rzdcx64

# Create DICOM Object
$DCM = New-Object -com rzdcx.DCXOBJ

# I assume you have a directory called DICOM with DICOM files in it
$files = @(Get-ChildItem ".\DICOM\*")

# Write headers
"filename, Patient Name, Patient ID"

# For each file extract and print patient name and patient id
foreach ($file in $files) {
  $DCM.openFile($file)
  $patname = $DCM.GetElement([int32]::Parse(00100010,'HexNumber')).Value
  $patid   = $DCM.GetElement([int32]::Parse(00100020,'HexNumber')).Value
  Write-Host $file "," $patname "," $patid
}

Try it!