Mercurial > hg > orthanc
annotate OrthancServer/Search/LookupIdentifierQuery.h @ 1791:91a5d39ec665 worklists
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 18 Nov 2015 17:26:00 +0100 |
parents | 9ead18ef460a |
children | b1291df2f780 |
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 public: | |
133 LookupIdentifierQuery(ResourceType level) : level_(level) | |
134 { | |
135 } | |
136 | |
137 ~LookupIdentifierQuery(); | |
138 | |
1748 | 139 bool IsIdentifier(const DicomTag& tag) |
140 { | |
141 return IsIdentifier(tag, level_); | |
142 } | |
1745 | 143 |
144 void AddConstraint(DicomTag tag, | |
145 IdentifierConstraintType type, | |
146 const std::string& value); | |
147 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
148 Disjunction& AddDisjunction(); |
1748 | 149 |
1746 | 150 ResourceType GetLevel() const |
151 { | |
152 return level_; | |
153 } | |
154 | |
155 size_t GetSize() const | |
1745 | 156 { |
157 return constraints_.size(); | |
158 } | |
159 | |
1748 | 160 // The database must be locked |
161 void Apply(std::list<std::string>& result, | |
162 IDatabaseWrapper& database); | |
1745 | 163 |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
164 void Apply(SetOfResources& result, |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
165 IDatabaseWrapper& database); |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
166 |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
167 static void LoadIdentifiers(const DicomTag*& tags, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
168 size_t& size, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
169 ResourceType level); |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
170 |
1748 | 171 static bool IsIdentifier(const DicomTag& tag, |
172 ResourceType level); | |
1745 | 173 |
174 static void StoreIdentifiers(IDatabaseWrapper& database, | |
175 int64_t resource, | |
176 ResourceType level, | |
177 const DicomMap& map); | |
1758 | 178 |
1764 | 179 static std::string NormalizeIdentifier(const std::string& value); |
180 | |
1758 | 181 void Print(std::ostream& s) const; |
1745 | 182 }; |
183 } |