changeset 4513:1f455b86b054

simplification in ServerContext
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Feb 2021 12:13:19 +0100
parents cff7fdfc83a4
children 5b929e6b3c36
files OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h
diffstat 3 files changed, 35 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Fri Feb 12 11:33:16 2021 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Fri Feb 12 12:13:19 2021 +0100
@@ -461,9 +461,9 @@
       // This path allows one to avoid the JSON decoding if no
       // simplification is asked, and if no "ignore-length" argument
       // is present
-      std::string full;
+      Json::Value full;
       context.ReadDicomAsJson(full, publicId);
-      call.GetOutput().AnswerBuffer(full, MimeType_Json);
+      call.GetOutput().AnswerJson(full);
     }
   }
 
--- a/OrthancServer/Sources/ServerContext.cpp	Fri Feb 12 11:33:16 2021 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Fri Feb 12 12:13:19 2021 +0100
@@ -807,42 +807,6 @@
   }
 
 
-  void ServerContext::ReadDicomAsJson(std::string& result,
-                                      const std::string& instancePublicId)
-  {
-    FileInfo attachment;
-    if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson))
-    {
-      StorageAccessor accessor(area_, GetMetricsRegistry());
-      accessor.Read(result, attachment);
-    }
-    else
-    {
-      // The "DICOM as JSON" summary is not available from the Orthanc
-      // store (most probably deleted), reconstruct it from the DICOM file
-      std::string dicom;
-      ReadDicom(dicom, instancePublicId);
-
-      LOG(INFO) << "Reconstructing the missing DICOM-as-JSON summary for instance: "
-                << instancePublicId;
-    
-      ParsedDicomFile parsed(dicom);
-
-      Json::Value summary;
-      OrthancConfiguration::DefaultDicomDatasetToJson(summary, parsed);
-
-      result = summary.toStyledString();
-
-      if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson,
-                         result.c_str(), result.size()))
-      {
-        throw OrthancException(ErrorCode_InternalError,
-                               "Cannot associate the DICOM-as-JSON summary to instance: " + instancePublicId);
-      }
-    }
-  }
-
-
   void ServerContext::ReadDicomAsJson(Json::Value& result,
                                       const std::string& instancePublicId,
                                       const std::set<DicomTag>& ignoreTagLength)
@@ -850,7 +814,39 @@
     if (ignoreTagLength.empty())
     {
       std::string tmp;
-      ReadDicomAsJson(tmp, instancePublicId);
+
+      {
+        FileInfo attachment;
+        if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson))
+        {
+          StorageAccessor accessor(area_, GetMetricsRegistry());
+          accessor.Read(tmp, attachment);
+        }
+        else
+        {
+          // The "DICOM as JSON" summary is not available from the Orthanc
+          // store (most probably deleted), reconstruct it from the DICOM file
+          std::string dicom;
+          ReadDicom(dicom, instancePublicId);
+
+          LOG(INFO) << "Reconstructing the missing DICOM-as-JSON summary for instance: "
+                    << instancePublicId;
+    
+          ParsedDicomFile parsed(dicom);
+
+          Json::Value summary;
+          OrthancConfiguration::DefaultDicomDatasetToJson(summary, parsed);
+
+          tmp = summary.toStyledString();
+
+          if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson,
+                             tmp.c_str(), tmp.size()))
+          {
+            throw OrthancException(ErrorCode_InternalError,
+                                   "Cannot associate the DICOM-as-JSON summary to instance: " + instancePublicId);
+          }
+        }
+      }
 
       if (!Toolbox::ReadJson(result, tmp))
       {
--- a/OrthancServer/Sources/ServerContext.h	Fri Feb 12 11:33:16 2021 +0100
+++ b/OrthancServer/Sources/ServerContext.h	Fri Feb 12 12:13:19 2021 +0100
@@ -312,9 +312,6 @@
                                      FileContentType attachmentType,
                                      CompressionType compression);
 
-    void ReadDicomAsJson(std::string& result,
-                         const std::string& instancePublicId);
-
     void ReadDicomAsJson(Json::Value& result,
                          const std::string& instancePublicId,
                          const std::set<DicomTag>& ignoreTagLength);