PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::samples Namespace Reference

Namespaces

namespace  colors
 ANSI escape codes for terminal colors.
 
namespace  events
 
namespace  sop_class
 

Classes

struct  access_control_config
 Access control configuration. More...
 
struct  anonymization_config
 Anonymization configuration. More...
 
class  config_loader
 
struct  database_config
 Database configuration for index storage. More...
 
struct  image_params
 Image parameters for test data generation. More...
 
struct  logging_config
 Logging configuration. More...
 
class  mini_pacs
 
struct  mini_pacs_config
 Configuration options for Mini PACS. More...
 
struct  mini_pacs_statistics
 Runtime statistics for Mini PACS operations. More...
 
struct  monitoring_config
 Health monitoring configuration. More...
 
struct  mpps_entry
 MPPS instance for tracking procedure progress. More...
 
struct  patient_info
 Patient information for test data generation. More...
 
struct  production_config
 Complete production PACS configuration. More...
 
class  production_pacs
 
struct  production_statistics
 Extended statistics for production PACS. More...
 
struct  rest_api_config
 REST API server configuration. More...
 
class  scoped_signal_handler
 
struct  security_config
 Complete security configuration. More...
 
struct  server_config
 DICOM server configuration. More...
 
class  signal_handler
 
struct  storage_config
 File storage configuration. More...
 
struct  study_info
 Study information for test data generation. More...
 
class  test_data_generator
 
struct  tls_config
 TLS security configuration for DICOM connections. More...
 
struct  worklist_entry
 Worklist item for MWL queries. More...
 

Functions

auto supports_color () noexcept -> bool
 Check if the terminal supports ANSI colors.
 
void set_color_enabled (bool enabled)
 Enable or disable color output globally.
 
auto is_color_enabled () noexcept -> bool
 Check if colors are currently enabled.
 
void print_header (std::string_view title)
 Print a header/title with decorative border.
 
void print_section (std::string_view title)
 Print a section header.
 
void print_success (std::string_view message)
 Print a success message.
 
void print_error (std::string_view message)
 Print an error message.
 
void print_warning (std::string_view message)
 Print a warning message.
 
void print_info (std::string_view message)
 Print an informational message.
 
void print_debug (std::string_view message)
 Print a debug message.
 
void print_dataset_summary (const core::dicom_dataset &ds)
 Print a summary of a DICOM dataset.
 
void print_dataset_elements (const core::dicom_dataset &ds, size_t max_value_length=60)
 Print all elements in a DICOM dataset.
 
void print_box (const std::vector< std::string > &lines)
 Print text in a decorative box.
 
void print_table (std::string_view title, const std::vector< std::pair< std::string, std::string > > &rows)
 Print a key-value table.
 
void print_progress (size_t current, size_t total, int width=40, std::string_view label="Progress")
 Print a progress bar.
 
void clear_line ()
 Clear the current line (for updating progress)
 
auto format_bytes (uint64_t bytes) -> std::string
 Format a byte size for human-readable display.
 
auto format_duration (uint64_t milliseconds) -> std::string
 Format a duration in milliseconds.
 
auto center_text (std::string_view text, size_t width) -> std::string
 Center a string within a given width.
 
auto truncate (std::string_view text, size_t max_length, std::string_view suffix="...") -> std::string
 Truncate a string to a maximum length.
 

Function Documentation

◆ center_text()

auto kcenon::pacs::samples::center_text ( std::string_view text,
size_t width ) -> std::string
nodiscard

Center a string within a given width.

Parameters
textThe text to center
widthThe total width
Returns
Centered string with padding

Definition at line 346 of file console_utils.cpp.

346 {
347 if (text.length() >= width) {
348 return std::string{text.substr(0, width)};
349 }
350
351 size_t padding = (width - text.length()) / 2;
352 return std::string(padding, ' ') + std::string{text} +
353 std::string(width - padding - text.length(), ' ');
354}

Referenced by print_header().

Here is the caller graph for this function:

◆ clear_line()

void kcenon::pacs::samples::clear_line ( )

Clear the current line (for updating progress)

Definition at line 302 of file console_utils.cpp.

302 {
303 std::cout << "\r" << std::string(kDefaultWidth, ' ') << "\r" << std::flush;
304}

◆ format_bytes()

