changeset 1831:3ae2ff249675

"/instances/.../header" to get the meta information (header) of the DICOM instance
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 26 Nov 2015 18:53:00 +0100
parents 2921384cc352
children b7da58699f92
files NEWS OrthancServer/FromDcmtkBridge.cpp OrthancServer/FromDcmtkBridge.h OrthancServer/OrthancRestApi/OrthancRestResources.cpp OrthancServer/ParsedDicomFile.cpp OrthancServer/ParsedDicomFile.h
diffstat 6 files changed, 58 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Nov 26 15:56:32 2015 +0100
+++ b/NEWS	Thu Nov 26 18:53:00 2015 +0100
@@ -16,6 +16,7 @@
   - ".../compress", ".../uncompress" and ".../is-compressed" for attachments
   - "/tools/create-archive" to create ZIP from a set of resources
   - "/tools/create-media" to create ZIP+DICOMDIR from a set of resources
+  - "/instances/.../header" to get the meta information (header) of the DICOM instance
 * "/tools/create-dicom":
   - Support of binary tags encoded using data URI scheme
   - Support of hierarchical structures (creation of sequences)
--- a/OrthancServer/FromDcmtkBridge.cpp	Thu Nov 26 15:56:32 2015 +0100
+++ b/OrthancServer/FromDcmtkBridge.cpp	Thu Nov 26 18:53:00 2015 +0100
@@ -804,6 +804,17 @@
   }
 
 
+  void FromDcmtkBridge::ToJson(Json::Value& target, 
+                               DcmMetaInfo& dataset,
+                               DicomToJsonFormat format,
+                               DicomToJsonFlags flags,
+                               unsigned int maxStringLength)
+  {
+    target = Json::objectValue;
+    DatasetToJson(target, dataset, format, flags, maxStringLength, Encoding_Ascii);
+  }
+
+
   std::string FromDcmtkBridge::GetName(const DicomTag& t)
   {
     // Some patches for important tags because of different DICOM
--- a/OrthancServer/FromDcmtkBridge.h	Thu Nov 26 15:56:32 2015 +0100
+++ b/OrthancServer/FromDcmtkBridge.h	Thu Nov 26 18:53:00 2015 +0100
@@ -37,6 +37,7 @@
 #include "../Core/DicomFormat/DicomMap.h"
 
 #include <dcmtk/dcmdata/dcdatset.h>
+#include <dcmtk/dcmdata/dcmetinf.h>
 #include <json/json.h>
 
 namespace Orthanc
@@ -79,6 +80,12 @@
                        DicomToJsonFlags flags,
                        unsigned int maxStringLength);
 
+    static void ToJson(Json::Value& target, 
+                       DcmMetaInfo& header,
+                       DicomToJsonFormat format,
+                       DicomToJsonFlags flags,
+                       unsigned int maxStringLength);
+
     static std::string GetName(const DicomTag& tag);
 
     static DicomTag ParseTag(const char* name);
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Thu Nov 26 15:56:32 2015 +0100
+++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Thu Nov 26 18:53:00 2015 +0100
@@ -1275,6 +1275,34 @@
   }
 
 
+  static void GetInstanceHeader(RestApiGetCall& call)
+  {
+    ServerContext& context = OrthancRestApi::GetContext(call);
+
+    std::string publicId = call.GetUriComponent("id", "");
+    bool simplify = call.HasArgument("simplify");
+
+    std::string dicomContent;
+    context.ReadFile(dicomContent, publicId, FileContentType_Dicom);
+
+    ParsedDicomFile dicom(dicomContent);
+
+    Json::Value header;
+    dicom.HeaderToJson(header, DicomToJsonFormat_Full);
+
+    if (simplify)
+    {
+      Json::Value simplified;
+      Toolbox::SimplifyTags(simplified, header);
+      call.GetOutput().AnswerJson(simplified);
+    }
+    else
+    {
+      call.GetOutput().AnswerJson(header);
+    }
+  }
+
+
   void OrthancRestApi::RegisterResources()
   {
     Register("/instances", ListResources<ResourceType_Instance>);
@@ -1323,6 +1351,7 @@
     Register("/instances/{id}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
     Register("/instances/{id}/image-int16", GetImage<ImageExtractionMode_Int16>);
     Register("/instances/{id}/matlab", GetMatlabImage);
+    Register("/instances/{id}/header", GetInstanceHeader);
 
     Register("/patients/{id}/protected", IsProtectedPatient);
     Register("/patients/{id}/protected", SetPatientProtection);
--- a/OrthancServer/ParsedDicomFile.cpp	Thu Nov 26 15:56:32 2015 +0100
+++ b/OrthancServer/ParsedDicomFile.cpp	Thu Nov 26 18:53:00 2015 +0100
@@ -1168,6 +1168,13 @@
   }
 
 
+  void ParsedDicomFile::HeaderToJson(Json::Value& target, 
+                                     DicomToJsonFormat format)
+  {
+    FromDcmtkBridge::ToJson(target, *pimpl_->file_->getMetaInfo(), format, DicomToJsonFlags_None, 0);
+  }
+
+
   bool ParsedDicomFile::HasTag(const DicomTag& tag) const
   {
     DcmTag key(tag.GetGroup(), tag.GetElement());
--- a/OrthancServer/ParsedDicomFile.h	Thu Nov 26 15:56:32 2015 +0100
+++ b/OrthancServer/ParsedDicomFile.h	Thu Nov 26 18:53:00 2015 +0100
@@ -153,6 +153,9 @@
                 DicomToJsonFlags flags,
                 unsigned int maxStringLength);
 
+    void HeaderToJson(Json::Value& target, 
+                      DicomToJsonFormat format);
+
     bool HasTag(const DicomTag& tag) const;
 
     void EmbedPdf(const std::string& pdf);