Mercurial > hg > orthanc
annotate OrthancServer/Search/LookupIdentifierQuery.h @ 2314:c54c9523adf8 issue-46-anonymization
add basic profile
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 Jul 2017 22:09:27 +0200 |
parents | a3a65de1840f |
children | 878b59270859 |
rev | line source |
---|---|
1745 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1745 | 4 * Department, University Hospital of Liege, Belgium |
2244
a3a65de1840f
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2121
diff
changeset
|
5 * Copyright (C) 2017 Osimis, Belgium |
1745 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #pragma once | |
35 | |
2121 | 36 #include "../ServerToolbox.h" |
1747 | 37 #include "../IDatabaseWrapper.h" |
1745 | 38 |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
39 #include "SetOfResources.h" |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
40 |
1745 | 41 #include <vector> |
42 #include <boost/noncopyable.hpp> | |
43 | |
44 namespace Orthanc | |
45 { | |
46 /** | |
47 * Primitive for wildcard matching, as defined in DICOM: | |
48 * http://dicom.nema.org/dicom/2013/output/chtml/part04/sect_C.2.html#sect_C.2.2.2.4 | |
49 * | |
50 * "Any occurrence of an "*" or a "?", then "*" shall match any | |
51 * sequence of characters (including a zero length value) and "?" | |
52 * shall match any single character. This matching is case | |
53 * sensitive, except for Attributes with an PN Value | |
54 * Representation (e.g., Patient Name (0010,0010))." | |
55 * | |
56 * Pay attention to the fact that "*" (resp. "?") generally | |
57 * corresponds to "%" (resp. "_") in primitive LIKE of SQL. The | |
58 * values "%", "_", "\" should in the user request should | |
59 * respectively be escaped as "\%", "\_" and "\\". | |
1746 | 60 * |
1745 | 61 * This matching must be case sensitive: The special case of PN VR |
62 * is taken into consideration by normalizing the query string in | |
63 * method "NormalizeIdentifier()". | |
64 **/ | |
65 | |
66 class LookupIdentifierQuery : public boost::noncopyable | |
67 { | |
1748 | 68 public: |
69 class Constraint | |
1745 | 70 { |
1748 | 71 private: |
1745 | 72 DicomTag tag_; |
73 IdentifierConstraintType type_; | |
74 std::string value_; | |
75 | |
1748 | 76 public: |
1745 | 77 Constraint(const DicomTag& tag, |
78 IdentifierConstraintType type, | |
79 const std::string& value) : | |
80 tag_(tag), | |
81 type_(type), | |
2121 | 82 value_(ServerToolbox::NormalizeIdentifier(value)) |
1745 | 83 { |
84 } | |
1748 | 85 |
86 const DicomTag& GetTag() const | |
87 { | |
88 return tag_; | |
89 } | |
90 | |
91 IdentifierConstraintType GetType() const | |
92 { | |
93 return type_; | |
94 } | |
95 | |
96 const std::string& GetValue() const | |
97 { | |
98 return value_; | |
99 } | |
1745 | 100 }; |
101 | |
1748 | 102 |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
103 class Disjunction : public boost::noncopyable |
1748 | 104 { |
105 private: | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
106 std::vector<Constraint*> disjunction_; |
1748 | 107 |
108 public: | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
109 ~Disjunction(); |
1748 | 110 |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
111 void Add(const DicomTag& tag, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
112 IdentifierConstraintType type, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
113 const std::string& value); |
1748 | 114 |
115 size_t GetSize() const | |
116 { | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
117 return disjunction_.size(); |
1748 | 118 } |
119 | |
120 const Constraint& GetConstraint(size_t i) const | |
121 { | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
122 return *disjunction_[i]; |
1748 | 123 } |
124 }; | |
125 | |
126 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
127 private: |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
128 typedef std::vector<Disjunction*> Constraints; |
1745 | 129 |
130 ResourceType level_; | |
131 Constraints constraints_; | |
132 | |
133 public: | |
134 LookupIdentifierQuery(ResourceType level) : level_(level) | |
135 { | |
136 } | |
137 | |
138 ~LookupIdentifierQuery(); | |
139 | |
1748 | 140 bool IsIdentifier(const DicomTag& tag) |
141 { | |
2121 | 142 return ServerToolbox::IsIdentifier(tag, level_); |
1748 | 143 } |
1745 | 144 |
145 void AddConstraint(DicomTag tag, | |
146 IdentifierConstraintType type, | |
147 const std::string& value); | |
148 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
149 Disjunction& AddDisjunction(); |
1748 | 150 |
1746 | 151 ResourceType GetLevel() const |
152 { | |
153 return level_; | |
154 } | |
155 | |
156 size_t GetSize() const | |
1745 | 157 { |
158 return constraints_.size(); | |
159 } | |
160 | |
1748 | 161 // The database must be locked |
162 void Apply(std::list<std::string>& result, | |
163 IDatabaseWrapper& database); | |
1745 | 164 |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
165 void Apply(SetOfResources& result, |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
166 IDatabaseWrapper& database); |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
167 |
1758 | 168 void Print(std::ostream& s) const; |
1745 | 169 }; |
170 } |