Mercurial > hg > orthanc
changeset 2607:44e268605478 jobs
ModifyInstanceOperation
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 19 May 2018 15:28:41 +0200 |
parents | f2b9d3256060 |
children | 25225f0b4f33 |
files | CMakeLists.txt OrthancServer/ServerJobs/LuaJobManager.cpp OrthancServer/ServerJobs/LuaJobManager.h OrthancServer/ServerJobs/ModifyInstanceOperation.cpp OrthancServer/ServerJobs/ModifyInstanceOperation.h OrthancServer/ServerJobs/SystemCallOperation.cpp |
diffstat | 6 files changed, 210 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Sat May 19 15:10:26 2018 +0200 +++ b/CMakeLists.txt Sat May 19 15:28:41 2018 +0200 @@ -93,6 +93,7 @@ OrthancServer/ServerJobs/DeleteResourceOperation.cpp OrthancServer/ServerJobs/DicomModalityStoreJob.cpp OrthancServer/ServerJobs/LuaJobManager.cpp + OrthancServer/ServerJobs/ModifyInstanceOperation.cpp OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp OrthancServer/ServerJobs/StorePeerOperation.cpp OrthancServer/ServerJobs/StoreScuOperation.cpp
--- a/OrthancServer/ServerJobs/LuaJobManager.cpp Sat May 19 15:10:26 2018 +0200 +++ b/OrthancServer/ServerJobs/LuaJobManager.cpp Sat May 19 15:28:41 2018 +0200 @@ -34,15 +34,16 @@ #include "../PrecompiledHeadersServer.h" #include "LuaJobManager.h" +#include "../../Core/JobsEngine/Operations/LogJobOperation.h" #include "DeleteResourceOperation.h" +#include "ModifyInstanceOperation.h" #include "StorePeerOperation.h" #include "StoreScuOperation.h" #include "SystemCallOperation.h" -#include "../../Core/JobsEngine/Operations/LogJobOperation.h" -#include "DicomInstanceOperationValue.h" #include "../../Core/JobsEngine/Operations/NullOperationValue.h" #include "../../Core/JobsEngine/Operations/StringOperationValue.h" +#include "DicomInstanceOperationValue.h" namespace Orthanc { @@ -196,7 +197,7 @@ assert(jobLock_.get() != NULL); return jobLock_->AddOperation(new SystemCallOperation(command)); } - + size_t LuaJobManager::Lock::AddSystemCallOperation (const std::string& command, @@ -209,6 +210,15 @@ } + size_t LuaJobManager::Lock::AddModifyInstanceOperation(ServerContext& context, + DicomModification* modification) + { + assert(jobLock_.get() != NULL); + return jobLock_->AddOperation + (new ModifyInstanceOperation(context, RequestOrigin_Lua, modification)); + } + + void LuaJobManager::Lock::AddNullInput(size_t operation) { assert(jobLock_.get() != NULL);
--- a/OrthancServer/ServerJobs/LuaJobManager.h Sat May 19 15:10:26 2018 +0200 +++ b/OrthancServer/ServerJobs/LuaJobManager.h Sat May 19 15:28:41 2018 +0200 @@ -33,6 +33,7 @@ #pragma once +#include "../../Core/DicomParsing/DicomModification.h" #include "../../Core/DicomNetworking/TimeoutDicomConnectionManager.h" #include "../../Core/JobsEngine/JobsEngine.h" #include "../../Core/JobsEngine/Operations/SequenceOfOperationsJob.h" @@ -99,6 +100,9 @@ const std::vector<std::string>& preArguments, const std::vector<std::string>& postArguments); + size_t AddModifyInstanceOperation(ServerContext& context, + DicomModification* modification); + void AddNullInput(size_t operation); void AddStringInput(size_t operation,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/ServerJobs/ModifyInstanceOperation.cpp Sat May 19 15:28:41 2018 +0200 @@ -0,0 +1,126 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2018 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "../PrecompiledHeadersServer.h" +#include "ModifyInstanceOperation.h" + +#include "DicomInstanceOperationValue.h" + +#include "../../Core/Logging.h" + +namespace Orthanc +{ + ModifyInstanceOperation::ModifyInstanceOperation(ServerContext& context, + RequestOrigin origin, + DicomModification* modification) : + context_(context), + origin_(origin), + modification_(modification) + { + if (modification == NULL) + { + throw OrthancException(ErrorCode_NullPointer); + } + + modification_->SetAllowManualIdentifiers(true); + + if (modification_->IsReplaced(DICOM_TAG_PATIENT_ID)) + { + modification_->SetLevel(ResourceType_Patient); + } + else if (modification_->IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) + { + modification_->SetLevel(ResourceType_Study); + } + else if (modification_->IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) + { + modification_->SetLevel(ResourceType_Series); + } + else + { + modification_->SetLevel(ResourceType_Instance); + } + + if (origin_ != RequestOrigin_Lua) + { + // TODO If issued from HTTP, "remoteIp" and "username" must be provided + throw OrthancException(ErrorCode_NotImplemented); + } + } + + void ModifyInstanceOperation::Apply(JobOperationValues& outputs, + const JobOperationValue& input) + { + if (input.GetType() != JobOperationValue::Type_DicomInstance) + { + throw OrthancException(ErrorCode_BadParameterType); + } + + const DicomInstanceOperationValue& instance = + dynamic_cast<const DicomInstanceOperationValue&>(input); + + LOG(INFO) << "Lua: Modifying instance " << instance.GetId(); + + std::auto_ptr<ParsedDicomFile> modified; + + { + ServerContext::DicomCacheLocker lock(context_, instance.GetId()); + modified.reset(lock.GetDicom().Clone(true)); + } + + try + { + modification_->Apply(*modified); + + DicomInstanceToStore toStore; + assert(origin_ == RequestOrigin_Lua); + toStore.SetLuaOrigin(); + toStore.SetParsedDicomFile(*modified); + + // TODO other metadata + toStore.AddMetadata(ResourceType_Instance, MetadataType_ModifiedFrom, instance.GetId()); + + std::string modifiedId; + context_.Store(modifiedId, toStore); + + // Only chain with other commands if this command succeeds + outputs.Append(input.Clone()); + } + catch (OrthancException& e) + { + LOG(ERROR) << "Lua: Unable to modify instance " << instance.GetId() + << ": " << e.What(); + } + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/ServerJobs/ModifyInstanceOperation.h Sat May 19 15:28:41 2018 +0200 @@ -0,0 +1,64 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2018 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "../../Core/JobsEngine/Operations/IJobOperation.h" +#include "../../Core/DicomParsing/DicomModification.h" + +#include "../ServerContext.h" + +namespace Orthanc +{ + class ModifyInstanceOperation : public IJobOperation + { + private: + ServerContext& context_; + RequestOrigin origin_; + std::auto_ptr<DicomModification> modification_; + + public: + ModifyInstanceOperation(ServerContext& context, + RequestOrigin origin, + DicomModification* modification); // Takes ownership + + const DicomModification& GetModification() const + { + return *modification_; + } + + virtual void Apply(JobOperationValues& outputs, + const JobOperationValue& input); + }; +} +
--- a/OrthancServer/ServerJobs/SystemCallOperation.cpp Sat May 19 15:10:26 2018 +0200 +++ b/OrthancServer/ServerJobs/SystemCallOperation.cpp Sat May 19 15:28:41 2018 +0200 @@ -96,7 +96,7 @@ info += " " + arguments[i]; } - LOG(INFO) << "Lua: System call: " << info; + LOG(INFO) << "Lua: System call: \"" << info << "\""; try { @@ -107,7 +107,7 @@ } catch (OrthancException& e) { - LOG(ERROR) << "Lua: Failed system call - " << info << ": " << e.What(); + LOG(ERROR) << "Lua: Failed system call - \"" << info << "\": " << e.What(); } } }