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