auto kcenon::pacs::samples::format_bytes ( uint64_t bytes) -> std::string
nodiscard

Format a byte size for human-readable display.

Parameters
bytesNumber of bytes
Returns
Formatted string (e.g., "1.5 MB", "256 KB")

Definition at line 310 of file console_utils.cpp.

310 {
311 constexpr uint64_t KB = 1024;
312 constexpr uint64_t MB = KB * 1024;
313 constexpr uint64_t GB = MB * 1024;
314
315 std::ostringstream oss;
316 oss << std::fixed << std::setprecision(1);
317
318 if (bytes >= GB) {
319 oss << static_cast<double>(bytes) / static_cast<double>(GB) << " GB";
320 } else if (bytes >= MB) {
321 oss << static_cast<double>(bytes) / static_cast<double>(MB) << " MB";
322 } else if (bytes >= KB) {
323 oss << static_cast<double>(bytes) / static_cast<double>(KB) << " KB";
324 } else {
325 oss << bytes << " B";
326 }
327
328 return oss.str();
329}

◆ format_duration()

auto kcenon::pacs::samples::format_duration ( uint64_t milliseconds) -> std::string
nodiscard

Format a duration in milliseconds.

Parameters
millisecondsDuration in milliseconds
Returns
Formatted string (e.g., "1.5s", "250ms")

Definition at line 331 of file console_utils.cpp.

331 {
332 std::ostringstream oss;
333 oss << std::fixed << std::setprecision(1);
334
335 if (milliseconds >= 60000) {
336 oss << static_cast<double>(milliseconds) / 60000.0 << " min";
337 } else if (milliseconds >= 1000) {
338 oss << static_cast<double>(milliseconds) / 1000.0 << " s";
339 } else {
340 oss << milliseconds << " ms";
341 }
342
343 return oss.str();
344}

◆ is_color_enabled()

auto kcenon::pacs::samples::is_color_enabled ( ) -> bool
nodiscardnoexcept

Check if colors are currently enabled.

Returns
true if colors are enabled

Definition at line 92 of file console_utils.cpp.

92 {
93 if (!g_color_checked) {
94 g_color_enabled = supports_color();
95 g_color_checked = true;
96 }
97 return g_color_enabled;
98}
auto supports_color() noexcept -> bool
Check if the terminal supports ANSI colors.

References supports_color().

Here is the call graph for this function:

◆ print_box()

void kcenon::pacs::samples::print_box ( const std::vector< std::string > & lines)

Print text in a decorative box.

Parameters
linesVector of text lines to display

Example output: ┌─────────────────────────────────┐ │ Line 1 │ │ Line 2 │ └─────────────────────────────────┘

Definition at line 228 of file console_utils.cpp.

228 {
229 if (lines.empty()) {
230 return;
231 }
232
233 // Find maximum line length
234 size_t max_len = 0;
235 for (const auto& line : lines) {
236 max_len = std::max(max_len, line.length());
237 }
238 max_len = std::min(max_len, static_cast<size_t>(kDefaultWidth - 4));
239
240 std::cout << color(colors::dim);
241 std::cout << "+" << std::string(max_len + 2, '-') << "+\n";
242 for (const auto& line : lines) {
243 std::cout << "| " << std::left << std::setw(static_cast<int>(max_len))
244 << truncate(line, max_len) << " |\n";
245 }
246 std::cout << "+" << std::string(max_len + 2, '-') << "+\n";
247 std::cout << color(colors::reset);
248}

References color, kcenon::pacs::samples::colors::dim, kcenon::pacs::samples::colors::reset, and truncate().

