# HG changeset patch # User Sebastien Jodogne # Date 1539855857 -7200 # Node ID e5e3253a11646c297180168e6e4a0ee4e09bd766 # Parent 9ff17eb830ec8eefa2c19ad30f699ff4c3709d2e DicomInstanceToStore::GetHasher() diff -r 9ff17eb830ec -r e5e3253a1164 OrthancServer/DicomInstanceToStore.cpp --- a/OrthancServer/DicomInstanceToStore.cpp Thu Oct 18 10:53:22 2018 +0200 +++ b/OrthancServer/DicomInstanceToStore.cpp Thu Oct 18 11:44:17 2018 +0200 @@ -146,14 +146,18 @@ } - struct DicomInstanceToStore::PImpl + class DicomInstanceToStore::PImpl { - DicomInstanceOrigin origin_; - SmartContainer buffer_; - SmartContainer parsed_; - SmartContainer summary_; - SmartContainer json_; - MetadataMap metadata_; + public: + DicomInstanceOrigin origin_; + SmartContainer buffer_; + SmartContainer parsed_; + SmartContainer summary_; + SmartContainer json_; + MetadataMap metadata_; + + private: + std::auto_ptr hasher_; void ComputeMissingInformation() { @@ -225,6 +229,7 @@ } + public: const char* GetBufferData() { ComputeMissingInformation(); @@ -284,6 +289,22 @@ } + DicomInstanceHasher& GetHasher() + { + if (hasher_.get() == NULL) + { + hasher_.reset(new DicomInstanceHasher(GetSummary())); + } + + if (hasher_.get() == NULL) + { + throw OrthancException(ErrorCode_InternalError); + } + + return *hasher_; + } + + bool LookupTransferSyntax(std::string& result) { ComputeMissingInformation(); @@ -396,4 +417,10 @@ { return pimpl_->LookupTransferSyntax(result); } + + + DicomInstanceHasher& DicomInstanceToStore::GetHasher() + { + return pimpl_->GetHasher(); + } } diff -r 9ff17eb830ec -r e5e3253a1164 OrthancServer/DicomInstanceToStore.h --- a/OrthancServer/DicomInstanceToStore.h Thu Oct 18 10:53:22 2018 +0200 +++ b/OrthancServer/DicomInstanceToStore.h Thu Oct 18 11:44:17 2018 +0200 @@ -33,6 +33,7 @@ #pragma once +#include "../Core/DicomFormat/DicomInstanceHasher.h" #include "../Core/DicomFormat/DicomMap.h" #include "DicomInstanceOrigin.h" #include "ServerEnumerations.h" @@ -49,7 +50,7 @@ typedef std::map, std::string> MetadataMap; private: - struct PImpl; + class PImpl; boost::shared_ptr pimpl_; public: @@ -84,5 +85,7 @@ const Json::Value& GetJson(); bool LookupTransferSyntax(std::string& result); + + DicomInstanceHasher& GetHasher(); }; } diff -r 9ff17eb830ec -r e5e3253a1164 OrthancServer/ServerContext.cpp --- a/OrthancServer/ServerContext.cpp Thu Oct 18 10:53:22 2018 +0200 +++ b/OrthancServer/ServerContext.cpp Thu Oct 18 11:44:17 2018 +0200 @@ -316,10 +316,7 @@ { StorageAccessor accessor(area_); - { - DicomInstanceHasher hasher(dicom.GetSummary()); - resultPublicId = hasher.HashInstance(); - } + resultPublicId = dicom.GetHasher().HashInstance(); Json::Value simplifiedTags; ServerToolbox::SimplifyTags(simplifiedTags, dicom.GetJson(), DicomToJsonFormat_Human); diff -r 9ff17eb830ec -r e5e3253a1164 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Thu Oct 18 10:53:22 2018 +0200 +++ b/OrthancServer/ServerIndex.cpp Thu Oct 18 11:44:17 2018 +0200 @@ -621,8 +621,6 @@ instanceMetadata.clear(); - DicomInstanceHasher hasher(instanceToStore.GetSummary()); - try { Transaction t(*this); @@ -631,14 +629,14 @@ { ResourceType type; int64_t tmp; - if (db_.LookupResource(tmp, type, hasher.HashInstance())) + if (db_.LookupResource(tmp, type, instanceToStore.GetHasher().HashInstance())) { assert(type == ResourceType_Instance); if (overwrite_) { // Overwrite the old instance - LOG(INFO) << "Overwriting instance: " << hasher.HashInstance(); + LOG(INFO) << "Overwriting instance: " << instanceToStore.GetHasher().HashInstance(); db_.DeleteResource(tmp); } else @@ -658,10 +656,10 @@ instanceSize += it->GetCompressedSize(); } - Recycle(instanceSize, hasher.HashPatient()); + Recycle(instanceSize, instanceToStore.GetHasher().HashPatient()); // Create the instance - int64_t instance = CreateResource(hasher.HashInstance(), ResourceType_Instance); + int64_t instance = CreateResource(instanceToStore.GetHasher().HashInstance(), ResourceType_Instance); ServerToolbox::StoreMainDicomTags(db_, instance, ResourceType_Instance, dicomSummary); // Detect up to which level the patient/study/series/instance @@ -674,26 +672,26 @@ { ResourceType dummy; - if (db_.LookupResource(series, dummy, hasher.HashSeries())) + if (db_.LookupResource(series, dummy, instanceToStore.GetHasher().HashSeries())) { assert(dummy == ResourceType_Series); // The patient, the study and the series already exist - bool ok = (db_.LookupResource(patient, dummy, hasher.HashPatient()) && - db_.LookupResource(study, dummy, hasher.HashStudy())); + bool ok = (db_.LookupResource(patient, dummy, instanceToStore.GetHasher().HashPatient()) && + db_.LookupResource(study, dummy, instanceToStore.GetHasher().HashStudy())); assert(ok); } - else if (db_.LookupResource(study, dummy, hasher.HashStudy())) + else if (db_.LookupResource(study, dummy, instanceToStore.GetHasher().HashStudy())) { assert(dummy == ResourceType_Study); // New series: The patient and the study already exist isNewSeries = true; - bool ok = db_.LookupResource(patient, dummy, hasher.HashPatient()); + bool ok = db_.LookupResource(patient, dummy, instanceToStore.GetHasher().HashPatient()); assert(ok); } - else if (db_.LookupResource(patient, dummy, hasher.HashPatient())) + else if (db_.LookupResource(patient, dummy, instanceToStore.GetHasher().HashPatient())) { assert(dummy == ResourceType_Patient); @@ -713,21 +711,21 @@ // Create the series if needed if (isNewSeries) { - series = CreateResource(hasher.HashSeries(), ResourceType_Series); + series = CreateResource(instanceToStore.GetHasher().HashSeries(), ResourceType_Series); ServerToolbox::StoreMainDicomTags(db_, series, ResourceType_Series, dicomSummary); } // Create the study if needed if (isNewStudy) { - study = CreateResource(hasher.HashStudy(), ResourceType_Study); + study = CreateResource(instanceToStore.GetHasher().HashStudy(), ResourceType_Study); ServerToolbox::StoreMainDicomTags(db_, study, ResourceType_Study, dicomSummary); } // Create the patient if needed if (isNewPatient) { - patient = CreateResource(hasher.HashPatient(), ResourceType_Patient); + patient = CreateResource(instanceToStore.GetHasher().HashPatient(), ResourceType_Patient); ServerToolbox::StoreMainDicomTags(db_, patient, ResourceType_Patient, dicomSummary); } @@ -853,13 +851,13 @@ SeriesStatus seriesStatus = GetSeriesStatus(series); if (seriesStatus == SeriesStatus_Complete) { - LogChange(series, ChangeType_CompletedSeries, ResourceType_Series, hasher.HashSeries()); + LogChange(series, ChangeType_CompletedSeries, ResourceType_Series, instanceToStore.GetHasher().HashSeries()); } // Mark the parent resources of this instance as unstable - MarkAsUnstable(series, ResourceType_Series, hasher.HashSeries()); - MarkAsUnstable(study, ResourceType_Study, hasher.HashStudy()); - MarkAsUnstable(patient, ResourceType_Patient, hasher.HashPatient()); + MarkAsUnstable(series, ResourceType_Series, instanceToStore.GetHasher().HashSeries()); + MarkAsUnstable(study, ResourceType_Study, instanceToStore.GetHasher().HashStudy()); + MarkAsUnstable(patient, ResourceType_Patient, instanceToStore.GetHasher().HashPatient()); t.Commit(instanceSize); diff -r 9ff17eb830ec -r e5e3253a1164 OrthancServer/ServerIndex.h --- a/OrthancServer/ServerIndex.h Thu Oct 18 10:53:22 2018 +0200 +++ b/OrthancServer/ServerIndex.h Thu Oct 18 11:44:17 2018 +0200 @@ -38,7 +38,6 @@ #include "../Core/Cache/LeastRecentlyUsedIndex.h" #include "../Core/SQLite/Connection.h" #include "../Core/DicomFormat/DicomMap.h" -#include "../Core/DicomFormat/DicomInstanceHasher.h" #include "ServerEnumerations.h" #include "IDatabaseWrapper.h" diff -r 9ff17eb830ec -r e5e3253a1164 UnitTestsSources/ServerIndexTests.cpp --- a/UnitTestsSources/ServerIndexTests.cpp Thu Oct 18 10:53:22 2018 +0200 +++ b/UnitTestsSources/ServerIndexTests.cpp Thu Oct 18 11:44:17 2018 +0200 @@ -820,6 +820,11 @@ ids.push_back(hasher.HashStudy()); ids.push_back(hasher.HashSeries()); ids.push_back(hasher.HashInstance()); + + ASSERT_EQ(hasher.HashPatient(), toStore.GetHasher().HashPatient()); + ASSERT_EQ(hasher.HashStudy(), toStore.GetHasher().HashStudy()); + ASSERT_EQ(hasher.HashSeries(), toStore.GetHasher().HashSeries()); + ASSERT_EQ(hasher.HashInstance(), toStore.GetHasher().HashInstance()); } index.ComputeStatistics(tmp); @@ -884,6 +889,7 @@ DicomInstanceToStore toStore; toStore.SetSummary(instance); toStore.SetOrigin(DicomInstanceOrigin::FromPlugins()); + ASSERT_EQ(id, toStore.GetHasher().HashInstance()); std::string id2; ASSERT_EQ(StoreStatus_Success, context.Store(id2, toStore));