Mercurial > hg > orthanc
changeset 1735:a001f6226c7c
primitives for flags in dicom-to-json conversions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 21 Oct 2015 16:25:09 +0200 |
parents | e2675b37eb01 |
children | b953c6eef28d |
files | OrthancServer/DicomInstanceToStore.cpp OrthancServer/FromDcmtkBridge.cpp OrthancServer/FromDcmtkBridge.h OrthancServer/Internals/StoreScp.cpp OrthancServer/ParsedDicomFile.cpp OrthancServer/ParsedDicomFile.h OrthancServer/ServerEnumerations.h UnitTestsSources/FromDcmtkTests.cpp |
diffstat | 8 files changed, 66 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/DicomInstanceToStore.cpp Wed Oct 21 14:28:57 2015 +0200 +++ b/OrthancServer/DicomInstanceToStore.cpp Wed Oct 21 16:25:09 2015 +0200 @@ -110,7 +110,9 @@ { json_.Allocate(); FromDcmtkBridge::ToJson(json_.GetContent(), GetDataset(parsed_.GetContent()), - DicomToJsonFormat_Full, 256 /* max string length */); + DicomToJsonFormat_Full, + DicomToJsonFlags_Default, + 256 /* max string length */); } }
--- a/OrthancServer/FromDcmtkBridge.cpp Wed Oct 21 14:28:57 2015 +0200 +++ b/OrthancServer/FromDcmtkBridge.cpp Wed Oct 21 16:25:09 2015 +0200 @@ -678,6 +678,7 @@ static void DatasetToJson(Json::Value& parent, DcmItem& item, DicomToJsonFormat format, + DicomToJsonFlags flags, unsigned int maxStringLength, Encoding encoding); @@ -685,6 +686,7 @@ void FromDcmtkBridge::ToJson(Json::Value& parent, DcmElement& element, DicomToJsonFormat format, + DicomToJsonFlags flags, unsigned int maxStringLength, Encoding encoding) { @@ -715,7 +717,7 @@ { DcmItem* child = sequence.getItem(i); Json::Value& v = target.append(Json::objectValue); - DatasetToJson(v, *child, format, maxStringLength, encoding); + DatasetToJson(v, *child, format, flags, maxStringLength, encoding); } } } @@ -724,6 +726,7 @@ static void DatasetToJson(Json::Value& parent, DcmItem& item, DicomToJsonFormat format, + DicomToJsonFlags flags, unsigned int maxStringLength, Encoding encoding) { @@ -732,7 +735,16 @@ for (unsigned long i = 0; i < item.card(); i++) { DcmElement* element = item.getElement(i); - FromDcmtkBridge::ToJson(parent, *element, format, maxStringLength, encoding); + if (element == NULL) + { + throw OrthancException(ErrorCode_InternalError); + } + + if ((flags & DicomToJsonFlags_IncludePrivateTags) || + !element->getTag().isPrivate()) + { + FromDcmtkBridge::ToJson(parent, *element, format, flags, maxStringLength, encoding); + } } } @@ -740,10 +752,11 @@ void FromDcmtkBridge::ToJson(Json::Value& target, DcmDataset& dataset, DicomToJsonFormat format, + DicomToJsonFlags flags, unsigned int maxStringLength) { target = Json::objectValue; - DatasetToJson(target, dataset, format, maxStringLength, DetectEncoding(dataset)); + DatasetToJson(target, dataset, format, flags, maxStringLength, DetectEncoding(dataset)); }
--- a/OrthancServer/FromDcmtkBridge.h Wed Oct 21 14:28:57 2015 +0200 +++ b/OrthancServer/FromDcmtkBridge.h Wed Oct 21 16:25:09 2015 +0200 @@ -70,12 +70,14 @@ static void ToJson(Json::Value& parent, DcmElement& element, DicomToJsonFormat format, + DicomToJsonFlags flags, unsigned int maxStringLength, - Encoding encoding); + Encoding dicomEncoding); static void ToJson(Json::Value& target, DcmDataset& dataset, DicomToJsonFormat format, + DicomToJsonFlags flags, unsigned int maxStringLength); static std::string GetName(const DicomTag& tag);
--- a/OrthancServer/Internals/StoreScp.cpp Wed Oct 21 14:28:57 2015 +0200 +++ b/OrthancServer/Internals/StoreScp.cpp Wed Oct 21 16:25:09 2015 +0200 @@ -169,7 +169,9 @@ { FromDcmtkBridge::Convert(summary, **imageDataSet); FromDcmtkBridge::ToJson(dicomJson, **imageDataSet, - DicomToJsonFormat_Full, 256 /* max string length */); + DicomToJsonFormat_Full, + DicomToJsonFlags_Default, + 256 /* max string length */); if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, **imageDataSet)) {
--- a/OrthancServer/ParsedDicomFile.cpp Wed Oct 21 14:28:57 2015 +0200 +++ b/OrthancServer/ParsedDicomFile.cpp Wed Oct 21 16:25:09 2015 +0200 @@ -1120,9 +1120,10 @@ void ParsedDicomFile::ToJson(Json::Value& target, DicomToJsonFormat format, + DicomToJsonFlags flags, unsigned int maxStringLength) { - FromDcmtkBridge::ToJson(target, *pimpl_->file_->getDataset(), format, maxStringLength); + FromDcmtkBridge::ToJson(target, *pimpl_->file_->getDataset(), format, flags, maxStringLength); }
--- a/OrthancServer/ParsedDicomFile.h Wed Oct 21 14:28:57 2015 +0200 +++ b/OrthancServer/ParsedDicomFile.h Wed Oct 21 16:25:09 2015 +0200 @@ -134,6 +134,7 @@ void ToJson(Json::Value& target, DicomToJsonFormat format, + DicomToJsonFlags flags, unsigned int maxStringLength); bool HasTag(const DicomTag& tag) const;
--- a/OrthancServer/ServerEnumerations.h Wed Oct 21 14:28:57 2015 +0200 +++ b/OrthancServer/ServerEnumerations.h Wed Oct 21 16:25:09 2015 +0200 @@ -108,6 +108,18 @@ DicomToJsonFormat_Simple }; + enum DicomToJsonFlags + { + DicomToJsonFlags_IncludeBinary = (1 << 0), + DicomToJsonFlags_IncludePrivateTags = (1 << 1), + DicomToJsonFlags_IncludeUnknownTags = (1 << 2), + DicomToJsonFlags_IncludePixelData = (1 << 3), + + // Some predefined combinations + DicomToJsonFlags_None = 0, + DicomToJsonFlags_Default = DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_IncludeUnknownTags + }; + /** * WARNING: Do not change the explicit values in the enumerations
--- a/UnitTestsSources/FromDcmtkTests.cpp Wed Oct 21 14:28:57 2015 +0200 +++ b/UnitTestsSources/FromDcmtkTests.cpp Wed Oct 21 16:25:09 2015 +0200 @@ -339,7 +339,7 @@ element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8)); Json::Value b; - FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Short, 0, Encoding_Ascii); + FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0, Encoding_Ascii); ASSERT_EQ("Hello", b["0010,0010"].asString()); } @@ -363,7 +363,7 @@ element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, true, Encoding_Utf8)); Json::Value b; - FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Short, 0, Encoding_Ascii); + FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0, Encoding_Ascii); ASSERT_EQ("Hello", b["0010,0010"].asString()); } @@ -374,7 +374,7 @@ { Json::Value b; - FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Short, 0, Encoding_Ascii); + FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0, Encoding_Ascii); ASSERT_EQ(Json::arrayValue, b["0008,1110"].type()); ASSERT_EQ(2, b["0008,1110"].size()); @@ -391,7 +391,7 @@ { Json::Value b; - FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Full, 0, Encoding_Ascii); + FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Full, DicomToJsonFlags_Default, 0, Encoding_Ascii); Json::Value c; Toolbox::SimplifyTags(c, b); @@ -470,7 +470,7 @@ { Json::Value b; - f.ToJson(b, DicomToJsonFormat_Full, 0); + f.ToJson(b, DicomToJsonFormat_Full, DicomToJsonFlags_Default, 0); Json::Value c; Toolbox::SimplifyTags(c, b); @@ -515,8 +515,28 @@ f.Replace(DICOM_TAG_PATIENT_NAME, s, false); Json::Value v; - f.ToJson(v, DicomToJsonFormat_Simple, 0); + f.ToJson(v, DicomToJsonFormat_Simple, DicomToJsonFlags_Default, 0); ASSERT_EQ(v["PatientName"].asString(), std::string(testEncodingsExpected[i])); } } } + +TEST(ParsedDicomFile, ToJsonFlags) +{ + { + ParsedDicomFile f; + f.Insert(DicomTag(0x7053, 0x1000), "Some private tag", false); + + Json::Value v; + f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0); + ASSERT_EQ(Json::objectValue, v.type()); + ASSERT_EQ(5, v.getMemberNames().size()); + ASSERT_FALSE(v.isMember("7053-1000")); + + f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludePrivateTags, 0); + ASSERT_EQ(Json::objectValue, v.type()); + ASSERT_EQ(6, v.getMemberNames().size()); + ASSERT_TRUE(v.isMember("7053,1000")); + ASSERT_EQ(Json::nullValue, v["7053,1000"].type()); + } +}