comparison UnitTestsSources/DatabaseLookupTests.cpp @ 2893:1723cbba55c7 db-changes

testing DicomTagConstraint
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 16 Oct 2018 19:47:09 +0200
parents
children 039a9d262d64 4e43e67f8ecf
comparison
equal deleted inserted replaced
2892:ce310baccda6 2893:1723cbba55c7
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-2018 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 "PrecompiledHeadersUnitTests.h"
35 #include "gtest/gtest.h"
36
37 #include "../OrthancServer/Search/DatabaseLookup.h"
38 #include "../Core/OrthancException.h"
39
40 using namespace Orthanc;
41
42
43 TEST(DatabaseLookup, SingleConstraint)
44 {
45 {
46 ASSERT_THROW(DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Equal,
47 "HEL*LO", true), OrthancException);
48 ASSERT_THROW(DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Equal,
49 "HEL?LO", true), OrthancException);
50 ASSERT_THROW(DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Equal,
51 true), OrthancException);
52
53 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Equal, "HELLO", true);
54 ASSERT_TRUE(tag.IsMatch("HELLO"));
55 ASSERT_FALSE(tag.IsMatch("hello"));
56
57 ASSERT_TRUE(tag.IsCaseSensitive());
58 ASSERT_EQ(ConstraintType_Equal, tag.GetConstraintType());
59
60 ASSERT_FALSE(tag.HasTagInfo());
61 ASSERT_THROW(tag.GetTagType(), OrthancException);
62 ASSERT_THROW(tag.GetLevel(), OrthancException);
63
64 tag.SetTagInfo(DicomTagType_Identifier, ResourceType_Series);
65 ASSERT_TRUE(tag.HasTagInfo());
66 ASSERT_EQ(DicomTagType_Identifier, tag.GetTagType());
67 ASSERT_EQ(ResourceType_Series, tag.GetLevel());
68
69 DicomMap m;
70 ASSERT_FALSE(tag.IsMatch(m));
71 m.SetNullValue(DICOM_TAG_PATIENT_NAME);
72 ASSERT_FALSE(tag.IsMatch(m));
73 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", true /* binary */);
74 ASSERT_FALSE(tag.IsMatch(m));
75 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false /* string */);
76 ASSERT_TRUE(tag.IsMatch(m));
77 }
78
79 {
80 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Equal, "HELlo", false);
81 ASSERT_TRUE(tag.IsMatch("HELLO"));
82 ASSERT_TRUE(tag.IsMatch("hello"));
83
84 ASSERT_EQ("HELlo", tag.GetValue());
85 }
86
87 {
88 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Wildcard, "HE*L?O", true);
89 ASSERT_TRUE(tag.IsMatch("HELLO"));
90 ASSERT_TRUE(tag.IsMatch("HELLLLLO"));
91 ASSERT_TRUE(tag.IsMatch("HELxO"));
92 ASSERT_FALSE(tag.IsMatch("hello"));
93 }
94
95 {
96 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Wildcard, "HE*l?o", false);
97 ASSERT_TRUE(tag.IsMatch("HELLO"));
98 ASSERT_TRUE(tag.IsMatch("HELLLLLO"));
99 ASSERT_TRUE(tag.IsMatch("HELxO"));
100 ASSERT_TRUE(tag.IsMatch("hello"));
101
102 ASSERT_FALSE(tag.IsCaseSensitive());
103 ASSERT_EQ(ConstraintType_Wildcard, tag.GetConstraintType());
104 }
105
106 {
107 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_SmallerOrEqual, "123", true);
108 ASSERT_TRUE(tag.IsMatch("120"));
109 ASSERT_TRUE(tag.IsMatch("123"));
110 ASSERT_FALSE(tag.IsMatch("124"));
111 }
112
113 {
114 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_GreaterOrEqual, "123", true);
115 ASSERT_FALSE(tag.IsMatch("122"));
116 ASSERT_TRUE(tag.IsMatch("123"));
117 ASSERT_TRUE(tag.IsMatch("124"));
118 }
119
120 {
121 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_List, true);
122 ASSERT_FALSE(tag.IsMatch("CT"));
123 ASSERT_FALSE(tag.IsMatch("MR"));
124
125 tag.AddValue("CT");
126 ASSERT_TRUE(tag.IsMatch("CT"));
127 ASSERT_FALSE(tag.IsMatch("MR"));
128
129 tag.AddValue("MR");
130 ASSERT_TRUE(tag.IsMatch("CT"));
131 ASSERT_TRUE(tag.IsMatch("MR"));
132 ASSERT_FALSE(tag.IsMatch("ct"));
133 ASSERT_FALSE(tag.IsMatch("mr"));
134
135 ASSERT_THROW(tag.GetValue(), OrthancException);
136 ASSERT_EQ(2u, tag.GetValues().size());
137 }
138
139 {
140 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_List, false);
141
142 tag.AddValue("ct");
143 tag.AddValue("mr");
144
145 ASSERT_TRUE(tag.IsMatch("CT"));
146 ASSERT_TRUE(tag.IsMatch("MR"));
147 ASSERT_TRUE(tag.IsMatch("ct"));
148 ASSERT_TRUE(tag.IsMatch("mr"));
149 }
150 }
151
152
153
154 TEST(DatabaseLookup, FromDicom)
155 {
156 {
157 DatabaseLookup lookup;
158 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_ID, "HELLO", true);
159 ASSERT_EQ(1u, lookup.GetConstraintsCount());
160 ASSERT_EQ(ConstraintType_Equal, lookup.GetConstraint(0).GetConstraintType());
161 ASSERT_EQ("HELLO", lookup.GetConstraint(0).GetValue());
162 ASSERT_TRUE(lookup.GetConstraint(0).IsCaseSensitive());
163
164 ASSERT_TRUE(lookup.GetConstraint(0).HasTagInfo());
165 ASSERT_EQ(DicomTagType_Identifier, lookup.GetConstraint(0).GetTagType());
166 ASSERT_EQ(ResourceType_Patient, lookup.GetConstraint(0).GetLevel());
167 }
168
169 {
170 DatabaseLookup lookup;
171 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_ID, "HELLO", false);
172 ASSERT_EQ(1u, lookup.GetConstraintsCount());
173
174 // This is *not* a PN VR => "false" above is *not* used
175 ASSERT_TRUE(lookup.GetConstraint(0).IsCaseSensitive());
176 }
177
178 {
179 DatabaseLookup lookup;
180 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_NAME, "HELLO", true);
181 ASSERT_EQ(1u, lookup.GetConstraintsCount());
182 ASSERT_TRUE(lookup.GetConstraint(0).IsCaseSensitive());
183 }
184
185 {
186 DatabaseLookup lookup;
187 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_NAME, "HELLO", false);
188 ASSERT_EQ(1u, lookup.GetConstraintsCount());
189
190 // This is a PN VR => "false" above is used
191 ASSERT_FALSE(lookup.GetConstraint(0).IsCaseSensitive());
192 }
193
194 {
195 DatabaseLookup lookup;
196 lookup.AddDicomConstraint(DICOM_TAG_SERIES_DESCRIPTION, "2012-2016", false);
197
198 ASSERT_TRUE(lookup.GetConstraint(0).HasTagInfo());
199 ASSERT_EQ(DicomTagType_Main, lookup.GetConstraint(0).GetTagType());
200 ASSERT_EQ(ResourceType_Series, lookup.GetConstraint(0).GetLevel());
201
202 // This is not a data VR
203 ASSERT_EQ(ConstraintType_Equal, lookup.GetConstraint(0).GetConstraintType());
204 }
205
206 {
207 DatabaseLookup lookup;
208 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_BIRTH_DATE, "2012-2016", false);
209
210 // This is a data VR => range is effective
211 ASSERT_EQ(2u, lookup.GetConstraintsCount());
212
213 ASSERT_TRUE(lookup.GetConstraint(0).GetConstraintType() != lookup.GetConstraint(1).GetConstraintType());
214
215 for (size_t i = 0; i < 2; i++)
216 {
217 ASSERT_TRUE(lookup.GetConstraint(i).GetConstraintType() == ConstraintType_SmallerOrEqual ||
218 lookup.GetConstraint(i).GetConstraintType() == ConstraintType_GreaterOrEqual);
219 }
220 }
221
222 {
223 DatabaseLookup lookup;
224 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_BIRTH_DATE, "2012-", false);
225
226 ASSERT_EQ(1u, lookup.GetConstraintsCount());
227 ASSERT_EQ(ConstraintType_GreaterOrEqual, lookup.GetConstraint(0).GetConstraintType());
228 ASSERT_EQ("2012", lookup.GetConstraint(0).GetValue());
229 }
230
231 {
232 DatabaseLookup lookup;
233 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_BIRTH_DATE, "-2016", false);
234
235 ASSERT_EQ(1u, lookup.GetConstraintsCount());
236 ASSERT_EQ(DICOM_TAG_PATIENT_BIRTH_DATE, lookup.GetConstraint(0).GetTag());
237 ASSERT_EQ(ConstraintType_SmallerOrEqual, lookup.GetConstraint(0).GetConstraintType());
238 ASSERT_EQ("2016", lookup.GetConstraint(0).GetValue());
239 }
240
241 {
242 DatabaseLookup lookup;
243 lookup.AddDicomConstraint(DICOM_TAG_MODALITIES_IN_STUDY, "CT\\MR", false);
244
245 ASSERT_EQ(1u, lookup.GetConstraintsCount());
246 ASSERT_EQ(DICOM_TAG_MODALITY, lookup.GetConstraint(0).GetTag());
247 ASSERT_EQ(ResourceType_Series, lookup.GetConstraint(0).GetLevel());
248 ASSERT_EQ(ConstraintType_List, lookup.GetConstraint(0).GetConstraintType());
249
250 const std::set<std::string>& values = lookup.GetConstraint(0).GetValues();
251 ASSERT_EQ(2u, values.size());
252 ASSERT_TRUE(values.find("CT") != values.end());
253 ASSERT_TRUE(values.find("MR") != values.end());
254 ASSERT_TRUE(values.find("nope") == values.end());
255 }
256
257 {
258 DatabaseLookup lookup;
259 lookup.AddDicomConstraint(DICOM_TAG_STUDY_DESCRIPTION, "CT\\MR", false);
260
261 ASSERT_EQ(1u, lookup.GetConstraintsCount());
262 ASSERT_EQ(DICOM_TAG_STUDY_DESCRIPTION, lookup.GetConstraint(0).GetTag());
263 ASSERT_EQ(ResourceType_Study, lookup.GetConstraint(0).GetLevel());
264 ASSERT_EQ(ConstraintType_List, lookup.GetConstraint(0).GetConstraintType());
265
266 const std::set<std::string>& values = lookup.GetConstraint(0).GetValues();
267 ASSERT_EQ(2u, values.size());
268 ASSERT_TRUE(values.find("CT") != values.end());
269 ASSERT_TRUE(values.find("MR") != values.end());
270 ASSERT_TRUE(values.find("nope") == values.end());
271 }
272
273 {
274 DatabaseLookup lookup;
275 lookup.AddDicomConstraint(DICOM_TAG_STUDY_DESCRIPTION, "HE*O", false);
276
277 ASSERT_EQ(1u, lookup.GetConstraintsCount());
278 ASSERT_EQ(ConstraintType_Wildcard, lookup.GetConstraint(0).GetConstraintType());
279 }
280
281 {
282 DatabaseLookup lookup;
283 lookup.AddDicomConstraint(DICOM_TAG_STUDY_DESCRIPTION, "HE?O", false);
284
285 ASSERT_EQ(1u, lookup.GetConstraintsCount());
286 ASSERT_EQ(ConstraintType_Wildcard, lookup.GetConstraint(0).GetConstraintType());
287 }
288
289 {
290 DatabaseLookup lookup;
291 lookup.AddDicomConstraint(DICOM_TAG_RELATED_FRAME_OF_REFERENCE_UID, "TEST", false);
292
293 ASSERT_TRUE(lookup.GetConstraint(0).HasTagInfo());
294 ASSERT_EQ(DicomTagType_Generic, lookup.GetConstraint(0).GetTagType());
295 ASSERT_EQ(ResourceType_Instance, lookup.GetConstraint(0).GetLevel());
296 }
297 }