diff OrthancServer/OrthancRestApi2.cpp @ 226:8a26a8e85edf

refactoring to read files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 30 Nov 2012 09:45:29 +0100
parents 03aa59ecf6d8
children 209ca3f6db62
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi2.cpp	Thu Nov 29 22:28:05 2012 +0100
+++ b/OrthancServer/OrthancRestApi2.cpp	Fri Nov 30 09:45:29 2012 +0100
@@ -45,7 +45,8 @@
 
 
 #define RETRIEVE_CONTEXT(call)                                          \
-  OrthancRestApi2& contextApi = dynamic_cast<OrthancRestApi2&>(call.GetContext()); \
+  OrthancRestApi2& contextApi =                                         \
+    dynamic_cast<OrthancRestApi2&>(call.GetContext());                  \
   ServerContext& context = contextApi.GetContext()
 
 
@@ -150,19 +151,8 @@
   {
     RETRIEVE_CONTEXT(call);
 
-    CompressionType compressionType;
-    std::string fileUuid;
     std::string publicId = call.GetUriComponent("id", "");
-
-    if (context.GetIndex().GetFile(fileUuid, compressionType, publicId, AttachedFileType_Dicom))
-    {
-      assert(compressionType == CompressionType_None);
-
-      FilesystemHttpSender sender(context.GetFileStorage(), fileUuid);
-      sender.SetDownloadFilename(fileUuid + ".dcm");
-      sender.SetContentType("application/dicom");
-      call.GetOutput().AnswerFile(sender);
-    }
+    context.AnswerFile(call.GetOutput(), publicId, AttachedFileType_Dicom);
   }
 
 
@@ -171,27 +161,20 @@
   {
     RETRIEVE_CONTEXT(call);
 
-    CompressionType compressionType;
-    std::string fileUuid;
     std::string publicId = call.GetUriComponent("id", "");
-
-    if (context.GetIndex().GetFile(fileUuid, compressionType, publicId, AttachedFileType_Json))
-    {
-      assert(compressionType == CompressionType_None);
-
-      Json::Value full;
-      ReadJson(full, context.GetFileStorage(), fileUuid);
+    
+    Json::Value full;
+    context.ReadJson(full, publicId);
 
-      if (simplify)
-      {
-        Json::Value simplified;
-        SimplifyTags(simplified, full);
-        call.GetOutput().AnswerJson(simplified);
-      }
-      else
-      {
-        call.GetOutput().AnswerJson(full);
-      }
+    if (simplify)
+    {
+      Json::Value simplified;
+      SimplifyTags(simplified, full);
+      call.GetOutput().AnswerJson(simplified);
+    }
+    else
+    {
+      call.GetOutput().AnswerJson(full);
     }
   }
 
@@ -259,7 +242,12 @@
       }
       catch (OrthancException& e)
       {
-        //if (e.GetErrorCode() == ErrorCode_NotImplemented)
+        if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange)
+        {
+          // The frame number is out of the range for this DICOM
+          // instance, the resource is not existent
+        }
+        else
         {
           std::string root = "";
           for (size_t i = 1; i < call.GetFullUri().size(); i++)