Friday, January 24, 2020

Update DICOM tags with PowerShell



Using the dicom PowerShell Module



Get the DICOM Powershell Module
https://www.powershellgallery.com/packages/Dicom/1.0.10.0


Powershell Script
================================================
# Update DICOM file TAGS

# Use this command to install Dicom Module - Install-Module -Name Dicom


$curpath = $(Get-Location).Path
$targetFolder = $curpath + "\*.dcm"
$dcmfiles = Get-ChildItem $targetFolder

# Series Description Tag Names Hash table
        $seriesDescriptionS = @{
            LAP='Leg Full Left AP (Stitched)'
            LL='Leg Full Left Lat (Stitched)'
            RAP='Leg Full Right AP (Stitched)'
            RL='Leg Full Right Lat (Stitched)'
        }



#Process targeted dicom files

ForEach ($dcmfile in $dcmfiles) {

$dicomfile = Import-dicom -Filename $dcmfile
$dicom = Read-Dicom -DicomFile $dicomfile
$dicom.SeriesDescription
$PatientID=$dicom.PatientID
$newseriesDescription = $seriesDescriptionS.($dcmfile.BaseName.ToUpper())
$tempfolder = "c:\support\dcmtemp"
# Look for file names with ll,rl,rap, or rl to processs and insert tags
    if ($newseriesDescription) {


    edit-dicom -DicomFile $dicomfile -Tag "0018,1164" -Value '0.150000\0.150000'
    edit-dicom -DicomFile $dicomfile -Tag "0008,103e" -Value $newseriesDescription
    Export-Dicom -DicomFile $dicomfile -DestinationPath $tempfolder
    $tempfile = $tempfolder + "\DICOM\0000001"
    $targetFile = $curpath + "\" + $PatientID + "-" +$dcmfile.BaseName.ToUpper() + "s.dcm"
    $targetFile
    Copy-Item -Path $tempfile -Destination $targetFile


    }
}

Remove-Item $tempfolder -Force  -Recurse -ErrorAction SilentlyContinue

1 comment:

  1. A (DICOM) Data Element Tag is represented as (gggg,eeee), where gggg equates to the Group Number and eeee equates to the Element
    Number within that Group. Data Element Tags are represented in hexadecimal notation as specified for each named Data Element
    in this Standard.

    ref: http://dicomlookup.com/pdf2016/part06.pdf

    ReplyDelete