# HG changeset patch # User Sebastien Jodogne # Date 1356004906 -3600 # Node ID 86bb79522f19fb9cdeecb56db5c7369ce54f315f # Parent 4eea080e6e7a6f7e75ae08f36f1bb1c974fe9ce8 name of the private tags diff -r 4eea080e6e7a -r 86bb79522f19 OrthancServer/FromDcmtkBridge.cpp --- a/OrthancServer/FromDcmtkBridge.cpp Wed Dec 19 14:57:18 2012 +0100 +++ b/OrthancServer/FromDcmtkBridge.cpp Thu Dec 20 13:01:46 2012 +0100 @@ -571,9 +571,9 @@ } - void ParsedDicomFile::ReplaceInternal(const DicomTag& tag, - const std::string& value, - bool insertOnAbsent) + void ParsedDicomFile::Replace(const DicomTag& tag, + const std::string& value, + DicomReplaceMode mode) { DcmTagKey key(tag.GetGroup(), tag.GetElement()); DcmElement* element = NULL; @@ -581,14 +581,18 @@ if (!file_->getDataset()->findAndGetElement(key, element).good() || element == NULL) { - if (insertOnAbsent) + // This field does not exist, act wrt. the specified "mode" + switch (mode) { - // This field does not exist, use "Insert()" instead - Insert(tag, value); - } - else - { - throw OrthancException(ErrorCode_InternalError); + case DicomReplaceMode_InsertIfAbsent: + Insert(tag, value); + break; + + case DicomReplaceMode_ThrowIfAbsent: + throw OrthancException(ErrorCode_InexistentItem); + + case DicomReplaceMode_IgnoreIfAbsent: + return; } } else @@ -606,27 +610,13 @@ * option. **/ if (tag == DICOM_TAG_SOP_CLASS_UID) - ReplaceInternal(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value, true); + Replace(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value, DicomReplaceMode_InsertIfAbsent); if (tag == DICOM_TAG_SOP_INSTANCE_UID) - ReplaceInternal(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value, true); + Replace(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value, DicomReplaceMode_InsertIfAbsent); } - void ParsedDicomFile::Replace(const DicomTag& tag, - const std::string& value) - { - return ReplaceInternal(tag, value, false); - } - - void ParsedDicomFile::InsertOrReplace(const DicomTag& tag, - const std::string& value) - { - return ReplaceInternal(tag, value, true); - } - - - void ParsedDicomFile::Answer(RestApiOutput& output) { std::string serialized; @@ -879,8 +869,15 @@ assert(target.type() == Json::objectValue); DicomTag tag(FromDcmtkBridge::GetTag(element)); + const std::string formattedTag = tag.Format(); + +#if 0 const std::string tagName = FromDcmtkBridge::GetName(tag); - const std::string formattedTag = tag.Format(); +#else + // This version of the code gives access to the name of the private tags + DcmTag tagbis(element.getTag()); + const std::string tagName(tagbis.getTagName()); +#endif if (element.isLeaf()) { @@ -1122,6 +1119,7 @@ } // End of patches +#if 0 DcmTagKey tag(t.GetGroup(), t.GetElement()); const DcmDataDictionary& dict = dcmDataDict.rdlock(); const DcmDictEntry* entry = dict.findEntry(tag, NULL); @@ -1134,6 +1132,18 @@ dcmDataDict.unlock(); return s; +#else + DcmTag tag(t.GetGroup(), t.GetElement()); + const char* name = tag.getTagName(); + if (name == NULL) + { + return "Unknown"; + } + else + { + return std::string(name); + } +#endif } @@ -1155,6 +1165,7 @@ return DicomTag(group, element); } +#if 0 const DcmDataDictionary& dict = dcmDataDict.rdlock(); const DcmDictEntry* entry = dict.findEntry(name); @@ -1170,6 +1181,17 @@ dcmDataDict.unlock(); return tag; } +#else + DcmTag tag; + if (DcmTag::findTagFromName(name, tag).good()) + { + return DicomTag(tag.getGTag(), tag.getETag()); + } + else + { + throw OrthancException("Unknown DICOM tag"); + } +#endif } diff -r 4eea080e6e7a -r 86bb79522f19 OrthancServer/FromDcmtkBridge.h --- a/OrthancServer/FromDcmtkBridge.h Wed Dec 19 14:57:18 2012 +0100 +++ b/OrthancServer/FromDcmtkBridge.h Thu Dec 20 13:01:46 2012 +0100 @@ -57,6 +57,13 @@ DicomRootLevel_Instance }; + enum DicomReplaceMode + { + DicomReplaceMode_InsertIfAbsent, + DicomReplaceMode_ThrowIfAbsent, + DicomReplaceMode_IgnoreIfAbsent + }; + class ParsedDicomFile : public IDynamicObject { private: @@ -67,10 +74,6 @@ { } - void ReplaceInternal(const DicomTag& tag, - const std::string& value, - bool insertOnAbsent); - void Setup(const char* content, size_t size); @@ -106,14 +109,12 @@ void Remove(const DicomTag& tag); - void Replace(const DicomTag& tag, - const std::string& value); - void Insert(const DicomTag& tag, const std::string& value); - - void InsertOrReplace(const DicomTag& tag, - const std::string& value); + + void Replace(const DicomTag& tag, + const std::string& value, + DicomReplaceMode mode); }; class FromDcmtkBridge diff -r 4eea080e6e7a -r 86bb79522f19 OrthancServer/OrthancRestApi.cpp --- a/OrthancServer/OrthancRestApi.cpp Wed Dec 19 14:57:18 2012 +0100 +++ b/OrthancServer/OrthancRestApi.cpp Thu Dec 20 13:01:46 2012 +0100 @@ -841,8 +841,9 @@ // Modification of DICOM instances ------------------------------------------ - static void ModifyInstanceInternal(ParsedDicomFile& toModify, - const Json::Value& replacements) + static void ReplaceInstanceInternal(ParsedDicomFile& toModify, + const Json::Value& replacements, + DicomReplaceMode mode) { if (!replacements.isObject()) { @@ -857,15 +858,18 @@ std::string value = replacements[name].asString(); DicomTag tag = FromDcmtkBridge::ParseTag(name); - toModify.Replace(tag, value); + toModify.Replace(tag, value, mode); } // A new SOP instance UID is automatically generated std::string instanceUid = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Instance); - toModify.Replace(DICOM_TAG_SOP_INSTANCE_UID, instanceUid); + toModify.Replace(DICOM_TAG_SOP_INSTANCE_UID, instanceUid, DicomReplaceMode_InsertIfAbsent); } + + + static void ModifyInstance(RestApi::PostCall& call) { RETRIEVE_CONTEXT(call); @@ -877,7 +881,7 @@ if (call.ParseJsonRequest(request)) { std::auto_ptr modified(dicom.Clone()); - ModifyInstanceInternal(*modified, request); + ReplaceInstanceInternal(*modified, request, DicomReplaceMode_InsertIfAbsent); modified->Answer(call.GetOutput()); } @@ -885,8 +889,6 @@ std::string seriesUid = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series); modified->Replace(DICOM_TAG_SERIES_INSTANCE_UID, seriesUid); modified->Replace(DICOM_TAG_STUDY_INSTANCE_UID, studyUid);*/ - - }