Mercurial > hg > orthanc
annotate OrthancServer/OrthancMoveRequestHandler.cpp @ 1427:d710ea64f0fd
Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 29 Jun 2015 12:42:54 +0200 |
parents | f528849ee9f7 |
children | f967bdf8534e |
rev | line source |
---|---|
619 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1231
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1231
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
619 | 5 * |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
32 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include "PrecompiledHeadersServer.h" |
619 | 34 #include "OrthancMoveRequestHandler.h" |
35 | |
36 #include <glog/logging.h> | |
37 | |
38 #include "OrthancInitialization.h" | |
1371
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
39 #include "FromDcmtkBridge.h" |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
40 #include "../Core/DicomFormat/DicomArray.h" |
619 | 41 |
42 namespace Orthanc | |
43 { | |
44 namespace | |
45 { | |
46 // Anonymous namespace to avoid clashes between compilation modules | |
47 | |
48 class OrthancMoveRequestIterator : public IMoveRequestIterator | |
49 { | |
50 private: | |
51 ServerContext& context_; | |
1427
d710ea64f0fd
Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1371
diff
changeset
|
52 const std::string& localAet_; |
619 | 53 std::vector<std::string> instances_; |
54 size_t position_; | |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
55 RemoteModalityParameters remote_; |
771 | 56 |
619 | 57 public: |
58 OrthancMoveRequestIterator(ServerContext& context, | |
771 | 59 const std::string& aet, |
619 | 60 const std::string& publicId) : |
61 context_(context), | |
1427
d710ea64f0fd
Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1371
diff
changeset
|
62 localAet_(context.GetDefaultLocalApplicationEntityTitle()), |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
63 position_(0) |
619 | 64 { |
771 | 65 LOG(INFO) << "Sending resource " << publicId << " to modality \"" << aet << "\""; |
619 | 66 |
67 std::list<std::string> tmp; | |
68 context_.GetIndex().GetChildInstances(tmp, publicId); | |
69 | |
70 instances_.reserve(tmp.size()); | |
656 | 71 for (std::list<std::string>::iterator it = tmp.begin(); it != tmp.end(); ++it) |
619 | 72 { |
73 instances_.push_back(*it); | |
74 } | |
771 | 75 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
76 remote_ = Configuration::GetModalityUsingAet(aet); |
619 | 77 } |
78 | |
79 virtual unsigned int GetSubOperationCount() const | |
80 { | |
81 return instances_.size(); | |
82 } | |
83 | |
84 virtual Status DoNext() | |
85 { | |
86 if (position_ >= instances_.size()) | |
87 { | |
88 return Status_Failure; | |
89 } | |
90 | |
91 const std::string& id = instances_[position_++]; | |
92 | |
93 std::string dicom; | |
94 context_.ReadFile(dicom, id, FileContentType_Dicom); | |
771 | 95 |
96 { | |
776 | 97 ReusableDicomUserConnection::Locker locker |
1427
d710ea64f0fd
Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1371
diff
changeset
|
98 (context_.GetReusableDicomUserConnection(), localAet_, remote_); |
776 | 99 locker.GetConnection().Store(dicom); |
771 | 100 } |
619 | 101 |
102 return Status_Success; | |
103 } | |
104 }; | |
105 } | |
106 | |
107 | |
1162 | 108 bool OrthancMoveRequestHandler::LookupIdentifier(std::string& publicId, |
1231
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
109 DicomTag tag, |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
110 const DicomMap& input) |
619 | 111 { |
112 if (!input.HasTag(tag)) | |
113 { | |
114 return false; | |
115 } | |
116 | |
117 std::string value = input.GetValue(tag).AsString(); | |
118 | |
119 std::list<std::string> ids; | |
1162 | 120 context_.GetIndex().LookupIdentifier(ids, tag, value); |
619 | 121 |
122 if (ids.size() != 1) | |
123 { | |
124 return false; | |
125 } | |
126 else | |
127 { | |
128 publicId = ids.front(); | |
129 return true; | |
130 } | |
131 } | |
132 | |
133 | |
771 | 134 IMoveRequestIterator* OrthancMoveRequestHandler::Handle(const std::string& aet, |
619 | 135 const DicomMap& input) |
136 { | |
771 | 137 LOG(WARNING) << "Move-SCU request received for AET \"" << aet << "\""; |
619 | 138 |
1371
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
139 { |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
140 DicomArray query(input); |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
141 for (size_t i = 0; i < query.GetSize(); i++) |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
142 { |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
143 if (!query.GetElement(i).GetValue().IsNull()) |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
144 { |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
145 LOG(INFO) << " " << query.GetElement(i).GetTag() |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
146 << " " << FromDcmtkBridge::GetName(query.GetElement(i).GetTag()) |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
147 << " = " << query.GetElement(i).GetValue().AsString(); |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
148 } |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
149 } |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
150 } |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
151 |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
152 |
f528849ee9f7
DICOM Query/Retrieve available from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
153 |
619 | 154 /** |
155 * Retrieve the query level. | |
156 **/ | |
157 | |
1231
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
158 ResourceType level; |
619 | 159 const DicomValue* levelTmp = input.TestAndGetValue(DICOM_TAG_QUERY_RETRIEVE_LEVEL); |
1231
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
160 |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
161 if (levelTmp != NULL) |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
162 { |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
163 level = StringToResourceType(levelTmp->AsString().c_str()); |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
164 } |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
165 else |
619 | 166 { |
1231
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
167 // The query level is not present in the C-Move request, which |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
168 // does not follow the DICOM standard. This is for instance the |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
169 // behavior of Tudor DICOM. Try and automatically deduce the |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
170 // query level: Start from the instance level, going up to the |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
171 // patient level until a valid DICOM identifier is found. |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
172 |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
173 std::string publicId; |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
174 |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
175 if (LookupIdentifier(publicId, DICOM_TAG_SOP_INSTANCE_UID, input) || |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
176 LookupIdentifier(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input) || |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
177 LookupIdentifier(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input) || |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
178 LookupIdentifier(publicId, DICOM_TAG_PATIENT_ID, input)) |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
179 { |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
180 return new OrthancMoveRequestIterator(context_, aet, publicId); |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
181 } |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
182 else |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
183 { |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
184 // No identifier is present in the request. |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
185 throw OrthancException(ErrorCode_BadRequest); |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
186 } |
619 | 187 } |
188 | |
1231
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
189 |
619 | 190 |
191 /** | |
192 * Lookup for the resource to be sent. | |
193 **/ | |
194 | |
195 bool ok; | |
196 std::string publicId; | |
197 | |
198 switch (level) | |
199 { | |
200 case ResourceType_Patient: | |
1162 | 201 ok = LookupIdentifier(publicId, DICOM_TAG_PATIENT_ID, input); |
619 | 202 break; |
203 | |
204 case ResourceType_Study: | |
1162 | 205 ok = LookupIdentifier(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input); |
619 | 206 break; |
207 | |
208 case ResourceType_Series: | |
1162 | 209 ok = LookupIdentifier(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input); |
619 | 210 break; |
211 | |
212 case ResourceType_Instance: | |
1162 | 213 ok = LookupIdentifier(publicId, DICOM_TAG_SOP_INSTANCE_UID, input); |
619 | 214 break; |
215 | |
216 default: | |
217 ok = false; | |
218 } | |
219 | |
220 if (!ok) | |
221 { | |
222 throw OrthancException(ErrorCode_BadRequest); | |
223 } | |
224 | |
771 | 225 return new OrthancMoveRequestIterator(context_, aet, publicId); |
619 | 226 } |
227 } |