Referenced by main(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_dataset_elements()

void kcenon::pacs::samples::print_dataset_elements ( const core::dicom_dataset & ds,
size_t max_value_length = 60 )

Print all elements in a DICOM dataset.

Parameters
dsThe dataset to display
max_value_lengthMaximum length for value display (truncated if longer)

Displays all elements with tag, VR, and value.

Definition at line 201 of file console_utils.cpp.

202 {
203 std::cout << color(colors::bold)
204 << std::left << std::setw(14) << "Tag"
205 << std::setw(6) << "VR"
206 << "Value"
207 << color(colors::reset) << "\n";
208 std::cout << std::string(kDefaultWidth, '-') << "\n";
209
210 for (const auto& [tag, element] : ds) {
211 std::cout << color(colors::cyan) << tag.to_string() << color(colors::reset)
212 << " ";
213
214 std::cout << color(colors::yellow)
215 << std::setw(4) << encoding::to_string(element.vr())
216 << color(colors::reset) << " ";
217
218 auto value_result = element.as_string();
219 std::string value = value_result.is_ok() ? value_result.value() : "<binary>";
220 std::cout << truncate(value, max_value_length) << "\n";
221 }
222}
auto truncate(std::string_view text, size_t max_length, std::string_view suffix) -> std::string
Truncate a string to a maximum length.

References kcenon::pacs::samples::colors::bold, color, kcenon::pacs::samples::colors::cyan, kcenon::pacs::samples::colors::reset, kcenon::pacs::encoding::to_string(), truncate(), and kcenon::pacs::samples::colors::yellow.

Here is the call graph for this function:

◆ print_dataset_summary()

void kcenon::pacs::samples::print_dataset_summary ( const core::dicom_dataset & ds)

Print a summary of a DICOM dataset.

Parameters
dsThe dataset to summarize

Displays key patient, study, series, and image information in a formatted table.

Definition at line 164 of file console_utils.cpp.

164 {
165 using namespace core::tags;
166
167 std::vector<std::pair<std::string, std::string>> patient_rows = {
168 {"Patient Name", ds.get_string(patient_name)},
169 {"Patient ID", ds.get_string(patient_id)},
170 {"Birth Date", ds.get_string(patient_birth_date)},
171 {"Sex", ds.get_string(patient_sex)},
172 };
173 print_table("Patient", patient_rows);
174
175 std::vector<std::pair<std::string, std::string>> study_rows = {
176 {"Study UID", truncate(ds.get_string(study_instance_uid), 40)},
177 {"Study Date", ds.get_string(study_date)},
178 {"Accession #", ds.get_string(accession_number)},
179 {"Description", ds.get_string(study_description)},
180 };
181 print_table("Study", study_rows);
182
183 std::vector<std::pair<std::string, std::string>> series_rows = {
184 {"Series UID", truncate(ds.get_string(series_instance_uid), 40)},
185 {"Modality", ds.get_string(modality)},
186 {"Series #", ds.get_string(series_number)},
187 {"Description", ds.get_string(series_description)},
188 };
189 print_table("Series", series_rows);
190
191 std::vector<std::pair<std::string, std::string>> image_rows = {
192 {"SOP Instance", truncate(ds.get_string(sop_instance_uid), 40)},
193 {"Rows", ds.get_string(rows)},
194 {"Columns", ds.get_string(columns)},
195 {"Bits Allocated", ds.get_string(bits_allocated)},
196 {"Photometric", ds.get_string(photometric_interpretation)},
197 };
198 print_table("Image", image_rows);
199}
auto get_string(dicom_tag tag, std::string_view default_value="") const -> std::string
Get the string value of an element.
void print_table(std::string_view title, const std::vector< std::pair< std::string, std::string > > &rows)
Print a key-value table.

References kcenon::pacs::core::dicom_dataset::get_string(), print_table(), and truncate().

Here is the call graph for this function:

◆ print_debug()

void kcenon::pacs::samples::print_debug ( std::string_view message)

Print a debug message.

Parameters
messageThe message text

Prints with dim/gray color.

Definition at line 155 of file console_utils.cpp.

155 {
156 std::cout << color(colors::dim) << "[DEBUG] " << message
157 << color(colors::reset) << "\n";
158}

References color, kcenon::pacs::samples::colors::dim, and kcenon::pacs::samples::colors::reset.

◆ print_error()

void kcenon::pacs::samples::print_error ( std::string_view message)

Print an error message.

Parameters
messageThe message text

Prints with red color and X symbol.

Definition at line 140 of file console_utils.cpp.

140 {
141 std::cout << color(colors::red) << "[ERROR] " << color(colors::reset)
142 << message << "\n";
143}

References color, kcenon::pacs::samples::colors::red, and kcenon::pacs::samples::colors::reset.

Referenced by main(), and main().

Here is the caller graph for this function:

◆ print_header()

void kcenon::pacs::samples::print_header ( std::string_view title)

Print a header/title with decorative border.

Parameters
titleThe title text

Example output: ╔══════════════════════════════════════════════════════════════════════════╗ ║ PACS System Sample Application ║ ╚══════════════════════════════════════════════════════════════════════════╝

Definition at line 118 of file console_utils.cpp.

118 {
119 std::cout << color(colors::bold) << color(colors::cyan);
120 std::cout << "\n";
121 std::cout << std::string(kDefaultWidth, '=') << "\n";
122 std::cout << center_text(title, kDefaultWidth) << "\n";
123 std::cout << std::string(kDefaultWidth, '=') << "\n";
124 std::cout << color(colors::reset) << "\n";
125}
auto center_text(std::string_view text, size_t width) -> std::string
Center a string within a given width.

References kcenon::pacs::samples::colors::bold, center_text(), color, kcenon::pacs::samples::colors::cyan, and kcenon::pacs::samples::colors::reset.

Referenced by main(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_info()

void kcenon::pacs::samples::print_info ( std::string_view message)

Print an informational message.

Parameters
messageThe message text

Prints with cyan color and info symbol.

Definition at line 150 of file console_utils.cpp.

150 {
151 std::cout << color(colors::cyan) << "[INFO] " << color(colors::reset)
152 << message << "\n";
153}

References color, kcenon::pacs::samples::colors::cyan, and kcenon::pacs::samples::colors::reset.

Referenced by main().

Here is the caller graph for this function:

◆ print_progress()

void kcenon::pacs::samples::print_progress ( size_t current,
size_t total,
int width = 40,
std::string_view label = "Progress" )

Print a progress bar.

Parameters
currentCurrent value
totalTotal value
widthWidth of the progress bar in characters
labelOptional label to display

Example output: Processing: [████████████░░░░░░░░] 60% (6/10)

Definition at line 278 of file console_utils.cpp.

279 {
280 if (total == 0) {
281 return;
282 }
283
284 double progress = static_cast<double>(current) / static_cast<double>(total);
285 int filled = static_cast<int>(progress * width);
286 int percent = static_cast<int>(progress * 100.0);
287
288 std::cout << "\r" << label << ": [";
289 std::cout << color(colors::green);
290 for (int i = 0; i < filled; ++i) {
291 std::cout << "#";
292 }
293 std::cout << color(colors::dim);
294 for (int i = filled; i < width; ++i) {
295 std::cout << "-";
296 }
297 std::cout << color(colors::reset);
298 std::cout << "] " << std::setw(3) << percent << "% ("
299 << current << "/" << total << ")" << std::flush;
300}

References color, kcenon::pacs::samples::colors::dim, kcenon::pacs::samples::colors::green, and kcenon::pacs::samples::colors::reset.

◆ print_section()

void kcenon::pacs::samples::print_section ( std::string_view title)

Print a section header.

Parameters
titleThe section title

Example output: ─── Configuration ───────────────────────────────────────────────────────────

Definition at line 127 of file console_utils.cpp.

127 {
128 std::string line = "--- " + std::string(title) + " ";
129 line += std::string(kDefaultWidth - line.length(), '-');
130
131 std::cout << "\n" << color(colors::bold) << color(colors::blue)
132 << line << color(colors::reset) << "\n\n";
133}

References kcenon::pacs::samples::colors::blue, kcenon::pacs::samples::colors::bold, color, and kcenon::pacs::samples::colors::reset.

Referenced by main(), and main().

Here is the caller graph for this function:

◆ print_success()

void kcenon::pacs::samples::print_success ( std::string_view message)

Print a success message.

Parameters
messageThe message text

Prints with green color and checkmark symbol.

Definition at line 135 of file console_utils.cpp.

135 {
136 std::cout << color(colors::green) << "[OK] " << color(colors::reset)
137 << message << "\n";
138}

References color, kcenon::pacs::samples::colors::green, and kcenon::pacs::samples::colors::reset.

Referenced by main(), and main().

Here is the caller graph for this function:

◆ print_table()

void kcenon::pacs::samples::print_table ( std::string_view title,
const std::vector< std::pair< std::string, std::string > > & rows )

Print a key-value table.

Parameters
titleTable title
rowsVector of {key, value} pairs

Example output: ┌─ Patient Information ───────────┐ │ Name: DOE^JOHN │ │ ID: PAT001 │ │ Sex: M │ └─────────────────────────────────┘

Definition at line 250 of file console_utils.cpp.

251 {
252 if (rows.empty()) {
253 return;
254 }
255
256 // Find maximum key length
257 size_t max_key_len = 0;
258 for (const auto& [key, _] : rows) {
259 max_key_len = std::max(max_key_len, key.length());
260 }
261
262 std::cout << color(colors::bold) << color(colors::magenta)
263 << title << ":" << color(colors::reset) << "\n";
264
265 for (const auto& [key, value] : rows) {
266 std::cout << " " << color(colors::dim)
267 << std::right << std::setw(static_cast<int>(max_key_len)) << key
268 << color(colors::reset) << ": "
269 << value << "\n";
270 }
271 std::cout << "\n";
272}

References kcenon::pacs::samples::colors::bold, color, kcenon::pacs::samples::colors::dim, kcenon::pacs::samples::colors::magenta, and kcenon::pacs::samples::colors::reset.

Referenced by main(), main(), and print_dataset_summary().

Here is the caller graph for this function:

◆ print_warning()

void kcenon::pacs::samples::print_warning ( std::string_view message)

Print a warning message.

Parameters
messageThe message text

Prints with yellow color and warning symbol.

Definition at line 145 of file console_utils.cpp.

145 {
146 std::cout << color(colors::yellow) << "[WARN] " << color(colors::reset)
147 << message << "\n";
148}

References color, kcenon::pacs::samples::colors::reset, and kcenon::pacs::samples::colors::yellow.

◆ set_color_enabled()

void kcenon::pacs::samples::set_color_enabled ( bool enabled)

Enable or disable color output globally.

Parameters
enabledWhether to enable colors

When disabled, all color functions will output plain text.

Definition at line 87 of file console_utils.cpp.

87 {
88 g_color_enabled = enabled;
89 g_color_checked = true;
90}

◆ supports_color()

auto kcenon::pacs::samples::supports_color ( ) -> bool
nodiscardnoexcept

Check if the terminal supports ANSI colors.

Returns
true if ANSI colors are supported

Checks environment variables and terminal type to determine support.

Definition at line 41 of file console_utils.cpp.

41 {
42 // Check if stdout is a terminal
43 if (!isatty(fileno(stdout))) {
44 return false;
45 }
46
47#ifdef _WIN32
48 // Enable virtual terminal processing on Windows 10+
49 HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
50 if (hOut == INVALID_HANDLE_VALUE) {
51 return false;
52 }
53
54 DWORD dwMode = 0;
55 if (!GetConsoleMode(hOut, &dwMode)) {
56 return false;
57 }
58
59 dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
60 if (!SetConsoleMode(hOut, dwMode)) {
61 // Fallback: check if TERM is set (e.g., running in mintty)
62 const char* term = std::getenv("TERM");
63 return term != nullptr;
64 }
65 return true;
66#else
67 // Check common environment variables
68 const char* term = std::getenv("TERM");
69 if (term == nullptr) {
70 return false;
71 }
72
73 // Check for dumb terminal
74 if (std::string_view{term} == "dumb") {
75 return false;
76 }
77
78 // Check for NO_COLOR environment variable
79 if (std::getenv("NO_COLOR") != nullptr) {
80 return false;
81 }
82
83 return true;
84#endif
85}

Referenced by is_color_enabled().

Here is the caller graph for this function:

◆ truncate()

auto kcenon::pacs::samples::truncate ( std::string_view text,
size_t max_length,
std::string_view suffix = "..." ) -> std::string
nodiscard

Truncate a string to a maximum length.

Parameters
textThe text to truncate
max_lengthMaximum length
suffixSuffix to add when truncated (default: "...")
Returns
Truncated string

Definition at line 356 of file console_utils.cpp.

357 {
358 if (text.length() <= max_length) {
359 return std::string{text};
360 }
361
362 if (max_length <= suffix.length()) {
363 return std::string{suffix.substr(0, max_length)};
364 }
365
366 return std::string{text.substr(0, max_length - suffix.length())} +
367 std::string{suffix};
368}

Referenced by print_box(), print_dataset_elements(), and print_dataset_summary().

Here is the caller graph for this function: