diff Core/DicomFormat/DicomMap.cpp @ 3652:335611d2b6cd storage-commitment

integration mainline->storage-commitment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Feb 2020 13:24:48 +0100
parents 05df4860aea6 46cb00e4adbb
children cccd97333e3d
line wrap: on
line diff
--- a/Core/DicomFormat/DicomMap.cpp	Tue Feb 04 20:00:48 2020 +0100
+++ b/Core/DicomFormat/DicomMap.cpp	Wed Feb 05 13:24:48 2020 +0100
@@ -55,7 +55,7 @@
     };
   }
 
-  static const MainDicomTag PATIENT_MAIN_DICOM_TAGS_2[] =
+  static const MainDicomTag PATIENT_MAIN_DICOM_TAGS[] =
   {
     // { DicomTag(0x0010, 0x1010), "PatientAge" },
     // { DicomTag(0x0010, 0x1040), "PatientAddress" },
@@ -66,7 +66,7 @@
     { DICOM_TAG_PATIENT_ID, "PatientID" }
   };
     
-  static const MainDicomTag STUDY_MAIN_DICOM_TAGS_2[] =
+  static const MainDicomTag STUDY_MAIN_DICOM_TAGS[] =
   {
     // { DicomTag(0x0010, 0x1020), "PatientSize" },
     // { DicomTag(0x0010, 0x1030), "PatientWeight" },
@@ -84,7 +84,7 @@
     { DICOM_TAG_REFERRING_PHYSICIAN_NAME, "ReferringPhysicianName" }
   };
     
-  static const MainDicomTag SERIES_MAIN_DICOM_TAGS_2[] =
+  static const MainDicomTag SERIES_MAIN_DICOM_TAGS[] =
   {
     // { DicomTag(0x0010, 0x1080), "MilitaryRank" },
     { DicomTag(0x0008, 0x0021), "SeriesDate" },
@@ -97,7 +97,7 @@
     { DicomTag(0x0018, 0x0024), "SequenceName" },
     { DicomTag(0x0018, 0x1030), "ProtocolName" },
     { DicomTag(0x0020, 0x0011), "SeriesNumber" },
-    { DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES, "CardiacNumberOfImage" },
+    { DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES, "CardiacNumberOfImages" },
     { DICOM_TAG_IMAGES_IN_ACQUISITION, "ImagesInAcquisition" },
     { DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS, "NumberOfTemporalPositions" },
     { DICOM_TAG_NUMBER_OF_SLICES, "NumberOfSlices" },
@@ -105,15 +105,15 @@
     { DICOM_TAG_SERIES_INSTANCE_UID, "SeriesInstanceUID" },
 
     // New in db v6
-    { DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "ImageOrientationPatientt" },  // TODO - Should have an unit test that fails
+    { DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "ImageOrientationPatient" },
     { DICOM_TAG_SERIES_TYPE, "SeriesType" },
-    { DICOM_TAG_OPERATOR_NAME, "OperatorName" },
+    { DICOM_TAG_OPERATOR_NAME, "OperatorsName" },
     { DICOM_TAG_PERFORMED_PROCEDURE_STEP_DESCRIPTION, "PerformedProcedureStepDescription" },
     { DICOM_TAG_ACQUISITION_DEVICE_PROCESSING_DESCRIPTION, "AcquisitionDeviceProcessingDescription" },
-    { DICOM_TAG_CONTRAST_BOLUS_AGENT, "ContrastBolusAgen" }
+    { DICOM_TAG_CONTRAST_BOLUS_AGENT, "ContrastBolusAgent" }
   };
     
-  static const MainDicomTag INSTANCE_MAIN_DICOM_TAGS_2[] =
+  static const MainDicomTag INSTANCE_MAIN_DICOM_TAGS[] =
   {
     { DicomTag(0x0008, 0x0012), "InstanceCreationDate" },
     { DicomTag(0x0008, 0x0013), "InstanceCreationTime" },
@@ -137,111 +137,32 @@
      **/
     { DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "ImageOrientationPatient" }  // New in Orthanc 1.4.2
   };
