# HG changeset patch # User Sebastien Jodogne # Date 1448560380 -3600 # Node ID 3ae2ff2496756f25a0369c61d895b12e40da0811 # Parent 2921384cc3529c31313febdc12be6e92562fecf8 "/instances/.../header" to get the meta information (header) of the DICOM instance diff -r 2921384cc352 -r 3ae2ff249675 NEWS --- 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) diff -r 2921384cc352 -r 3ae2ff249675 OrthancServer/FromDcmtkBridge.cpp --- 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 diff -r 2921384cc352 -r 3ae2ff249675 OrthancServer/FromDcmtkBridge.h --- 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 +#include #include 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); diff -r 2921384cc352 -r 3ae2ff249675 OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- 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); @@ -1323,6 +1351,7 @@ Register("/instances/{id}/image-uint16", GetImage); Register("/instances/{id}/image-int16", GetImage); Register("/instances/{id}/matlab", GetMatlabImage); + Register("/instances/{id}/header", GetInstanceHeader); Register("/patients/{id}/protected", IsProtectedPatient); Register("/patients/{id}/protected", SetPatientProtection); diff -r 2921384cc352 -r 3ae2ff249675 OrthancServer/ParsedDicomFile.cpp --- 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()); diff -r 2921384cc352 -r 3ae2ff249675 OrthancServer/ParsedDicomFile.h --- 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);