Skip to contents

Overview

dicomtk provides a tidyverse-friendly interface to DICOM networking (dcmnet, dcmqrdb, dcmwlm, dcmtls): - dicom_connect(): Configure a remote DIMSE PACS peer, DICOMweb REST endpoint, or local PACS storage directory. - dicom_tls_config(): Configure BCP 195 TLS transport security (dcmtls). - dicom_echo(): Verify connectivity via DICOM Upper Layer A-ASSOCIATE-RQ + C-ECHO-RQ. - dicom_find(): Query studies, series, or instances as a tidy tibble. - dicom_get(): Retrieve matched DICOM files into a local directory. - dicom_send() / dicom_receive(): Store and receive DICOM objects (C-STORE). - dicom_qrdb_index() & dicom_worklist(): Local index database (dcmqrdb) and Modality Worklist (dcmwlm).

library(dicomtk)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk")

# 1. Start a local PACS storage receiver (SCP directory)
pacs_dir <- tempfile("local_pacs_")
conn <- dicom_receive(pacs_dir, port = 11112, aetitle = "DICOMTK-SCP")
conn
#> ℹ DICOM Connection: DICOMTK-SCP -> DICOMTK-SCP@127.0.0.1:11112
#> ℹ Local PACS directory: C:\Users\lauye\AppData\Local\Temp\RtmpOw6Eyu\local_pacs_56b44b6c70b

# 2. Verify PACS connectivity
dicom_echo(conn)
#> # A tibble: 1 × 7
#>   host       port called_ae   success status        message           elapsed_ms
#>   <chr>     <int> <chr>       <lgl>   <chr>         <chr>                  <dbl>
#> 1 127.0.0.1 11112 DICOMTK-SCP TRUE    SUCCESS_LOCAL "Local DICOM rep…        0.1

# 3. Send DICOM file(s) to the PACS peer (C-STORE)
dicom_send(dcm_file, conn)
#> # A tibble: 1 × 4
#>   file                                                destination success status
#>   <chr>                                               <chr>       <lgl>   <chr> 
#> 1 "C:\\Users\\lauye\\AppData\\Local\\Temp\\RtmpeuFNW… "C:\\Users… TRUE    STORE…

# 4. Query PACS studies with tidyverse piping and retrieve matching files
retrieved_files <- conn |>
  dicom_find(level = "STUDY") |>
  dicom_get()

retrieved_files
#> [1] "C:\\Users\\lauye\\AppData\\Local\\Temp\\RtmpOw6Eyu\\dicom_get_56b4100c635a\\example.dcm"

# 5. Build a local dcmqrdb index table
dicom_qrdb_index(pacs_dir) |>
  select(PatientID, Modality, Rows, Columns)
#> # A tibble: 1 × 4
#>   PatientID Modality Rows  Columns
#>   <chr>     <chr>    <chr> <chr>  
#> 1 98890234  CT       512   512