Mercurial > hg > orthanc
annotate OrthancServer/Search/LookupIdentifierQuery.h @ 1759:e268412adcf1 db-changes
removal of old implementation of search
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Oct 2015 12:59:18 +0100 |
parents | 318c2e83c2bd |
children | 9ead18ef460a |
rev | line source |
---|---|
1745 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, 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 | |
33 #pragma once | |
34 | |
1747 | 35 #include "../ServerEnumerations.h" |
36 #include "../IDatabaseWrapper.h" | |
1745 | 37 |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
38 #include "SetOfResources.h" |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
39 |
1745 | 40 #include <vector> |
41 #include <boost/noncopyable.hpp> | |
42 | |
43 namespace Orthanc | |
44 { | |
45 /** | |
46 * Primitive for wildcard matching, as defined in DICOM: | |
47 * http://dicom.nema.org/dicom/2013/output/chtml/part04/sect_C.2.html#sect_C.2.2.2.4 | |
48 * | |
49 * "Any occurrence of an "*" or a "?", then "*" shall match any | |
50 * sequence of characters (including a zero length value) and "?" | |
51 * shall match any single character. This matching is case | |
52 * sensitive, except for Attributes with an PN Value | |
53 * Representation (e.g., Patient Name (0010,0010))." | |
54 * | |
55 * Pay attention to the fact that "*" (resp. "?") generally | |
56 * corresponds to "%" (resp. "_") in primitive LIKE of SQL. The | |
57 * values "%", "_", "\" should in the user request should | |
58 * respectively be escaped as "\%", "\_" and "\\". | |
1746 | 59 * |
1745 | 60 * This matching must be case sensitive: The special case of PN VR |
61 * is taken into consideration by normalizing the query string in | |
62 * method "NormalizeIdentifier()". | |
63 **/ | |
64 | |
65 class LookupIdentifierQuery : public boost::noncopyable | |
66 { | |
1748 | 67 public: |
68 class Constraint | |
1745 | 69 { |
1748 | 70 private: |
1745 | 71 DicomTag tag_; |
72 IdentifierConstraintType type_; | |
73 std::string value_; | |
74 | |
1748 | 75 public: |
1745 | 76 Constraint(const DicomTag& tag, |
77 IdentifierConstraintType type, | |
78 const std::string& value) : | |
79 tag_(tag), | |
80 type_(type), | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
81 value_(NormalizeIdentifier(value)) |
1745 | 82 { |
83 } | |
1748 | 84 |
85 const DicomTag& GetTag() const | |
86 { | |
87 return tag_; | |
88 } | |
89 | |
90 IdentifierConstraintType GetType() const | |
91 { | |
92 return type_; | |
93 } | |
94 | |
95 const std::string& GetValue() const | |
96 { | |
97 return value_; | |
98 } | |
1745 | 99 }; |
100 | |
1748 | 101 |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
102 class Disjunction : public boost::noncopyable |
1748 | 103 { |
104 private: | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
105 std::vector<Constraint*> disjunction_; |
1748 | 106 |
107 public: | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
108 ~Disjunction(); |
1748 | 109 |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
110 void Add(const DicomTag& tag, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
111 IdentifierConstraintType type, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
112 const std::string& value); |
1748 | 113 |
114 size_t GetSize() const | |
115 { | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
116 return disjunction_.size(); |
1748 | 117 } |
118 | |
119 const Constraint& GetConstraint(size_t i) const | |
120 { | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
121 return *disjunction_[i]; |
1748 | 122 } |
123 }; | |
124 | |
125 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
126 private: |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
127 typedef std::vector<Disjunction*> Constraints; |
1745 | 128 |
129 ResourceType level_; | |
130 Constraints constraints_; | |
131 | |
132 static std::string NormalizeIdentifier(const std::string& value); | |
133 | |
134 public: | |
135 LookupIdentifierQuery(ResourceType level) : level_(level) | |
136 { | |
137 } | |
138 | |
139 ~LookupIdentifierQuery(); | |
140 | |
1748 | 141 bool IsIdentifier(const DicomTag& tag) |
142 { | |
143 return IsIdentifier(tag, level_); | |
144 } | |
1745 | 145 |
146 void AddConstraint(DicomTag tag, | |
147 IdentifierConstraintType type, | |
148 const std::string& value); | |
149 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
150 Disjunction& AddDisjunction(); |
1748 | 151 |
1746 | 152 ResourceType GetLevel() const |
153 { | |
154 return level_; | |
155 } | |
156 | |
157 size_t GetSize() const | |
1745 | 158 { |
159 return constraints_.size(); | |
160 } | |
161 | |
1748 | 162 // The database must be locked |
163 void Apply(std::list<std::string>& result, | |
164 IDatabaseWrapper& database); | |
1745 | 165 |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
166 void Apply(SetOfResources& result, |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
167 IDatabaseWrapper& database); |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
168 |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
169 static void LoadIdentifiers(const DicomTag*& tags, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
170 size_t& size, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
171 ResourceType level); |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
172 |
1748 | 173 static bool IsIdentifier(const DicomTag& tag, |
174 ResourceType level); | |
1745 | 175 |
176 static void StoreIdentifiers(IDatabaseWrapper& database, | |
177 int64_t resource, | |
178 ResourceType level, | |
179 const DicomMap& map); | |
1758 | 180 |
181 void Print(std::ostream& s) const; | |
1745 | 182 }; |
183 } |