changeset 4504:7d1eabfac6e0

removed cached dicom-as-json from DicomInstanceToStore
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Feb 2021 11:29:53 +0100
parents b525e0c3cff0
children 97d103b57cd1
files OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Sources/DicomInstanceToStore.cpp OrthancServer/Sources/DicomInstanceToStore.h OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/main.cpp OrthancServer/UnitTestsSources/UnitTestsMain.cpp
diffstat 6 files changed, 24 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Tue Feb 09 17:05:45 2021 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Wed Feb 10 11:29:53 2021 +0100
@@ -2932,16 +2932,19 @@
       case _OrthancPluginService_GetInstanceJson:
       case _OrthancPluginService_GetInstanceSimplifiedJson:
       {
+        Json::Value dicomAsJson;
+        OrthancConfiguration::DefaultDicomDatasetToJson(dicomAsJson, instance.GetParsedDicomFile());
+        
         std::string s;
 
         if (service == _OrthancPluginService_GetInstanceJson)
         {
-          Toolbox::WriteStyledJson(s, instance.GetJson());
+          Toolbox::WriteStyledJson(s, dicomAsJson);
         }
         else
         {
           Json::Value simplified;
-          Toolbox::SimplifyDicomAsJson(simplified, instance.GetJson(), DicomToJsonFormat_Human);
+          Toolbox::SimplifyDicomAsJson(simplified, dicomAsJson, DicomToJsonFormat_Human);
           Toolbox::WriteStyledJson(s, simplified);
         }
 
--- a/OrthancServer/Sources/DicomInstanceToStore.cpp	Tue Feb 09 17:05:45 2021 +0100
+++ b/OrthancServer/Sources/DicomInstanceToStore.cpp	Wed Feb 10 11:29:53 2021 +0100
@@ -158,7 +158,6 @@
     size_t                               bufferSize_;
     SmartContainer<ParsedDicomFile>      parsed_;
     SmartContainer<DicomMap>             summary_;
-    SmartContainer<Json::Value>          json_;
     MetadataMap                          metadata_;
 
     PImpl() :
@@ -194,8 +193,7 @@
     void ComputeMissingInformation()
     {
       if (hasBuffer_ &&
-          summary_.HasContent() &&
-          json_.HasContent())
+          summary_.HasContent())
       {
         // Fine, everything is available
         return; 
@@ -229,32 +227,20 @@
         hasBuffer_ = true;
       }
 
-      if (summary_.HasContent() &&
-          json_.HasContent())
-      {
-        return;
-      }
-
-      // At this point, we know that the DICOM file is available as a
-      // memory buffer, but that its summary or its JSON version is
-      // missing
-
-      ParseDicomFile();
-      assert(parsed_.HasContent());
-
-      // At this point, we have parsed the DICOM file
-    
       if (!summary_.HasContent())
       {
+        // At this point, we know that the DICOM file is available as a
+        // memory buffer, but that its summary or its JSON version is
+        // missing
+        
+        ParseDicomFile();
+        assert(parsed_.HasContent());
+
+        // At this point, we have parsed the DICOM file
+        
         summary_.Allocate();
         OrthancConfiguration::DefaultExtractDicomSummary(summary_.GetContent(), parsed_.GetContent());
       }
-    
-      if (!json_.HasContent())
-      {
-        json_.Allocate();
-        OrthancConfiguration::DefaultDicomDatasetToJson(json_.GetContent(), parsed_.GetContent());
-      }
     }
 
 
@@ -328,19 +314,6 @@
     }
 
     
-    const Json::Value& GetJson()
-    {
-      ComputeMissingInformation();
-    
-      if (!json_.HasContent())
-      {
-        throw OrthancException(ErrorCode_InternalError);
-      }
-
-      return json_.GetConstContent();
-    }
-
-
     DicomInstanceHasher& GetHasher()
     {
       if (hasher_.get() == NULL)
@@ -444,12 +417,6 @@
   }
 
 
-  void DicomInstanceToStore::SetJson(const Json::Value& json)
-  {
-    pimpl_->json_.SetConstReference(json);
-  }
-
-
   const DicomInstanceToStore::MetadataMap& DicomInstanceToStore::GetMetadata() const
   {
     return pimpl_->metadata_;
@@ -488,12 +455,6 @@
   }
 
     
