zdavatz / gdt2dicom

Convert a gdt file and an image folder to a dicom file
GNU General Public License v3.0
0 stars 1 forks source link

Add Dicom Custom Tags when creating .wl file #20

Closed zdavatz closed 1 year ago

zdavatz commented 1 year ago
  1. We need to be able to add DICOM custom tags when creating the worklist file:
  2. dcmodify -i "0008,0060=ECG" test.dcm
  3. dcmodify -i "0032,1060=holter" test.dcm
  4. This should be able to be done when doing gdt2dicom --gdt-file epat.gdt --output epat.wl
  5. Maybe something like: gdt2dicom --gdt-file epat.gdt --tag 0008,0060=ECG,0032,1060=holter --output epat.wl
zdavatz commented 1 year ago

This script will do the trick:

$directory = 'S:\GDT-E-PAT-Vitabyte'
$originalFileName = 'epat.gdt'

# Check if the file exists in the directory
$files = Get-ChildItem -Path $directory -Filter $originalFileName

if ($files.Count -gt 0) {
    $timestamp = Get-Date -Format 'yyyyMMddHHmmss'
    $counter = 1

    foreach ($file in $files) {
        $extension = $file.Extension
        $newName = "$timestamp" + "_epat_$counter" + $extension
        $newPath = Join-Path -Path $directory -ChildPath $newName
        Rename-Item -Path $file.FullName -NewName $newPath
        $counter++
    }

    Write-Host "Files renamed successfully."
} else {
    Write-Host "No files named '$originalFileName' found in the directory."
}

$gdtDirectory = 'S:\GDT-E-PAT-Vitabyte'
$outputDirectory = 'C:\Users\medi-lan\gdt2dicom\dicom\medilan_MWL'
$gdt2dicomExe = 'C:\Users\medi-lan\gdt2dicom\gdt2dicom.exe'

# Create the output directory if it doesn't exist
if (-not (Test-Path -Path $outputDirectory)) {
    New-Item -ItemType Directory -Path $outputDirectory | Out-Null
}

# Get all GDT files in the input directory
$gdtFiles = Get-ChildItem -Path $gdtDirectory -Filter '*.gdt'

foreach ($gdtFile in $gdtFiles) {
    $outputFile = Join-Path -Path $outputDirectory -ChildPath ($gdtFile.Name -replace '\.gdt$', '.wl')
    & $gdt2dicomExe --gdt-file $gdtFile.FullName --output $outputFile
}

Get-ChildItem -Path $outputDirectory -Filter "*.wl" | ForEach-Object {
    & "dcmodify" -i "0008,0060=ECG" "$($_.FullName)"
    & "dcmodify" -i "0032,1060=holter" "$($_.FullName)"
}