## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----workflow-----------------------------------------------------------------
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

# 2. Verify PACS connectivity
dicom_echo(conn)

# 3. Send DICOM file(s) to the PACS peer (C-STORE)
dicom_send(dcm_file, conn)

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

retrieved_files

# 5. Build a local dcmqrdb index table
dicom_qrdb_index(pacs_dir) |>
  select(PatientID, Modality, Rows, Columns)

