Mercurial > hg > orthanc
diff OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 1641:4e56b5a206b7
Support of binary tags encoded using data URI scheme
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Sep 2015 12:43:05 +0200 |
parents | 48224db51ee7 |
children | 1558b3226b18 |
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Wed Sep 23 12:02:39 2015 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Wed Sep 23 12:43:05 2015 +0200 @@ -40,6 +40,7 @@ #include "../OrthancInitialization.h" #include <boost/lexical_cast.hpp> +#include <boost/algorithm/string/predicate.hpp> namespace Orthanc { @@ -485,7 +486,8 @@ static void InjectTags(ParsedDicomFile& dicom, - const Json::Value& tags) + const Json::Value& tags, + bool interpretBinaryTags) { if (tags.type() != Json::objectValue) { @@ -503,8 +505,8 @@ } std::string value = tags[name].asString(); + DicomTag tag = FromDcmtkBridge::ParseTag(name); - DicomTag tag = FromDcmtkBridge::ParseTag(name); if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET) { if (tag != DICOM_TAG_PATIENT_ID && @@ -527,6 +529,13 @@ { throw OrthancException(ErrorCode_CreateDicomUseContent); } + else if (interpretBinaryTags && + boost::starts_with(value, "data:application/octet-stream;base64,")) + { + std::string mime, binary; + Toolbox::DecodeDataUriScheme(mime, binary, value); + dicom.Replace(tag, binary); + } else { dicom.Replace(tag, Toolbox::ConvertFromUtf8(value, dicom.GetEncoding())); @@ -538,7 +547,8 @@ static void CreateSeries(RestApiPostCall& call, ParsedDicomFile& base /* in */, - const Json::Value& content) + const Json::Value& content, + bool interpretBinaryTags) { assert(content.isArray()); assert(content.size() > 0); @@ -571,7 +581,7 @@ if (content[i].isMember("Tags")) { - InjectTags(*dicom, content[i]["Tags"]); + InjectTags(*dicom, content[i]["Tags"], interpretBinaryTags); } } @@ -744,6 +754,19 @@ } } + + bool interpretBinaryTags = true; + if (request.isMember("InterpretBinaryTags")) + { + const Json::Value& v = request["InterpretBinaryTags"]; + if (v.type() != Json::booleanValue) + { + throw OrthancException(ErrorCode_BadRequest); + } + + interpretBinaryTags = v.asBool(); + } + // Inject time-related information std::string date, time; @@ -771,7 +794,7 @@ } - InjectTags(dicom, request["Tags"]); + InjectTags(dicom, request["Tags"], interpretBinaryTags); // Inject the content (either an image, or a PDF file) @@ -789,7 +812,7 @@ if (content.size() > 0) { // Let's create a series instead of a single instance - CreateSeries(call, dicom, content); + CreateSeries(call, dicom, content, interpretBinaryTags); return; } }