changeset 1160:80671157d051

generalization of create-dicom
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 17 Sep 2014 11:57:28 +0200
parents 8c9574576f42
children 82cbf1480aac 3db41779d8f9
files OrthancServer/DicomModification.cpp OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/ParsedDicomFile.cpp OrthancServer/ParsedDicomFile.h
diffstat 4 files changed, 96 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DicomModification.cpp	Fri Sep 12 15:53:57 2014 +0200
+++ b/OrthancServer/DicomModification.cpp	Wed Sep 17 11:57:28 2014 +0200
@@ -244,28 +244,88 @@
     {
       throw OrthancException(ErrorCode_BadRequest);
     }
+    
 
+    // Sanity checks
     if (level_ == ResourceType_Patient && !IsReplaced(DICOM_TAG_PATIENT_ID))
     {
       LOG(ERROR) << "When modifying a patient, her PatientID is required to be modified";
       throw OrthancException(ErrorCode_BadRequest);
     }
 
-    if (level_ > ResourceType_Patient && IsReplaced(DICOM_TAG_PATIENT_ID))
+    if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
+    {
+      LOG(ERROR) << "When modifying a patient, the StudyInstanceUID cannot be manually modified";
+      throw OrthancException(ErrorCode_BadRequest);
+    }
+
+    if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
+    {
+      LOG(ERROR) << "When modifying a patient, the SeriesInstanceUID cannot be manually modified";
+      throw OrthancException(ErrorCode_BadRequest);
+    }
+
+    if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
     {
+      LOG(ERROR) << "When modifying a patient, the SopInstanceUID cannot be manually modified";
+      throw OrthancException(ErrorCode_BadRequest);
+    }
+
+    if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_PATIENT_ID))
+    {
+      LOG(ERROR) << "When modifying a study, the parent PatientID cannot be manually modified";
+      throw OrthancException(ErrorCode_BadRequest);
+    }
+
+    if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
+    {
+      LOG(ERROR) << "When modifying a study, the SeriesInstanceUID cannot be manually modified";
+      throw OrthancException(ErrorCode_BadRequest);
+    }
+
+    if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
+    {
+      LOG(ERROR) << "When modifying a study, the SopInstanceUID cannot be manually modified";
       throw OrthancException(ErrorCode_BadRequest);
     }
 
-    if (level_ > ResourceType_Study && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
+    if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_PATIENT_ID))
+    {
+      LOG(ERROR) << "When modifying a series, the parent PatientID cannot be manually modified";
+      throw OrthancException(ErrorCode_BadRequest);
+    }
+
+    if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
     {
+      LOG(ERROR) << "When modifying a series, the parent StudyInstanceUID cannot be manually modified";
+      throw OrthancException(ErrorCode_BadRequest);
+    }
+
+    if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
+    {
+      LOG(ERROR) << "When modifying a series, the SopInstanceUID cannot be manually modified";
       throw OrthancException(ErrorCode_BadRequest);
     }
 
-    if (level_ > ResourceType_Series && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
+    if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_PATIENT_ID))
     {
+      LOG(ERROR) << "When modifying an instance, the parent PatientID cannot be manually modified";
       throw OrthancException(ErrorCode_BadRequest);
     }
 
+    if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
+    {
+      LOG(ERROR) << "When modifying an instance, the parent StudyInstanceUID cannot be manually modified";
+      throw OrthancException(ErrorCode_BadRequest);
+    }
+
+    if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
+    {
+      LOG(ERROR) << "When modifying an instance, the parent SeriesInstanceUID cannot be manually modified";
+      throw OrthancException(ErrorCode_BadRequest);
+    }
+
+
     // (1) Remove the private tags, if need be
     if (removePrivateTags_)
     {
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Fri Sep 12 15:53:57 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Wed Sep 17 11:57:28 2014 +0200
@@ -431,29 +431,28 @@
     // curl http://localhost:8042/tools/create-dicom -X POST -d '{"PatientName":"Hello^World"}'
     // curl http://localhost:8042/tools/create-dicom -X POST -d '{"PatientName":"Hello^World","PixelData":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII="}'
 
-    Json::Value request;
-    if (call.ParseJsonRequest(request) && request.isObject())
+    Json::Value replacements;
+    if (call.ParseJsonRequest(replacements) && replacements.isObject())
     {
-      DicomModification modification;
-      modification.SetLevel(ResourceType_Patient);
-      ParseReplacements(modification, request);
-
-      // If no PatientID is specified, create a random one
-      if (!modification.IsReplaced(DICOM_TAG_PATIENT_ID))
-      {
-        modification.Replace(DICOM_TAG_PATIENT_ID, Toolbox::GenerateUuid());
-      }
-
       ParsedDicomFile dicom;
 
-      if (modification.IsReplaced(DICOM_TAG_PIXEL_DATA))
+      Json::Value::Members members = replacements.getMemberNames();
+      for (size_t i = 0; i < members.size(); i++)
       {
-        dicom.EmbedImage(modification.GetReplacement(DICOM_TAG_PIXEL_DATA));
-        modification.Keep(DICOM_TAG_PIXEL_DATA);
+        const std::string& name = members[i];
+        std::string value = replacements[name].asString();
+
+        DicomTag tag = FromDcmtkBridge::ParseTag(name);
+        if (tag == DICOM_TAG_PIXEL_DATA)
+        {
+          dicom.EmbedImage(value);
+        }
+        else
+        {
+          dicom.Replace(tag, value);
+        }
       }
 
-      modification.Apply(dicom);
-
       DicomInstanceToStore toStore;
       toStore.SetParsedDicomFile(dicom);
 
--- a/OrthancServer/ParsedDicomFile.cpp	Fri Sep 12 15:53:57 2014 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Wed Sep 17 11:57:28 2014 +0200
@@ -80,6 +80,7 @@
 
 #include "ParsedDicomFile.h"
 
+#include "ServerToolbox.h"
 #include "FromDcmtkBridge.h"
 #include "ToDcmtkBridge.h"
 #include "Internals/DicomImageDecoder.h"
@@ -1285,4 +1286,17 @@
     Replace(DICOM_TAG_SPECIFIC_CHARACTER_SET, s, DicomReplaceMode_InsertIfAbsent);
   }
 
+  void ParsedDicomFile::ToJson(Json::Value& target, bool simplify)
+  {
+    if (simplify)
+    {
+      Json::Value tmp;
+      FromDcmtkBridge::ToJson(tmp, *pimpl_->file_->getDataset());
+      SimplifyTags(target, tmp);
+    }
+    else
+    {
+      FromDcmtkBridge::ToJson(target, *pimpl_->file_->getDataset());
+    }
+  }
 }
--- a/OrthancServer/ParsedDicomFile.h	Fri Sep 12 15:53:57 2014 +0200
+++ b/OrthancServer/ParsedDicomFile.h	Wed Sep 17 11:57:28 2014 +0200
@@ -118,6 +118,9 @@
     Encoding GetEncoding() const;
 
     void SetEncoding(Encoding encoding);
+
+    void ToJson(Json::Value& target, 
+                bool simplify);
   };
 
 }