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