PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
container_adapter.h
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
18#pragma once
19
24
25#include <kcenon/common/patterns/result.h>
26
27#include <container.h>
28
29#include <cstdint>
30#include <span>
31#include <string>
32#include <vector>
33
35
71public:
73 template <typename T>
75
76 // =========================================================================
77 // VR to Container Value Mapping
78 // =========================================================================
79
94 [[nodiscard]] static auto to_container_value(const core::dicom_element& element)
95 -> container_module::optimized_value;
96
108 [[nodiscard]] static auto from_container_value(
109 core::dicom_tag tag,
111 const container_module::optimized_value& val) -> core::dicom_element;
112
113 // =========================================================================
114 // Dataset Serialization
115 // =========================================================================
116
130 [[nodiscard]] static auto serialize_dataset(const core::dicom_dataset& dataset)
131 -> std::shared_ptr<container_module::value_container>;
132
142 [[nodiscard]] static auto deserialize_dataset(
143 const container_module::value_container& container)
145
146 // =========================================================================
147 // Binary Serialization
148 // =========================================================================
149
159 [[nodiscard]] static auto to_binary(const core::dicom_dataset& dataset)
160 -> std::vector<uint8_t>;
161
171 [[nodiscard]] static auto from_binary(std::span<const uint8_t> data)
173
174 // =========================================================================
175 // Utility Functions
176 // =========================================================================
177
184 [[nodiscard]] static auto get_container_type(encoding::vr_type vr) noexcept
185 -> container_module::value_types;
186
193 [[nodiscard]] static constexpr auto maps_to_string(encoding::vr_type vr) noexcept
194 -> bool {
196 }
197
204 [[nodiscard]] static constexpr auto maps_to_numeric(encoding::vr_type vr) noexcept
205 -> bool {
207 }
208
215 [[nodiscard]] static constexpr auto maps_to_binary(encoding::vr_type vr) noexcept
216 -> bool {
218 }
219
220private:
222 static constexpr std::string_view kProtocolVersion = "1.0.0";
223
225 static constexpr std::string_view kVersionKey = "_pacs_version";
226
228 static constexpr std::string_view kElementCountKey = "_element_count";
229
239 [[nodiscard]] static auto make_element_key(core::dicom_tag tag,
241 -> std::string;
242
249 [[nodiscard]] static auto parse_element_key(std::string_view key)
250 -> std::optional<std::pair<core::dicom_tag, encoding::vr_type>>;
251
258 [[nodiscard]] static auto sequence_to_container(
259 const core::dicom_element& element)
260 -> std::shared_ptr<container_module::value_container>;
261
268 [[nodiscard]] static auto container_to_sequence(
269 const container_module::value_container& container)
270 -> std::vector<core::dicom_dataset>;
271};
272
273} // namespace kcenon::pacs::integration
static auto serialize_dataset(const core::dicom_dataset &dataset) -> std::shared_ptr< container_module::value_container >
Serialize a DICOM dataset to a value_container.
static constexpr std::string_view kProtocolVersion
Protocol version for serialization format.
static constexpr auto maps_to_binary(encoding::vr_type vr) noexcept -> bool
Check if a VR maps to binary data.
static auto from_binary(std::span< const uint8_t > data) -> Result< core::dicom_dataset >
Deserialize binary data back to a DICOM dataset.
static auto from_container_value(core::dicom_tag tag, encoding::vr_type vr, const container_module::optimized_value &val) -> core::dicom_element
Convert a container value back to a DICOM element.
static auto sequence_to_container(const core::dicom_element &element) -> std::shared_ptr< container_module::value_container >
Convert sequence items to container array.
static auto to_binary(const core::dicom_dataset &dataset) -> std::vector< uint8_t >
Serialize a DICOM dataset to binary format.
static constexpr std::string_view kElementCountKey
Key for element count in container.
static auto to_container_value(const core::dicom_element &element) -> container_module::optimized_value
Convert a DICOM element to a container value.
static auto parse_element_key(std::string_view key) -> std::optional< std::pair< core::dicom_tag, encoding::vr_type > >
Parse an element key back to tag and VR.
static constexpr auto maps_to_string(encoding::vr_type vr) noexcept -> bool
Check if a VR maps to a string value.
static constexpr std::string_view kVersionKey
Key for protocol version in container.
static constexpr auto maps_to_numeric(encoding::vr_type vr) noexcept -> bool
Check if a VR maps to a numeric value.
static auto get_container_type(encoding::vr_type vr) noexcept -> container_module::value_types
Get the container value type for a DICOM VR.
static auto make_element_key(core::dicom_tag tag, encoding::vr_type vr) -> std::string
Create a key string for an element in the container.
static auto container_to_sequence(const container_module::value_container &container) -> std::vector< core::dicom_dataset >
Convert container array back to sequence items.
static auto deserialize_dataset(const container_module::value_container &container) -> Result< core::dicom_dataset >
Deserialize a value_container back to a DICOM dataset.
DICOM Dataset - ordered collection of Data Elements.
DICOM Data Element representation (Tag, VR, Value)
DICOM Tag representation (Group, Element pairs)
constexpr bool is_numeric_vr(vr_type vr) noexcept
Checks if a VR is a numeric type.
Definition vr_type.h:214
constexpr bool is_binary_vr(vr_type vr) noexcept
Checks if a VR is a binary/raw byte type.
Definition vr_type.h:196
vr_type
DICOM Value Representation (VR) types.
Definition vr_type.h:29
constexpr bool is_string_vr(vr_type vr) noexcept
Checks if a VR is a string type.
Definition vr_type.h:175
vr_encoding vr