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)
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 -> [email protected]:11112
#> ℹ Local PACS directory: /tmp/RtmpaA1qSb/local_pacs_105a4c24530c
# 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 repo… 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 /tmp/RtmpsZjcyy/Rinsteb7c77406f/dicomtk/extdata/ex… /tmp/Rtmpa… 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] "/tmp/RtmpaA1qSb/dicom_get_105a791ea507/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