changeset 3845:281045a1e6db

new "info" field in "ReceivedInstanceFilter()" callback
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 16 Apr 2020 17:59:47 +0200
parents c9c34bb50f0a
children 67e765d51bdf
files NEWS OrthancServer/DicomInstanceToStore.cpp OrthancServer/DicomInstanceToStore.h OrthancServer/LuaScripting.cpp
diffstat 4 files changed, 64 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Apr 16 17:27:18 2020 +0200
+++ b/NEWS	Thu Apr 16 17:59:47 2020 +0200
@@ -10,6 +10,11 @@
   - "/modalities/{id}/store-straight": Synchronously send the DICOM instance in POST
     body to another modality (alternative to command-line tools such as "storescu")
 
+Lua
+---
+
+* New "info" field in "ReceivedInstanceFilter()" callback, containing
+  "HasPixelData" and "TransferSyntaxUID" information
 
 Maintenance
 -----------
--- a/OrthancServer/DicomInstanceToStore.cpp	Thu Apr 16 17:27:18 2020 +0200
+++ b/OrthancServer/DicomInstanceToStore.cpp	Thu Apr 16 17:59:47 2020 +0200
@@ -169,6 +169,26 @@
   private:
     std::unique_ptr<DicomInstanceHasher>  hasher_;
 
+    void ParseDicomFile()
+    {
+      if (!parsed_.HasContent())
+      {
+        if (!hasBuffer_)
+        {
+          throw OrthancException(ErrorCode_InternalError);
+        }
+      
+        if (ownBuffer_.get() != NULL)
+        {
+          parsed_.TakeOwnership(new ParsedDicomFile(*ownBuffer_));
+        }
+        else
+        {
+          parsed_.TakeOwnership(new ParsedDicomFile(bufferData_, bufferSize_));
+        }
+      }
+    }
+
     void ComputeMissingInformation()
     {
       if (hasBuffer_ &&
@@ -217,18 +237,8 @@
       // memory buffer, but that its summary or its JSON version is
       // missing
 
-      assert(hasBuffer_);
-      if (!parsed_.HasContent())
-      {
-        if (ownBuffer_.get() != NULL)
-        {
-          parsed_.TakeOwnership(new ParsedDicomFile(*ownBuffer_));
-        }
-        else
-        {
-          parsed_.TakeOwnership(new ParsedDicomFile(bufferData_, bufferSize_));
-        }
-      }
+      ParseDicomFile();
+      assert(parsed_.HasContent());
 
       // At this point, we have parsed the DICOM file
     
@@ -369,6 +379,22 @@
 
       return false;
     }
+
+
+    bool HasPixelData()
+    {
+      ComputeMissingInformation();
+      ParseDicomFile();
+      
+      if (parsed_.HasContent())
+      {
+        return parsed_.GetContent().HasTag(DICOM_TAG_PIXEL_DATA);
+      }
+      else
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }
+    }
   };
 
 
@@ -459,9 +485,9 @@
   }
 
 
-  bool DicomInstanceToStore::LookupTransferSyntax(std::string& result)
+  bool DicomInstanceToStore::LookupTransferSyntax(std::string& result) const
   {
-    return pimpl_->LookupTransferSyntax(result);
+    return const_cast<PImpl&>(*pimpl_).LookupTransferSyntax(result);
   }
 
 
@@ -469,4 +495,9 @@
   {
     return pimpl_->GetHasher();
   }
+
+  bool DicomInstanceToStore::HasPixelData() const
+  {
+    return const_cast<PImpl&>(*pimpl_).HasPixelData();
+  }
 }
--- a/OrthancServer/DicomInstanceToStore.h	Thu Apr 16 17:27:18 2020 +0200
+++ b/OrthancServer/DicomInstanceToStore.h	Thu Apr 16 17:59:47 2020 +0200
@@ -87,8 +87,10 @@
     
     const Json::Value& GetJson();
 
-    bool LookupTransferSyntax(std::string& result);
+    bool LookupTransferSyntax(std::string& result) const;
 
     DicomInstanceHasher& GetHasher();
+
+    bool HasPixelData() const;
   };
 }
--- a/OrthancServer/LuaScripting.cpp	Thu Apr 16 17:27:18 2020 +0200
+++ b/OrthancServer/LuaScripting.cpp	Thu Apr 16 17:59:47 2020 +0200
@@ -874,6 +874,17 @@
       instance.GetOrigin().Format(origin);
       call.PushJson(origin);
 
+      Json::Value info = Json::objectValue;
+      info["HasPixelData"] = instance.HasPixelData();
+
+      std::string s;
+      if (instance.LookupTransferSyntax(s))
+      {
+        info["TransferSyntaxUID"] = s;
+      }
+
+      call.PushJson(info);
+
       if (!call.ExecutePredicate())
       {
         return false;