Mercurial > hg > orthanc
changeset 1822:9ed9458aa44f
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 25 Nov 2015 10:06:50 +0100 |
parents | 580951a33583 |
children | 0ef4e6e66b56 |
files | OrthancServer/DicomInstanceToStore.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h UnitTestsSources/ServerIndexTests.cpp |
diffstat | 5 files changed, 31 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/DicomInstanceToStore.cpp Tue Nov 24 17:46:32 2015 +0100 +++ b/OrthancServer/DicomInstanceToStore.cpp Wed Nov 25 10:06:50 2015 +0100 @@ -63,18 +63,23 @@ { if (!parsed_.HasContent()) { - throw OrthancException(ErrorCode_NotImplemented); + if (!summary_.HasContent()) + { + throw OrthancException(ErrorCode_NotImplemented); + } + else + { + parsed_.TakeOwnership(new ParsedDicomFile(summary_.GetConstContent())); + } } - else + + // Serialize the parsed DICOM file + buffer_.Allocate(); + if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer_.GetContent(), + *parsed_.GetContent().GetDcmtkObject().getDataset())) { - // Serialize the parsed DICOM file - buffer_.Allocate(); - if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer_.GetContent(), - *parsed_.GetContent().GetDcmtkObject().getDataset())) - { - LOG(ERROR) << "Unable to serialize a DICOM file to a memory buffer"; - throw OrthancException(ErrorCode_InternalError); - } + LOG(ERROR) << "Unable to serialize a DICOM file to a memory buffer"; + throw OrthancException(ErrorCode_InternalError); } }
--- a/OrthancServer/ServerContext.cpp Tue Nov 24 17:46:32 2015 +0100 +++ b/OrthancServer/ServerContext.cpp Wed Nov 25 10:06:50 2015 +0100 @@ -236,8 +236,7 @@ typedef std::map<MetadataType, std::string> InstanceMetadata; InstanceMetadata instanceMetadata; - StoreStatus status = index_.Store(instanceMetadata, dicom.GetSummary(), attachments, - dicom.GetRemoteAet(), dicom.GetMetadata()); + StoreStatus status = index_.Store(instanceMetadata, dicom, attachments); // Only keep the metadata for the "instance" level dicom.GetMetadata().clear();
--- a/OrthancServer/ServerIndex.cpp Tue Nov 24 17:46:32 2015 +0100 +++ b/OrthancServer/ServerIndex.cpp Wed Nov 25 10:06:50 2015 +0100 @@ -50,6 +50,7 @@ #include "FromDcmtkBridge.h" #include "ServerContext.h" +#include "DicomInstanceToStore.h" #include <boost/lexical_cast.hpp> #include <stdio.h> @@ -593,16 +594,17 @@ StoreStatus ServerIndex::Store(std::map<MetadataType, std::string>& instanceMetadata, - const DicomMap& dicomSummary, - const Attachments& attachments, - const std::string& remoteAet, - const MetadataMap& metadata) + DicomInstanceToStore& instanceToStore, + const Attachments& attachments) { boost::mutex::scoped_lock lock(mutex_); + const DicomMap& dicomSummary = instanceToStore.GetSummary(); + const ServerIndex::MetadataMap& metadata = instanceToStore.GetMetadata(); + instanceMetadata.clear(); - DicomInstanceHasher hasher(dicomSummary); + DicomInstanceHasher hasher(instanceToStore.GetSummary()); try { @@ -766,8 +768,8 @@ db_.SetMetadata(instance, MetadataType_Instance_ReceptionDate, now); instanceMetadata[MetadataType_Instance_ReceptionDate] = now; - db_.SetMetadata(instance, MetadataType_Instance_RemoteAet, remoteAet); - instanceMetadata[MetadataType_Instance_RemoteAet] = remoteAet; + db_.SetMetadata(instance, MetadataType_Instance_RemoteAet, instanceToStore.GetRemoteAet()); + instanceMetadata[MetadataType_Instance_RemoteAet] = instanceToStore.GetRemoteAet(); const DicomValue* value; if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL ||
--- a/OrthancServer/ServerIndex.h Tue Nov 24 17:46:32 2015 +0100 +++ b/OrthancServer/ServerIndex.h Wed Nov 25 10:06:50 2015 +0100 @@ -42,11 +42,11 @@ #include "IDatabaseWrapper.h" - namespace Orthanc { class LookupResource; class ServerContext; + class DicomInstanceToStore; class ServerIndex : public boost::noncopyable { @@ -140,10 +140,8 @@ void SetMaximumPatientCount(unsigned int count); StoreStatus Store(std::map<MetadataType, std::string>& instanceMetadata, - const DicomMap& dicomSummary, - const Attachments& attachments, - const std::string& remoteAet, - const MetadataMap& metadata); + DicomInstanceToStore& instance, + const Attachments& attachments); void ComputeStatistics(Json::Value& target);
--- a/UnitTestsSources/ServerIndexTests.cpp Tue Nov 24 17:46:32 2015 +0100 +++ b/UnitTestsSources/ServerIndexTests.cpp Wed Nov 25 10:06:50 2015 +0100 @@ -796,8 +796,9 @@ instance.SetValue(DICOM_TAG_SOP_INSTANCE_UID, "instance-" + id); std::map<MetadataType, std::string> instanceMetadata; - ServerIndex::MetadataMap metadata; - ASSERT_EQ(StoreStatus_Success, index.Store(instanceMetadata, instance, attachments, "", metadata)); + DicomInstanceToStore toStore; + toStore.SetSummary(instance); + ASSERT_EQ(StoreStatus_Success, index.Store(instanceMetadata, toStore, attachments)); ASSERT_EQ(2u, instanceMetadata.size()); ASSERT_TRUE(instanceMetadata.find(MetadataType_Instance_RemoteAet) != instanceMetadata.end()); ASSERT_TRUE(instanceMetadata.find(MetadataType_Instance_ReceptionDate) != instanceMetadata.end());