changeset 788:7ebe4bf87196

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 05 May 2014 18:39:36 +0200
parents ac18946afa74
children 55dae8c5a6ab
files OrthancServer/DicomModification.cpp OrthancServer/DicomModification.h OrthancServer/FromDcmtkBridge.cpp OrthancServer/FromDcmtkBridge.h OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/OrthancRestApi/OrthancRestSystem.cpp
diffstat 6 files changed, 66 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DicomModification.cpp	Mon May 05 15:52:14 2014 +0200
+++ b/OrthancServer/DicomModification.cpp	Mon May 05 18:39:36 2014 +0200
@@ -37,21 +37,21 @@
 namespace Orthanc
 {
   void DicomModification::MapDicomIdentifier(ParsedDicomFile& dicom,
-                                             DicomRootLevel level)
+                                             ResourceType level)
   {
     std::auto_ptr<DicomTag> tag;
 
     switch (level)
     {
-      case DicomRootLevel_Study:
+      case ResourceType_Study:
         tag.reset(new DicomTag(DICOM_TAG_STUDY_INSTANCE_UID));
         break;
 
-      case DicomRootLevel_Series:
+      case ResourceType_Series:
         tag.reset(new DicomTag(DICOM_TAG_SERIES_INSTANCE_UID));
         break;
 
-      case DicomRootLevel_Instance:
+      case ResourceType_Instance:
         tag.reset(new DicomTag(DICOM_TAG_SOP_INSTANCE_UID));
         break;
 
@@ -84,7 +84,7 @@
   DicomModification::DicomModification()
   {
     removePrivateTags_ = false;
-    level_ = DicomRootLevel_Instance;
+    level_ = ResourceType_Instance;
   }
 
   void DicomModification::Keep(const DicomTag& tag)
@@ -135,7 +135,7 @@
     removePrivateTags_ = removed;
   }
 
-  void DicomModification::SetLevel(DicomRootLevel level)
+  void DicomModification::SetLevel(ResourceType level)
   {
     uidMap_.clear();
     level_ = level;
@@ -146,7 +146,7 @@
     removals_.clear();
     replacements_.clear();
     removePrivateTags_ = true;
-    level_ = DicomRootLevel_Patient;
+    level_ = ResourceType_Patient;
     uidMap_.clear();
 
     // This is Table E.1-1 from PS 3.15-2008 - DICOM Part 15: Security and System Management Profiles
@@ -212,7 +212,7 @@
     replacements_.insert(std::make_pair(DicomTag(0x0012, 0x0062), "YES"));
 
     // (*) Choose a random patient name and ID
-    std::string patientId = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient);
+    std::string patientId = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient);
     replacements_[DICOM_TAG_PATIENT_ID] = patientId;
     replacements_[DICOM_TAG_PATIENT_NAME] = patientId;
   }
