Mercurial > hg > orthanc
annotate OrthancServer/ServerJobs/DicomModalityStoreJob.cpp @ 2713:301adea5cc7f jobs
integration mainline->jobs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Jul 2018 11:37:36 +0200 |
parents | a21b244efb37 |
children | 7cfc8d266f41 |
rev | line source |
---|---|
2603 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
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 "../PrecompiledHeadersServer.h" | |
35 #include "DicomModalityStoreJob.h" | |
36 | |
37 #include "../../Core/Logging.h" | |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
38 #include "../../Core/SerializationToolbox.h" |
2603 | 39 |
40 namespace Orthanc | |
41 { | |
42 void DicomModalityStoreJob::OpenConnection() | |
43 { | |
44 if (connection_.get() == NULL) | |
45 { | |
46 connection_.reset(new DicomUserConnection); | |
47 connection_->SetLocalApplicationEntityTitle(localAet_); | |
48 connection_->SetRemoteModality(remote_); | |
49 } | |
50 } | |
51 | |
52 | |
53 bool DicomModalityStoreJob::HandleInstance(const std::string& instance) | |
54 { | |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2624
diff
changeset
|
55 assert(IsStarted()); |
2603 | 56 OpenConnection(); |
57 | |
58 LOG(INFO) << "Sending instance " << instance << " to modality \"" | |
59 << remote_.GetApplicationEntityTitle() << "\""; | |
60 | |
61 std::string dicom; | |
2624
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
62 |
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
63 try |
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
64 { |
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
65 context_.ReadDicom(dicom, instance); |
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
66 } |
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
67 catch (OrthancException& e) |
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
68 { |
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
69 LOG(WARNING) << "An instance was removed after the job was issued: " << instance; |
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
70 return false; |
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
71 } |
2603 | 72 |
73 if (HasMoveOriginator()) | |
74 { | |
75 connection_->Store(dicom, moveOriginatorAet_, moveOriginatorId_); | |
76 } | |
77 else | |
78 { | |
79 connection_->Store(dicom); | |
80 } | |
81 | |
82 //boost::this_thread::sleep(boost::posix_time::milliseconds(500)); | |
83 | |
84 return true; | |
85 } | |
86 | |
87 | |
88 DicomModalityStoreJob::DicomModalityStoreJob(ServerContext& context) : | |
89 context_(context), | |
90 localAet_("ORTHANC"), | |
91 moveOriginatorId_(0) // By default, not a C-MOVE | |
92 { | |
93 } | |
94 | |
95 | |
96 void DicomModalityStoreJob::SetLocalAet(const std::string& aet) | |
97 { | |
98 if (IsStarted()) | |
99 { | |
100 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
101 } | |
102 else | |
103 { | |
104 localAet_ = aet; | |
105 } | |
106 } | |
107 | |
108 | |
109 void DicomModalityStoreJob::SetRemoteModality(const RemoteModalityParameters& remote) | |
110 { | |
111 if (IsStarted()) | |
112 { | |
113 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
114 } | |
115 else | |
116 { | |
117 remote_ = remote; | |
118 } | |
119 } | |
120 | |
121 | |
122 const std::string& DicomModalityStoreJob::GetMoveOriginatorAet() const | |
123 { | |
124 if (HasMoveOriginator()) | |
125 { | |
126 return moveOriginatorAet_; | |
127 } | |
128 else | |
129 { | |
130 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
131 } | |
132 } | |
133 | |
134 | |
135 uint16_t DicomModalityStoreJob::GetMoveOriginatorId() const | |
136 { | |
137 if (HasMoveOriginator()) | |
138 { | |
139 return moveOriginatorId_; | |
140 } | |
141 else | |
142 { | |
143 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
144 } | |
145 } | |
146 | |
147 | |
148 void DicomModalityStoreJob::SetMoveOriginator(const std::string& aet, | |
149 int id) | |
150 { | |
151 if (IsStarted()) | |
152 { | |
153 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
154 } | |
155 else if (id < 0 || | |
156 id >= 65536) | |
157 { | |
158 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
159 } | |
160 else | |
161 { | |
162 moveOriginatorId_ = static_cast<uint16_t>(id); | |
163 moveOriginatorAet_ = aet; | |
164 } | |
165 } | |
166 | |
167 void DicomModalityStoreJob::ReleaseResources() // For pausing jobs | |
168 { | |
169 connection_.reset(NULL); | |
170 } | |
171 | |
172 | |
173 void DicomModalityStoreJob::GetPublicContent(Json::Value& value) | |
174 { | |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2624
diff
changeset
|
175 SetOfInstancesJob::GetPublicContent(value); |
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2624
diff
changeset
|
176 |
2603 | 177 value["LocalAet"] = localAet_; |
178 value["RemoteAet"] = remote_.GetApplicationEntityTitle(); | |
179 | |
180 if (HasMoveOriginator()) | |
181 { | |
182 value["MoveOriginatorAET"] = GetMoveOriginatorAet(); | |
183 value["MoveOriginatorID"] = GetMoveOriginatorId(); | |
184 } | |
185 } | |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
186 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
187 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
188 static const char* LOCAL_AET = "LocalAet"; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
189 static const char* REMOTE = "Remote"; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
190 static const char* MOVE_ORIGINATOR_AET = "MoveOriginatorAet"; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
191 static const char* MOVE_ORIGINATOR_ID = "MoveOriginatorId"; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
192 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
193 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
194 DicomModalityStoreJob::DicomModalityStoreJob(ServerContext& context, |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
195 const Json::Value& serialized) : |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
196 SetOfInstancesJob(serialized), |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
197 context_(context) |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
198 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
199 localAet_ = SerializationToolbox::ReadString(serialized, LOCAL_AET); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
200 remote_ = RemoteModalityParameters(serialized[REMOTE]); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
201 moveOriginatorAet_ = SerializationToolbox::ReadString(serialized, MOVE_ORIGINATOR_AET); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
202 moveOriginatorId_ = static_cast<uint16_t> |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
203 (SerializationToolbox::ReadUnsignedInteger(serialized, MOVE_ORIGINATOR_ID)); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
204 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
205 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
206 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
207 bool DicomModalityStoreJob::Serialize(Json::Value& target) |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
208 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
209 if (!SetOfInstancesJob::Serialize(target)) |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
210 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
211 return false; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
212 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
213 else |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
214 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
215 target[LOCAL_AET] = localAet_; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
216 remote_.Serialize(target[REMOTE]); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
217 target[MOVE_ORIGINATOR_AET] = moveOriginatorAet_; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
218 target[MOVE_ORIGINATOR_ID] = moveOriginatorId_; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
219 return true; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
220 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2640
diff
changeset
|
221 } |
2603 | 222 } |