# HG changeset patch # User Sebastien Jodogne # Date 1448442410 -3600 # Node ID 9ed9458aa44fcd28b5fb07825e6ceeea6db62fb6 # Parent 580951a3358376a146f0a4c7d3c9ff57bf7a27bc refactoring diff -r 580951a33583 -r 9ed9458aa44f OrthancServer/DicomInstanceToStore.cpp --- 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); } } diff -r 580951a33583 -r 9ed9458aa44f OrthancServer/ServerContext.cpp --- 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 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(); diff -r 580951a33583 -r 9ed9458aa44f OrthancServer/ServerIndex.cpp --- 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 #include @@ -593,16 +594,17 @@ StoreStatus ServerIndex::Store(std::map& 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 || diff -r 580951a33583 -r 9ed9458aa44f OrthancServer/ServerIndex.h --- 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& instanceMetadata, - const DicomMap& dicomSummary, - const Attachments& attachments, - const std::string& remoteAet, - const MetadataMap& metadata); + DicomInstanceToStore& instance, + const Attachments& attachments); void ComputeStatistics(Json::Value& target); diff -r 580951a33583 -r 9ed9458aa44f UnitTestsSources/ServerIndexTests.cpp --- 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 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());