GithubHelp home page GithubHelp logo

gdt2dicom's Introduction

ypm

ywesee Pharma Monitor

Use Cases

  1. Monitor RSS Feeds in file rss_feeds.txt
  2. Monitor the RSS Feeds based on keywords in file keywords.txt
  3. Make Hash-Tags out of Keywords and make Hash-Tags clickable.
  4. Sort monitored articles by country.
  5. Show article count by country.
  6. Keywords and RSS-Feed-Links must be stored in a DB.

Running the App

meteor npm i
meteor

gdt2dicom's People

Contributors

b123400 avatar zdavatz avatar

Watchers

 avatar  avatar

Forkers

b123400

gdt2dicom's Issues

First name and family Name are still wrong

  1. When converting to DICOM worklist files, First name and Family name are still mixed up.
  2. Family name (surname) always has to come first in the DICOM Worklist file, then the first names.
  3. MOZART^WOLFGANG^AMADEUS

`dciodvfy` Validator output

  1. Patients with the same name should use the same Study ID. Some software is Study Root not Patient Root. We could use the Patient ID as Study ID.
  2. The validator https://dclunie.com/dicom3tools/dciodvfy.html
  3. sudo apt-get install dicom3tools
  4. dciodvfy 2.dcm
  5. Gives this output:
Warning - Missing attribute or value that would be needed to build DICOMDIR - Study Date
Warning - Missing attribute or value that would be needed to build DICOMDIR - Study Time
Warning - Missing attribute or value that would be needed to build DICOMDIR - Study ID
Warning - Missing attribute or value that would be needed to build DICOMDIR - Modality
Warning - Missing attribute or value that would be needed to build DICOMDIR - Series Number
Warning - Missing attribute or value that would be needed to build DICOMDIR - Instance Number
Warning - Value dubious for this VR - (0x0010,0x0010) PN Patient's Name  PN [1] = <Hans Muster> - Retired Person Name form
MultiframeTrueColorSCImage
Error - Missing attribute Type 2C Conditional Element=<Laterality> Module=<GeneralSeries>

Grab JPGs reclusively

Look in current directory for directory names with 1-5 digits and recursively grab all jpgs in the folder and rename all jpgs with the 1-5 digit folder name in which the jpg was found. Save the renamed files in directory epat.

# Set the base directory
$baseDir = "C:\Users\zdava\Downloads\ul\ul\Convert"

# Output directory
$outputDir = "C:\Users\zdava\Downloads\ul\ul\Convert\epat"
# Create the output directory if it doesn't exist
if (-not (Test-Path -Path $outputDir)) {
    New-Item -ItemType Directory -Path $outputDir | Out-Null
}

# Get subdirectories with names exactly 10 digits long
$subdirectories = Get-ChildItem -Path $baseDir -Directory | Where-Object { $_.Name -match '^\d{1,5}$' }

# Iterate through each subdirectory
foreach ($subdirectory in $subdirectories) {
    # Get the 10-digit folder name
    $folderName = $subdirectory.Name

    # Get all JPG files in the current subdirectory and its subfolders
    $jpgFiles = Get-ChildItem -Path $subdirectory.FullName -Recurse -Filter *.jpg

    # Iterate through JPG files and rename them
    foreach ($jpgFile in $jpgFiles) {
        # Build the new filename
        $newFilename = "{0}_{1}" -f $folderName, $jpgFile.Name

        # Build the full path for the new file
        $newFilePath = Join-Path -Path $outputDir -ChildPath $newFilename

        # Move the file to the output directory with the new name
        Move-Item -Path $jpgFile.FullName -Destination $newFilePath -Force
    }
}

Write-Host "Files renamed and saved in epat directory!"

StoreSCP

StoreSCP just doesn't care about the called aetitle and accepts whatever DICOM association comes in on it's listen port. Besides, aetitles would be a very poor mechanism for access control since they are user configurable.

dcmrecv.exe -d -aet echonas -od . 257

