Mercurial > hg > orthanc
diff OrthancServer/FromDcmtkBridge.cpp @ 1690:ae09132e4237
FromJson
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 07 Oct 2015 17:42:42 +0200 |
parents | 26083d84d237 |
children | e447f3cb8b30 |
line wrap: on
line diff
--- a/OrthancServer/FromDcmtkBridge.cpp Wed Oct 07 16:54:05 2015 +0200 +++ b/OrthancServer/FromDcmtkBridge.cpp Wed Oct 07 17:42:42 2015 +0200 @@ -695,12 +695,13 @@ Encoding encoding); - static void ElementToJson(Json::Value& parent, - DcmElement& element, - DicomToJsonFormat format, - unsigned int maxStringLength, - Encoding encoding) + void FromDcmtkBridge::ToJson(Json::Value& parent, + DcmElement& element, + DicomToJsonFormat format, + unsigned int maxStringLength, + Encoding encoding) { + parent = Json::objectValue; Json::Value& target = PrepareNode(parent, element, format); if (element.isLeaf()) @@ -739,7 +740,7 @@ for (unsigned long i = 0; i < item.card(); i++) { DcmElement* element = item.getElement(i); - ElementToJson(parent, *element, format, maxStringLength, encoding); + FromDcmtkBridge::ToJson(parent, *element, format, maxStringLength, encoding); } } @@ -754,25 +755,6 @@ } - - void FromDcmtkBridge::ToJson(Json::Value& target, - const std::string& path, - DicomToJsonFormat format, - unsigned int maxStringLength) - { - DcmFileFormat dicom; - if (!dicom.loadFile(path.c_str()).good()) - { - throw OrthancException(ErrorCode_BadFileFormat); - } - else - { - FromDcmtkBridge::ToJson(target, *dicom.getDataset(), format, maxStringLength); - } - } - - - std::string FromDcmtkBridge::GetName(const DicomTag& t) { // Some patches for important tags because of different DICOM @@ -1333,10 +1315,42 @@ { std::auto_ptr<DcmElement> element; - if (value.type() == Json::stringValue) + switch (value.type()) { - element.reset(CreateElementForTag(tag)); - FillElementWithString(*element, tag, value.asString(), decodeBinaryTags); + case Json::stringValue: + element.reset(CreateElementForTag(tag)); + FillElementWithString(*element, tag, value.asString(), decodeBinaryTags); + break; + + case Json::arrayValue: + { + DcmTag key(tag.GetGroup(), tag.GetElement()); + if (key.getEVR() != EVR_SQ) + { + throw OrthancException(ErrorCode_BadParameterType); + } + + DcmSequenceOfItems* sequence = new DcmSequenceOfItems(key, value.size()); + element.reset(sequence); + + for (Json::Value::ArrayIndex i = 0; i < value.size(); i++) + { + std::auto_ptr<DcmItem> item(new DcmItem); + + Json::Value::Members members = value[i].getMemberNames(); + for (Json::Value::ArrayIndex j = 0; j < members.size(); j++) + { + item->insert(FromJson(value[i][members[j]], ParseTag(members[j]), decodeBinaryTags)); + } + + sequence->append(item.release()); + } + + break; + } + + default: + throw OrthancException(ErrorCode_BadParameterType); } return element.release();