-  const Json::Value& DicomInstanceToStore::GetJson() const
-  {
-    return const_cast<PImpl&>(*pimpl_).GetJson();
-  }
-
-
   bool DicomInstanceToStore::LookupTransferSyntax(std::string& result) const
   {
     return const_cast<PImpl&>(*pimpl_).LookupTransferSyntax(result);
--- a/OrthancServer/Sources/DicomInstanceToStore.h	Tue Feb 09 17:05:45 2021 +0100
+++ b/OrthancServer/Sources/DicomInstanceToStore.h	Wed Feb 10 11:29:53 2021 +0100
@@ -69,8 +69,6 @@
 
     void SetSummary(const DicomMap& summary);
 
-    void SetJson(const Json::Value& json);
-
     const MetadataMap& GetMetadata() const;
 
     MetadataMap& GetMetadata();
@@ -84,8 +82,6 @@
     size_t GetBufferSize() const;
 
     const DicomMap& GetSummary();
-    
-    const Json::Value& GetJson() const;
 
     bool LookupTransferSyntax(std::string& result) const;
 
--- a/OrthancServer/Sources/ServerContext.cpp	Tue Feb 09 17:05:45 2021 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Wed Feb 10 11:29:53 2021 +0100
@@ -526,8 +526,11 @@
 
       resultPublicId = dicom.GetHasher().HashInstance();
 
+      Json::Value dicomAsJson;
+      OrthancConfiguration::DefaultDicomDatasetToJson(dicomAsJson, dicom.GetParsedDicomFile());
+      
       Json::Value simplifiedTags;
-      Toolbox::SimplifyDicomAsJson(simplifiedTags, dicom.GetJson(), DicomToJsonFormat_Human);
+      Toolbox::SimplifyDicomAsJson(simplifiedTags, dicomAsJson, DicomToJsonFormat_Human);
 
       // Test if the instance must be filtered out
       bool accepted = true;
@@ -578,7 +581,7 @@
       FileInfo jsonInfo;
       if (true /* TODO - !area_.HasReadRange() || !hasPixelDataOffset */)
       {
-        jsonInfo = accessor.Write(dicom.GetJson().toStyledString(), 
+        jsonInfo = accessor.Write(dicomAsJson.toStyledString(), 
                                   FileContentType_DicomAsJson, compression, storeMD5_);
         attachments.push_back(jsonInfo);
       }
--- a/OrthancServer/Sources/main.cpp	Tue Feb 09 17:05:45 2021 +0100
+++ b/OrthancServer/Sources/main.cpp	Wed Feb 10 11:29:53 2021 +0100
@@ -89,15 +89,12 @@
                       const std::string& calledAet) ORTHANC_OVERRIDE 
   {
     DicomMap dicomSummary;
-    Json::Value dicomJson;
     std::string dicomFile;
 
     const std::set<DicomTag> ignoreTagLength;
 
     // TODO => Parameters in class "DicomServer"
     FromDcmtkBridge::ExtractDicomSummary(dicomSummary, dicom, ORTHANC_MAXIMUM_TAG_LENGTH, ignoreTagLength);
-    FromDcmtkBridge::ExtractDicomAsJson(dicomJson, dicom, DicomToJsonFormat_Full,
-                                        DicomToJsonFlags_Default, ORTHANC_MAXIMUM_TAG_LENGTH, ignoreTagLength);
 
     if (!FromDcmtkBridge::SaveToMemoryBuffer(dicomFile, dicom))
     {
@@ -111,7 +108,6 @@
                         (remoteIp.c_str(), remoteAet.c_str(), calledAet.c_str()));
       toStore.SetBuffer(dicomFile.c_str(), dicomFile.size());
       toStore.SetSummary(dicomSummary);
-      toStore.SetJson(dicomJson);
 
       std::string id;
       context_.Store(id, toStore, StoreInstanceMode_Default);
--- a/OrthancServer/UnitTestsSources/UnitTestsMain.cpp	Tue Feb 09 17:05:45 2021 +0100
+++ b/OrthancServer/UnitTestsSources/UnitTestsMain.cpp	Wed Feb 10 11:29:53 2021 +0100
@@ -250,8 +250,11 @@
   DicomInstanceToStore toStore;
   toStore.SetParsedDicomFile(dicom);
 
+  Json::Value dicomAsJson;
+  OrthancConfiguration::DefaultDicomDatasetToJson(dicomAsJson, toStore.GetParsedDicomFile());
+  
   DicomMap m;
-  m.FromDicomAsJson(toStore.GetJson());
+  m.FromDicomAsJson(dicomAsJson);
 
   ASSERT_EQ("ISO_IR 100", m.GetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET).GetContent());