Mercurial > hg > orthanc-databases
annotate Resources/Orthanc/Databases/DatabaseConstraint.cpp @ 505:38e428f8179d
more detailed error messages
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Fri, 24 May 2024 16:39:38 +0200 |
parents | ecd0b719cff5 |
children | 54d518dcd74a |
rev | line source |
---|---|
152 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
459
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
397
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
397
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
152 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #if !defined(ORTHANC_BUILDING_SERVER_LIBRARY) | |
24 # error Macro ORTHANC_BUILDING_SERVER_LIBRARY must be defined | |
25 #endif | |
26 | |
27 #if ORTHANC_BUILDING_SERVER_LIBRARY == 1 | |
28 # include "../PrecompiledHeadersServer.h" | |
29 #endif | |
30 | |
31 #include "DatabaseConstraint.h" | |
32 | |
33 #if ORTHANC_BUILDING_SERVER_LIBRARY == 1 | |
34 # include "../../../OrthancFramework/Sources/OrthancException.h" | |
35 #else | |
36 # include <OrthancException.h> | |
37 #endif | |
38 | |
170 | 39 #include <cassert> |
40 | |
41 | |
152 | 42 namespace Orthanc |
43 { | |
44 namespace Plugins | |
45 { | |
46 #if ORTHANC_ENABLE_PLUGINS == 1 | |
47 OrthancPluginResourceType Convert(ResourceType type) | |
48 { | |
49 switch (type) | |
50 { | |
51 case ResourceType_Patient: | |
52 return OrthancPluginResourceType_Patient; | |
53 | |
54 case ResourceType_Study: | |
55 return OrthancPluginResourceType_Study; | |
56 | |
57 case ResourceType_Series: | |
58 return OrthancPluginResourceType_Series; | |
59 | |
60 case ResourceType_Instance: | |
61 return OrthancPluginResourceType_Instance; | |
62 | |
63 default: | |
64 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
65 } | |
66 } | |
67 #endif | |
68 | |
69 | |
70 #if ORTHANC_ENABLE_PLUGINS == 1 | |
71 ResourceType Convert(OrthancPluginResourceType type) | |
72 { | |
73 switch (type) | |
74 { | |
75 case OrthancPluginResourceType_Patient: | |
76 return ResourceType_Patient; | |
77 | |
78 case OrthancPluginResourceType_Study: | |
79 return ResourceType_Study; | |
80 | |
81 case OrthancPluginResourceType_Series: | |
82 return ResourceType_Series; | |
83 | |
84 case OrthancPluginResourceType_Instance: | |
85 return ResourceType_Instance; | |
86 | |
87 default: | |
88 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
89 } | |
90 } | |
91 #endif | |
92 | |
93 | |
94 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | |
95 OrthancPluginConstraintType Convert(ConstraintType constraint) | |
96 { | |
97 switch (constraint) | |
98 { | |
99 case ConstraintType_Equal: | |
100 return OrthancPluginConstraintType_Equal; | |
101 | |
102 case ConstraintType_GreaterOrEqual: | |
103 return OrthancPluginConstraintType_GreaterOrEqual; | |
104 | |
105 case ConstraintType_SmallerOrEqual: | |
106 return OrthancPluginConstraintType_SmallerOrEqual; | |
107 | |
108 case ConstraintType_Wildcard: | |
109 return OrthancPluginConstraintType_Wildcard; | |
110 | |
111 case ConstraintType_List: | |
112 return OrthancPluginConstraintType_List; | |
113 | |
114 default: | |
115 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
116 } | |
117 } | |
118 #endif | |
119 | |
120 | |
121 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | |
122 ConstraintType Convert(OrthancPluginConstraintType constraint) | |
123 { | |
124 switch (constraint) | |
125 { | |
126 case OrthancPluginConstraintType_Equal: | |
127 return ConstraintType_Equal; | |
128 | |
129 case OrthancPluginConstraintType_GreaterOrEqual: | |
130 return ConstraintType_GreaterOrEqual; | |
131 | |
132 case OrthancPluginConstraintType_SmallerOrEqual: | |
133 return ConstraintType_SmallerOrEqual; | |
134 | |
135 case OrthancPluginConstraintType_Wildcard: | |
136 return ConstraintType_Wildcard; | |
137 | |
138 case OrthancPluginConstraintType_List: | |
139 return ConstraintType_List; | |
140 | |
141 default: | |
142 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
143 } | |
144 } | |
145 #endif | |
146 } | |
147 | |
148 DatabaseConstraint::DatabaseConstraint(ResourceType level, | |
149 const DicomTag& tag, | |
150 bool isIdentifier, | |
151 ConstraintType type, | |
152 const std::vector<std::string>& values, | |
153 bool caseSensitive, | |
154 bool mandatory) : | |
155 level_(level), | |
156 tag_(tag), | |
157 isIdentifier_(isIdentifier), | |
158 constraintType_(type), | |
159 values_(values), | |
160 caseSensitive_(caseSensitive), | |
161 mandatory_(mandatory) | |
162 { | |
163 if (type != ConstraintType_List && | |
164 values_.size() != 1) | |
165 { | |
166 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
167 } | |
168 } | |
169 | |
170 | |
171 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | |
172 DatabaseConstraint::DatabaseConstraint(const OrthancPluginDatabaseConstraint& constraint) : | |
173 level_(Plugins::Convert(constraint.level)), | |
174 tag_(constraint.tagGroup, constraint.tagElement), | |
175 isIdentifier_(constraint.isIdentifierTag), | |
176 constraintType_(Plugins::Convert(constraint.type)), | |
177 caseSensitive_(constraint.isCaseSensitive), | |
178 mandatory_(constraint.isMandatory) | |
179 { | |
180 if (constraintType_ != ConstraintType_List && | |
181 constraint.valuesCount != 1) | |
182 { | |
183 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
184 } | |
185 | |
186 values_.resize(constraint.valuesCount); | |
187 | |
188 for (uint32_t i = 0; i < constraint.valuesCount; i++) | |
189 { | |
190 assert(constraint.values[i] != NULL); | |
191 values_[i].assign(constraint.values[i]); | |
192 } | |
193 } | |
194 #endif | |
195 | |
196 | |
197 const std::string& DatabaseConstraint::GetValue(size_t index) const | |
198 { | |
199 if (index >= values_.size()) | |
200 { | |
201 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
202 } | |
203 else | |
204 { | |
205 return values_[index]; | |
206 } | |
207 } | |
208 | |
209 | |
210 const std::string& DatabaseConstraint::GetSingleValue() const | |
211 { | |
212 if (values_.size() != 1) | |
213 { | |
214 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
215 } | |
216 else | |
217 { | |
218 return values_[0]; | |
219 } | |
220 } | |
221 | |
222 | |
223 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | |
224 void DatabaseConstraint::EncodeForPlugins(OrthancPluginDatabaseConstraint& constraint, | |
225 std::vector<const char*>& tmpValues) const | |
226 { | |
227 memset(&constraint, 0, sizeof(constraint)); | |
228 | |
229 tmpValues.resize(values_.size()); | |
230 | |
231 for (size_t i = 0; i < values_.size(); i++) | |
232 { | |
233 tmpValues[i] = values_[i].c_str(); | |
234 } | |
235 | |
236 constraint.level = Plugins::Convert(level_); | |
237 constraint.tagGroup = tag_.GetGroup(); | |
238 constraint.tagElement = tag_.GetElement(); | |
239 constraint.isIdentifierTag = isIdentifier_; | |
240 constraint.isCaseSensitive = caseSensitive_; | |
241 constraint.isMandatory = mandatory_; | |
242 constraint.type = Plugins::Convert(constraintType_); | |
243 constraint.valuesCount = values_.size(); | |
244 constraint.values = (tmpValues.empty() ? NULL : &tmpValues[0]); | |
245 } | |
246 #endif | |
247 } |