Mercurial > hg > orthanc
annotate OrthancServer/ServerJobs/DicomModalityStoreJob.cpp @ 2624:714dcddeb65f jobs
asynchronous c-movoe
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 24 May 2018 21:44:22 +0200 |
parents | 988936118354 |
children | c691fcf66071 |
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" | |
38 | |
39 namespace Orthanc | |
40 { | |
41 void DicomModalityStoreJob::OpenConnection() | |
42 { | |
43 if (connection_.get() == NULL) | |
44 { | |
45 connection_.reset(new DicomUserConnection); | |
46 connection_->SetLocalApplicationEntityTitle(localAet_); | |
47 connection_->SetRemoteModality(remote_); | |
48 } | |
49 } | |
50 | |
51 | |
52 bool DicomModalityStoreJob::HandleInstance(const std::string& instance) | |
53 { | |
54 OpenConnection(); | |
55 | |
56 LOG(INFO) << "Sending instance " << instance << " to modality \"" | |
57 << remote_.GetApplicationEntityTitle() << "\""; | |
58 | |
59 std::string dicom; | |
2624
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
60 |
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
61 try |
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 context_.ReadDicom(dicom, instance); |
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 catch (OrthancException& e) |
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 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
|
68 return false; |
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
69 } |
2603 | 70 |
71 if (HasMoveOriginator()) | |
72 { | |
73 connection_->Store(dicom, moveOriginatorAet_, moveOriginatorId_); | |
74 } | |
75 else | |
76 { | |
77 connection_->Store(dicom); | |
78 } | |
79 | |
80 //boost::this_thread::sleep(boost::posix_time::milliseconds(500)); | |
81 | |
82 return true; | |
83 } | |
84 | |
85 | |
86 DicomModalityStoreJob::DicomModalityStoreJob(ServerContext& context) : | |
87 context_(context), | |
88 localAet_("ORTHANC"), | |
89 moveOriginatorId_(0) // By default, not a C-MOVE | |
90 { | |
91 } | |
92 | |
93 | |
94 void DicomModalityStoreJob::SetLocalAet(const std::string& aet) | |
95 { | |
96 if (IsStarted()) | |
97 { | |
98 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
99 } | |
100 else | |
101 { | |
102 localAet_ = aet; | |
103 } | |
104 } | |
105 | |
106 | |
107 void DicomModalityStoreJob::SetRemoteModality(const RemoteModalityParameters& remote) | |
108 { | |
109 if (IsStarted()) | |
110 { | |
111 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
112 } | |
113 else | |
114 { | |
115 remote_ = remote; | |
116 } | |
117 } | |
118 | |
119 | |
120 const std::string& DicomModalityStoreJob::GetMoveOriginatorAet() const | |
121 { | |
122 if (HasMoveOriginator()) | |
123 { | |
124 return moveOriginatorAet_; | |
125 } | |
126 else | |
127 { | |
128 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
129 } | |
130 } | |
131 | |
132 | |
133 uint16_t DicomModalityStoreJob::GetMoveOriginatorId() const | |
134 { | |
135 if (HasMoveOriginator()) | |
136 { | |
137 return moveOriginatorId_; | |
138 } | |
139 else | |
140 { | |
141 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
142 } | |
143 } | |
144 | |
145 | |
146 void DicomModalityStoreJob::SetMoveOriginator(const std::string& aet, | |
147 int id) | |
148 { | |
149 if (IsStarted()) | |
150 { | |
151 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
152 } | |
153 else if (id < 0 || | |
154 id >= 65536) | |
155 { | |
156 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
157 } | |
158 else | |
159 { | |
160 moveOriginatorId_ = static_cast<uint16_t>(id); | |
161 moveOriginatorAet_ = aet; | |
162 } | |
163 } | |
164 | |
165 void DicomModalityStoreJob::ReleaseResources() // For pausing jobs | |
166 { | |
167 connection_.reset(NULL); | |
168 } | |
169 | |
170 | |
171 void DicomModalityStoreJob::GetPublicContent(Json::Value& value) | |
172 { | |
2624
714dcddeb65f
asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
173 value["Description"] = GetDescription(); |
2603 | 174 value["LocalAet"] = localAet_; |
175 value["RemoteAet"] = remote_.GetApplicationEntityTitle(); | |
176 | |
177 if (HasMoveOriginator()) | |
178 { | |
179 value["MoveOriginatorAET"] = GetMoveOriginatorAet(); | |
180 value["MoveOriginatorID"] = GetMoveOriginatorId(); | |
181 } | |
182 | |
183 value["InstancesCount"] = static_cast<uint32_t>(GetInstances().size()); | |
184 value["FailedInstancesCount"] = static_cast<uint32_t>(GetFailedInstances().size()); | |
185 } | |
186 } |