@@ -220,9 +220,9 @@
   void DicomModification::Apply(ParsedDicomFile& toModify)
   {
     // Check the request
-    assert(DicomRootLevel_Patient + 1 == DicomRootLevel_Study &&
-           DicomRootLevel_Study + 1 == DicomRootLevel_Series &&
-           DicomRootLevel_Series + 1 == DicomRootLevel_Instance);
+    assert(ResourceType_Patient + 1 == ResourceType_Study &&
+           ResourceType_Study + 1 == ResourceType_Series &&
+           ResourceType_Series + 1 == ResourceType_Instance);
 
     if (IsRemoved(DICOM_TAG_PATIENT_ID) ||
         IsRemoved(DICOM_TAG_STUDY_INSTANCE_UID) ||
@@ -232,22 +232,22 @@
       throw OrthancException(ErrorCode_BadRequest);
     }
 
-    if (level_ == DicomRootLevel_Patient && !IsReplaced(DICOM_TAG_PATIENT_ID))
+    if (level_ == ResourceType_Patient && !IsReplaced(DICOM_TAG_PATIENT_ID))
     {
       throw OrthancException(ErrorCode_BadRequest);
     }
 
-    if (level_ > DicomRootLevel_Patient && IsReplaced(DICOM_TAG_PATIENT_ID))
+    if (level_ > ResourceType_Patient && IsReplaced(DICOM_TAG_PATIENT_ID))
     {
       throw OrthancException(ErrorCode_BadRequest);
     }
 
-    if (level_ > DicomRootLevel_Study && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
+    if (level_ > ResourceType_Study && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
     {
       throw OrthancException(ErrorCode_BadRequest);
     }
 
-    if (level_ > DicomRootLevel_Series && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
+    if (level_ > ResourceType_Series && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
     {
       throw OrthancException(ErrorCode_BadRequest);
     }
@@ -269,23 +269,23 @@
     for (Replacements::const_iterator it = replacements_.begin(); 
          it != replacements_.end(); ++it)
     {
-      toModify.Replace(it->first, it->second, DicomReplaceMode_InsertIfAbsent);
+      toModify.Replace(it->first, it->second, FromDcmtkBridge::ReplaceMode_InsertIfAbsent);
     }
 
     // (4) Update the DICOM identifiers
-    if (level_ <= DicomRootLevel_Study)
+    if (level_ <= ResourceType_Study)
     {
-      MapDicomIdentifier(toModify, DicomRootLevel_Study);
+      MapDicomIdentifier(toModify, ResourceType_Study);
     }
 
-    if (level_ <= DicomRootLevel_Series)
+    if (level_ <= ResourceType_Series)
     {
-      MapDicomIdentifier(toModify, DicomRootLevel_Series);
+      MapDicomIdentifier(toModify, ResourceType_Series);
     }
 
-    if (level_ <= DicomRootLevel_Instance)  // Always true
+    if (level_ <= ResourceType_Instance)  // Always true
     {
-      MapDicomIdentifier(toModify, DicomRootLevel_Instance);
+      MapDicomIdentifier(toModify, ResourceType_Instance);
     }
   }
 }
--- a/OrthancServer/DicomModification.h	Mon May 05 15:52:14 2014 +0200
+++ b/OrthancServer/DicomModification.h	Mon May 05 18:39:36 2014 +0200
@@ -48,16 +48,16 @@
   private:
     typedef std::set<DicomTag> Removals;
     typedef std::map<DicomTag, std::string> Replacements;
-    typedef std::map< std::pair<DicomRootLevel, std::string>, std::string>  UidMap;
+    typedef std::map< std::pair<ResourceType, std::string>, std::string>  UidMap;
 
     Removals removals_;
     Replacements replacements_;
     bool removePrivateTags_;
-    DicomRootLevel level_;
+    ResourceType level_;
     UidMap uidMap_;
 
     void MapDicomIdentifier(ParsedDicomFile& dicom,
-                            DicomRootLevel level);
+                            ResourceType level);
 
   public:
     DicomModification();
@@ -82,9 +82,9 @@
       return removePrivateTags_;
     }
 
-    void SetLevel(DicomRootLevel level);
+    void SetLevel(ResourceType level);
 
-    DicomRootLevel GetLevel() const
+    ResourceType GetLevel() const
     {
       return level_;
     }
--- a/OrthancServer/FromDcmtkBridge.cpp	Mon May 05 15:52:14 2014 +0200
+++ b/OrthancServer/FromDcmtkBridge.cpp	Mon May 05 18:39:36 2014 +0200
@@ -784,7 +784,7 @@
 
   void ParsedDicomFile::Replace(const DicomTag& tag,
                                 const std::string& value,
-                                DicomReplaceMode mode)
+                                FromDcmtkBridge::ReplaceMode mode)
   {
     DcmTagKey key(tag.GetGroup(), tag.GetElement());
     DcmElement* element = NULL;
@@ -795,14 +795,14 @@
       // This field does not exist, act wrt. the specified "mode"
       switch (mode)
       {
-        case DicomReplaceMode_InsertIfAbsent:
+        case FromDcmtkBridge::ReplaceMode_InsertIfAbsent:
           Insert(tag, value);
           break;
 
-        case DicomReplaceMode_ThrowIfAbsent:
+        case FromDcmtkBridge::ReplaceMode_ThrowIfAbsent:
           throw OrthancException(ErrorCode_InexistentItem);
 
-        case DicomReplaceMode_IgnoreIfAbsent:
+        case FromDcmtkBridge::ReplaceMode_IgnoreIfAbsent:
           return;
       }
     }
@@ -820,11 +820,18 @@
      * options. You can disable this behaviour by using the -nmu
      * option.
      **/
+
     if (tag == DICOM_TAG_SOP_CLASS_UID)
-      Replace(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value, DicomReplaceMode_InsertIfAbsent);
+    {
+      Replace(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value,
+              FromDcmtkBridge::ReplaceMode_InsertIfAbsent);
+    }
 
     if (tag == DICOM_TAG_SOP_INSTANCE_UID)
-      Replace(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value, DicomReplaceMode_InsertIfAbsent);
+    {
+      Replace(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value, 
+              FromDcmtkBridge::ReplaceMode_InsertIfAbsent);
+    }
   }
 
     
@@ -1653,25 +1660,25 @@
   }
 
 
