PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
sr_storage.cpp
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
11
12#include <algorithm>
13#include <array>
14
16
17// =============================================================================
18// Transfer Syntaxes
19// =============================================================================
20
21std::vector<std::string> get_sr_transfer_syntaxes() {
22 return {
23 // Explicit VR Little Endian (preferred for interoperability)
24 "1.2.840.10008.1.2.1",
25 // Implicit VR Little Endian (universal baseline)
26 "1.2.840.10008.1.2",
27 // Deflated Explicit VR Little Endian (good for large SRs)
28 "1.2.840.10008.1.2.1.99"
29 };
30}
31
32// =============================================================================
33// SR Document Type
34// =============================================================================
35
68
69std::string_view to_string(sr_document_type type) noexcept {
70 switch (type) {
72 return "Basic Text SR";
74 return "Enhanced SR";
76 return "Comprehensive SR";
78 return "Comprehensive 3D SR";
80 return "Extensible SR";
82 return "Key Object Selection";
84 return "CAD SR";
86 return "Dose Report SR";
88 return "Procedure Log SR";
90 return "Other SR";
91 }
92 return "Unknown SR";
93}
94
95// =============================================================================
96// SR Value Types
97// =============================================================================
98
99namespace {
100
101constexpr std::string_view value_type_strings[] = {
102 "TEXT",
103 "CODE",
104 "NUM",
105 "DATETIME",
106 "DATE",
107 "TIME",
108 "UIDREF",
109 "PNAME",
110 "COMPOSITE",
111 "IMAGE",
112 "WAVEFORM",
113 "SCOORD",
114 "SCOORD3D",
115 "TCOORD",
116 "CONTAINER",
117 "TABLE"
118};
119
120} // namespace
121
122std::string_view to_string(sr_value_type type) noexcept {
123 auto index = static_cast<size_t>(type);
124 if (index < std::size(value_type_strings)) {
125 return value_type_strings[index];
126 }
127 return "UNKNOWN";
128}
129
130sr_value_type parse_sr_value_type(std::string_view value) noexcept {
131 if (value == "TEXT") return sr_value_type::text;
132 if (value == "CODE") return sr_value_type::code;
133 if (value == "NUM") return sr_value_type::num;
134 if (value == "DATETIME") return sr_value_type::datetime;
135 if (value == "DATE") return sr_value_type::date;
136 if (value == "TIME") return sr_value_type::time;
137 if (value == "UIDREF") return sr_value_type::uidref;
138 if (value == "PNAME") return sr_value_type::pname;
139 if (value == "COMPOSITE") return sr_value_type::composite;
140 if (value == "IMAGE") return sr_value_type::image;
141 if (value == "WAVEFORM") return sr_value_type::waveform;
142 if (value == "SCOORD") return sr_value_type::scoord;
143 if (value == "SCOORD3D") return sr_value_type::scoord3d;
144 if (value == "TCOORD") return sr_value_type::tcoord;
145 if (value == "CONTAINER") return sr_value_type::container;
146 if (value == "TABLE") return sr_value_type::table;
148}
149
150bool is_valid_sr_value_type(std::string_view value) noexcept {
152}
153
154// =============================================================================
155// SR Relationship Types
156// =============================================================================
157
158std::string_view to_string(sr_relationship_type type) noexcept {
159 switch (type) {
161 return "CONTAINS";
163 return "HAS OBS CONTEXT";
165 return "HAS ACQ CONTEXT";
167 return "HAS CONCEPT MOD";
169 return "HAS PROPERTIES";
171 return "INFERRED FROM";
173 return "SELECTED FROM";
175 return "UNKNOWN";
176 }
177 return "UNKNOWN";
178}
179
180sr_relationship_type parse_sr_relationship_type(std::string_view value) noexcept {
181 if (value == "CONTAINS") return sr_relationship_type::contains;
182 if (value == "HAS OBS CONTEXT") return sr_relationship_type::has_obs_context;
183 if (value == "HAS ACQ CONTEXT") return sr_relationship_type::has_acq_context;
184 if (value == "HAS CONCEPT MOD") return sr_relationship_type::has_concept_mod;
185 if (value == "HAS PROPERTIES") return sr_relationship_type::has_properties;
186 if (value == "INFERRED FROM") return sr_relationship_type::inferred_from;
187 if (value == "SELECTED FROM") return sr_relationship_type::selected_from;
189}
190
191// =============================================================================
192// SR Completion and Verification
193// =============================================================================
194
195std::string_view to_string(sr_completion_flag flag) noexcept {
196 switch (flag) {
198 return "PARTIAL";
200 return "COMPLETE";
201 }
202 return "PARTIAL";
203}
204
205sr_completion_flag parse_sr_completion_flag(std::string_view value) noexcept {
206 if (value == "COMPLETE") {
208 }
210}
211
212std::string_view to_string(sr_verification_flag flag) noexcept {
213 switch (flag) {
215 return "UNVERIFIED";
217 return "VERIFIED";
218 }
219 return "UNVERIFIED";
220}
221
222sr_verification_flag parse_sr_verification_flag(std::string_view value) noexcept {
223 if (value == "VERIFIED") {
225 }
227}
228
229// =============================================================================
230// SOP Class Information
231// =============================================================================
232
233namespace {
234
235constexpr std::array<sr_sop_class_info, 17> sr_sop_classes = {{
236 // Basic SR types
237 {
239 "Basic Text SR Storage",
240 "Simple text-based structured report",
242 false,
243 false,
244 false
245 },
246 {
248 "Enhanced SR Storage",
249 "Enhanced structured report with image references",
251 false,
252 false,
253 true
254 },
255 {
257 "Comprehensive SR Storage",
258 "Comprehensive structured report with spatial coordinates",
260 false,
261 true,
262 true
263 },
264 {
266 "Comprehensive 3D SR Storage",
267 "Comprehensive structured report with 3D spatial coordinates",
269 false,
270 true,
271 true
272 },
273 {
275 "Extensible SR Storage",
276 "Extensible structured report with table support",
278 false,
279 true,
280 true
281 },
282
283 // Key Object Selection
284 {
286 "Key Object Selection Document Storage",
287 "Document for marking significant images",
289 false,
290 false,
291 false
292 },
293
294 // CAD SR types
295 {
297 "Mammography CAD SR Storage",
298 "Computer-aided detection results for mammography",
300 false,
301 true,
302 false
303 },
304 {
306 "Chest CAD SR Storage",
307 "Computer-aided detection results for chest imaging",
309 false,
310 true,
311 false
312 },
313 {
315 "Colon CAD SR Storage",
316 "Computer-aided detection results for colonography",
318 false,
319 true,
320 false
321 },
322
323 // Dose reports
324 {
326 "X-Ray Radiation Dose SR Storage",
327 "Radiation dose structured report for X-ray procedures",
329 false,
330 false,
331 false
332 },
333 {
335 "Radiopharmaceutical Radiation Dose SR Storage",
336 "Radiation dose for nuclear medicine procedures",
338 false,
339 false,
340 false
341 },
342 {
344 "Patient Radiation Dose SR Storage",
345 "Cumulative patient radiation dose report",
347 false,
348 false,
349 false
350 },
351 {
353 "Enhanced X-Ray Radiation Dose SR Storage",
354 "Enhanced radiation dose report with detailed exposure data",
356 false,
357 false,
358 false
359 },
360
361 // Other specialized SR
362 {
364 "Acquisition Context SR Storage",
365 "Acquisition context documentation",
367 false,
368 false,
369 false
370 },
371 {
373 "Simplified Adult Echo SR Storage",
374 "Simplified echocardiography structured report",
376 false,
377 false,
378 true
379 },
380 {
382 "Planned Imaging Agent Administration SR Storage",
383 "Planned contrast agent administration record",
385 false,
386 false,
387 false
388 },
389 {
391 "Performed Imaging Agent Administration SR Storage",
392 "Performed contrast agent administration record",
394 false,
395 false,
396 false
397 }
398}};
399
400} // namespace
401
402std::vector<std::string>
403get_sr_storage_sop_classes(bool include_cad, bool include_dose) {
404 std::vector<std::string> result;
405 result.reserve(sr_sop_classes.size());
406
407 for (const auto& info : sr_sop_classes) {
408 bool include = true;
409
410 if (!include_cad && info.document_type == sr_document_type::cad) {
411 include = false;
412 }
413 if (!include_dose && info.document_type == sr_document_type::dose_report) {
414 include = false;
415 }
416
417 if (include) {
418 result.emplace_back(info.uid);
419 }
420 }
421
422 return result;
423}
424
425const sr_sop_class_info*
426get_sr_sop_class_info(std::string_view uid) noexcept {
427 auto it = std::find_if(
428 sr_sop_classes.begin(),
429 sr_sop_classes.end(),
430 [uid](const auto& info) { return info.uid == uid; }
431 );
432
433 if (it != sr_sop_classes.end()) {
434 return &(*it);
435 }
436 return nullptr;
437}
438
439bool is_sr_storage_sop_class(std::string_view uid) noexcept {
440 return get_sr_sop_class_info(uid) != nullptr;
441}
442
443bool is_cad_sr_storage_sop_class(std::string_view uid) noexcept {
444 const auto* info = get_sr_sop_class_info(uid);
445 return info != nullptr && info->document_type == sr_document_type::cad;
446}
447
448bool is_dose_sr_storage_sop_class(std::string_view uid) noexcept {
449 const auto* info = get_sr_sop_class_info(uid);
450 return info != nullptr && info->document_type == sr_document_type::dose_report;
451}
452
453bool sr_supports_spatial_coords(std::string_view uid) noexcept {
454 const auto* info = get_sr_sop_class_info(uid);
455 return info != nullptr && info->supports_spatial_coords;
456}
457
458// =============================================================================
459// SR Template Identification
460// =============================================================================
461
486
487} // namespace kcenon::pacs::services::sop_classes
constexpr std::string_view mammography_cad_report
Mammography CAD Report (TID 4000)
Definition sr_storage.h:383
constexpr std::string_view key_object_selection
Key Object Selection (TID 2010)
Definition sr_storage.h:401
constexpr std::string_view chest_cad_report
Chest CAD Report (TID 4100)
Definition sr_storage.h:386
constexpr std::string_view xray_radiation_dose_report
X-Ray Radiation Dose Report (TID 10001)
Definition sr_storage.h:392
constexpr std::string_view colon_cad_report
Colon CAD Report (TID 4200)
Definition sr_storage.h:389
constexpr std::string_view basic_diagnostic_imaging_report
Basic Diagnostic Imaging Report (TID 2000)
Definition sr_storage.h:380
constexpr std::string_view comprehensive_sr_storage_uid
Comprehensive SR Storage SOP Class UID.
Definition sr_storage.h:46
sr_relationship_type
SR Content Item Relationship Type (0040,A010)
Definition sr_storage.h:227
@ inferred_from
INFERRED FROM - Inference source.
@ selected_from
SELECTED FROM - Selection source.
@ has_concept_mod
HAS CONCEPT MOD - Concept modifier.
@ has_obs_context
HAS OBS CONTEXT - Observation context.
@ has_acq_context
HAS ACQ CONTEXT - Acquisition context.
constexpr std::string_view simplified_adult_echo_sr_storage_uid
Simplified Adult Echo SR Storage SOP Class UID.
Definition sr_storage.h:87
constexpr std::string_view colon_cad_sr_storage_uid
Colon CAD SR Storage SOP Class UID.
Definition sr_storage.h:71
sr_document_type get_sr_document_type(std::string_view uid) noexcept
Get SR document type for a SOP Class UID.
constexpr std::string_view patient_radiation_dose_sr_storage_uid
Patient Radiation Dose SR Storage SOP Class UID.
Definition sr_storage.h:91
constexpr std::string_view mammography_cad_sr_storage_uid
Mammography CAD SR Storage SOP Class UID.
Definition sr_storage.h:63
bool is_dose_sr_storage_sop_class(std::string_view uid) noexcept
Check if a SOP Class UID is a Dose Report SR Storage SOP Class.
constexpr std::string_view radiopharmaceutical_radiation_dose_sr_storage_uid
Radiopharmaceutical Radiation Dose SR Storage SOP Class UID.
Definition sr_storage.h:79
sr_completion_flag parse_sr_completion_flag(std::string_view value) noexcept
Parse SR completion flag from DICOM string.
bool is_sr_storage_sop_class(std::string_view uid) noexcept
Check if a SOP Class UID is an SR Storage SOP Class.
constexpr std::string_view acquisition_context_sr_storage_uid
Acquisition Context SR Storage SOP Class UID.
Definition sr_storage.h:83
bool sr_supports_spatial_coords(std::string_view uid) noexcept
Check if an SR SOP Class supports spatial coordinates.
std::vector< std::string > get_sr_transfer_syntaxes()
Get recommended transfer syntaxes for SR objects.
bool is_valid_sr_value_type(std::string_view value) noexcept
Check if SR value type string is valid.
bool is_cad_sr_storage_sop_class(std::string_view uid) noexcept
Check if a SOP Class UID is a CAD SR Storage SOP Class.
constexpr std::string_view basic_text_sr_storage_uid
Basic Text SR Storage SOP Class UID.
Definition sr_storage.h:38
sr_document_type
SR Document type classification.
Definition sr_storage.h:141
@ procedure_log
Procedure Log - Procedure documentation.
@ enhanced
Enhanced SR - References to images/waveforms.
@ comprehensive
Comprehensive SR - Complex with spatial coords.
@ comprehensive_3d
Comprehensive 3D SR - 3D spatial coordinates.
@ basic_text
Basic Text SR - Simple text reports.
@ cad
CAD SR - Computer-aided detection results.
@ key_object_selection
Key Object Selection - Image selection.
@ dose_report
Dose Report - Radiation dose information.
sr_completion_flag
SR Completion Flag (0040,A491)
Definition sr_storage.h:259
@ partial
PARTIAL - Document is not complete.
sr_value_type parse_sr_value_type(std::string_view value) noexcept
Parse SR value type from DICOM string.
constexpr std::string_view performed_imaging_agent_admin_sr_storage_uid
Performed Imaging Agent Administration SR Storage SOP Class UID.
Definition sr_storage.h:99
std::string_view get_recommended_sr_template(std::string_view uid) noexcept
Get recommended template ID for an SR SOP Class.
sr_relationship_type parse_sr_relationship_type(std::string_view value) noexcept
Parse SR relationship type from DICOM string.
constexpr std::string_view extensible_sr_storage_uid
Extensible SR Storage SOP Class UID.
Definition sr_storage.h:54
sr_verification_flag parse_sr_verification_flag(std::string_view value) noexcept
Parse SR verification flag from DICOM string.
constexpr std::string_view enhanced_sr_storage_uid
Enhanced SR Storage SOP Class UID.
Definition sr_storage.h:42
const sr_sop_class_info * get_sr_sop_class_info(std::string_view uid) noexcept
Get information about a specific SR SOP Class.
constexpr std::string_view xray_radiation_dose_sr_storage_uid
X-Ray Radiation Dose SR Storage SOP Class UID.
Definition sr_storage.h:75
constexpr std::string_view planned_imaging_agent_admin_sr_storage_uid
Planned Imaging Agent Administration SR Storage SOP Class UID.
Definition sr_storage.h:95
constexpr std::string_view comprehensive_3d_sr_storage_uid
Comprehensive 3D SR Storage SOP Class UID.
Definition sr_storage.h:50
sr_verification_flag
SR Verification Flag (0040,A493)
Definition sr_storage.h:281
@ verified
VERIFIED - Verified by authorized person.
constexpr std::string_view chest_cad_sr_storage_uid
Chest CAD SR Storage SOP Class UID.
Definition sr_storage.h:67
constexpr std::string_view key_object_selection_document_storage_uid
Key Object Selection Document Storage SOP Class UID.
Definition sr_storage.h:112
sr_value_type
SR Content Item Value Type (0040,A040)
Definition sr_storage.h:177
@ scoord
SCOORD - Spatial coordinates (2D)
@ container
CONTAINER - Container for other items.
@ waveform
WAVEFORM - Reference to waveform.
@ table
TABLE - Tabular data (Extensible SR)
@ scoord3d
SCOORD3D - Spatial coordinates (3D)
@ composite
COMPOSITE - Reference to composite object.
std::string_view to_string(dx_photometric_interpretation interp) noexcept
Convert photometric interpretation enum to DICOM string.
std::vector< std::string > get_sr_storage_sop_classes(bool include_cad=true, bool include_dose=true)
Get all SR Storage SOP Class UIDs.
constexpr std::string_view enhanced_xray_radiation_dose_sr_storage_uid
Enhanced X-Ray Radiation Dose SR Storage SOP Class UID.
Definition sr_storage.h:103
Structured Report (SR) Storage SOP Classes.
std::string_view uid