Mercurial > hg > orthanc
annotate OrthancServer/ServerJobs/DicomMoveScuJob.cpp @ 3505:b2d4dd16dae8
removed C++11 primitive
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Aug 2019 12:21:23 +0200 |
parents | a215182a0c2f |
children | 94f4a18a79cc |
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 | |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2871
diff
changeset
|
5 * Copyright (C) 2017-2019 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 | |
36 #include "../../Core/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"; |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
43 |
2867 | 44 namespace Orthanc |
45 { | |
46 class DicomMoveScuJob::Command : public SetOfCommandsJob::ICommand | |
47 { | |
48 private: | |
49 DicomMoveScuJob& that_; | |
50 std::auto_ptr<DicomMap> findAnswer_; | |
51 | |
52 public: | |
53 Command(DicomMoveScuJob& that, | |
54 const DicomMap& findAnswer) : | |
55 that_(that), | |
56 findAnswer_(findAnswer.Clone()) | |
57 { | |
58 } | |
59 | |
60 virtual bool Execute() | |
61 { | |
62 that_.Retrieve(*findAnswer_); | |
63 return true; | |
64 } | |
65 | |
66 virtual void Serialize(Json::Value& target) const | |
67 { | |
68 findAnswer_->Serialize(target); | |
69 } | |
70 }; | |
71 | |
72 | |
73 class DicomMoveScuJob::Unserializer : | |
74 public SetOfCommandsJob::ICommandUnserializer | |
75 { | |
76 private: | |
77 DicomMoveScuJob& that_; | |
78 | |
79 public: | |
80 Unserializer(DicomMoveScuJob& that) : | |
81 that_(that) | |
82 { | |
83 } | |
84 | |
85 virtual ICommand* Unserialize(const Json::Value& source) const | |
86 { | |
87 DicomMap findAnswer; | |
88 findAnswer.Unserialize(source); | |
89 return new Command(that_, findAnswer); | |
90 } | |
91 }; | |
92 | |
93 | |
94 | |
95 void DicomMoveScuJob::Retrieve(const DicomMap& findAnswer) | |
96 { | |
97 if (connection_.get() == NULL) | |
98 { | |
99 connection_.reset(new DicomUserConnection(localAet_, remote_)); | |
100 connection_->Open(); | |
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 { | |
156 localAet_ = aet; | |
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 { | |
182 remote_ = remote; | |
183 } | |
184 } | |
185 | |
186 | |
187 void DicomMoveScuJob::Stop(JobStopReason reason) | |
188 { | |
189 connection_.reset(); | |
190 } | |
191 | |
192 | |
193 void DicomMoveScuJob::GetPublicContent(Json::Value& value) | |
194 { | |
195 SetOfCommandsJob::GetPublicContent(value); | |
196 | |
197 value["LocalAet"] = localAet_; | |
198 value["RemoteAet"] = remote_.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
|
199 value["Query"] = query_; |
2867 | 200 } |
201 | |
202 | |
203 DicomMoveScuJob::DicomMoveScuJob(ServerContext& context, | |
204 const Json::Value& serialized) : | |
205 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
|
206 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
|
207 query_(Json::arrayValue) |
2867 | 208 { |
209 localAet_ = SerializationToolbox::ReadString(serialized, LOCAL_AET); | |
210 targetAet_ = SerializationToolbox::ReadString(serialized, TARGET_AET); | |
211 remote_ = RemoteModalityParameters(serialized[REMOTE]); | |
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 |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
213 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
|
214 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
|
215 { |
a215182a0c2f
"DicomMoveScu" jobs provide the associated C-FIND answer in their "Query" public field
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
216 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
|
217 } |
2867 | 218 } |
219 | |
220 | |
221 bool DicomMoveScuJob::Serialize(Json::Value& target) | |
222 { | |
223 if (!SetOfCommandsJob::Serialize(target)) | |
224 { | |
225 return false; | |
226 } | |
227 else | |
228 { | |
229 target[LOCAL_AET] = localAet_; | |
230 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
|
231 target[QUERY] = query_; |
2871
6eebc2eb3168
refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
232 remote_.Serialize(target[REMOTE], true /* force advanced format */); |
2867 | 233 return true; |
234 } | |
235 } | |
236 } |