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

## ----setup--------------------------------------------------------------------
library(dicomtk)
library(dplyr)

# Verify bundled DCMTK 3.7.1 engine & dictionary
dicom_info()

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

# Long tidy tibble of DICOM elements
hdr <- read_dicom(dcm_file)
hdr |>
  filter(group %in% c("0008", "0028")) |>
  select(tag, vr, keyword, name, value) |>
  head(10)

# Wide format (1 row per file, columns named by DICOM keyword)
read_dicom(dcm_file, wide = TRUE) |>
  select(any_of(c("file", "Modality", "Rows", "Columns", "BitsAllocated")))

## ----plot-dicom, fig.width = 5, fig.height = 5--------------------------------
plot_dicom(dcm_file, window = "auto", palette = "gray", title = "Example DICOM Slice")

## ----anonymize----------------------------------------------------------------
anon_path <- dicom_anonymize(
  dcm_file,
  patient_name = "STUDY^SUBJECT01",
  patient_id = "SUBJ001",
  shift_days = -365
)
dicom_tag_value(anon_path, c("PatientName", "PatientID", "PatientIdentityRemoved"))

## ----llm-demo-----------------------------------------------------------------
# Configure local Ollama or OpenAI/Anthropic provider
# ollama_llm <- dicom_llm("ollama", model = "llava:13b")
# openai_llm <- dicom_llm("openai", model = "gpt-4o")
# claude_llm <- dicom_llm("anthropic", model = "claude-sonnet-4-20250514")

# Deterministic local mode for offline reproducibility
local_ai <- dicom_llm("offline")
dicom_summarize(dcm_file, llm = local_ai)
dicom_report(dcm_file, llm = local_ai)

