Mercurial > hg > orthanc
changeset 5039:28db9663fc2d
DicomSequencesMap + fix unit tests
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 27 Jun 2022 10:48:46 +0200 |
parents | f8bea9c1c0fc |
children | 1c08cd68250a |
files | OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp OrthancServer/Sources/Database/StatelessDatabaseOperations.h OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerIndex.cpp OrthancServer/Sources/ServerIndex.h OrthancServer/UnitTestsSources/ServerIndexTests.cpp |
diffstat | 6 files changed, 41 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Fri Jun 24 16:44:38 2022 +0200 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Mon Jun 27 10:48:46 2022 +0200 @@ -45,14 +45,28 @@ namespace Orthanc { - // copy all tags from Json - void DicomSequencesMap::FromJson(const Json::Value& value) + // copy all tags from Json (used to read from metadata) + void DicomSequencesMap::Deserialize(const Json::Value& serialized) { - Json::Value::Members members = value.getMemberNames(); + Json::Value::Members members = serialized.getMemberNames(); for (size_t i = 0; i < members.size(); i++) { DicomTag tag = FromDcmtkBridge::ParseTag(members[i].c_str()); - sequences_[tag] = value[members[i]]; + sequences_[tag] = serialized[members[i]]; + } + } + + // serialize a subet of tags (used to store in the metadata) + void DicomSequencesMap::Serialize(Json::Value& target, const std::set<DicomTag>& tags) const + { + // add the sequences to "target" + for (std::map<DicomTag, Json::Value>::const_iterator it = sequences_.begin(); + it != sequences_.end(); ++it) + { + if (tags.find(it->first) != tags.end()) + { + target[it->first.Format()] = it->second; + } } } @@ -926,7 +940,7 @@ Toolbox::ReadJson(jsonMetadata, serializedSequences); assert(jsonMetadata["Version"].asInt() == 1); - target.sequences_.FromJson(jsonMetadata["Sequences"]); + target.sequences_.Deserialize(jsonMetadata["Sequences"]); } // check if we have access to all requestedTags or if we must get tags from parents @@ -2897,7 +2911,7 @@ StoreStatus StatelessDatabaseOperations::Store(std::map<MetadataType, std::string>& instanceMetadata, const DicomMap& dicomSummary, - const std::map<DicomTag, Json::Value>& sequencesToStore, + const DicomSequencesMap& sequencesToStore, const Attachments& attachments, const MetadataMap& metadata, const DicomInstanceOrigin& origin, @@ -2916,7 +2930,7 @@ StoreStatus storeStatus_; std::map<MetadataType, std::string>& instanceMetadata_; const DicomMap& dicomSummary_; - const std::map<DicomTag, Json::Value>& sequencesToStore_; + const DicomSequencesMap& sequencesToStore_; const Attachments& attachments_; const MetadataMap& metadata_; const DicomInstanceOrigin& origin_; @@ -2950,10 +2964,10 @@ static void SetMainDicomSequenceMetadata(ResourcesContent& content, int64_t resource, - const std::map<DicomTag, Json::Value>& sequencesToStore, // all sequences for all levels ! + const DicomSequencesMap& sequencesToStore, // all sequences for all levels ! ResourceType level) { - if (sequencesToStore.size() > 0) + if (sequencesToStore.GetSize() > 0) { const std::set<DicomTag>& levelTags = DicomMap::GetMainDicomTags(level); std::set<DicomTag> levelSequences; @@ -2966,19 +2980,9 @@ Json::Value jsonMetadata; jsonMetadata["Version"] = 1; - Json::Value jsonSequences = Json::objectValue; - - for (std::set<DicomTag>::const_iterator it = levelSequences.begin(); - it != levelSequences.end(); ++it) - { - std::map<DicomTag, Json::Value>::const_iterator foundSeq = sequencesToStore.find(*it); - if (foundSeq != sequencesToStore.end()) - { - jsonSequences[it->Format()] = foundSeq->second; - } - } - jsonMetadata["Sequences"] = jsonSequences; - + jsonMetadata["Sequences"] = Json::objectValue; + sequencesToStore.Serialize(jsonMetadata["Sequences"], levelSequences); + std::string serialized; Toolbox::WriteFastJson(serialized, jsonMetadata); @@ -3044,7 +3048,7 @@ public: Operations(std::map<MetadataType, std::string>& instanceMetadata, const DicomMap& dicomSummary, - const std::map<DicomTag, Json::Value>& sequencesToStore, + const DicomSequencesMap& sequencesToStore, const Attachments& attachments, const MetadataMap& metadata, const DicomInstanceOrigin& origin,
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h Fri Jun 24 16:44:38 2022 +0200 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h Mon Jun 27 10:48:46 2022 +0200 @@ -46,9 +46,15 @@ { std::map<DicomTag, Json::Value> sequences_; - void FromJson(const Json::Value& serialized); + void Deserialize(const Json::Value& serialized); + void Serialize(Json::Value& target, const std::set<DicomTag>& tags) const; void FromDicomAsJson(const Json::Value& dicomAsJson, const std::set<DicomTag>& tags); void ToJson(Json::Value& target, DicomToJsonFormat format) const; + + size_t GetSize() const + { + return sequences_.size(); + } }; struct ExpandedResource : public boost::noncopyable @@ -665,7 +671,7 @@ StoreStatus Store(std::map<MetadataType, std::string>& instanceMetadata, const DicomMap& dicomSummary, - const std::map<DicomTag, Json::Value>& sequencesToStore, + const DicomSequencesMap& sequencesToStore, const Attachments& attachments, const MetadataMap& metadata, const DicomInstanceOrigin& origin,
--- a/OrthancServer/Sources/ServerContext.cpp Fri Jun 24 16:44:38 2022 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Mon Jun 27 10:48:46 2022 +0200 @@ -531,7 +531,7 @@ std::set<DicomTag> allMainDicomTags = DicomMap::GetAllMainDicomTags(); std::set<DicomTag> mainDicomSequences; DicomMap::ExtractSequences(mainDicomSequences, allMainDicomTags); - std::map<DicomTag, Json::Value> sequencesToStore; + DicomSequencesMap sequencesToStore; try { @@ -544,15 +544,7 @@ Json::Value dicomAsJson; // -> this includes the sequences dicom.GetDicomAsJson(dicomAsJson, mainDicomSequences /*ignoreTagLength*/); // make sure that sequences that we wish to store in DB are not 'cropped' - - for (std::set<DicomTag>::const_iterator it = mainDicomSequences.begin(); - it != mainDicomSequences.end(); ++it) - { - if (dicomAsJson.isMember(it->Format())) - { - sequencesToStore[*it] = dicomAsJson[it->Format()]; - } - } + sequencesToStore.FromDicomAsJson(dicomAsJson, mainDicomSequences); Json::Value simplifiedTags; Toolbox::SimplifyDicomAsJson(simplifiedTags, dicomAsJson, DicomToJsonFormat_Human);
--- a/OrthancServer/Sources/ServerIndex.cpp Fri Jun 24 16:44:38 2022 +0200 +++ b/OrthancServer/Sources/ServerIndex.cpp Mon Jun 27 10:48:46 2022 +0200 @@ -511,7 +511,7 @@ StoreStatus ServerIndex::Store(std::map<MetadataType, std::string>& instanceMetadata, const DicomMap& dicomSummary, - const std::map<DicomTag, Json::Value>& sequencesToStore, + const DicomSequencesMap& sequencesToStore, const ServerIndex::Attachments& attachments, const ServerIndex::MetadataMap& metadata, const DicomInstanceOrigin& origin,
--- a/OrthancServer/Sources/ServerIndex.h Fri Jun 24 16:44:38 2022 +0200 +++ b/OrthancServer/Sources/ServerIndex.h Mon Jun 27 10:48:46 2022 +0200 @@ -77,7 +77,7 @@ StoreStatus Store(std::map<MetadataType, std::string>& instanceMetadata, const DicomMap& dicomSummary, - const std::map<DicomTag, Json::Value>& sequencesToStore, + const DicomSequencesMap& sequencesToStore, const Attachments& attachments, const MetadataMap& metadata, const DicomInstanceOrigin& origin,
--- a/OrthancServer/UnitTestsSources/ServerIndexTests.cpp Fri Jun 24 16:44:38 2022 +0200 +++ b/OrthancServer/UnitTestsSources/ServerIndexTests.cpp Mon Jun 27 10:48:46 2022 +0200 @@ -732,13 +732,14 @@ { DicomMap summary; + DicomSequencesMap sequences; OrthancConfiguration::DefaultExtractDicomSummary(summary, toStore->GetParsedDicomFile()); toStore->SetOrigin(DicomInstanceOrigin::FromPlugins()); DicomTransferSyntax transferSyntax; bool hasTransferSyntax = dicom.LookupTransferSyntax(transferSyntax); ASSERT_EQ(StoreStatus_Success, index.Store( - instanceMetadata, summary, attachments, toStore->GetMetadata(), + instanceMetadata, summary, sequences, attachments, toStore->GetMetadata(), toStore->GetOrigin(), false /* don't overwrite */, hasTransferSyntax, transferSyntax, true /* pixel data offset */, 42, false)); }