Mercurial > hg > orthanc
annotate OrthancServer/OrthancMoveRequestHandler.cpp @ 1234:a65ad39596cb
fix issue #25
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 05 Dec 2014 11:11:58 +0100 |
parents | 703fcd797186 |
children | 6e7e5ed91c2d |
rev | line source |
---|---|
619 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
619 | 4 * Belgium |
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" | |
39 | |
40 namespace Orthanc | |
41 { | |
42 namespace | |
43 { | |
44 // Anonymous namespace to avoid clashes between compilation modules | |
45 | |
46 class OrthancMoveRequestIterator : public IMoveRequestIterator | |
47 { | |
48 private: | |
49 ServerContext& context_; | |
50 std::vector<std::string> instances_; | |
51 size_t position_; | |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
52 RemoteModalityParameters remote_; |
771 | 53 |
619 | 54 public: |
55 OrthancMoveRequestIterator(ServerContext& context, | |
771 | 56 const std::string& aet, |
619 | 57 const std::string& publicId) : |
58 context_(context), | |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
59 position_(0) |
619 | 60 { |
771 | 61 LOG(INFO) << "Sending resource " << publicId << " to modality \"" << aet << "\""; |
619 | 62 |
63 std::list<std::string> tmp; | |
64 context_.GetIndex().GetChildInstances(tmp, publicId); | |
65 | |
66 instances_.reserve(tmp.size()); | |
656 | 67 for (std::list<std::string>::iterator it = tmp.begin(); it != tmp.end(); ++it) |
619 | 68 { |
69 instances_.push_back(*it); | |
70 } | |
771 | 71 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
72 remote_ = Configuration::GetModalityUsingAet(aet); |
619 | 73 } |
74 | |
75 virtual unsigned int GetSubOperationCount() const | |
76 { | |
77 return instances_.size(); | |
78 } | |
79 | |
80 virtual Status DoNext() | |
81 { | |
82 if (position_ >= instances_.size()) | |
83 { | |
84 return Status_Failure; | |
85 } | |
86 | |
87 const std::string& id = instances_[position_++]; | |
88 | |
89 std::string dicom; | |
90 context_.ReadFile(dicom, id, FileContentType_Dicom); | |
771 | 91 |
92 { | |
776 | 93 ReusableDicomUserConnection::Locker locker |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
94 (context_.GetReusableDicomUserConnection(), remote_); |
776 | 95 locker.GetConnection().Store(dicom); |
771 | 96 } |
619 | 97 |
98 return Status_Success; | |
99 } | |
100 }; | |
101 } | |
102 | |
103 | |
1162 | 104 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
|
105 DicomTag tag, |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
106 const DicomMap& input) |
619 | 107 { |
108 if (!input.HasTag(tag)) | |
109 { | |
110 return false; | |
111 } | |
112 | |
113 std::string value = input.GetValue(tag).AsString(); | |
114 | |
115 std::list<std::string> ids; | |
1162 | 116 context_.GetIndex().LookupIdentifier(ids, tag, value); |
619 | 117 |
118 if (ids.size() != 1) | |
119 { | |
120 return false; | |
121 } | |
122 else | |
123 { | |
124 publicId = ids.front(); | |
125 return true; | |
126 } | |
127 } | |
128 | |
129 | |
771 | 130 IMoveRequestIterator* OrthancMoveRequestHandler::Handle(const std::string& aet, |
619 | 131 const DicomMap& input) |
132 { | |
771 | 133 LOG(WARNING) << "Move-SCU request received for AET \"" << aet << "\""; |
619 | 134 |
135 /** | |
136 * Retrieve the query level. | |
137 **/ | |
138 | |
1231
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
139 ResourceType level; |
619 | 140 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
|
141 |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
142 if (levelTmp != NULL) |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
143 { |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
144 level = StringToResourceType(levelTmp->AsString().c_str()); |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
145 } |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
146 else |
619 | 147 { |
1231
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
148 // 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
|
149 // 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
|
150 // 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
|
151 // 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
|
152 // 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
|
153 |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
154 std::string publicId; |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
155 |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 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
|
160 { |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
161 return new OrthancMoveRequestIterator(context_, aet, publicId); |
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 else |
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 // 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
|
166 throw OrthancException(ErrorCode_BadRequest); |
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
167 } |
619 | 168 } |
169 | |
1231
703fcd797186
Support of Tudor DICOM in Query/Retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
170 |
619 | 171 |
172 /** | |
173 * Lookup for the resource to be sent. | |
174 **/ | |
175 | |
176 bool ok; | |
177 std::string publicId; | |
178 | |
179 switch (level) | |
180 { | |
181 case ResourceType_Patient: | |
1162 | 182 ok = LookupIdentifier(publicId, DICOM_TAG_PATIENT_ID, input); |
619 | 183 break; |
184 | |
185 case ResourceType_Study: | |
1162 | 186 ok = LookupIdentifier(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input); |
619 | 187 break; |
188 | |
189 case ResourceType_Series: | |
1162 | 190 ok = LookupIdentifier(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input); |
619 | 191 break; |
192 | |
193 case ResourceType_Instance: | |
1162 | 194 ok = LookupIdentifier(publicId, DICOM_TAG_SOP_INSTANCE_UID, input); |
619 | 195 break; |
196 | |
197 default: | |
198 ok = false; | |
199 } | |
200 | |
201 if (!ok) | |
202 { | |
203 throw OrthancException(ErrorCode_BadRequest); | |
204 } | |
205 | |
771 | 206 return new OrthancMoveRequestIterator(context_, aet, publicId); |
619 | 207 } |
208 } |