`dicom2gdt` does not put Patient ID first in exported png file name

  1. When running
  2. .\dicom2gdt.exe --dicom-file USm.1.2.840.113619.2.435.385968960.1709821542.73.1.512 --gdt-file .\gdt\ --jpegs .\jpgs\
  3. the extracted .png files do not start with the patient ID that is outputted by dcmdump
  4. Every .png file name has to start with the patient ID and then _ and the the DICOM unique ID.

`cargo build` error on Windows

PS C:\Users\zdava\Documents\gdt2dicom\gdt2dicom> cargo build
error: failed to select a version for `env_logger`.
    ... required by package `gdt2dicom v0.1.0 (C:\Users\zdava\Documents\gdt2dicom\gdt2dicom)`
versions that meet the requirements `^0.11.0` (locked to 0.11.0) are: 0.11.0

the package `gdt2dicom` depends on `env_logger`, with features: `anstream` but `env_logger` does not have these features.
 It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.


failed to select a version for `env_logger` which could resolve this conflict

Create Worklist file from GDT file with `gdt2dcm`

  1. Create the binary gdt2dcm
  2. This command takes the GDT file as input and converts it to a DICOM Worklists file with the ending .wl.
  3. See: https://forum.dcmtk.org/viewtopic.php?t=1475
  4. Sample worklist dump files: https://github.com/InsightSoftwareConsortium/DCMTK/blob/master/dcmwlm/data/wlistdb/OFFIS/
  5. A worklist file does not contain images.
  6. The worklist file then has to be served using the command wlmscpfs (not part of gdt2dcm).
  7. Currently testing with: wlmscpfs.exe -v -dfp C:\Users\medi-lan\gdt2dicom\dicom\medilan_MWL\ 107
  8. Still getting this error:
I: Association Received (SDS-SRV1:CorScribe -> medilan_MWL)
I: Refusing Association (bad application entity service)

You can test the worklist file using these steps:

  1. Create a directory, i.e. dicom
  2. Create a subdirectory, i.e. medilan_MWL
  3. Create an empty file in the subdirectory medilan_MWL called lockfile
  4. Convert a dump file to worklist file with: dump2dcm.exe .\wklist1.dump.txt .\wklist1.wl in the medilan_MWL dir.
  5. Start the worklist server with: wlmscpfs.exe -v -dfp C:\Users\zdava\dicom\ 107
  6. Query the worklist server with Worklist Client (WL SCU) by @bettar
  7. query_wlmscpfs
  8. You can also use the commandline tool to test: findscu -aet zeno -aec medilan_MWL -k "(0010,0010)=HEWETT*" localhost 107 do not confuse calling and called.

Linux github Build complains about missing `glibc`

  1. Download gdt2dicom or dicom2gdt from github
  2. Trying to run it, results in
/tmp/target/release> ./dicom2gdt 
./dicom2gdt: /lib64/libc.so.6: version `GLIBC_2.33' not found (required by ./dicom2gdt)
./dicom2gdt: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by ./dicom2gdt)
./dicom2gdt: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by ./dicom2gdt)
/tmp/target/release> ./dicom2gdt 
./dicom2gdt: /lib64/libc.so.6: version `GLIBC_2.33' not found (required by ./dicom2gdt)
./dicom2gdt: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by ./dicom2gdt)
./dicom2gdt: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by ./dicom2gdt)

Create `gdt2opp` for Dexis software.

  1. The Dexis software needs this XML Format to import new patient data, as they do not yet support the DICOM Worklist modality:
<?xml version="1.0" encoding="UTF-8"?>
<opp version="1.2">
      <command type="UPDATE_CREATE" silent="NO"/>
      <software name="My first PMS software App" version="1.0.0.1"/>
      <patient reference="c19ea492ca35" firstName="John" lastName="Doe" birthdate="1992-03-31" gender="MALE">
      </patient>
</opp>
  1. Open Practice Protocol v1.3.pdf

Cargo Build Error auf Linux

error: failed to select a version for `env_logger`.
    ... required by package `gdt2dicom v0.1.0 (/home/zeno/.software/gdt2dicom)`
versions that meet the requirements `^0.11.0` (locked to 0.11.0) are: 0.11.0

the package `gdt2dicom` depends on `env_logger`, with features: `anstream` but `env_logger` does not have these features.
 It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.

