Mercurial > hg > orthanc
annotate OrthancServer/OrthancMoveRequestHandler.cpp @ 803:4689e400e0fa
directory to store the results of the unit tests
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 07 May 2014 09:29:11 +0200 |
parents | be87dd517416 |
children | 401a9633e492 |
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 | |
32 #include "OrthancMoveRequestHandler.h" | |
33 | |
34 #include <glog/logging.h> | |
35 | |
36 #include "OrthancInitialization.h" | |
37 | |
38 namespace Orthanc | |
39 { | |
40 namespace | |
41 { | |
42 // Anonymous namespace to avoid clashes between compilation modules | |
43 | |
44 class OrthancMoveRequestIterator : public IMoveRequestIterator | |
45 { | |
46 private: | |
47 ServerContext& context_; | |
48 std::vector<std::string> instances_; | |
49 size_t position_; | |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
50 RemoteModalityParameters remote_; |
771 | 51 |
619 | 52 public: |
53 OrthancMoveRequestIterator(ServerContext& context, | |
771 | 54 const std::string& aet, |
619 | 55 const std::string& publicId) : |
56 context_(context), | |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
57 position_(0) |
619 | 58 { |
771 | 59 LOG(INFO) << "Sending resource " << publicId << " to modality \"" << aet << "\""; |
619 | 60 |
61 std::list<std::string> tmp; | |
62 context_.GetIndex().GetChildInstances(tmp, publicId); | |
63 | |
64 instances_.reserve(tmp.size()); | |
656 | 65 for (std::list<std::string>::iterator it = tmp.begin(); it != tmp.end(); ++it) |
619 | 66 { |
67 instances_.push_back(*it); | |
68 } | |
771 | 69 |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
70 remote_ = GetModalityUsingAet(aet); |
619 | 71 } |
72 | |
73 virtual unsigned int GetSubOperationCount() const | |
74 { | |
75 return instances_.size(); | |
76 } | |
77 | |
78 virtual Status DoNext() | |
79 { | |
80 if (position_ >= instances_.size()) | |
81 { | |
82 return Status_Failure; | |
83 } | |
84 | |
85 const std::string& id = instances_[position_++]; | |
86 | |
87 std::string dicom; | |
88 context_.ReadFile(dicom, id, FileContentType_Dicom); | |
771 | 89 |
90 { | |
776 | 91 ReusableDicomUserConnection::Locker locker |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
92 (context_.GetReusableDicomUserConnection(), remote_); |
776 | 93 locker.GetConnection().Store(dicom); |
771 | 94 } |
619 | 95 |
96 return Status_Success; | |
97 } | |
98 }; | |
99 } | |
100 | |
101 | |
102 bool OrthancMoveRequestHandler::LookupResource(std::string& publicId, | |
103 DicomTag tag, | |
104 const DicomMap& input) | |
105 { | |
106 if (!input.HasTag(tag)) | |
107 { | |
108 return false; | |
109 } | |
110 | |
111 std::string value = input.GetValue(tag).AsString(); | |
112 | |
113 std::list<std::string> ids; | |
114 context_.GetIndex().LookupTagValue(ids, tag, value); | |
115 | |
116 if (ids.size() != 1) | |
117 { | |
118 return false; | |
119 } | |
120 else | |
121 { | |
122 publicId = ids.front(); | |
123 return true; | |
124 } | |
125 } | |
126 | |
127 | |
771 | 128 IMoveRequestIterator* OrthancMoveRequestHandler::Handle(const std::string& aet, |
619 | 129 const DicomMap& input) |
130 { | |
771 | 131 LOG(WARNING) << "Move-SCU request received for AET \"" << aet << "\""; |
619 | 132 |
133 | |
134 /** | |
135 * Retrieve the query level. | |
136 **/ | |
137 | |
138 const DicomValue* levelTmp = input.TestAndGetValue(DICOM_TAG_QUERY_RETRIEVE_LEVEL); | |
139 if (levelTmp == NULL) | |
140 { | |
141 throw OrthancException(ErrorCode_BadRequest); | |
142 } | |
143 | |
144 ResourceType level = StringToResourceType(levelTmp->AsString().c_str()); | |
145 | |
146 /** | |
147 * Lookup for the resource to be sent. | |
148 **/ | |
149 | |
150 bool ok; | |
151 std::string publicId; | |
152 | |
153 switch (level) | |
154 { | |
155 case ResourceType_Patient: | |
156 ok = LookupResource(publicId, DICOM_TAG_PATIENT_ID, input); | |
157 break; | |
158 | |
159 case ResourceType_Study: | |
160 ok = LookupResource(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input); | |
161 break; | |
162 | |
163 case ResourceType_Series: | |
164 ok = LookupResource(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input); | |
165 break; | |
166 | |
167 case ResourceType_Instance: | |
168 ok = LookupResource(publicId, DICOM_TAG_SOP_INSTANCE_UID, input); | |
169 break; | |
170 | |
171 default: | |
172 ok = false; | |
173 } | |
174 | |
175 if (!ok) | |
176 { | |
177 throw OrthancException(ErrorCode_BadRequest); | |
178 } | |
179 | |
771 | 180 return new OrthancMoveRequestIterator(context_, aet, publicId); |
619 | 181 } |
182 } |