Mercurial > hg > orthanc
annotate OrthancServer/ServerJobs/ModifyInstanceOperation.cpp @ 2618:ef5b45884972 jobs
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 22 May 2018 12:59:38 +0200 |
parents | 2f3007bf0708 |
children | c691fcf66071 |
rev | line source |
---|---|
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 **/ |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "../PrecompiledHeadersServer.h" |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "ModifyInstanceOperation.h" |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 #include "DicomInstanceOperationValue.h" |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 #include "../../Core/Logging.h" |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 namespace Orthanc |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 ModifyInstanceOperation::ModifyInstanceOperation(ServerContext& context, |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 RequestOrigin origin, |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 DicomModification* modification) : |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 context_(context), |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 origin_(origin), |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 modification_(modification) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 if (modification == NULL) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 throw OrthancException(ErrorCode_NullPointer); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 modification_->SetAllowManualIdentifiers(true); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 if (modification_->IsReplaced(DICOM_TAG_PATIENT_ID)) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 modification_->SetLevel(ResourceType_Patient); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 else if (modification_->IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 modification_->SetLevel(ResourceType_Study); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 else if (modification_->IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 modification_->SetLevel(ResourceType_Series); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 else |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 modification_->SetLevel(ResourceType_Instance); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 if (origin_ != RequestOrigin_Lua) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 // TODO If issued from HTTP, "remoteIp" and "username" must be provided |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 throw OrthancException(ErrorCode_NotImplemented); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 void ModifyInstanceOperation::Apply(JobOperationValues& outputs, |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2607
diff
changeset
|
82 const JobOperationValue& input, |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2607
diff
changeset
|
83 IDicomConnectionManager& connectionManager) |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 if (input.GetType() != JobOperationValue::Type_DicomInstance) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 throw OrthancException(ErrorCode_BadParameterType); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 const DicomInstanceOperationValue& instance = |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 dynamic_cast<const DicomInstanceOperationValue&>(input); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 LOG(INFO) << "Lua: Modifying instance " << instance.GetId(); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 std::auto_ptr<ParsedDicomFile> modified; |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 ServerContext::DicomCacheLocker lock(context_, instance.GetId()); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 modified.reset(lock.GetDicom().Clone(true)); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 try |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 modification_->Apply(*modified); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 DicomInstanceToStore toStore; |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 assert(origin_ == RequestOrigin_Lua); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 toStore.SetLuaOrigin(); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 toStore.SetParsedDicomFile(*modified); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 // TODO other metadata |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 toStore.AddMetadata(ResourceType_Instance, MetadataType_ModifiedFrom, instance.GetId()); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 std::string modifiedId; |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 context_.Store(modifiedId, toStore); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 // Only chain with other commands if this command succeeds |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
118 outputs.Append(new DicomInstanceOperationValue(instance.GetServerContext(), modifiedId)); |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 catch (OrthancException& e) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 LOG(ERROR) << "Lua: Unable to modify instance " << instance.GetId() |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 << ": " << e.What(); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 } |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
126 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
127 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
128 void ModifyInstanceOperation::Serialize(Json::Value& target) const |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
129 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
130 target["Type"] = "ModifyInstance"; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
131 target["Origin"] = EnumerationToString(origin_); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
132 modification_->Serialize(target["Modification"]); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
133 } |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 |