Mercurial > hg > orthanc
diff OrthancServer/ParsedDicomFile.cpp @ 1307:f796207e3df1
Fix replacement and insertion of private DICOM tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 11 Feb 2015 10:26:17 +0100 |
parents | 6e7e5ed91c2d |
children | 60cc0ee61edb |
line wrap: on
line diff
--- a/OrthancServer/ParsedDicomFile.cpp Tue Feb 10 17:17:25 2015 +0100 +++ b/OrthancServer/ParsedDicomFile.cpp Wed Feb 11 10:26:17 2015 +0100 @@ -807,13 +807,30 @@ + void ParsedDicomFile::Insert(const DicomTag& tag, const std::string& value) { - std::auto_ptr<DcmElement> element(CreateElementForTag(tag)); - FillElementWithString(*element, tag, value); + OFCondition cond; + + if (FromDcmtkBridge::IsPrivateTag(tag)) + { + // This is a private tag + // http://support.dcmtk.org/redmine/projects/dcmtk/wiki/howto_addprivatedata - if (!pimpl_->file_->getDataset()->insert(element.release(), false, false).good()) + DcmTag key(tag.GetGroup(), tag.GetElement(), EVR_OB); + cond = pimpl_->file_->getDataset()->putAndInsertUint8Array + (key, (const Uint8*) value.c_str(), value.size(), false); + } + else + { + std::auto_ptr<DcmElement> element(CreateElementForTag(tag)); + FillElementWithString(*element, tag, value); + + cond = pimpl_->file_->getDataset()->insert(element.release(), false, false); + } + + if (!cond.good()) { // This field already exists throw OrthancException(ErrorCode_InternalError); @@ -847,7 +864,17 @@ } else { - FillElementWithString(*element, tag, value); + if (FromDcmtkBridge::IsPrivateTag(tag)) + { + if (!element->putUint8Array((const Uint8*) value.c_str(), value.size()).good()) + { + throw OrthancException(ErrorCode_InternalError); + } + } + else + { + FillElementWithString(*element, tag, value); + } } @@ -888,25 +915,53 @@ { DcmTagKey k(tag.GetGroup(), tag.GetElement()); DcmDataset& dataset = *pimpl_->file_->getDataset(); - DcmElement* element = NULL; - if (!dataset.findAndGetElement(k, element).good() || - element == NULL) + + if (FromDcmtkBridge::IsPrivateTag(tag)) { - return false; - } + const Uint8* data = NULL; // This is freed in the destructor of the dataset + long unsigned int count = 0; - std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(*element, pimpl_->encoding_)); + if (dataset.findAndGetUint8Array(k, data, &count).good()) + { + if (count > 0) + { + assert(data != NULL); + value.assign(reinterpret_cast<const char*>(data), count); + } + else + { + value.clear(); + } - if (v.get() == NULL) - { - value = ""; + return true; + } + else + { + return false; + } } else { - value = v->AsString(); + DcmElement* element = NULL; + if (!dataset.findAndGetElement(k, element).good() || + element == NULL) + { + return false; + } + + std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(*element, pimpl_->encoding_)); + + if (v.get() == NULL) + { + value = ""; + } + else + { + value = v->AsString(); + } + + return true; } - - return true; }