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!


9 comments:

  1. change:
    $rzdcx64 = Resolve-Path .\rzdcx\win32\rzdcx.dll

    to:
    $rzdcx64 = Resolve-Path .\rzdcx\x64\rzdcx.dll

    ReplyDelete
  2. Hi Roni, there is a little typo in the script that leads to the following COM exception:

    80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

    It's due to a wrong path to the x64 dll, that should be:

    $rzdcx64 = Resolve-Path .\rzdcx\x64\rzdcx.dll

    Hope this helps

    ReplyDelete
  3. I always get this error... any ideas on what I'm doing wrong?


    PS C:\> # Create DICOM Object
    $DCM = New-Object -com rzdcx.DCXOBJ
    New-Object : Retrieving the COM class factory for component with CLSID {D0F02240-CB2C-468B-9DF5-E0FC4CA94839} failed due to the following error: 80040154 Class not registered (Exception
    from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
    At line:2 char:8
    + $DCM = New-Object -com rzdcx.DCXOBJ
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

    ReplyDelete
  4. New File name and location: http://downloads.roniza.com/rzdcx/2.1.0.5/RZDCX-2105.zip

    ReplyDelete
  5. newer version change download to ..... http://downloads.roniza.com/rzdcx/2.1.0.5/RZDCX-2105.zip

    ReplyDelete
  6. The Latest Version of RZDCX is v2.1.0.6, which can be found at the following URL.

    https://downloads.roniza.com/rzdcx/2.1.0.6/RZDCX-2106.zip

    ReplyDelete
  7. Latest Version of RZDCX is v2.1.0.6, which you can Download via the following URL.

    https://downloads.roniza.com/rzdcx/2.1.0.6/RZDCX-2106.zip

    ReplyDelete

Hi, Thank you for commenting. Please note that comments are moderated and will not show immediately. Please don't put links in your comments as they will not be published.