Mercurial > hg > orthanc-databases
comparison Framework/Plugins/DatabaseConstraint.h @ 547:b8e6e7a19424
un-sharing DatabaseConstraint and ISqlLookupFormatter with Orthanc core
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Sep 2024 13:18:35 +0200 |
parents | |
children | 25005693297b |
comparison
equal
deleted
inserted
replaced
542:a8f9d44e7842 | 547:b8e6e7a19424 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium | |
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium | |
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
8 * | |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU Affero General Public License | |
11 * as published by the Free Software Foundation, either version 3 of | |
12 * the License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * Affero General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU Affero General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 /** | |
25 * NB: Until 2024-09-09, this file was synchronized with the following | |
26 * folder from the Orthanc main project: | |
27 * https://orthanc.uclouvain.be/hg/orthanc/file/default/OrthancServer/Sources/Search/ | |
28 **/ | |
29 | |
30 | |
31 #pragma once | |
32 | |
33 #if !defined(ORTHANC_BUILDING_SERVER_LIBRARY) | |
34 # error Macro ORTHANC_BUILDING_SERVER_LIBRARY must be defined | |
35 #endif | |
36 | |
37 #if ORTHANC_BUILDING_SERVER_LIBRARY == 1 | |
38 # include "../../../OrthancFramework/Sources/DicomFormat/DicomMap.h" | |
39 #else | |
40 // This is for the "orthanc-databases" project to reuse this file | |
41 # include <DicomFormat/DicomMap.h> | |
42 #endif | |
43 | |
44 #define ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT 0 | |
45 | |
46 #if ORTHANC_ENABLE_PLUGINS == 1 | |
47 # include <orthanc/OrthancCDatabasePlugin.h> | |
48 # if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1 | |
49 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 2) | |
50 # undef ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT | |
51 # define ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT 1 | |
52 # endif | |
53 # endif | |
54 #endif | |
55 | |
56 #include <deque> | |
57 | |
58 namespace Orthanc | |
59 { | |
60 enum ConstraintType | |
61 { | |
62 ConstraintType_Equal, | |
63 ConstraintType_SmallerOrEqual, | |
64 ConstraintType_GreaterOrEqual, | |
65 ConstraintType_Wildcard, | |
66 ConstraintType_List | |
67 }; | |
68 | |
69 namespace Plugins | |
70 { | |
71 #if ORTHANC_ENABLE_PLUGINS == 1 | |
72 OrthancPluginResourceType Convert(ResourceType type); | |
73 #endif | |
74 | |
75 #if ORTHANC_ENABLE_PLUGINS == 1 | |
76 ResourceType Convert(OrthancPluginResourceType type); | |
77 #endif | |
78 | |
79 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | |
80 OrthancPluginConstraintType Convert(ConstraintType constraint); | |
81 #endif | |
82 | |
83 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | |
84 ConstraintType Convert(OrthancPluginConstraintType constraint); | |
85 #endif | |
86 } | |
87 | |
88 | |
89 // This class is also used by the "orthanc-databases" project | |
90 class DatabaseConstraint : public boost::noncopyable | |
91 { | |
92 private: | |
93 ResourceType level_; | |
94 DicomTag tag_; | |
95 bool isIdentifier_; | |
96 ConstraintType constraintType_; | |
97 std::vector<std::string> values_; | |
98 bool caseSensitive_; | |
99 bool mandatory_; | |
100 | |
101 public: | |
102 DatabaseConstraint(ResourceType level, | |
103 const DicomTag& tag, | |
104 bool isIdentifier, | |
105 ConstraintType type, | |
106 const std::vector<std::string>& values, | |
107 bool caseSensitive, | |
108 bool mandatory); | |
109 | |
110 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | |
111 explicit DatabaseConstraint(const OrthancPluginDatabaseConstraint& constraint); | |
112 #endif | |
113 | |
114 ResourceType GetLevel() const | |
115 { | |
116 return level_; | |
117 } | |
118 | |
119 const DicomTag& GetTag() const | |
120 { | |
121 return tag_; | |
122 } | |
123 | |
124 bool IsIdentifier() const | |
125 { | |
126 return isIdentifier_; | |
127 } | |
128 | |
129 ConstraintType GetConstraintType() const | |
130 { | |
131 return constraintType_; | |
132 } | |
133 | |
134 size_t GetValuesCount() const | |
135 { | |
136 return values_.size(); | |
137 } | |
138 | |
139 const std::string& GetValue(size_t index) const; | |
140 | |
141 const std::string& GetSingleValue() const; | |
142 | |
143 bool IsCaseSensitive() const | |
144 { | |
145 return caseSensitive_; | |
146 } | |
147 | |
148 bool IsMandatory() const | |
149 { | |
150 return mandatory_; | |
151 } | |
152 | |
153 bool IsMatch(const DicomMap& dicom) const; | |
154 | |
155 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | |
156 void EncodeForPlugins(OrthancPluginDatabaseConstraint& constraint, | |
157 std::vector<const char*>& tmpValues) const; | |
158 #endif | |
159 }; | |
160 | |
161 | |
162 class DatabaseConstraints : public boost::noncopyable | |
163 { | |
164 private: | |
165 std::deque<DatabaseConstraint*> constraints_; | |
166 | |
167 public: | |
168 ~DatabaseConstraints() | |
169 { | |
170 Clear(); | |
171 } | |
172 | |
173 void Clear(); | |
174 | |
175 void AddConstraint(DatabaseConstraint* constraint); // Takes ownership | |
176 | |
177 bool IsEmpty() const | |
178 { | |
179 return constraints_.empty(); | |
180 } | |
181 | |
182 size_t GetSize() const | |
183 { | |
184 return constraints_.size(); | |
185 } | |
186 | |
187 const DatabaseConstraint& GetConstraint(size_t index) const; | |
188 }; | |
189 } |