Mercurial > hg > orthanc-dicomweb
changeset 16:a90389070513
return US values
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 19 May 2015 13:05:57 +0200 |
parents | 0ed8bbf35577 |
children | f02d68327265 |
files | Core/Dicom.cpp Core/Dicom.h Core/DicomResults.cpp Core/DicomResults.h Core/MultipartWriter.cpp Plugin/WadoRs.cpp |
diffstat | 6 files changed, 76 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Dicom.cpp Thu May 07 17:56:15 2015 +0200 +++ b/Core/Dicom.cpp Tue May 19 13:05:57 2015 +0200 @@ -24,6 +24,7 @@ #include "MultipartWriter.h" #include <gdcmDictEntry.h> +#include <gdcmStringFilter.h> #include <boost/lexical_cast.hpp> #include <json/writer.h> @@ -191,20 +192,20 @@ * being retrieved as bulk data. We commented out some of them, as * they correspond to strings and not to binary data. **/ - return (vr == "FL" || - vr == "FD" || + return (//vr == "FL" || + //vr == "FD" || //vr == "IS" || vr == "LT" || vr == "OB" || vr == "OD" || vr == "OF" || vr == "OW" || - vr == "SL" || - vr == "SS" || + //vr == "SL" || + //vr == "SS" || //vr == "ST" || - vr == "UL" || + //vr == "UL" || vr == "UN" || - vr == "US" || + //vr == "US" || vr == "UT"); } @@ -250,6 +251,8 @@ static bool ConvertDicomStringToUf8(std::string& result, + const gdcm::Dict& dictionary, + const gdcm::File* file, const gdcm::DataElement& element, const Encoding sourceEncoding) { @@ -259,6 +262,26 @@ return false; } + if (file != NULL) + { + bool isSequence; + std::string vr = GetVRName(isSequence, dictionary, element); + if (!isSequence && ( + vr == "FL" || + vr == "FD" || + vr == "SL" || + vr == "SS" || + vr == "UL" || + vr == "US" + )) + { + gdcm::StringFilter f; + f.SetFile(*file); + result = f.ToString(element.GetTag()); + return true; + } + } + if (sourceEncoding == Encoding_Utf8) { result.assign(data->GetPointer(), data->GetLength()); @@ -276,6 +299,7 @@ static void DicomToXmlInternal(pugi::xml_node& target, const gdcm::Dict& dictionary, + const gdcm::File* file, const gdcm::DataSet& dicom, const Encoding sourceEncoding, const std::string& bulkUri) @@ -325,7 +349,7 @@ childUri = bulkUri + std::string(path) + "/" + number + "/"; } - DicomToXmlInternal(item, dictionary, seq->GetItem(i).GetNestedDataSet(), sourceEncoding, childUri); + DicomToXmlInternal(item, dictionary, file, seq->GetItem(i).GetNestedDataSet(), sourceEncoding, childUri); } } else if (IsBulkData(vr)) @@ -345,7 +369,7 @@ value.append_attribute("number").set_value("1"); std::string tmp; - if (ConvertDicomStringToUf8(tmp, *it, sourceEncoding)) + if (ConvertDicomStringToUf8(tmp, dictionary, file, *it, sourceEncoding)) { value.append_child(pugi::node_pcdata).set_value(tmp.c_str()); } @@ -356,6 +380,7 @@ static void DicomToXml(pugi::xml_document& target, const gdcm::Dict& dictionary, + const gdcm::File* file, const gdcm::DataSet& dicom, const std::string& bulkUriRoot) { @@ -365,7 +390,7 @@ root.append_attribute("xmlns:xsi").set_value("http://www.w3.org/2001/XMLSchema-instance"); Encoding encoding = DetectEncoding(dicom); - DicomToXmlInternal(root, dictionary, dicom, encoding, bulkUriRoot); + DicomToXmlInternal(root, dictionary, file, dicom, encoding, bulkUriRoot); pugi::xml_node decl = target.prepend_child(pugi::node_declaration); decl.append_attribute("version").set_value("1.0"); @@ -375,6 +400,7 @@ static void DicomToJsonInternal(Json::Value& target, const gdcm::Dict& dictionary, + const gdcm::File* file, const gdcm::DataSet& dicom, const std::string& bulkUri, Encoding sourceEncoding) @@ -421,7 +447,7 @@ childUri = bulkUri + std::string(path) + "/" + number + "/"; } - DicomToJsonInternal(child, dictionary, seq->GetItem(i).GetNestedDataSet(), childUri, sourceEncoding); + DicomToJsonInternal(child, dictionary, file, seq->GetItem(i).GetNestedDataSet(), childUri, sourceEncoding); node["Value"].append(child); } } @@ -439,7 +465,7 @@ node["Value"] = Json::arrayValue; std::string value; - if (ConvertDicomStringToUf8(value, *it, sourceEncoding)) + if (ConvertDicomStringToUf8(value, dictionary, file, *it, sourceEncoding)) { node["Value"].append(value.c_str()); } @@ -452,16 +478,18 @@ static void DicomToJson(Json::Value& target, const gdcm::Dict& dictionary, + const gdcm::File* file, const gdcm::DataSet& dicom, const std::string& bulkUriRoot) { Encoding encoding = DetectEncoding(dicom); - DicomToJsonInternal(target, dictionary, dicom, bulkUriRoot, encoding); + DicomToJsonInternal(target, dictionary, file, dicom, bulkUriRoot, encoding); } void GenerateSingleDicomAnswer(std::string& result, const gdcm::Dict& dictionary, + const gdcm::File* file, // Can be NULL const gdcm::DataSet& dicom, bool isXml, bool isBulkAccessible) @@ -475,7 +503,7 @@ if (isXml) { pugi::xml_document doc; - DicomToXml(doc, dictionary, dicom, bulkUriRoot); + DicomToXml(doc, dictionary, file, dicom, bulkUriRoot); ChunkedBufferWriter writer; doc.save(writer, " ", pugi::format_default, pugi::encoding_utf8); @@ -485,7 +513,7 @@ else { Json::Value v; - DicomToJson(v, dictionary, dicom, bulkUriRoot); + DicomToJson(v, dictionary, file, dicom, bulkUriRoot); Json::FastWriter writer; result = writer.write(v); @@ -501,7 +529,7 @@ bool isBulkAccessible) { std::string answer; - GenerateSingleDicomAnswer(answer, dictionary, dicom, isXml, isBulkAccessible); + GenerateSingleDicomAnswer(answer, dictionary, NULL, dicom, isXml, isBulkAccessible); OrthancPluginAnswerBuffer(context, output, answer.c_str(), answer.size(), isXml ? "application/dicom+xml" : "application/json"); }
--- a/Core/Dicom.h Thu May 07 17:56:15 2015 +0200 +++ b/Core/Dicom.h Tue May 19 13:05:57 2015 +0200 @@ -60,6 +60,11 @@ Setup(dicom); } + const gdcm::File& GetFile() const + { + return reader_.GetFile(); + } + const gdcm::DataSet& GetDataSet() const { return reader_.GetFile().GetDataSet(); @@ -77,6 +82,7 @@ void GenerateSingleDicomAnswer(std::string& result, const gdcm::Dict& dictionary, + const gdcm::File* file, // Can be NULL const gdcm::DataSet& dicom, bool isXml, bool isBulkAccessible);
--- a/Core/DicomResults.cpp Thu May 07 17:56:15 2015 +0200 +++ b/Core/DicomResults.cpp Tue May 19 13:05:57 2015 +0200 @@ -36,12 +36,14 @@ jsonWriter_.AddChunk("[\n"); } - void DicomResults::Add(const gdcm::DataSet& dicom) + + void DicomResults::AddInternal(const gdcm::File* file, + const gdcm::DataSet& dicom) { if (isXml_) { std::string answer; - GenerateSingleDicomAnswer(answer, dictionary_, dicom, true, isBulkAccessible_); + GenerateSingleDicomAnswer(answer, dictionary_, file, dicom, true, isBulkAccessible_); xmlWriter_.AddPart(answer); } else @@ -52,7 +54,7 @@ } std::string item; - GenerateSingleDicomAnswer(item, dictionary_, dicom, false, isBulkAccessible_); + GenerateSingleDicomAnswer(item, dictionary_, file, dicom, false, isBulkAccessible_); jsonWriter_.AddChunk(item); }
--- a/Core/DicomResults.h Thu May 07 17:56:15 2015 +0200 +++ b/Core/DicomResults.h Tue May 19 13:05:57 2015 +0200 @@ -25,6 +25,7 @@ #include <gdcmDataSet.h> #include <gdcmDict.h> +#include <gdcmFile.h> namespace OrthancPlugins { @@ -38,12 +39,23 @@ bool isXml_; bool isBulkAccessible_; + void AddInternal(const gdcm::File* file, + const gdcm::DataSet& dicom); + public: DicomResults(const gdcm::Dict& dictionary, bool isXml, bool isBulkAccessible); - void Add(const gdcm::DataSet& dicom); + void Add(const gdcm::File& file) + { + AddInternal(&file, file.GetDataSet()); + } + + void Add(const gdcm::DataSet& dicom) + { + AddInternal(NULL, dicom); + } void Answer(OrthancPluginContext* context, OrthancPluginRestOutput* output);
--- a/Core/MultipartWriter.cpp Thu May 07 17:56:15 2015 +0200 +++ b/Core/MultipartWriter.cpp Tue May 19 13:05:57 2015 +0200 @@ -20,6 +20,8 @@ #include "MultipartWriter.h" +#include <boost/lexical_cast.hpp> + namespace OrthancPlugins { MultipartWriter::MultipartWriter(const std::string& contentType) : @@ -33,6 +35,7 @@ { std::string header = "--" + boundary_ + "\n"; header += "Content-Type: " + contentType_ + "\n"; + header += "Content-Length: " + boost::lexical_cast<std::string>(part.size()) + "\n"; header += "MIME-Version: 1.0\n\n"; chunks_.AddChunk(header); chunks_.AddChunk(part);
--- a/Plugin/WadoRs.cpp Thu May 07 17:56:15 2015 +0200 +++ b/Plugin/WadoRs.cpp Tue May 19 13:05:57 2015 +0200 @@ -236,7 +236,7 @@ if (OrthancPlugins::RestApiGetString(content, context_, *it)) { OrthancPlugins::ParsedDicomFile dicom(content); - results.Add(dicom.GetDataSet()); + results.Add(dicom.GetFile()); } } @@ -611,11 +611,13 @@ const gdcm::ByteValue* data = element.GetByteValue(); if (!data) { - printf("AIE\n"); - return false; + content.clear(); + } + else + { + content.assign(data->GetPointer(), data->GetLength()); } - content.assign(data->GetPointer(), data->GetLength()); return true; }