Mercurial > hg > orthanc
annotate OrthancServer/ServerJobs/DicomMoveScuJob.cpp @ 3204:8792867b739a
fix incorrect "too many results"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 06 Feb 2019 16:46:08 +0100 |
parents | beeeb6096f27 |
children | a215182a0c2f |
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 |
39 namespace Orthanc | |
40 { | |
41 class DicomMoveScuJob::Command : public SetOfCommandsJob::ICommand | |
42 { | |
43 private: | |
44 DicomMoveScuJob& that_; | |
45 std::auto_ptr<DicomMap> findAnswer_; | |
46 | |
47 public: | |
48 Command(DicomMoveScuJob& that, | |
49 const DicomMap& findAnswer) : | |
50 that_(that), | |
51 findAnswer_(findAnswer.Clone()) | |
52 { | |
53 } | |
54 | |
55 virtual bool Execute() | |
56 { | |
57 that_.Retrieve(*findAnswer_); | |
58 return true; | |
59 } | |
60 | |
61 virtual void Serialize(Json::Value& target) const | |
62 { | |
63 findAnswer_->Serialize(target); | |
64 } | |
65 }; | |
66 | |
67 | |
68 class DicomMoveScuJob::Unserializer : | |
69 public SetOfCommandsJob::ICommandUnserializer | |
70 { | |
71 private: | |
72 DicomMoveScuJob& that_; | |
73 | |
74 public: | |
75 Unserializer(DicomMoveScuJob& that) : | |
76 that_(that) | |
77 { | |
78 } | |
79 | |
80 virtual ICommand* Unserialize(const Json::Value& source) const | |
81 { | |
82 DicomMap findAnswer; | |
83 findAnswer.Unserialize(source); | |
84 return new Command(that_, findAnswer); | |
85 } | |
86 }; | |
87 | |
88 | |
89 | |
90 void DicomMoveScuJob::Retrieve(const DicomMap& findAnswer) | |
91 { | |
92 if (connection_.get() == NULL) | |
93 { | |
94 connection_.reset(new DicomUserConnection(localAet_, remote_)); | |
95 connection_->Open(); | |
96 } | |
97 | |
98 connection_->Move(targetAet_, findAnswer); | |
99 } | |
100 | |
101 | |
102 void DicomMoveScuJob::AddFindAnswer(const DicomMap& answer) | |
103 { | |
104 AddCommand(new Command(*this, answer)); | |
105 } | |
106 | |
107 | |
108 void DicomMoveScuJob::AddFindAnswer(QueryRetrieveHandler& query, | |
109 size_t i) | |
110 { | |
111 DicomMap answer; | |
112 query.GetAnswer(answer, i); | |
113 AddFindAnswer(answer); | |
114 } | |
115 | |
116 | |
117 void DicomMoveScuJob::SetLocalAet(const std::string& aet) | |
118 { | |
119 if (IsStarted()) | |
120 { | |
121 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
122 } | |
123 else | |
124 { | |
125 localAet_ = aet; | |
126 } | |
127 } | |
128 | |
129 | |
130 void DicomMoveScuJob::SetTargetAet(const std::string& aet) | |
131 { | |
132 if (IsStarted()) | |
133 { | |
134 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
135 } | |
136 else | |
137 { | |
138 targetAet_ = aet; | |
139 } | |
140 } | |
141 | |
142 | |
143 void DicomMoveScuJob::SetRemoteModality(const RemoteModalityParameters& remote) | |
144 { | |
145 if (IsStarted()) | |
146 { | |
147 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
148 } | |
149 else | |
150 { | |
151 remote_ = remote; | |
152 } | |
153 } | |
154 | |
155 | |
156 void DicomMoveScuJob::Stop(JobStopReason reason) | |
157 { | |
158 connection_.reset(); | |
159 } | |
160 | |
161 | |
162 void DicomMoveScuJob::GetPublicContent(Json::Value& value) | |
163 { | |
164 SetOfCommandsJob::GetPublicContent(value); | |
165 | |
166 value["LocalAet"] = localAet_; | |
167 value["RemoteAet"] = remote_.GetApplicationEntityTitle(); | |
168 } | |
169 | |
170 | |
171 static const char* LOCAL_AET = "LocalAet"; | |
172 static const char* TARGET_AET = "TargetAet"; | |
173 static const char* REMOTE = "Remote"; | |
174 | |
175 DicomMoveScuJob::DicomMoveScuJob(ServerContext& context, | |
176 const Json::Value& serialized) : | |
177 SetOfCommandsJob(new Unserializer(*this), serialized), | |
178 context_(context) | |
179 { | |
180 localAet_ = SerializationToolbox::ReadString(serialized, LOCAL_AET); | |
181 targetAet_ = SerializationToolbox::ReadString(serialized, TARGET_AET); | |
182 remote_ = RemoteModalityParameters(serialized[REMOTE]); | |
183 } | |
184 | |
185 | |
186 bool DicomMoveScuJob::Serialize(Json::Value& target) | |
187 { | |
188 if (!SetOfCommandsJob::Serialize(target)) | |
189 { | |
190 return false; | |
191 } | |
192 else | |
193 { | |
194 target[LOCAL_AET] = localAet_; | |
195 target[TARGET_AET] = targetAet_; | |
2871
6eebc2eb3168
refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
196 remote_.Serialize(target[REMOTE], true /* force advanced format */); |
2867 | 197 return true; |
198 } | |
199 } | |
200 } |