-    
-
-  
-  static const DicomTag PATIENT_MAIN_DICOM_TAGS[] =
-  {
-    //DicomTag(0x0010, 0x1010), // PatientAge
-    //DicomTag(0x0010, 0x1040)  // PatientAddress
-    DicomTag(0x0010, 0x0010),   // PatientName
-    DicomTag(0x0010, 0x0030),   // PatientBirthDate
-    DicomTag(0x0010, 0x0040),   // PatientSex
-    DicomTag(0x0010, 0x1000),   // OtherPatientIDs
-    DICOM_TAG_PATIENT_ID
-  };
-
-  static const DicomTag STUDY_MAIN_DICOM_TAGS[] =
-  {
-    //DicomTag(0x0010, 0x1020), // PatientSize
-    //DicomTag(0x0010, 0x1030)  // PatientWeight
-    DICOM_TAG_STUDY_DATE,
-    DicomTag(0x0008, 0x0030),   // StudyTime
-    DicomTag(0x0020, 0x0010),   // StudyID
-    DICOM_TAG_STUDY_DESCRIPTION,
-    DICOM_TAG_ACCESSION_NUMBER,
-    DICOM_TAG_STUDY_INSTANCE_UID,
-    DICOM_TAG_REQUESTED_PROCEDURE_DESCRIPTION,   // New in db v6
-    DICOM_TAG_INSTITUTION_NAME,                  // New in db v6
-    DICOM_TAG_REQUESTING_PHYSICIAN,              // New in db v6
-    DICOM_TAG_REFERRING_PHYSICIAN_NAME           // New in db v6
-  };
-
-  static const DicomTag SERIES_MAIN_DICOM_TAGS[] =
-  {
-    //DicomTag(0x0010, 0x1080), // MilitaryRank
-    DicomTag(0x0008, 0x0021),   // SeriesDate
-    DicomTag(0x0008, 0x0031),   // SeriesTime
-    DICOM_TAG_MODALITY,
-    DicomTag(0x0008, 0x0070),   // Manufacturer
-    DicomTag(0x0008, 0x1010),   // StationName
-    DICOM_TAG_SERIES_DESCRIPTION,
-    DicomTag(0x0018, 0x0015),   // BodyPartExamined
-    DicomTag(0x0018, 0x0024),   // SequenceName
-    DicomTag(0x0018, 0x1030),   // ProtocolName
-    DicomTag(0x0020, 0x0011),   // SeriesNumber
-    DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES,
-    DICOM_TAG_IMAGES_IN_ACQUISITION,
-    DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS,
-    DICOM_TAG_NUMBER_OF_SLICES,
-    DICOM_TAG_NUMBER_OF_TIME_SLICES,
-    DICOM_TAG_SERIES_INSTANCE_UID,
-    DICOM_TAG_IMAGE_ORIENTATION_PATIENT,                  // New in db v6
-    DICOM_TAG_SERIES_TYPE,                                // New in db v6
-    DICOM_TAG_OPERATOR_NAME,                              // New in db v6
-    DICOM_TAG_PERFORMED_PROCEDURE_STEP_DESCRIPTION,       // New in db v6
-    DICOM_TAG_ACQUISITION_DEVICE_PROCESSING_DESCRIPTION,  // New in db v6
-    DICOM_TAG_CONTRAST_BOLUS_AGENT                        // New in db v6
-  };
-
-  static const DicomTag INSTANCE_MAIN_DICOM_TAGS[] =
-  {
-    DicomTag(0x0008, 0x0012),   // InstanceCreationDate
-    DicomTag(0x0008, 0x0013),   // InstanceCreationTime
-    DicomTag(0x0020, 0x0012),   // AcquisitionNumber
-    DICOM_TAG_IMAGE_INDEX,
-    DICOM_TAG_INSTANCE_NUMBER,
-    DICOM_TAG_NUMBER_OF_FRAMES,
-    DICOM_TAG_TEMPORAL_POSITION_IDENTIFIER,
-    DICOM_TAG_SOP_INSTANCE_UID,
-    DICOM_TAG_IMAGE_POSITION_PATIENT,    // New in db v6
-    DICOM_TAG_IMAGE_COMMENTS,            // New in db v6
-
-    /**
-     * Main DICOM tags that are not part of any release of the
-     * database schema yet, and that will be part of future db v7. In
-     * the meantime, the user must call "/tools/reconstruct" once to
-     * access these tags if the corresponding DICOM files where
-     * indexed in the database by an older version of Orthanc.
-     **/
-    DICOM_TAG_IMAGE_ORIENTATION_PATIENT  // New in Orthanc 1.4.2
-  };
 
 
-  void DicomMap::LoadMainDicomTags(const DicomTag*& tags,
-                                   size_t& size,
-                                   ResourceType level)
+  static void LoadMainDicomTags(const MainDicomTag*& tags,
+                                size_t& size,
+                                ResourceType level)
   {
     switch (level)
     {
       case ResourceType_Patient:
         tags = PATIENT_MAIN_DICOM_TAGS;
-        size = sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(DicomTag);
+        size = sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(MainDicomTag);
         break;
 
       case ResourceType_Study:
         tags = STUDY_MAIN_DICOM_TAGS;
-        size = sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(DicomTag);
+        size = sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(MainDicomTag);
         break;
 
       case ResourceType_Series:
         tags = SERIES_MAIN_DICOM_TAGS;
-        size = sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(DicomTag);
+        size = sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(MainDicomTag);
         break;
 
       case ResourceType_Instance:
         tags = INSTANCE_MAIN_DICOM_TAGS;
-        size = sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(DicomTag);
+        size = sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(MainDicomTag);
         break;
 
       default:
@@ -250,55 +171,106 @@
   }
 
 
-  void DicomMap::SetValue(uint16_t group, 
-                          uint16_t element, 
-                          DicomValue* value)
+  static void LoadMainDicomTags(std::map<DicomTag, std::string>& target,
+                                ResourceType level)
+  {
+    const MainDicomTag* tags = NULL;
+    size_t size;
+    LoadMainDicomTags(tags, size, level);
+
+    assert(tags != NULL &&
+           size != 0);
+
+    for (size_t i = 0; i < size; i++)
+    {
+      assert(target.find(tags[i].tag_) == target.end());
+      
+      target[tags[i].tag_] = tags[i].name_;
+    }
+  }
+
+
+  namespace
+  {
+    class DicomTag2 : public DicomTag
+    {
+    public:
+      DicomTag2() :
+        DicomTag(0, 0)   // To make std::map<> happy
+      {
+      }
+
+      DicomTag2(const DicomTag& tag) :
+        DicomTag(tag)
+      {
+      }
+    };
+  }
+
+
+  static void LoadMainDicomTags(std::map<std::string, DicomTag2>& target,
+                                ResourceType level)
+  {
+    const MainDicomTag* tags = NULL;
+    size_t size;
+    LoadMainDicomTags(tags, size, level);
+
+    assert(tags != NULL &&
+           size != 0);
+
+    for (size_t i = 0; i < size; i++)
+    {
+      assert(target.find(tags[i].name_) == target.end());
+      
+      target[tags[i].name_] = tags[i].tag_;
+    }
+  }
+
+
+  void DicomMap::SetValueInternal(uint16_t group, 
+                                  uint16_t element, 
+                                  DicomValue* value)
   {
     DicomTag tag(group, element);
-    Map::iterator it = map_.find(tag);
+    Content::iterator it = content_.find(tag);
 
-    if (it != map_.end())
+    if (it != content_.end())
     {
       delete it->second;
       it->second = value;
     }
     else
     {
-      map_.insert(std::make_pair(tag, value));
+      content_.insert(std::make_pair(tag, value));
     }
   }
 
-  void DicomMap::SetValue(DicomTag tag, 
-                          DicomValue* value)
-  {
-    SetValue(tag.GetGroup(), tag.GetElement(), value);
-  }
-
 
   void DicomMap::Clear()
   {
-    for (Map::iterator it = map_.begin(); it != map_.end(); ++it)
+    for (Content::iterator it = content_.begin(); it != content_.end(); ++it)
     {
       assert(it->second != NULL);
       delete it->second;
     }
 
-    map_.clear();
+    content_.clear();
   }
 
 
-  void DicomMap::ExtractTags(DicomMap& result,
-                             const DicomTag* tags,
-                             size_t count) const
+  static void ExtractTags(DicomMap& result,
+                          const DicomMap::Content& source,
+                          const MainDicomTag* tags,
+                          size_t count)
   {
     result.Clear();
 
     for (unsigned int i = 0; i < count; i++)
     {
-      Map::const_iterator it = map_.find(tags[i]);
-      if (it != map_.end())
+      DicomMap::Content::const_iterator it = source.find(tags[i].tag_);
+      if (it != source.end())
       {
-        result.SetValue(it->first, it->second->Clone());
+        result.SetValue(it->first, *it->second /* value will be cloned */);
       }
     }
   }
@@ -306,22 +278,22 @@
 
   void DicomMap::ExtractPatientInformation(DicomMap& result) const
   {
-    ExtractTags(result, PATIENT_MAIN_DICOM_TAGS, sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(DicomTag));
+    ExtractTags(result, content_, PATIENT_MAIN_DICOM_TAGS, sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(MainDicomTag));
   }
 
   void DicomMap::ExtractStudyInformation(DicomMap& result) const
   {
-    ExtractTags(result, STUDY_MAIN_DICOM_TAGS, sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(DicomTag));
+    ExtractTags(result, content_, STUDY_MAIN_DICOM_TAGS, sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(MainDicomTag));
   }
 
   void DicomMap::ExtractSeriesInformation(DicomMap& result) const
   {
-    ExtractTags(result, SERIES_MAIN_DICOM_TAGS, sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(DicomTag));
+    ExtractTags(result, content_, SERIES_MAIN_DICOM_TAGS, sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(MainDicomTag));
   }
 
   void DicomMap::ExtractInstanceInformation(DicomMap& result) const
   {
-    ExtractTags(result, INSTANCE_MAIN_DICOM_TAGS, sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(DicomTag));
+    ExtractTags(result, content_, INSTANCE_MAIN_DICOM_TAGS, sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(MainDicomTag));
   }
 
 
@@ -330,9 +302,9 @@
   {
     std::auto_ptr<DicomMap> result(new DicomMap);
 
-    for (Map::const_iterator it = map_.begin(); it != map_.end(); ++it)
+    for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it)
     {
-      result->map_.insert(std::make_pair(it->first, it->second->Clone()));
+      result->content_.insert(std::make_pair(it->first, it->second->Clone()));
     }
 
     return result.release();
@@ -343,9 +315,9 @@
   {
     Clear();
 
-    for (Map::const_iterator it = other.map_.begin(); it != other.map_.end(); ++it)
+    for (Content::const_iterator it = other.content_.begin(); it != other.content_.end(); ++it)
     {
-      map_.insert(std::make_pair(it->first, it->second->Clone()));
+      content_.insert(std::make_pair(it->first, it->second->Clone()));
     }
   }
 
@@ -367,9 +339,9 @@
 
   const DicomValue* DicomMap::TestAndGetValue(const DicomTag& tag) const
   {
-    Map::const_iterator it = map_.find(tag);
+    Content::const_iterator it = content_.find(tag);
 
-    if (it == map_.end())
+    if (it == content_.end())
     {
       return NULL;
     }
@@ -382,35 +354,35 @@
 
   void DicomMap::Remove(const DicomTag& tag) 
   {
-    Map::iterator it = map_.find(tag);
-    if (it != map_.end())
+    Content::iterator it = content_.find(tag);
+    if (it != content_.end())
     {
       delete it->second;
-      map_.erase(it);
+      content_.erase(it);
     }
   }
 
 
   static void SetupFindTemplate(DicomMap& result,
-                                const DicomTag* tags,
+                                const MainDicomTag* tags,
                                 size_t count) 
   {
     result.Clear();
 
     for (size_t i = 0; i < count; i++)
     {
-      result.SetValue(tags[i], "", false);
+      result.SetValue(tags[i].tag_, "", false);
     }
   }
 
   void DicomMap::SetupFindPatientTemplate(DicomMap& result)
   {
-    SetupFindTemplate(result, PATIENT_MAIN_DICOM_TAGS, sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(DicomTag));
+    SetupFindTemplate(result, PATIENT_MAIN_DICOM_TAGS, sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(MainDicomTag));
   }
 
   void DicomMap::SetupFindStudyTemplate(DicomMap& result)
   {
-    SetupFindTemplate(result, STUDY_MAIN_DICOM_TAGS, sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(DicomTag));
+    SetupFindTemplate(result, STUDY_MAIN_DICOM_TAGS, sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(MainDicomTag));
     result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "", false);
     result.SetValue(DICOM_TAG_PATIENT_ID, "", false);
 
@@ -423,7 +395,7 @@
 
   void DicomMap::SetupFindSeriesTemplate(DicomMap& result)
   {
-    SetupFindTemplate(result, SERIES_MAIN_DICOM_TAGS, sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(DicomTag));
+    SetupFindTemplate(result, SERIES_MAIN_DICOM_TAGS, sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(MainDicomTag));
     result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "", false);
     result.SetValue(DICOM_TAG_PATIENT_ID, "", false);
     result.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "", false);
@@ -445,7 +417,7 @@
 
   void DicomMap::SetupFindInstanceTemplate(DicomMap& result)
   {
-    SetupFindTemplate(result, INSTANCE_MAIN_DICOM_TAGS, sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(DicomTag));
+    SetupFindTemplate(result, INSTANCE_MAIN_DICOM_TAGS, sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(MainDicomTag));
     result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "", false);
     result.SetValue(DICOM_TAG_PATIENT_ID, "", false);
     result.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "", false);
