83 std::span<const uint8_t> data);
121 [[nodiscard]] static auto from_string(
dicom_tag tag, encoding::vr_type
vr,
132 template <typename T>
133 requires std::is_arithmetic_v<T>
145 template <typename T>
146 requires std::is_arithmetic_v<T>
164 [[nodiscard]]
constexpr auto vr() const noexcept -> encoding::vr_type {
return vr_; }
170 [[nodiscard]]
auto length() const noexcept -> uint32_t {
171 return static_cast<uint32_t
>(
data_.size());
178 [[nodiscard]]
auto raw_data() const noexcept -> std::span<const uint8_t> {
186 [[nodiscard]]
auto is_empty() const noexcept ->
bool {
return data_.empty(); }
221 template <typename T>
222 requires std::is_arithmetic_v<T>
230 template <typename T>
231 requires std::is_arithmetic_v<T>
300 void set_value(std::span<const uint8_t> data);
313 template <typename T>
314 requires std::is_arithmetic_v<T>
328 [[nodiscard]] auto
apply_padding(std::string_view str) const -> std::
string;
336 encoding::vr_type
vr) -> std::
string;
344 requires std::is_arithmetic_v<T>
353 requires std::is_arithmetic_v<T>
357 std::vector<uint8_t> data(values.size() *
sizeof(T));
359 for (
size_t i = 0; i < values.size(); ++i) {
360 std::memcpy(data.data() + i *
sizeof(T), &values[i],
sizeof(T));
363 elem.set_value(data);
368 requires std::is_arithmetic_v<T>
370 if (
data_.size() <
sizeof(T)) {
373 "Insufficient data for numeric conversion: expected " +
374 std::to_string(
sizeof(T)) +
" bytes, got " +
375 std::to_string(
data_.size()));
379 std::memcpy(&result,
data_.data(),
sizeof(T));
380 return kcenon::pacs::ok(result);
384 requires std::is_arithmetic_v<T>
386 if (
data_.size() %
sizeof(T) != 0) {
387 return kcenon::pacs::pacs_error<std::vector<T>>(
389 "Data size not aligned for numeric type: " +
390 std::to_string(
data_.size()) +
" bytes is not divisible by " +
391 std::to_string(
sizeof(T)));
394 const size_t count =
data_.size() /
sizeof(T);
395 std::vector<T> result(count);
397 for (
size_t i = 0; i < count; ++i) {
398 std::memcpy(&result[i],
data_.data() + i *
sizeof(T),
sizeof(T));
401 return kcenon::pacs::ok(result);
405 requires std::is_arithmetic_v<T>
407 data_.resize(
sizeof(T));
408 std::memcpy(
data_.data(), &value,
sizeof(T));
auto is_sequence() const noexcept -> bool
Check if this element is a sequence.
auto apply_padding(std::string_view str) const -> std::string
Apply DICOM padding to ensure even length.
auto length() const noexcept -> uint32_t
Get the value length in bytes.
constexpr auto tag() const noexcept -> dicom_tag
Get the element's tag.
auto sequence_item(std::size_t index) const -> const dicom_dataset &
Get a specific sequence item by index.
auto as_numeric() const -> kcenon::pacs::Result< T >
Get the value as a numeric type.
static auto from_numeric_list(dicom_tag tag, encoding::vr_type vr, std::span< const T > values) -> dicom_element
Create an element from multiple numeric values.
auto raw_data() const noexcept -> std::span< const uint8_t >
Get the raw data bytes.
std::vector< dicom_dataset > sequence_items_
dicom_element(dicom_element &&) noexcept
Move constructor.
std::vector< uint8_t > data_
auto as_numeric_list() const -> kcenon::pacs::Result< std::vector< T > >
Get multi-valued numeric data as a list.
void add_sequence_item(dicom_dataset item)
Add a new item to the sequence.
void set_value(std::span< const uint8_t > data)
Set the raw value data.
constexpr auto vr() const noexcept -> encoding::vr_type
Get the element's VR.
void set_numeric(T value)
Set the value from a numeric value.
dicom_element(const dicom_element &)
Copy constructor.
dicom_element(dicom_tag tag, encoding::vr_type vr) noexcept
Construct an empty element with given tag and VR.
auto as_string() const -> kcenon::pacs::Result< std::string >
Get the value as a string.
static auto remove_padding(std::string_view str, encoding::vr_type vr) -> std::string
Remove DICOM padding from a string value.
auto sequence_item_count() const noexcept -> std::size_t
Get the number of items in the sequence.
void set_string(std::string_view value)
Set the value from a string.
auto as_string_list() const -> kcenon::pacs::Result< std::vector< std::string > >
Get multi-valued string as a list.
static auto from_numeric(dicom_tag tag, encoding::vr_type vr, T value) -> dicom_element
Create an element from a numeric value.
auto sequence_items() -> std::vector< dicom_dataset > &
Get mutable access to sequence items.
auto is_empty() const noexcept -> bool
Check if the element has no value.
DICOM Tag representation (Group, Element pairs)
vr_type
DICOM Value Representation (VR) types.
@ SQ
Sequence of Items (undefined length)
constexpr int data_size_mismatch
Result< T > pacs_error(int code, const std::string &message, const std::string &details="")
Create a PACS error result with module context.
Result<T> type aliases and helpers for PACS system.