Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/DicomMoveScuJob.cpp @ 4071:d6b7fb0f9652 framework
improved DownloadOrthancFramework.cmake
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 15 Jun 2020 12:26:45 +0200 |
parents | 05b8fd21089c |
children | d962a2996637 |
rev | line source |
---|---|
2867 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3303
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
2867 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "DicomMoveScuJob.h" | |
35 | |
4045 | 36 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" |
3095
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
37 #include "../ServerContext.h" |
2867 | 38 |
3303
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
39 static const char* const LOCAL_AET = "LocalAet"; |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
40 static const char* const TARGET_AET = "TargetAet"; |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
41 static const char* const REMOTE = "Remote"; |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
42 static const char* const QUERY = "Query"; |
3870
09798f2b985f
added a Timeout argument to every DICOM command + 'TargetAet' not mandatory anymore in /retrieve
Alain Mazy <alain@mazy.be>
parents:
3843
diff
changeset
|
43 static const char* const TIMEOUT = "Timeout"; |
3303
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
44 |
2867 | 45 namespace Orthanc |
46 { | |
47 class DicomMoveScuJob::Command : public SetOfCommandsJob::ICommand | |
48 { | |
49 private: | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
50 DicomMoveScuJob& that_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
51 std::unique_ptr<DicomMap> findAnswer_; |
2867 | 52 |
53 public: | |
54 Command(DicomMoveScuJob& that, | |
55 const DicomMap& findAnswer) : | |
56 that_(that), | |
57 findAnswer_(findAnswer.Clone()) | |
58 { | |
59 } | |
60 | |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
61 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE |
2867 | 62 { |
63 that_.Retrieve(*findAnswer_); | |
64 return true; | |
65 } | |
66 | |
3763
5ff5d5a0fd28
adding missing ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
67 virtual void Serialize(Json::Value& target) const ORTHANC_OVERRIDE |
2867 | 68 { |
69 findAnswer_->Serialize(target); | |
70 } | |
71 }; | |
72 | |
73 | |
74 class DicomMoveScuJob::Unserializer : | |
75 public SetOfCommandsJob::ICommandUnserializer | |
76 { | |
77 private: | |
78 DicomMoveScuJob& that_; | |
79 | |
80 public: | |
81 Unserializer(DicomMoveScuJob& that) : | |
82 that_(that) | |
83 { | |
84 } | |
85 | |
86 virtual ICommand* Unserialize(const Json::Value& source) const | |
87 { | |
88 DicomMap findAnswer; | |
89 findAnswer.Unserialize(source); | |
90 return new Command(that_, findAnswer); | |
91 } | |
92 }; | |
93 | |
94 | |
95 | |
96 void DicomMoveScuJob::Retrieve(const DicomMap& findAnswer) | |
97 { | |
98 if (connection_.get() == NULL) | |
99 { | |
3877
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
100 connection_.reset(new DicomControlUserConnection(parameters_)); |
2867 | 101 } |
102 | |
103 connection_->Move(targetAet_, findAnswer); | |
104 } | |
3303
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
105 |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
106 |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
107 static void AddTagIfString(Json::Value& target, |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
108 const DicomMap& answer, |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
109 const DicomTag& tag) |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
110 { |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
111 const DicomValue* value = answer.TestAndGetValue(tag); |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
112 if (value != NULL && |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
113 !value->IsNull() && |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
114 !value->IsBinary()) |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
115 { |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
116 target[tag.Format()] = value->GetContent(); |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
117 } |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
118 } |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
119 |
2867 | 120 |
121 void DicomMoveScuJob::AddFindAnswer(const DicomMap& answer) | |
122 { | |
3303
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
123 assert(query_.type() == Json::arrayValue); |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
124 |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
125 // Copy the identifiers tags, if they exist |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
126 Json::Value item = Json::objectValue; |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
127 AddTagIfString(item, answer, DICOM_TAG_QUERY_RETRIEVE_LEVEL); |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
128 AddTagIfString(item, answer, DICOM_TAG_PATIENT_ID); |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
129 AddTagIfString(item, answer, DICOM_TAG_STUDY_INSTANCE_UID); |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
130 AddTagIfString(item, answer, DICOM_TAG_SERIES_INSTANCE_UID); |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
131 AddTagIfString(item, answer, DICOM_TAG_SOP_INSTANCE_UID); |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
132 AddTagIfString(item, answer, DICOM_TAG_ACCESSION_NUMBER); |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
133 query_.append(item); |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
134 |
2867 | 135 AddCommand(new Command(*this, answer)); |
136 } | |
137 | |
138 | |
139 void DicomMoveScuJob::AddFindAnswer(QueryRetrieveHandler& query, | |
140 size_t i) | |
141 { | |
142 DicomMap answer; | |
143 query.GetAnswer(answer, i); | |
144 AddFindAnswer(answer); | |
145 } | |
146 | |
147 | |
148 void DicomMoveScuJob::SetLocalAet(const std::string& aet) | |
149 { | |
150 if (IsStarted()) | |
151 { | |
152 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
153 } | |
154 else | |
155 { | |
3877
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
156 parameters_.SetLocalApplicationEntityTitle(aet); |
2867 | 157 } |
158 } | |
159 | |
160 | |
161 void DicomMoveScuJob::SetTargetAet(const std::string& aet) | |
162 { | |
163 if (IsStarted()) | |
164 { | |
165 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
166 } | |
167 else | |
168 { | |
169 targetAet_ = aet; | |
170 } | |
171 } | |
172 | |
173 | |
174 void DicomMoveScuJob::SetRemoteModality(const RemoteModalityParameters& remote) | |
175 { | |
176 if (IsStarted()) | |
177 { | |
178 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
179 } | |
180 else | |
181 { | |
3877
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
182 parameters_.SetRemoteModality(remote); |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
183 } |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
184 } |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
185 |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
186 |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
187 void DicomMoveScuJob::SetTimeout(uint32_t seconds) |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
188 { |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
189 if (IsStarted()) |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
190 { |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
191 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
192 } |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
193 else |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
194 { |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
195 parameters_.SetTimeout(seconds); |
2867 | 196 } |
197 } | |
198 | |
199 | |
200 void DicomMoveScuJob::Stop(JobStopReason reason) | |
201 { | |
202 connection_.reset(); | |
203 } | |
204 | |
205 | |
206 void DicomMoveScuJob::GetPublicContent(Json::Value& value) | |
207 { | |
208 SetOfCommandsJob::GetPublicContent(value); | |
3877
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
209 |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
210 value["LocalAet"] = parameters_.GetLocalApplicationEntityTitle(); |
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
211 value["RemoteAet"] = parameters_.GetRemoteModality().GetApplicationEntityTitle(); |
3303
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
212 value["Query"] = query_; |
2867 | 213 } |
214 | |
215 | |
216 DicomMoveScuJob::DicomMoveScuJob(ServerContext& context, | |
217 const Json::Value& serialized) : | |
218 SetOfCommandsJob(new Unserializer(*this), serialized), | |
3303
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
219 context_(context), |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
220 query_(Json::arrayValue) |
2867 | 221 { |
3877
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
222 parameters_ = DicomAssociationParameters::UnserializeJob(serialized); |
2867 | 223 targetAet_ = SerializationToolbox::ReadString(serialized, TARGET_AET); |
3303
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
224 |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
225 if (serialized.isMember(QUERY) && |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
226 serialized[QUERY].type() == Json::arrayValue) |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
227 { |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
228 query_ = serialized[QUERY]; |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
229 } |
2867 | 230 } |
231 | |
232 | |
233 bool DicomMoveScuJob::Serialize(Json::Value& target) | |
234 { | |
235 if (!SetOfCommandsJob::Serialize(target)) | |
236 { | |
237 return false; | |
238 } | |
239 else | |
240 { | |
3877
4b4f387c6bb8
making DicomMoveScuJob more consistent with DicomModalityStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3875
diff
changeset
|
241 parameters_.SerializeJob(target); |
2867 | 242 target[TARGET_AET] = targetAet_; |
3303
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
243 target[QUERY] = query_; |
2867 | 244 return true; |
245 } | |
246 } | |
247 } |