@@ -465,38 +437,13 @@
 
   bool DicomMap::IsMainDicomTag(const DicomTag& tag, ResourceType level)
   {
-    const DicomTag *tags = NULL;
+    const MainDicomTag *tags = NULL;
     size_t size;
-
-    switch (level)
-    {
-      case ResourceType_Patient:
-        tags = PATIENT_MAIN_DICOM_TAGS;
-        size = sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(DicomTag);
-        break;
-
-      case ResourceType_Study:
-        tags = STUDY_MAIN_DICOM_TAGS;
-        size = sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(DicomTag);
-        break;
-
-      case ResourceType_Series:
-        tags = SERIES_MAIN_DICOM_TAGS;
-        size = sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(DicomTag);
-        break;
-
-      case ResourceType_Instance:
-        tags = INSTANCE_MAIN_DICOM_TAGS;
-        size = sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(DicomTag);
-        break;
-
-      default:
-        throw OrthancException(ErrorCode_ParameterOutOfRange);
-    }
+    LoadMainDicomTags(tags, size, level);
 
     for (size_t i = 0; i < size; i++)
     {
-      if (tags[i] == tag)
+      if (tags[i].tag_ == tag)
       {
         return true;
       }
@@ -516,38 +463,13 @@
 
   void DicomMap::GetMainDicomTagsInternal(std::set<DicomTag>& result, ResourceType level)
   {
-    const DicomTag *tags = NULL;
+    const MainDicomTag *tags = NULL;
     size_t size;
-
-    switch (level)
-    {
-      case ResourceType_Patient:
-        tags = PATIENT_MAIN_DICOM_TAGS;
-        size = sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(DicomTag);
-        break;
-
-      case ResourceType_Study:
-        tags = STUDY_MAIN_DICOM_TAGS;
-        size = sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(DicomTag);
-        break;
-
-      case ResourceType_Series:
-        tags = SERIES_MAIN_DICOM_TAGS;
-        size = sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(DicomTag);
-        break;
-
-      case ResourceType_Instance:
-        tags = INSTANCE_MAIN_DICOM_TAGS;
-        size = sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(DicomTag);
-        break;
-
-      default:
-        throw OrthancException(ErrorCode_ParameterOutOfRange);
-    }
+    LoadMainDicomTags(tags, size, level);
 
     for (size_t i = 0; i < size; i++)
     {
-      result.insert(tags[i]);
+      result.insert(tags[i].tag_);
     }
   }
 
@@ -573,8 +495,8 @@
   {
     tags.clear();
 
-    for (Map::const_iterator it = map_.begin();
-         it != map_.end(); ++it)
+    for (Content::const_iterator it = content_.begin();
+         it != content_.end(); ++it)
     {
       tags.insert(it->first);
     }
@@ -1124,14 +1046,14 @@
 
   void DicomMap::Merge(const DicomMap& other)
   {
-    for (Map::const_iterator it = other.map_.begin();
-         it != other.map_.end(); ++it)
+    for (Content::const_iterator it = other.content_.begin();
+         it != other.content_.end(); ++it)
     {
       assert(it->second != NULL);
 
-      if (map_.find(it->first) == map_.end())
+      if (content_.find(it->first) == content_.end())
       {
-        map_[it->first] = it->second->Clone();
+        content_[it->first] = it->second->Clone();
       }
     }
   }
@@ -1140,7 +1062,7 @@
   void DicomMap::ExtractMainDicomTagsInternal(const DicomMap& other,
                                               ResourceType level)
   {
-    const DicomTag* tags = NULL;
+    const MainDicomTag* tags = NULL;
     size_t size = 0;
 
     LoadMainDicomTags(tags, size, level);
@@ -1148,13 +1070,13 @@
 
     for (size_t i = 0; i < size; i++)
     {
-      Map::const_iterator found = other.map_.find(tags[i]);
+      Content::const_iterator found = other.content_.find(tags[i].tag_);
 
-      if (found != other.map_.end() &&
-          map_.find(tags[i]) == map_.end())
+      if (found != other.content_.end() &&
+          content_.find(tags[i].tag_) == content_.end())
       {
         assert(found->second != NULL);
-        map_[tags[i]] = found->second->Clone();
+        content_[tags[i].tag_] = found->second->Clone();
       }
     }
   }
@@ -1177,7 +1099,7 @@
     std::set<DicomTag> mainDicomTags;
     GetMainDicomTags(mainDicomTags);
 
-    for (Map::const_iterator it = map_.begin(); it != map_.end(); ++it)
+    for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it)
     {
       if (mainDicomTags.find(it->first) == mainDicomTags.end())
       {
@@ -1193,7 +1115,7 @@
   {
     target = Json::objectValue;
 
-    for (Map::const_iterator it = map_.begin(); it != map_.end(); ++it)
+    for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it)
     {
       assert(it->second != NULL);
       
@@ -1223,7 +1145,7 @@
       DicomTag tag(0, 0);
       
       if (!DicomTag::ParseHexadecimal(tag, tags[i].c_str()) ||
-          map_.find(tag) != map_.end())
+          content_.find(tag) != content_.end())
       {
         throw OrthancException(ErrorCode_BadFileFormat);
       }
@@ -1231,7 +1153,7 @@
       std::auto_ptr<DicomValue> value(new DicomValue);
       value->Unserialize(source[tags[i]]);
 
-      map_[tag] = value.release();
+      content_[tag] = value.release();
     }
   }
 
@@ -1390,9 +1312,9 @@
 
   void DicomMap::RemoveBinaryTags()
   {
-    Map kept;
+    Content kept;
 
-    for (Map::iterator it = map_.begin(); it != map_.end(); ++it)
+    for (Content::iterator it = content_.begin(); it != content_.end(); ++it)
     {
       assert(it->second != NULL);
 
@@ -1407,7 +1329,67 @@
       }
     }
 
-    map_ = kept;
+    content_ = kept;
+  }
+
+
+  void DicomMap::DumpMainDicomTags(Json::Value& target,
+                                   ResourceType level) const
+  {
+    std::map<DicomTag, std::string> mainTags;   // TODO - Create a singleton to hold this map
+    LoadMainDicomTags(mainTags, level);
+    
+    target = Json::objectValue;
+
+    for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it)
+    {
+      assert(it->second != NULL);
+      
+      if (!it->second->IsBinary() &&
+          !it->second->IsNull())
+      {
+        std::map<DicomTag, std::string>::const_iterator found = mainTags.find(it->first);
+
+        if (found != mainTags.end())
+        {
+          target[found->second] = it->second->GetContent();
+        }
+      }
+    }    
+  }
+  
+
+  void DicomMap::ParseMainDicomTags(const Json::Value& source,
+                                    ResourceType level)
+  {
+    if (source.type() != Json::objectValue)
+    {
+      throw OrthancException(ErrorCode_BadFileFormat);
+    }
+    
+    Clear();
+
+    std::map<std::string, DicomTag2> mainTags;   // TODO - Create a singleton to hold this map
+    LoadMainDicomTags(mainTags, level);
+    
+    Json::Value::Members members = source.getMemberNames();
+    for (size_t i = 0; i < members.size(); i++)
+    {
+      std::map<std::string, DicomTag2>::const_iterator found = mainTags.find(members[i]);
+
+      if (found != mainTags.end())
+      {
+        const Json::Value& value = source[members[i]];
+        if (value.type() != Json::stringValue)
+        {
+          throw OrthancException(ErrorCode_BadFileFormat);
+        }
+        else
+        {
+          SetValue(found->second, value.asString(), false);
+        }
+      }
+    }
   }