annotate Resources/Orthanc/Databases/DatabaseConstraint.cpp @ 456:0ac99983abfa pg-transactions

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