annotate OrthancServer/OrthancFindRequestHandler.cpp @ 612:fdd5f7f9c4d7 find-move-scp

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Oct 2013 14:17:51 +0200
parents 9924aec1d694
children ec0b7a51d7bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
565
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege,
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
c931ac02db82 refactoring of find class
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
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include "OrthancFindRequestHandler.h"
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include <glog/logging.h>
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
35 #include <boost/regex.hpp>
565
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../Core/DicomFormat/DicomArray.h"
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
38 #include "ServerToolbox.h"
565
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace Orthanc
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
610
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
42 static std::string ToLowerCase(const std::string& s)
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
43 {
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
44 std::string result = s;
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
45 Toolbox::ToLowerCase(result);
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
46 return result;
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
47 }
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
48
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
49 static bool ApplyRangeConstraint(const std::string& value,
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
50 const std::string& constraint)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
51 {
610
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
52 size_t separator = constraint.find('-');
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
53 std::string lower = ToLowerCase(constraint.substr(0, separator));
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
54 std::string upper = ToLowerCase(constraint.substr(separator + 1));
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
55 std::string v = ToLowerCase(value);
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
56
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
57 if (lower.size() == 0 && upper.size() == 0)
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
58 {
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
59 return false;
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
60 }
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
61
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
62 if (lower.size() == 0)
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
63 {
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
64 return v <= upper;
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
65 }
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
66
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
67 if (upper.size() == 0)
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
68 {
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
69 return v >= lower;
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
70 }
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
71
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
72 return (v >= lower && v <= upper);
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
73 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
74
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
75
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
76 static bool ApplyListConstraint(const std::string& value,
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
77 const std::string& constraint)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
78 {
610
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
79 std::string v1 = ToLowerCase(value);
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
80
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
81 std::vector<std::string> items;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
82 Toolbox::TokenizeString(items, constraint, '\\');
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
83
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
84 for (size_t i = 0; i < items.size(); i++)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
85 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
86 Toolbox::ToLowerCase(items[i]);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
87 if (items[i] == v1)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
88 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
89 return true;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
90 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
91 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
92
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
93 return false;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
94 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
95
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
96
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
97 static bool Matches(const std::string& value,
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
98 const std::string& constraint)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
99 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
100 // http://www.itk.org/Wiki/DICOM_QueryRetrieve_Explained
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
101 // http://dicomiseasy.blogspot.be/2012/01/dicom-queryretrieve-part-i.html
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
102
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
103 if (constraint.find('-') != std::string::npos)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
104 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
105 return ApplyRangeConstraint(value, constraint);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
106 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
107
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
108 if (constraint.find('\\') != std::string::npos)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
109 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
110 return ApplyListConstraint(value, constraint);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
111 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
112
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
113 if (constraint.find('*') != std::string::npos ||
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
114 constraint.find('?') != std::string::npos)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
115 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
116 // TODO - Cache the constructed regular expression
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
117 boost::regex pattern(Toolbox::WildcardToRegularExpression(constraint),
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
118 boost::regex::icase /* case insensitive search */);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
119 return boost::regex_match(value, pattern);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
120 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
121 else
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
122 {
610
5ba825b87b21 fix static build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 608
diff changeset
123 return ToLowerCase(value) == ToLowerCase(constraint);
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
124 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
125 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
126
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
127
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
128 static bool LookupOneInstance(std::string& result,
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
129 ServerIndex& index,
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
130 const std::string& id,
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
131 ResourceType type)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
132 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
133 if (type == ResourceType_Instance)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
134 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
135 result = id;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
136 return true;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
137 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
138
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
139 std::string childId;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
140
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
141 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
142 std::list<std::string> children;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
143 index.GetChildInstances(children, id);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
144
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
145 if (children.size() == 0)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
146 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
147 return false;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
148 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
149
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
150 childId = children.front();
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
151 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
152
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
153 return LookupOneInstance(result, index, childId, GetChildResourceType(type));
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
154 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
155
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
156
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
157 static bool Matches(const Json::Value& resource,
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
158 const DicomArray& query)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
159 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
160 for (size_t i = 0; i < query.GetSize(); i++)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
161 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
162 if (query.GetElement(i).GetValue().IsNull() ||
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
163 query.GetElement(i).GetTag() == DICOM_TAG_QUERY_RETRIEVE_LEVEL ||
611
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
164 query.GetElement(i).GetTag() == DICOM_TAG_SPECIFIC_CHARACTER_SET ||
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
165 query.GetElement(i).GetTag() == DICOM_TAG_MODALITIES_IN_STUDY)
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
166 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
167 continue;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
168 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
169
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
170 std::string tag = query.GetElement(i).GetTag().Format();
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
171 std::string value;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
172 if (resource.isMember(tag))
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
173 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
174 value = resource.get(tag, Json::arrayValue).get("Value", "").asString();
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
175 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
176
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
177 if (!Matches(value, query.GetElement(i).GetValue().AsString()))
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
178 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
179 return false;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
180 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
181 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
182
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
183 return true;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
184 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
185
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
186
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
187 static void AddAnswer(DicomFindAnswers& answers,
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
188 const Json::Value& resource,
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
189 const DicomArray& query)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
190 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
191 DicomMap result;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
192
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
193 for (size_t i = 0; i < query.GetSize(); i++)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
194 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
195 if (query.GetElement(i).GetTag() != DICOM_TAG_QUERY_RETRIEVE_LEVEL &&
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
196 query.GetElement(i).GetTag() != DICOM_TAG_SPECIFIC_CHARACTER_SET)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
197 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
198 std::string tag = query.GetElement(i).GetTag().Format();
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
199 std::string value;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
200 if (resource.isMember(tag))
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
201 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
202 value = resource.get(tag, Json::arrayValue).get("Value", "").asString();
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
203 result.SetValue(query.GetElement(i).GetTag(), value);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
204 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
205 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
206 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
207
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
208 answers.Add(result);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
209 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
210
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
211
612
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
212 static bool ApplyModalitiesInStudyFilter(Json::Value& filteredStudies,
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
213 const Json::Value& studies,
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
214 const DicomMap& input,
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
215 ServerIndex& index)
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
216 {
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
217 filteredStudies = Json::arrayValue;
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
218
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
219 const DicomValue& v = input.GetValue(DICOM_TAG_MODALITIES_IN_STUDY);
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
220 if (v.IsNull())
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
221 {
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
222 return false;
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
223 }
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
224
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
225 // Move the allowed modalities into a "std::set"
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
226 std::vector<std::string> tmp;
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
227 Toolbox::TokenizeString(tmp, v.AsString(), '\\');
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
228
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
229 std::set<std::string> modalities;
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
230 for (size_t i = 0; i < tmp.size(); i++)
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
231 {
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
232 modalities.insert(tmp[i]);
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
233 }
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
234
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
235 // Loop over the studies
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
236 for (Json::Value::ArrayIndex i = 0; i < studies.size(); i++)
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
237 {
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
238 try
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
239 {
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
240 // We are considering a single study. Check whether one of
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
241 // its child series matches one of the modalities.
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
242 Json::Value study;
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
243 if (index.LookupResource(study, studies[i].asString(), ResourceType_Study))
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
244 {
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
245 // Loop over the series of the considered study.
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
246 for (Json::Value::ArrayIndex j = 0; j < study["Series"].size(); j++) // (*)
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
247 {
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
248 Json::Value series;
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
249 if (index.LookupResource(series, study["Series"][j].asString(), ResourceType_Series))
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
250 {
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
251 // Get the modality of this series
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
252 if (series["MainDicomTags"].isMember("Modality"))
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
253 {
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
254 std::string modality = series["MainDicomTags"]["Modality"].asString();
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
255 if (modalities.find(modality) != modalities.end())
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
256 {
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
257 // This series of the considered study matches one
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
258 // of the required modalities. Take the study into
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
259 // consideration for future filtering.
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
260 filteredStudies.append(studies[i]);
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
261
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
262 // We have finished considering this study. Break the study loop at (*).
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
263 break;
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
264 }
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
265 }
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
266 }
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
267 }
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
268 }
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
269 }
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
270 catch (OrthancException&)
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
271 {
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
272 // This resource has probably been deleted during the find request
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
273 }
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
274 }
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
275
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
276 return true;
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
277 }
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
278
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
279
565
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 void OrthancFindRequestHandler::Handle(const DicomMap& input,
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 DicomFindAnswers& answers)
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 {
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 LOG(WARNING) << "Find-SCU request received";
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 /**
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 * Retrieve the query level.
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 **/
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 const DicomValue* levelTmp = input.TestAndGetValue(DICOM_TAG_QUERY_RETRIEVE_LEVEL);
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 if (levelTmp == NULL)
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 {
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 throw OrthancException(ErrorCode_BadRequest);
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 }
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 ResourceType level = StringToResourceType(levelTmp->AsString().c_str());
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 if (level != ResourceType_Patient &&
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 level != ResourceType_Study &&
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 level != ResourceType_Series)
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 {
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 throw OrthancException(ErrorCode_NotImplemented);
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 }
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 /**
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
306 * Retrieve all the resources for this query level.
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
307 **/
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
308
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
309 Json::Value resources;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
310 context_.GetIndex().GetAllUuids(resources, level);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
311 assert(resources.type() == Json::arrayValue);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
312
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
313 // TODO : Speed up using MainDicomTags (to avoid looping over ALL
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
314 // the resources and reading the JSON file for each of them)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
315
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
316
611
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
317
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
318 /**
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
319 * Apply filtering on modalities for studies, if asked (this is an
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
320 * extension to standard DICOM)
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
321 * http://www.medicalconnections.co.uk/kb/Filtering_on_and_Retrieving_the_Modality_in_a_C_FIND
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
322 **/
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
323
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
324 if (level == ResourceType_Study &&
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
325 input.HasTag(DICOM_TAG_MODALITIES_IN_STUDY))
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
326 {
612
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
327 Json::Value filtered;
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
328 if (ApplyModalitiesInStudyFilter(filtered, resources, input, context_.GetIndex()))
611
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
329 {
612
fdd5f7f9c4d7 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
330 resources = filtered;
611
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
331 }
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
332 }
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
333
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
334
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
335 /**
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
336 * Loop over all the resources for this query level.
565
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 **/
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 DicomArray query(input);
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
340 for (Json::Value::ArrayIndex i = 0; i < resources.size(); i++)
565
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 {
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
342 try
565
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 {
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
344 std::string instance;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
345 if (LookupOneInstance(instance, context_.GetIndex(), resources[i].asString(), level))
565
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 {
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
347 Json::Value resource;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
348 context_.ReadJson(resource, instance);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
349
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
350 if (Matches(resource, query))
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
351 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
352 AddAnswer(answers, resource, query);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
353 }
565
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 }
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 }
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
356 catch (OrthancException&)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
357 {
611
9924aec1d694 filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
358 // This resource has probably been deleted during the find request
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 565
diff changeset
359 }
565
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 }
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 }
c931ac02db82 refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 }