-  std::string FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel level)
+  std::string FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType level)
   {
     char uid[100];
 
     switch (level)
     {
-      case DicomRootLevel_Patient:
+      case ResourceType_Patient:
         // The "PatientID" field is of type LO (Long String), 64
         // Bytes Maximum. An UUID is of length 36, thus it can be used
         // as a random PatientID.
         return Toolbox::GenerateUuid();
 
-      case DicomRootLevel_Instance:
+      case ResourceType_Instance:
         return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT);
 
-      case DicomRootLevel_Series:
+      case ResourceType_Series:
         return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT);
 
-      case DicomRootLevel_Study:
+      case ResourceType_Study:
         return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT);
 
       default:
@@ -1746,10 +1753,10 @@
   ParsedDicomFile::ParsedDicomFile()
   {
     file_.reset(new DcmFileFormat);
-    Replace(DICOM_TAG_PATIENT_ID, FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient));
-    Replace(DICOM_TAG_STUDY_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Study));
-    Replace(DICOM_TAG_SERIES_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series));
-    Replace(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Instance));
+    Replace(DICOM_TAG_PATIENT_ID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient));
+    Replace(DICOM_TAG_STUDY_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study));
+    Replace(DICOM_TAG_SERIES_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series));
+    Replace(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance));
   }
 
 }
--- a/OrthancServer/FromDcmtkBridge.h	Mon May 05 15:52:14 2014 +0200
+++ b/OrthancServer/FromDcmtkBridge.h	Mon May 05 18:39:36 2014 +0200
@@ -43,24 +43,16 @@
 
 namespace Orthanc
 {
-  enum DicomRootLevel
-  {
-    DicomRootLevel_Patient,
-    DicomRootLevel_Study,
-    DicomRootLevel_Series,
-    DicomRootLevel_Instance
-  };
-
-  enum DicomReplaceMode
-  {
-    DicomReplaceMode_InsertIfAbsent,
-    DicomReplaceMode_ThrowIfAbsent,
-    DicomReplaceMode_IgnoreIfAbsent
-  };
-
   class FromDcmtkBridge
   {
   public:
+    enum ReplaceMode
+    {
+      ReplaceMode_InsertIfAbsent,
+      ReplaceMode_ThrowIfAbsent,
+      ReplaceMode_IgnoreIfAbsent
+    };
+
     static void Convert(DicomMap& target, DcmDataset& dataset);
 
     static DicomTag GetTag(const DcmElement& element);
@@ -119,7 +111,7 @@
     static void ToJson(Json::Value& result,
                        const DicomMap& values);
 
-    static std::string GenerateUniqueIdentifier(DicomRootLevel level);
+    static std::string GenerateUniqueIdentifier(ResourceType level);
 
     static bool SaveToMemoryBuffer(std::string& buffer,
                                    DcmDataset* dataSet);
@@ -177,7 +169,7 @@
 
     void Replace(const DicomTag& tag,
                  const std::string& value,
-                 DicomReplaceMode mode = DicomReplaceMode_InsertIfAbsent);
+                 FromDcmtkBridge::ReplaceMode mode = FromDcmtkBridge::ReplaceMode_InsertIfAbsent);
 
     void RemovePrivateTags();
 
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Mon May 05 15:52:14 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Mon May 05 18:39:36 2014 +0200
@@ -335,7 +335,7 @@
   {
     DicomModification modification;
 
-    // TODO : modification.SetLevel(DicomRootLevel_Series); ?????
+    // TODO : modification.SetLevel(ResourceType_Series); ?????
 
     if (ParseModifyRequest(modification, call))
     {
@@ -364,15 +364,15 @@
     switch (resourceType)
     {
       case ResourceType_Series:
-        modification.SetLevel(DicomRootLevel_Series);
+        modification.SetLevel(ResourceType_Series);
         break;
 
       case ResourceType_Study:
-        modification.SetLevel(DicomRootLevel_Study);
+        modification.SetLevel(ResourceType_Study);
         break;
 
       case ResourceType_Patient:
-        modification.SetLevel(DicomRootLevel_Patient);
+        modification.SetLevel(ResourceType_Patient);
         break;
 
       default:
--- a/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp	Mon May 05 15:52:14 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp	Mon May 05 18:39:36 2014 +0200
@@ -68,19 +68,19 @@
     std::string level = call.GetArgument("level", "");
     if (level == "patient")
     {
-      call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient), "text/plain");
+      call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient), "text/plain");
     }
     else if (level == "study")
     {
-      call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Study), "text/plain");
+      call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study), "text/plain");
     }
     else if (level == "series")
     {
-      call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series), "text/plain");
+      call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series), "text/plain");
     }
     else if (level == "instance")
     {
-      call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Instance), "text/plain");
+      call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance), "text/plain");
     }
   }