25 : tag_{tag}, vr_{
vr},
data_{}, sequence_items_{} {}
28 std::span<const uint8_t> data)
29 : tag_{tag}, vr_{
vr},
data_(data.begin(), data.end()), sequence_items_{} {}
54 return kcenon::pacs::ok(std::string{});
59 std::string_view raw{
reinterpret_cast<const char*
>(
data_.data()),
68 if (
data_.size() >= 2) {
70 return kcenon::pacs::ok(std::to_string(val.value()));
74 if (
data_.size() >= 2) {
76 return kcenon::pacs::ok(std::to_string(val.value()));
80 if (
data_.size() >= 4) {
82 return kcenon::pacs::ok(std::to_string(val.value()));
86 if (
data_.size() >= 4) {
88 return kcenon::pacs::ok(std::to_string(val.value()));
92 if (
data_.size() >= 8) {
94 return kcenon::pacs::ok(std::to_string(val.value()));
98 if (
data_.size() >= 8) {
100 return kcenon::pacs::ok(std::to_string(val.value()));
104 if (
data_.size() >= 4) {
106 return kcenon::pacs::ok(std::to_string(val.value()));
110 if (
data_.size() >= 8) {
112 return kcenon::pacs::ok(std::to_string(val.value()));
121 return kcenon::pacs::ok(
122 std::string{
reinterpret_cast<const char*
>(
data_.data()),
data_.size()});
128 if (str_result.is_err()) {
129 return kcenon::pacs::pacs_error<std::vector<std::string>>(
130 str_result.error().
code, str_result.error().message);
132 const std::string str = str_result.value();
134 std::vector<std::string> result;
136 return kcenon::pacs::ok(result);
140 std::string::size_type start = 0;
141 std::string::size_type pos = 0;
143 while ((pos = str.find(
'\\', start)) != std::string::npos) {
144 result.push_back(str.substr(start, pos - start));
149 result.push_back(str.substr(start));
151 return kcenon::pacs::ok(result);
164 return sequence_items_.at(index);
168 return sequence_items_.at(index);
172 return sequence_items_;
188 data_.assign(data.begin(), data.end());
194 data_.assign(padded.begin(), padded.end());
202 std::string result{str};
205 if (result.length() % 2 != 0) {
218 std::string result{str};
224 while (!result.empty() && result.back() == pad) {
230 while (!result.empty() && result.back() ==
' ') {
auto apply_padding(std::string_view str) const -> std::string
Apply DICOM padding to ensure even length.
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.
std::vector< dicom_dataset > sequence_items_
std::vector< uint8_t > data_
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.
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.
auto sequence_items() -> std::vector< dicom_dataset > &
Get mutable access to sequence items.
DICOM Dataset - ordered collection of Data Elements.
DICOM Data Element representation (Tag, VR, Value)
constexpr char padding_char(vr_type vr) noexcept
Gets the padding character for a VR.
constexpr bool is_numeric_vr(vr_type vr) noexcept
Checks if a VR is a numeric type.
vr_type
DICOM Value Representation (VR) types.
@ UL
Unsigned Long (4 bytes)
@ UI
Unique Identifier (64 chars max)
@ SL
Signed Long (4 bytes)
@ US
Unsigned Short (2 bytes)
@ FD
Floating Point Double (8 bytes)
@ FL
Floating Point Single (4 bytes)
@ SV
Signed 64-bit Very Long (8 bytes)
@ SS
Signed Short (2 bytes)
@ UV
Unsigned 64-bit Very Long (8 bytes)
constexpr bool is_string_vr(vr_type vr) noexcept
Checks if a VR is a string type.
Result<T> type aliases and helpers for PACS system.