Mercurial > hg > orthanc
changeset 6979:e716a4dd547c
added support for multiple values in AT value representation
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Fri, 03 Jul 2026 14:16:44 +0200 |
| parents | f54d6046149f |
| children | f70c53181244 |
| files | NEWS OrthancFramework/Sources/DicomFormat/DicomValue.cpp OrthancFramework/Sources/DicomFormat/DicomValue.h OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp |
| diffstat | 5 files changed, 128 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Fri Jul 03 13:53:08 2026 +0200 +++ b/NEWS Fri Jul 03 14:16:44 2026 +0200 @@ -63,6 +63,7 @@ ----------- * Added internal support for OV, SV, and UV value representations +* Added support for multiple values in AT value representation * Fix resubmit/pause/cancel and reloading of OrthancPeerStore and DicomModalityStore jobs (bug introduced in 1.12.10) * Fix OrthancPeerStore jobs that was using the loader threads only if transcoding
--- a/OrthancFramework/Sources/DicomFormat/DicomValue.cpp Fri Jul 03 13:53:08 2026 +0200 +++ b/OrthancFramework/Sources/DicomFormat/DicomValue.cpp Fri Jul 03 14:16:44 2026 +0200 @@ -330,4 +330,14 @@ throw OrthancException(ErrorCode_BadFileFormat); } } + + + DicomValue* DicomValue::CreateFromSwap(std::string& content, + bool isBinary) + { + std::unique_ptr<DicomValue> value(new DicomValue); + value->type_ = isBinary ? Type_Binary : Type_String; + value->content_.swap(content); + return value.release(); + } }
--- a/OrthancFramework/Sources/DicomFormat/DicomValue.h Fri Jul 03 13:53:08 2026 +0200 +++ b/OrthancFramework/Sources/DicomFormat/DicomValue.h Fri Jul 03 14:16:44 2026 +0200 @@ -109,5 +109,9 @@ void Serialize(Json::Value& target) const; void Unserialize(const Json::Value& source); + + // This constructor is most efficient + static DicomValue* CreateFromSwap(std::string& content, + bool isBinary); }; }
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp Fri Jul 03 13:53:08 2026 +0200 +++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp Fri Jul 03 14:16:44 2026 +0200 @@ -372,6 +372,66 @@ return new DicomValue; } } + + + class IElementFiller : public boost::noncopyable + { + public: + virtual ~IElementFiller() + { + } + + virtual bool FillSingleValue(DcmElement& element, + const std::string& value) const = 0; + + virtual bool FillMultipleValues(DcmElement& element, + const std::vector<std::string>& values) const = 0; + }; + + + class AttributeElementFiller : public IElementFiller + { + public: + bool FillSingleValue(DcmElement& element, + const std::string& value) const ORTHANC_OVERRIDE + { + DicomTag tag = FromDcmtkBridge::ParseTag(value); + return element.putTagVal(DcmTagKey(tag.GetGroup(), tag.GetElement())).good(); + } + + bool FillMultipleValues(DcmElement& element, + const std::vector<std::string>& values) const ORTHANC_OVERRIDE + { + std::vector<Uint16> tags; + tags.resize(2 * values.size()); + + for (size_t i = 0; i < values.size(); i++) + { + DicomTag tag = FromDcmtkBridge::ParseTag(values[i]); + tags[2 * i] = tag.GetGroup(); + tags[2 * i + 1] = tag.GetElement(); + } + + return element.putUint16Array(tags.empty() ? NULL : &tags[0], values.size()).good(); + } + }; + + + bool ApplyElementFiller(DcmElement& element, + const IElementFiller& filler, + const std::string& value) + { + if (value.find('\\') != std::string::npos) + { + std::vector<std::string> tokens; + Toolbox::TokenizeString(tokens, value, '\\'); + return filler.FillMultipleValues(element, tokens); + } + else + { + return filler.FillSingleValue(element, value); + } + }; } @@ -1054,16 +1114,31 @@ case EVR_AT: { - DcmTagKey tag; - if (dynamic_cast<DcmAttributeTag&>(element).getTagVal(tag, 0).good()) + // Support for multiple values was added in Orthanc 1.12.12 + DcmAttributeTag& content = dynamic_cast<DcmAttributeTag&>(element); + + ChunkedBuffer buffer; + for (unsigned long i = 0; i < content.getNumberOfValues(); i++) { - DicomTag t(tag.getGroup(), tag.getElement()); - return new DicomValue(t.Format(), false); + if (i > 0) + { + buffer.AddChunk("\\", 1); + } + + DcmTagKey tag; + if (content.getTagVal(tag, i).good()) + { + buffer.AddChunk(DicomTag(tag.getGroup(), tag.getElement()).Format()); + } + else + { + return new DicomValue; + } } - else - { - return new DicomValue; - } + + std::string s; + buffer.Flatten(s); + return DicomValue::CreateFromSwap(s, false); } @@ -2437,8 +2512,8 @@ case EVR_AT: // attribute tag, new in Orthanc 1.9.4 { - DicomTag value = ParseTag(utf8Value); - ok = element.putTagVal(DcmTagKey(value.GetGroup(), value.GetElement())).good(); + // Multiple values are supported since Orthanc 1.12.12 + ok = ApplyElementFiller(element, AttributeElementFiller(), *decoded); break; }
--- a/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp Fri Jul 03 13:53:08 2026 +0200 +++ b/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp Fri Jul 03 14:16:44 2026 +0200 @@ -3568,6 +3568,30 @@ const std::set<DicomTag> ignoreLength; { + e.reset(new DcmAttributeTag(DcmTag(0x0072, 0x0026))); // SelectorAttribute tag, which has AT as value representation + FromDcmtkBridge::FillElementWithString(*e, "HangingProtocolCreator" /* some random tag */, false, Encoding_Utf8); + + v.reset(FromDcmtkBridge::ConvertLeafElement(*e, DicomToJsonFlags_None, 0, 0, Encoding_Utf8, + false, ignoreLength, ValueRepresentation_PersonName)); + ASSERT_TRUE(v->IsString()); + ASSERT_EQ("0072,0008", v->GetContent()); // This is the "HangingProtocolCreator" tag + + ASSERT_TRUE(f.GetDcmtkObject().getDataset()->insert(e.release()).good()); + } + + { + e.reset(new DcmAttributeTag(DcmTag(0x0072, 0x0052))); // SelectorSequencePointer tag, which has AT as value representation (multiple) + FromDcmtkBridge::FillElementWithString(*e, "0072,0008\\PatientName\\HangingProtocolCreator" /* some random tags */, false, Encoding_Utf8); + + v.reset(FromDcmtkBridge::ConvertLeafElement(*e, DicomToJsonFlags_None, 0, 0, Encoding_Utf8, + false, ignoreLength, ValueRepresentation_PersonName)); + ASSERT_TRUE(v->IsString()); + ASSERT_EQ("0072,0008\\0010,0010\\0072,0008", v->GetContent()); + + ASSERT_TRUE(f.GetDcmtkObject().getDataset()->insert(e.release()).good()); + } + + { e.reset(new DcmByteString(DcmTag(0x0010, 0x0010))); FromDcmtkBridge::FillElementWithString(*e, "HELLO", false, Encoding_Utf8); @@ -3582,6 +3606,10 @@ std::string s; ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_PATIENT_NAME)); ASSERT_EQ("HELLO", s); + ASSERT_TRUE(f.GetTagValue(s, DicomTag(0x0072, 0x0026))); + ASSERT_EQ("0072,0008", s); + ASSERT_TRUE(f.GetTagValue(s, DicomTag(0x0072, 0x0052))); + ASSERT_EQ("0072,0008\\0010,0010\\0072,0008", s); }