Remove `(0008,0018)` before running `dump2dcm`

  1. The tag (0008,0018) has to be removed before running dump2dcm.
  2. This is the bare minimum dump file
(0008,0005) CS (no value available)                     #   0, 0 SpecificCharacterSet
(0008,0050) SH (no value available)                     #   0, 0 AccessionNumber
(0010,0010) PN [VIVALDI^ANTONIO]                        #  16, 1 PatientName
(0010,0020) LO [AV35674]                                #   8, 1 PatientID
(0010,0030) DA [16780304]                               #   8, 1 PatientBirthDate
(0010,0040) CS [M]                                      #   2, 1 PatientSex
(0010,2000) LO (no value available)                     #   0, 0 MedicalAlerts
(0010,2110) LO (no value available)                     #   0, 0 Allergies
(0020,000d) UI [1.2.276.0.7230010.3.2.101]              #  26, 1 StudyInstanceUID
(0032,1032) PN (no value available)                     #   0, 0 RequestingPhysician
(0032,1060) LO [holter]                                 #   6, 1 RequestedProcedureDescription
(0040,0100) SQ (Sequence with explicit length #=1)      #  50, 1 ScheduledProcedureStepSequence
  (fffe,e000) na (Item with explicit length #=3)          #  42, 1 Item
    (0008,0060) CS [ECG]                                    #   4, 1 Modality
    (0040,0002) DA [20230530]                               #   8, 1 ScheduledProcedureStepStartDate
    (0040,0003) TM [085607]                                 #   6, 1 ScheduledProcedureStepStartTime
  (fffe,e00d) na (ItemDelimitationItem for re-encoding)   #   0, 0 ItemDelimitationItem
(fffe,e0dd) na (SequenceDelimitationItem for re-encod.) #   0, 0 SequenceDelimitationItem

Use DICOM file as input

  1. Can we add an option to input some XML Tags.
  2. Input XML would be:
  3. UriSed.xml.txt
  4. AxioLab5.xml.txt
  5. The XML file would be in the image folder and should be automatically parsed, if it is there in the image folder.
  6. The other data would be added via the GDT input file.
  7. It should also be possible to pass the XML via commandline from any Folder.

Minimum Mortara HScribe Worklist requirements

  1. I just converted a GDT file to a Worklist file using Version 1.0.6
  2. The header still seems strange:
# Dicom-Meta-Information-Header
# Used TransferSyntax: Little Endian Explicit
(0002,0000) UL 148                                      #   4, 1 FileMetaInformationGroupLength
(0002,0001) OB 00\01                                    #   2, 1 FileMetaInformationVersion
(0002,0002) UI =MultiframeGrayscaleByteSecondaryCaptureImageStorage #  28, 1 MediaStorageSOPClassUID
(0002,0003) UI (no value available)                     #   0, 0 MediaStorageSOPInstanceUID
(0002,0010) UI =JPEGBaseline                            #  22, 1 TransferSyntaxUID
(0002,0012) UI [1.2.276.0.7230010.3.0.3.6.7]            #  28, 1 ImplementationClassUID
(0002,0013) SH [OFFIS_DCMTK_367]                        #  16, 1 ImplementationVersionName
  1. The header should be:
# Dicom-Meta-Information-Header
# Used TransferSyntax: Little Endian Explicit
(0002,0000) UL 198                                      #   4, 1 FileMetaInformationGroupLength
(0002,0001) OB 00\01                                    #   2, 1 FileMetaInformationVersion
(0002,0002) UI [1.2.276.0.7230010.3.1.0.1]              #  26, 1 MediaStorageSOPClassUID
(0002,0003) UI [1.2.276.0.7230010.3.1.4.3284257161.7184.1685536943.349] #  54, 1 MediaStorageSOPInstanceUID
(0002,0010) UI =LittleEndianExplicit                    #  20, 1 TransferSyntaxUID
(0002,0012) UI [1.2.276.0.7230010.3.0.3.6.7]            #  28, 1 ImplementationClassUID
(0002,0013) SH [OFFIS_DCMTK_367]                        #  16, 1 ImplementationVersionName
  1. Maybe xml2dcm creates "strange" headers.
  2. dump2dcm creates the right headers. But I do not know what happens if you first run xml2dcm
  3. Generating headers that work with Hscribe I do like this:
  4. Download dump file: https://raw.githubusercontent.com/InsightSoftwareConsortium/DCMTK/master/dcmwlm/data/wlistdb/OFFIS/wklist9.dump
  5. Convert Dump file to .wl file: dump2dcm.exe wklist9.dump wlist9.wl
  6. This input file also generates a correct MediaStorageSOPInstanceUID in the worklist file. https://raw.githubusercontent.com/InsightSoftwareConsortium/DCMTK/master/dcmwlm/data/wlistdb/OFFIS/wklist9.dump
  7. Depending on the contents of the .dump file dump2dcm will create different headers for the .wl file.

Implement gdt2vdds

  1. VDDS is a German Dental Standard.
  2. The patient ID has to be taken from the epat.gdt
  3. We need to convert the epat.gdt to the VDDS standard and send the file to the VDDS Software by calling the VDDS Software and reading the VDDS_MMI.ini for the parameters.
  4. vdds_media_1_4_druck.pdf
  5. Our software needs to read the VDDS_MMI.ini for the parameters. Sample of a VDDS_MMI.ini.txt the [BFS] tag can be ignored, it is being used for the "Befund".
  6. The BVS Tag we will read is NAME1=orangedental_byzz
  7. We call the BVS with Stage 1 and 3:
  8. Stufe 1: Die PVS ruft das Importmodul der BVS zur Übergabe der Patientendaten auf.
  9. Stufe 3: Die PVS ruft das Modul zum Export der Bildinformationen der BVS auf.
  10. Our PVS name is gdt2dicom_PVS. That we will have to write into VDDS_MMI.ini on the system.
  11. and then send the PatientTransfer.ini.txt (chapter 3.1)
  12. In the PatientTransfer.ini we can also specify where we want the JPEG files to be saved after the scan has been done. (chapter 3.2) MMOINFEXPORT, MMOINFEXPORT_OS
  13. To send the patient data we just do: c:\program files\byzz nxt\byzz.Vdds.exe PatientTransfer.ini
  14. For this we need a separate binary gdt2vdds
  15. Outputted images should be named: patientid_vorname_nachname_timestamp.jpg / tif / dcm

rename gdt file for Physioport

$folderPath = "S:\GDT-PhysioPort"
$fileName = "epat.gdt"
$newFileName = "vitaepat.gdt"

while ($true) {
    # Check if the file exists in the specified folder
    if (Test-Path (Join-Path $folderPath $fileName)) {
        # Rename the file
        Rename-Item (Join-Path $folderPath $fileName) (Join-Path $folderPath $newFileName)
        Write-Host "File '$fileName' found and renamed to '$newFileName'."
    }

    # Wait for 5 seconds before checking again
    Start-Sleep -Seconds 5
}

Add Dicom Custom Tags when creating .wl file

  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

Convert an image folder and a gdt file to a dicom file

  1. The GDT (see folder Starterpaket) file standard is widely used in Germany, but it does not contain image information.
  2. DICOM is a worldwide standard for imaging.
  3. With dcmtk tools you install img2dcm. img2dcm software converts JPEGs to DICOM files. img2dcm also takes XML as input.
  4. The software needs to take folder with JPEG images a GDT file and convert that into a dicom file using img2dcm. The folder name that contains the images can contain the Patient-ID. The patient ID is also in the GDT file.
  5. GDT sample file: 6301_Stammdaten_Uebermittelung.gdt.txt
  6. dcmdump of dcmtk tools will show you all the contents of a dicom file.
  7. dcm2xml.dtd will show you the valid XML that img2dcm can take as input. The GDT file has to be converted into valid DICOM XML according to dcm2xml.dtd.
  8. dcm2xml is also part of the dcmtk toolkit.

Start Worklist Server

worklist_server.ps1

$command = 'wlmscpfs.exe -v -d -dfr -dfp C:\Users\medi-lan\gdt2dicom\dicom\ 256'
Start-Process -FilePath "cmd.exe" -ArgumentList "/c `"$command`"" -WindowStyle Hidden

check if the worklist is running: tasklist.exe | findstr wlmscpfs

start_gdt2ws.ps1 -> #19 (comment)

while ($true) {
    # Run the command
    & "C:\Users\medi-lan\gdt2dicom\gdt2ws.ps1"

    # Pause for 10 seconds
    Start-Sleep -Seconds 10
}

gdt2vdds: `thread 'main' panicked at src\bin\gdt2vdds.rs:72:52:`

  1. Running this .\gdt2vdds.exe --gdt-file .\gdt\ --output .\jpeg2epat\ --bvs 3Shape
  2. I get:
[2024-03-01T11:21:51Z INFO  gdt2vdds] Loading VDDS_MMI: C:\Windows\VDDS_MMI.INI
thread 'main' panicked at src\bin\gdt2vdds.rs:72:52:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

PowerShell Script to convert `epat.gdt` to unique Worklist file

$directory = 'C:\Users\medi-lan\gdt2dicom\gdt'
$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 = 'C:\Users\medi-lan\gdt2dicom\gdt'
$outputDirectory = 'C:\Users\medi-lan\gdt2dicom\wl'
$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
}

Rename file names based on text file comparison

Powershell script to map file names of all files in a directory against a text file. UID of the filename has to updated if last name and first name match with the txt file. The format of the file name and the format of every line in the txt file are the same: After the first two __ comes the uid, after the thrid _ comes the last name and after the fourth _ comes the first name

# Set the paths for the input directory, text file, and output directory
$inputDirectory = "C:\Users\medi-lan\Documents\gdt2dicom\wrong_patient_id"
$textFilePath = "C:\Users\medi-lan\Documents\gdt2dicom\plist.txt"
$outputDirectory = "C:\Users\medi-lan\Documents\gdt2dicom\new_file_name"

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

# Read the content of the text file into a hashtable for quick lookup
$uidLookup = @{}
Get-Content -Path $textFilePath | ForEach-Object {
    $parts = $_ -split '_'
    $uid = $parts[2]
    $lastName = $parts[3]
    $firstName = $parts[4]
    $key = "$lastName,$firstName"
    $uidLookup[$key] = $uid
}

# Process files in the input directory
Get-ChildItem -Path $inputDirectory | ForEach-Object {
    if ($_.PSIsContainer -eq $false) {
        # Extract information from the file name
        $fileNameParts = $_.BaseName -split '_'
        $uid = $fileNameParts[2]
        $lastName = $fileNameParts[3]
        $firstName = $fileNameParts[4]

        # Check if there is a matching UID in the text file
        $key = "$lastName,$firstName"
        if ($uidLookup.ContainsKey($key)) {
            $uid = $uidLookup[$key]

            # Construct the new file name without "H__" and with ".pdf" extension
            $newFileName = "{1}_{2}_{3}_{4}.pdf" -f $fileNameParts[0], $fileNameParts[1], $uid, $lastName, $firstName

            # Build the full output path
            $outputPath = Join-Path -Path $outputDirectory -ChildPath $newFileName

            # Copy the file with the updated filename to the output directory
            Copy-Item -Path $_.FullName -Destination $outputPath
        }
    }
}

$files = Get-ChildItem -Path $outputDirectory

# Iterate through each file
foreach ($file in $files) {
    # Construct the new file name by removing underscores at the beginning
    $newFileName = $file.Name -replace '^_+'

    # Create the new file path
    $newFilePath = Join-Path -Path $outputDirectory -ChildPath $newFileName

    # Rename the file
    Rename-Item -Path $file.FullName -NewName $newFileName -Force
}

Write-Host "Underscores at the beginning of file names have been removed."

Write-Host "Script execution completed."

Canon `Aplio A` Pflichtfelder

  1. Canon Aplio A Pflichtfelder
  2. Pflichtfelder_Canon
(0008,0050) AccessionNumber
(0010,0010) PatientName
(0010,0020) PatientiD
(0020,000D) StudyinstanceUID
(0032,1060) RequestedProcedureDescription
(0040,0100) ScheduledProcedureStepSequence
ITEM 1|
(0008,0060) Modality
(0040,0001) ScheduledStationAETitle
(0040,0002) ScheduledProcedureStepStartDate
(0040,0003) ScheduledProcedureStepStartTime
(0040,0007) ScheduledProcedureStepDescription
(0040,0009) ScheduledProcedureStepID
ITEM 2
(0040,1001) RequestedProcedurelD

Dicom Conformance Statement Aplio a.pdf

dicom2gdt

  1. Create a dicom2gdt binary.
  2. Running dicom2gdt should convert a DICOM file to a GDT file, including the images and all the data about the patient from the DICOM file. Output files should be jpeg.
  3. dcmj2pnm --write-jpeg 1.dcm ./output --all-frames will write jpeg files.
  4. gdt.pdf

Add dicom tags

  1. Can we add dicom Tags via commandline when generating the DICOM file?
  2. dcmodify -i "0008,0060=ECG" test.dcm
  3. dcmodify -i "0032,1060=holter" test.dcm
  4. Would be nice if this could be done with gdt2dicom via a settings file or via commandline options.

Grab Dicom Tags and rename the file

With timestamp

# Specify input and output directories
$inputDir = "C:\Path\To\Input\Directory"
$outputDir = "C:\Path\To\Output\Directory"

# Get all DICOM files in the specified directory
$dicomFiles = Get-ChildItem -Path $inputDir -Filter *

foreach ($file in $dicomFiles) {
    # Use dcmdump to extract the DICOM tags
    $tags = & "dcmdump.exe" $file.FullName | Select-String -Pattern "(0010,0020|0010,0010|05af,0010)"

    # Extract values in between square brackets []
    $tagValues = $tags -replace '[^\[\]]*\[([^\[\]]*)\][^\[\]]*', '$1'

    # Ensure "0010,0020" is in the first position
    $sortedTagValues = $tagValues | Sort-Object {$_ -eq '0010,0020'} -Descending

    # Create a timestamp in the format YYYYMMDD_HHMMSS
    $timestamp = Get-Date -Format "yyyyMMdd_HHmmss"

    # Create a new filename based on the extracted values and timestamp
    $newFilename = "$($sortedTagValues -join '_')_$timestamp.dcm"

    # Construct the full path for the output file
    $outputPath = Join-Path -Path $outputDir -ChildPath $newFilename

    # Read the content of the original file as bytes
    $fileContent = [System.IO.File]::ReadAllBytes($file.FullName)

    # Write the content to the new file in the output directory
    [System.IO.File]::WriteAllBytes($outputPath, $fileContent)

    Write-Host "Copied and renamed $($file.FullName) to $outputPath"
}

Without timestamp

# Specify input and output directories
$inputDir = "C:\Path\To\Input\Directory"
$outputDir = "C:\Path\To\Output\Directory"

# Get all DICOM files in the specified directory
$dicomFiles = Get-ChildItem -Path $inputDir -Filter *

foreach ($file in $dicomFiles) {
    # Use dcmdump to extract the DICOM tags
    $tags = & "dcmdump.exe" $file.FullName | Select-String -Pattern "(0010,0020|0010,0010|05af,0010)"

    # Extract values in between square brackets []
    $tagValues = $tags -replace '[^\[\]]*\[([^\[\]]*)\][^\[\]]*', '$1'

    # Ensure "0010,0020" is in the first position
    $sortedTagValues = $tagValues | Sort-Object {$_ -eq '0010,0020'} -Descending

    # Create a new filename based on the extracted values
    $newFilename = "$($sortedTagValues -join '_').dcm"

    # Construct the full path for the output file
    $outputPath = Join-Path -Path $outputDir -ChildPath $newFilename

    # Read the content of the original file as bytes
    $fileContent = [System.IO.File]::ReadAllBytes($file.FullName)

    # Write the content to the new file in the output directory
    [System.IO.File]::WriteAllBytes($outputPath, $fileContent)

    Write-Host "Copied and renamed $($file.FullName) to $outputPath"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.