changeset 1699:8ca0e89798b2

"/modify" can insert/modify sequences
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Oct 2015 13:31:22 +0200
parents d78b87f93bcf
children f5ddbd9239dd
files NEWS OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/ParsedDicomFile.cpp OrthancServer/ParsedDicomFile.h Resources/Samples/Lua/ModifyInstanceWithSequence.lua UnitTestsSources/FromDcmtkTests.cpp
diffstat 6 files changed, 41 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Oct 09 12:29:21 2015 +0200
+++ b/NEWS	Fri Oct 09 13:31:22 2015 +0200
@@ -4,6 +4,7 @@
 * Add ".dcm" suffix to files in ZIP archives (cf. URI ".../archive")
 * "/tools/create-dicom": Support of binary tags encoded using data URI scheme
 * "/tools/create-dicom": Support of hierarchical structures (creation of sequences)
+* "/modify" can insert/modify sequences
 
 Plugins
 -------
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Fri Oct 09 12:29:21 2015 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Fri Oct 09 13:31:22 2015 +0200
@@ -98,12 +98,13 @@
     for (size_t i = 0; i < members.size(); i++)
     {
       const std::string& name = members[i];
-      std::string value = replacements[name].asString();
+      const Json::Value& value = replacements[name];
 
       DicomTag tag = FromDcmtkBridge::ParseTag(name);
       target.Replace(tag, value);
 
-      VLOG(1) << "Replace: " << name << " " << tag << " == " << value << std::endl;
+      VLOG(1) << "Replace: " << name << " " << tag 
+              << " == " << value.toStyledString() << std::endl;
     }
   }
 
--- a/OrthancServer/ParsedDicomFile.cpp	Fri Oct 09 12:29:21 2015 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Fri Oct 09 13:31:22 2015 +0200
@@ -591,15 +591,6 @@
 
 
   void ParsedDicomFile::Insert(const DicomTag& tag,
-                               const std::string& utf8Value)
-  {
-    std::auto_ptr<DcmElement> element(FromDcmtkBridge::CreateElementForTag(tag));
-    FromDcmtkBridge::FillElementWithString(*element, tag, utf8Value, false, GetEncoding());
-    InsertInternal(*pimpl_->file_->getDataset(), element.release());
-  }
-
-
-  void ParsedDicomFile::Insert(const DicomTag& tag,
                                const Json::Value& value,
                                bool decodeBinaryTags)
   {
--- a/OrthancServer/ParsedDicomFile.h	Fri Oct 09 12:29:21 2015 +0200
+++ b/OrthancServer/ParsedDicomFile.h	Fri Oct 09 13:31:22 2015 +0200
@@ -78,22 +78,19 @@
 
     void Remove(const DicomTag& tag);
 
-    void Insert(const DicomTag& tag,
-                const std::string& utf8Value);
+    void Replace(const DicomTag& tag,
+                 const std::string& utf8Value,
+                 DicomReplaceMode mode = DicomReplaceMode_InsertIfAbsent);
 
     void Replace(const DicomTag& tag,
-                 const std::string& utf8Value,
+                 const Json::Value& value,  // Assumed to be encoded with UTF-8
+                 bool decodeBinaryTags,
                  DicomReplaceMode mode = DicomReplaceMode_InsertIfAbsent);
 
     void Insert(const DicomTag& tag,
                 const Json::Value& value,   // Assumed to be encoded with UTF-8
                 bool decodeBinaryTags);
 
-    void Replace(const DicomTag& tag,
-                 const Json::Value& value,  // Assumed to be encoded with UTF-8
-                 bool decodeBinaryTags,
-                 DicomReplaceMode mode = DicomReplaceMode_InsertIfAbsent);
-
     void RemovePrivateTags()
     {
       RemovePrivateTagsInternal(NULL);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Samples/Lua/ModifyInstanceWithSequence.lua	Fri Oct 09 13:31:22 2015 +0200
@@ -0,0 +1,28 @@
+-- Answer to:
+-- https://groups.google.com/d/msg/orthanc-users/0ymHe1cDBCQ/YfD0NoOTn0wJ
+-- Applicable starting with Orthanc 0.9.5
+
+function OnStoredInstance(instanceId, tags, metadata, origin)
+   -- Do not modify twice the same file
+   if origin['RequestOrigin'] ~= 'Lua' then
+      local replace = {}
+      replace['0010,1002'] = {}
+      replace['0010,1002'][1] = {}
+      replace['0010,1002'][1]['PatientID'] = 'Hello'
+      replace['0010,1002'][2] = {}
+      replace['0010,1002'][2]['PatientID'] = 'World'
+
+      local request = {}
+      request['Replace'] = replace
+
+      -- Create the modified instance
+      local modified = RestApiPost('/instances/' .. instanceId .. '/modify',
+                                   DumpJson(request))
+
+      -- Upload the modified instance to the Orthanc store
+      RestApiPost('/instances/', modified)
+
+      -- Delete the original instance
+      RestApiDelete('/instances/' .. instanceId)
+   end
+end
--- a/UnitTestsSources/FromDcmtkTests.cpp	Fri Oct 09 12:29:21 2015 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Fri Oct 09 13:31:22 2015 +0200
@@ -105,7 +105,7 @@
   ParsedDicomFile o;
   o.Replace(DICOM_TAG_PATIENT_NAME, "coucou");
   ASSERT_FALSE(o.GetTagValue(s, privateTag));
-  o.Insert(privateTag, "private tag");
+  o.Insert(privateTag, "private tag", false);
   ASSERT_TRUE(o.GetTagValue(s, privateTag));
   ASSERT_STREQ("private tag", s.c_str());
 
@@ -270,7 +270,7 @@
       f.SetEncoding(testEncodings[i]);
 
       std::string s = Toolbox::ConvertToUtf8(testEncodingsEncoded[i], testEncodings[i]);
-      f.Insert(DICOM_TAG_PATIENT_NAME, s);
+      f.Insert(DICOM_TAG_PATIENT_NAME, s, false);
       f.SaveToMemoryBuffer(dicom);
     }
 
@@ -408,8 +408,8 @@
 {
   ParsedDicomFile f;
 
-  f.Insert(DICOM_TAG_PATIENT_NAME, "World");
-  ASSERT_THROW(f.Insert(DICOM_TAG_PATIENT_ID, "Hello"), OrthancException);  // Already existing tag
+  f.Insert(DICOM_TAG_PATIENT_NAME, "World", false);
+  ASSERT_THROW(f.Insert(DICOM_TAG_PATIENT_ID, "Hello", false), OrthancException);  // Already existing tag
   f.Replace(DICOM_TAG_SOP_INSTANCE_UID, "Toto");  // (*)
   f.Replace(DICOM_TAG_SOP_CLASS_UID, "Tata");  // (**)