Mercurial > hg > orthanc
comparison OrthancServer/Search/DicomTagConstraint.cpp @ 3055:71ac4f28176f db-changes
compatibility layer seems to be working
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Dec 2018 13:36:30 +0100 |
parents | ea653ec47f31 |
children | caa03eaeb097 |
comparison
equal
deleted
inserted
replaced
3054:3638de45a08c | 3055:71ac4f28176f |
---|---|
34 #include "../PrecompiledHeadersServer.h" | 34 #include "../PrecompiledHeadersServer.h" |
35 #include "DicomTagConstraint.h" | 35 #include "DicomTagConstraint.h" |
36 | 36 |
37 #include "../../Core/OrthancException.h" | 37 #include "../../Core/OrthancException.h" |
38 #include "../../Core/Toolbox.h" | 38 #include "../../Core/Toolbox.h" |
39 #include "../ServerToolbox.h" | |
40 #include "DatabaseConstraint.h" | |
39 | 41 |
40 #include <boost/regex.hpp> | 42 #include <boost/regex.hpp> |
41 | 43 |
42 namespace Orthanc | 44 namespace Orthanc |
43 { | 45 { |
90 const boost::regex& GetValue() const | 92 const boost::regex& GetValue() const |
91 { | 93 { |
92 return regex_; | 94 return regex_; |
93 } | 95 } |
94 }; | 96 }; |
97 | |
98 | |
99 void DicomTagConstraint::AssignSingleValue(const std::string& value) | |
100 { | |
101 if (constraintType_ != ConstraintType_Wildcard && | |
102 (value.find('*') != std::string::npos || | |
103 value.find('?') != std::string::npos)) | |
104 { | |
105 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
106 } | |
107 | |
108 if (constraintType_ == ConstraintType_Equal || | |
109 constraintType_ == ConstraintType_SmallerOrEqual || | |
110 constraintType_ == ConstraintType_GreaterOrEqual || | |
111 constraintType_ == ConstraintType_Wildcard) | |
112 { | |
113 values_.clear(); | |
114 values_.insert(value); | |
115 } | |
116 else | |
117 { | |
118 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
119 } | |
120 } | |
95 | 121 |
96 | 122 |
97 DicomTagConstraint::DicomTagConstraint(const DicomTag& tag, | 123 DicomTagConstraint::DicomTagConstraint(const DicomTag& tag, |
98 ConstraintType type, | 124 ConstraintType type, |
99 const std::string& value, | 125 const std::string& value, |
102 tag_(tag), | 128 tag_(tag), |
103 constraintType_(type), | 129 constraintType_(type), |
104 caseSensitive_(caseSensitive), | 130 caseSensitive_(caseSensitive), |
105 mandatory_(mandatory) | 131 mandatory_(mandatory) |
106 { | 132 { |
107 if (type == ConstraintType_Equal || | 133 AssignSingleValue(value); |
108 type == ConstraintType_SmallerOrEqual || | |
109 type == ConstraintType_GreaterOrEqual || | |
110 type == ConstraintType_Wildcard) | |
111 { | |
112 values_.insert(value); | |
113 } | |
114 else | |
115 { | |
116 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
117 } | |
118 | |
119 if (type != ConstraintType_Wildcard && | |
120 (value.find('*') != std::string::npos || | |
121 value.find('?') != std::string::npos)) | |
122 { | |
123 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
124 } | |
125 } | 134 } |
126 | 135 |
127 | 136 |
128 DicomTagConstraint::DicomTagConstraint(const DicomTag& tag, | 137 DicomTagConstraint::DicomTagConstraint(const DicomTag& tag, |
129 ConstraintType type, | 138 ConstraintType type, |
135 mandatory_(mandatory) | 144 mandatory_(mandatory) |
136 { | 145 { |
137 if (type != ConstraintType_List) | 146 if (type != ConstraintType_List) |
138 { | 147 { |
139 throw OrthancException(ErrorCode_ParameterOutOfRange); | 148 throw OrthancException(ErrorCode_ParameterOutOfRange); |
149 } | |
150 } | |
151 | |
152 | |
153 DicomTagConstraint::DicomTagConstraint(const DatabaseConstraint& constraint) : | |
154 tag_(constraint.GetTag()), | |
155 constraintType_(constraint.GetConstraintType()), | |
156 caseSensitive_(constraint.IsCaseSensitive()), | |
157 mandatory_(constraint.IsMandatory()) | |
158 { | |
159 assert(constraint.IsIdentifier() == | |
160 ServerToolbox::IsIdentifier(constraint.GetTag(), constraint.GetLevel())); | |
161 | |
162 if (constraint.IsIdentifier()) | |
163 { | |
164 // This conversion is only available for main DICOM tags, not for identifers | |
165 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
166 } | |
167 | |
168 if (constraintType_ == ConstraintType_List) | |
169 { | |
170 for (size_t i = 0; i < constraint.GetValuesCount(); i++) | |
171 { | |
172 AddValue(constraint.GetValue(i)); | |
173 } | |
174 } | |
175 else | |
176 { | |
177 AssignSingleValue(constraint.GetSingleValue()); | |
140 } | 178 } |
141 } | 179 } |
142 | 180 |
143 | 181 |
144 void DicomTagConstraint::AddValue(const std::string& value) | 182 void DicomTagConstraint::AddValue(const std::string& value) |