annotate OrthancServer/ResourceFinder.cpp @ 1724:7e0b5e413c7c db-changes

C-Move SCP for studies using AccessionNumber tag
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Oct 2015 11:02:06 +0200
parents 21d31da73374
children 1ae29c5e52fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "PrecompiledHeadersServer.h"
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
34 #include "ResourceFinder.h"
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
35
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1384
diff changeset
36 #include "../Core/Logging.h"
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
37 #include "FromDcmtkBridge.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
38 #include "ServerContext.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
39
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
42 class ResourceFinder::CandidateResources
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
44 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
45 typedef std::map<DicomTag, std::string> Query;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
46
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
47 ResourceFinder& finder_;
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
48 ServerIndex& index_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
49 ResourceType level_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
50 bool isFilterApplied_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
51 std::set<std::string> filtered_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
52
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
53
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
54 static void ListToSet(std::set<std::string>& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
55 const std::list<std::string>& source)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
56 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
57 for (std::list<std::string>::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
58 it = source.begin(); it != source.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
59 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
60 target.insert(*it);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
61 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
62 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
63
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
64
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
65 public:
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
66 CandidateResources(ResourceFinder& finder) :
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
67 finder_(finder),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
68 index_(finder.context_.GetIndex()),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
69 level_(ResourceType_Patient),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
70 isFilterApplied_(false)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
71 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
72 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
73
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
74 ResourceType GetLevel() const
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
76 return level_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
77 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
78
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
79 void GoDown()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
80 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
81 assert(level_ != ResourceType_Instance);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
82
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
83 if (isFilterApplied_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
84 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
85 std::set<std::string> tmp = filtered_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
86
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
87 filtered_.clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
88
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
89 for (std::set<std::string>::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
90 it = tmp.begin(); it != tmp.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
91 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
92 std::list<std::string> children;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
93 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
94 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
95 index_.GetChildren(children, *it);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
96 ListToSet(filtered_, children);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
97 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
98 catch (OrthancException&)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
99 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
100 // The resource was removed in the meantime
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
101 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
102 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
103 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
104
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
105 switch (level_)
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
107 case ResourceType_Patient:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
108 level_ = ResourceType_Study;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
109 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
110
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
111 case ResourceType_Study:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
112 level_ = ResourceType_Series;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
113 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
114
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
115 case ResourceType_Series:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
116 level_ = ResourceType_Instance;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
117 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
118
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
119 default:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
120 throw OrthancException(ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
121 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
122 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
124
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
125 void Flatten(std::list<std::string>& resources) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
126 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
127 resources.clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
128
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
129 if (isFilterApplied_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
130 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
131 for (std::set<std::string>::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
132 it = filtered_.begin(); it != filtered_.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
133 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
134 resources.push_back(*it);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
135 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
136 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
137 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
138 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
139 index_.GetAllUuids(resources, level_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
140 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
141 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
142
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
143
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
144 void RestrictIdentifier(const IQuery& query,
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
145 const DicomTag& tag)
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
146 {
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
147 assert((level_ == ResourceType_Patient && tag == DICOM_TAG_PATIENT_ID) ||
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
148 (level_ == ResourceType_Study && tag == DICOM_TAG_STUDY_INSTANCE_UID) ||
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
149 (level_ == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) ||
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
150 (level_ == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) ||
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
151 (level_ == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID));
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
152
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
153 std::string value;
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
154 if (!query.RestrictIdentifier(value, tag))
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
155 {
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
156 return;
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
157 }
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
158
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
159 LOG(INFO) << "Lookup for identifier tag "
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
160 << FromDcmtkBridge::GetName(tag) << " (value: " << value << ")";
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
161
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
162 std::list<std::string> resources;
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
163 index_.LookupIdentifier(resources, tag, value, level_);
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
164
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
165 if (isFilterApplied_)
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
166 {
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
167 std::set<std::string> s;
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
168 ListToSet(s, resources);
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
169
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
170 std::set<std::string> tmp = filtered_;
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
171 filtered_.clear();
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
172
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
173 for (std::set<std::string>::const_iterator
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
174 it = tmp.begin(); it != tmp.end(); ++it)
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
175 {
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
176 if (s.find(*it) != s.end())
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
177 {
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
178 filtered_.insert(*it);
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
179 }
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
180 }
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
181 }
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
182 else
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
183 {
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
184 assert(filtered_.empty());
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
185 isFilterApplied_ = true;
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
186 ListToSet(filtered_, resources);
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
187 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
188 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
189
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
190
1677
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
191 void RestrictMainDicomTags(const IQuery& query,
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
192 bool filterPatientTagsAtStudyLevel)
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
193 {
1677
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
194 if (filterPatientTagsAtStudyLevel &&
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
195 level_ == ResourceType_Patient)
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
196 {
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
197 return;
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
198 }
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
199
1683
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
200 bool hasTagsAtThisLevel = query.HasMainDicomTagsFilter(level_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
201 bool hasTagsAtPatientLevel = (filterPatientTagsAtStudyLevel &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
202 level_ == ResourceType_Study &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
203 query.HasMainDicomTagsFilter(ResourceType_Patient));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
204
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
205 if (!hasTagsAtThisLevel && !hasTagsAtPatientLevel)
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
206 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
207 return;
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
210 std::list<std::string> resources;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
211 Flatten(resources);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
212
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
213 isFilterApplied_ = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
214 filtered_.clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
215
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
216 for (std::list<std::string>::const_iterator
1384
d6971e18a324 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
217 it = resources.begin(); it != resources.end(); ++it)
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
218 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
219 DicomMap mainTags;
1683
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
220
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
221 if (hasTagsAtThisLevel &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
222 (!index_.GetMainDicomTags(mainTags, *it, level_, level_) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
223 !query.FilterMainDicomTags(*it, level_, mainTags)))
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
224 {
1677
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
225 continue;
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
226 }
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
227
1683
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
228 if (hasTagsAtPatientLevel &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
229 (!index_.GetMainDicomTags(mainTags, *it, ResourceType_Study, ResourceType_Patient) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
230 !query.FilterMainDicomTags(*it, ResourceType_Patient, mainTags)))
1677
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
231 {
1683
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1677
diff changeset
232 continue;
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
233 }
1677
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
234
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
235 filtered_.insert(*it);
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
236 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
237 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
238 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
239
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
240
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
241 ResourceFinder::ResourceFinder(ServerContext& context) :
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
242 context_(context),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
243 maxResults_(0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
244 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
245 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
246
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
247
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
248 void ResourceFinder::ApplyAtLevel(CandidateResources& candidates,
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
249 const IQuery& query,
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
250 ResourceType level)
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
251 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
252 if (level != ResourceType_Patient)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
253 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
254 candidates.GoDown();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
255 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
256
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
257 switch (level)
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
258 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
259 case ResourceType_Patient:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
260 {
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
261 candidates.RestrictIdentifier(query, DICOM_TAG_PATIENT_ID);
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
262 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
263 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
264
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
265 case ResourceType_Study:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
266 {
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
267 candidates.RestrictIdentifier(query, DICOM_TAG_STUDY_INSTANCE_UID);
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
268 candidates.RestrictIdentifier(query, DICOM_TAG_ACCESSION_NUMBER);
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
269 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
270 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
271
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
272 case ResourceType_Series:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
273 {
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
274 candidates.RestrictIdentifier(query, DICOM_TAG_SERIES_INSTANCE_UID);
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
275 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
276 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
277
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
278 case ResourceType_Instance:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
279 {
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
280 candidates.RestrictIdentifier(query, DICOM_TAG_SOP_INSTANCE_UID);
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
281 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
282 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
283
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
284 default:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
285 throw OrthancException(ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
286 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
287
1677
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
288 if (query.GetLevel() == ResourceType_Patient)
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
289 {
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
290 candidates.RestrictMainDicomTags(query, false);
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
291 }
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
292 else
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
293 {
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
294 candidates.RestrictMainDicomTags(query, true);
a903d57d9f0c adaptation of search with patient tags at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
295 }
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
296 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
297
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
298
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
299
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
300 static bool LookupOneInstance(std::string& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
301 ServerIndex& index,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
302 const std::string& id,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
303 ResourceType type)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
304 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
305 if (type == ResourceType_Instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
306 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
307 result = id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
308 return true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
309 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
310
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
311 std::string childId;
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
313 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
314 std::list<std::string> children;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
315 index.GetChildInstances(children, id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
316
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
317 if (children.empty())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
318 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
319 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
320 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
321
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
322 childId = children.front();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
323 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
324
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
325 return LookupOneInstance(result, index, childId, GetChildResourceType(type));
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
328
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
329 bool ResourceFinder::Apply(std::list<std::string>& result,
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
330 const IQuery& query)
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
331 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
332 CandidateResources candidates(*this);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
333
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
334 ApplyAtLevel(candidates, query, ResourceType_Patient);
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
335
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
336 const ResourceType level = query.GetLevel();
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
337
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
338 if (level == ResourceType_Study ||
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
339 level == ResourceType_Series ||
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
340 level == ResourceType_Instance)
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
341 {
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
342 ApplyAtLevel(candidates, query, ResourceType_Study);
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
343 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
344
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
345 if (level == ResourceType_Series ||
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
346 level == ResourceType_Instance)
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
347 {
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
348 ApplyAtLevel(candidates, query, ResourceType_Series);
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
349 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
350
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
351 if (level == ResourceType_Instance)
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
352 {
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
353 ApplyAtLevel(candidates, query, ResourceType_Instance);
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
354 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
355
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
356 if (!query.HasInstanceFilter())
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
357 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
358 candidates.Flatten(result);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
360 if (maxResults_ != 0 &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
361 result.size() >= maxResults_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
362 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
363 result.resize(maxResults_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
364 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
365 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
366 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
367 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
368 return true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
369 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
370 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
371 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
372 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
373 std::list<std::string> tmp;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
374 candidates.Flatten(tmp);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
375
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
376 result.clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
377 for (std::list<std::string>::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
378 resource = tmp.begin(); resource != tmp.end(); ++resource)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
379 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
380 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
381 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
382 std::string instance;
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
383 if (LookupOneInstance(instance, context_.GetIndex(), *resource, level))
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
384 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
385 Json::Value content;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
386 context_.ReadJson(content, instance);
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1359
diff changeset
387 if (query.FilterInstance(*resource, content))
1359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
388 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
389 result.push_back(*resource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
390
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
391 if (maxResults_ != 0 &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
392 result.size() >= maxResults_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
393 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
394 // Too many results, stop before recording this new match
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
395 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
396 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
397 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
398 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
399 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
400 catch (OrthancException&)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
401 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
402 // This resource has been deleted since the search was started
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
403 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
404 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
405 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
406
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
407 return true; // All the matching resources have been returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
408 }
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 }