comparison OrthancServer/Sources/Search/DatabaseConstraint.cpp @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents OrthancServer/Search/DatabaseConstraint.cpp@94f4a18a79cc
children 05b8fd21089c
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
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-2020 Osimis S.A., Belgium
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 #include "../PrecompiledHeadersServer.h"
35 #include "DatabaseConstraint.h"
36
37 #include "../../Core/OrthancException.h"
38
39
40 namespace Orthanc
41 {
42 namespace Plugins
43 {
44 #if ORTHANC_ENABLE_PLUGINS == 1
45 OrthancPluginResourceType Convert(ResourceType type)
46 {
47 switch (type)
48 {
49 case ResourceType_Patient:
50 return OrthancPluginResourceType_Patient;
51
52 case ResourceType_Study:
53 return OrthancPluginResourceType_Study;
54
55 case ResourceType_Series:
56 return OrthancPluginResourceType_Series;
57
58 case ResourceType_Instance:
59 return OrthancPluginResourceType_Instance;
60
61 default:
62 throw OrthancException(ErrorCode_ParameterOutOfRange);
63 }
64 }
65 #endif
66
67
68 #if ORTHANC_ENABLE_PLUGINS == 1
69 ResourceType Convert(OrthancPluginResourceType type)
70 {
71 switch (type)
72 {
73 case OrthancPluginResourceType_Patient:
74 return ResourceType_Patient;
75
76 case OrthancPluginResourceType_Study:
77 return ResourceType_Study;
78
79 case OrthancPluginResourceType_Series:
80 return ResourceType_Series;
81
82 case OrthancPluginResourceType_Instance:
83 return ResourceType_Instance;
84
85 default:
86 throw OrthancException(ErrorCode_ParameterOutOfRange);
87 }
88 }
89 #endif
90
91
92 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
93 OrthancPluginConstraintType Convert(ConstraintType constraint)
94 {
95 switch (constraint)
96 {
97 case ConstraintType_Equal:
98 return OrthancPluginConstraintType_Equal;
99
100 case ConstraintType_GreaterOrEqual:
101 return OrthancPluginConstraintType_GreaterOrEqual;
102
103 case ConstraintType_SmallerOrEqual:
104 return OrthancPluginConstraintType_SmallerOrEqual;
105
106 case ConstraintType_Wildcard:
107 return OrthancPluginConstraintType_Wildcard;
108
109 case ConstraintType_List:
110 return OrthancPluginConstraintType_List;
111
112 default:
113 throw OrthancException(ErrorCode_ParameterOutOfRange);
114 }
115 }
116 #endif
117
118
119 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
120 ConstraintType Convert(OrthancPluginConstraintType constraint)
121 {
122 switch (constraint)
123 {
124 case OrthancPluginConstraintType_Equal:
125 return ConstraintType_Equal;
126
127 case OrthancPluginConstraintType_GreaterOrEqual:
128 return ConstraintType_GreaterOrEqual;
129
130 case OrthancPluginConstraintType_SmallerOrEqual:
131 return ConstraintType_SmallerOrEqual;
132
133 case OrthancPluginConstraintType_Wildcard:
134 return ConstraintType_Wildcard;
135
136 case OrthancPluginConstraintType_List:
137 return ConstraintType_List;
138
139 default:
140 throw OrthancException(ErrorCode_ParameterOutOfRange);
141 }
142 }
143 #endif
144 }
145
146 DatabaseConstraint::DatabaseConstraint(ResourceType level,
147 const DicomTag& tag,
148 bool isIdentifier,
149 ConstraintType type,
150 const std::vector<std::string>& values,
151 bool caseSensitive,
152 bool mandatory) :
153 level_(level),
154 tag_(tag),
155 isIdentifier_(isIdentifier),
156 constraintType_(type),
157 values_(values),
158 caseSensitive_(caseSensitive),
159 mandatory_(mandatory)
160 {
161 if (type != ConstraintType_List &&
162 values_.size() != 1)
163 {
164 throw OrthancException(ErrorCode_ParameterOutOfRange);
165 }
166 }
167
168
169 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
170 DatabaseConstraint::DatabaseConstraint(const OrthancPluginDatabaseConstraint& constraint) :
171 level_(Plugins::Convert(constraint.level)),
172 tag_(constraint.tagGroup, constraint.tagElement),
173 isIdentifier_(constraint.isIdentifierTag),
174 constraintType_(Plugins::Convert(constraint.type)),
175 caseSensitive_(constraint.isCaseSensitive),
176 mandatory_(constraint.isMandatory)
177 {
178 if (constraintType_ != ConstraintType_List &&
179 constraint.valuesCount != 1)
180 {
181 throw OrthancException(ErrorCode_ParameterOutOfRange);
182 }
183
184 values_.resize(constraint.valuesCount);
185
186 for (uint32_t i = 0; i < constraint.valuesCount; i++)
187 {
188 assert(constraint.values[i] != NULL);
189 values_[i].assign(constraint.values[i]);
190 }
191 }
192 #endif
193
194
195 const std::string& DatabaseConstraint::GetValue(size_t index) const
196 {
197 if (index >= values_.size())
198 {
199 throw OrthancException(ErrorCode_ParameterOutOfRange);
200 }
201 else
202 {
203 return values_[index];
204 }
205 }
206
207
208 const std::string& DatabaseConstraint::GetSingleValue() const
209 {
210 if (values_.size() != 1)
211 {
212 throw OrthancException(ErrorCode_BadSequenceOfCalls);
213 }
214 else
215 {
216 return values_[0];
217 }
218 }
219
220
221 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
222 void DatabaseConstraint::EncodeForPlugins(OrthancPluginDatabaseConstraint& constraint,
223 std::vector<const char*>& tmpValues) const
224 {
225 memset(&constraint, 0, sizeof(constraint));
226
227 tmpValues.resize(values_.size());
228
229 for (size_t i = 0; i < values_.size(); i++)
230 {
231 tmpValues[i] = values_[i].c_str();
232 }
233
234 constraint.level = Plugins::Convert(level_);
235 constraint.tagGroup = tag_.GetGroup();
236 constraint.tagElement = tag_.GetElement();
237 constraint.isIdentifierTag = isIdentifier_;
238 constraint.isCaseSensitive = caseSensitive_;
239 constraint.isMandatory = mandatory_;
240 constraint.type = Plugins::Convert(constraintType_);
241 constraint.valuesCount = values_.size();
242 constraint.values = (tmpValues.empty() ? NULL : &tmpValues[0]);
243 }
244 #endif
245 }