comparison OrthancServer/UnitTestsSources/DatabaseLookupTests.cpp @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents UnitTestsSources/DatabaseLookupTests.cpp@94f4a18a79cc
children 05b8fd21089c
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
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-2020 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, true), OrthancException);
48 ASSERT_THROW(DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Equal,
49 "HEL?LO", true, true), OrthancException);
50 ASSERT_THROW(DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Equal,
51 true, true), OrthancException);
52
53 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Equal, "HELLO", true, 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 DicomMap m;
61 ASSERT_FALSE(tag.IsMatch(m));
62 m.SetNullValue(DICOM_TAG_PATIENT_NAME);
63 ASSERT_FALSE(tag.IsMatch(m));
64 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", true /* binary */);
65 ASSERT_FALSE(tag.IsMatch(m));
66 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false /* string */);
67 ASSERT_TRUE(tag.IsMatch(m));
68 }
69
70 {
71 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Equal, "HELlo", false, true);
72 ASSERT_TRUE(tag.IsMatch("HELLO"));
73 ASSERT_TRUE(tag.IsMatch("hello"));
74
75 ASSERT_EQ("HELlo", tag.GetValue());
76 }
77
78 {
79 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Wildcard, "HE*L?O", true, true);
80 ASSERT_TRUE(tag.IsMatch("HELLO"));
81 ASSERT_TRUE(tag.IsMatch("HELLLLLO"));
82 ASSERT_TRUE(tag.IsMatch("HELxO"));
83 ASSERT_FALSE(tag.IsMatch("hello"));
84 }
85
86 {
87 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_Wildcard, "HE*l?o", false, true);
88 ASSERT_TRUE(tag.IsMatch("HELLO"));
89 ASSERT_TRUE(tag.IsMatch("HELLLLLO"));
90 ASSERT_TRUE(tag.IsMatch("HELxO"));
91 ASSERT_TRUE(tag.IsMatch("hello"));
92
93 ASSERT_FALSE(tag.IsCaseSensitive());
94 ASSERT_EQ(ConstraintType_Wildcard, tag.GetConstraintType());
95 }
96
97 {
98 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_SmallerOrEqual, "123", true, true);
99 ASSERT_TRUE(tag.IsMatch("120"));
100 ASSERT_TRUE(tag.IsMatch("123"));
101 ASSERT_FALSE(tag.IsMatch("124"));
102 ASSERT_TRUE(tag.IsMandatory());
103 }
104
105 {
106 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_GreaterOrEqual, "123", true, false);
107 ASSERT_FALSE(tag.IsMatch("122"));
108 ASSERT_TRUE(tag.IsMatch("123"));
109 ASSERT_TRUE(tag.IsMatch("124"));
110 ASSERT_FALSE(tag.IsMandatory());
111 }
112
113 {
114 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_List, true, true);
115 ASSERT_FALSE(tag.IsMatch("CT"));
116 ASSERT_FALSE(tag.IsMatch("MR"));
117
118 tag.AddValue("CT");
119 ASSERT_TRUE(tag.IsMatch("CT"));
120 ASSERT_FALSE(tag.IsMatch("MR"));
121
122 tag.AddValue("MR");
123 ASSERT_TRUE(tag.IsMatch("CT"));
124 ASSERT_TRUE(tag.IsMatch("MR"));
125 ASSERT_FALSE(tag.IsMatch("ct"));
126 ASSERT_FALSE(tag.IsMatch("mr"));
127
128 ASSERT_THROW(tag.GetValue(), OrthancException);
129 ASSERT_EQ(2u, tag.GetValues().size());
130 }
131
132 {
133 DicomTagConstraint tag(DICOM_TAG_PATIENT_NAME, ConstraintType_List, false, true);
134
135 tag.AddValue("ct");
136 tag.AddValue("mr");
137
138 ASSERT_TRUE(tag.IsMatch("CT"));
139 ASSERT_TRUE(tag.IsMatch("MR"));
140 ASSERT_TRUE(tag.IsMatch("ct"));
141 ASSERT_TRUE(tag.IsMatch("mr"));
142 }
143 }
144
145
146
147 TEST(DatabaseLookup, FromDicom)
148 {
149 {
150 DatabaseLookup lookup;
151 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_ID, "HELLO", true, true);
152 ASSERT_EQ(1u, lookup.GetConstraintsCount());
153 ASSERT_EQ(ConstraintType_Equal, lookup.GetConstraint(0).GetConstraintType());
154 ASSERT_EQ("HELLO", lookup.GetConstraint(0).GetValue());
155 ASSERT_TRUE(lookup.GetConstraint(0).IsCaseSensitive());
156 }
157
158 {
159 DatabaseLookup lookup;
160 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_ID, "HELLO", false, true);
161 ASSERT_EQ(1u, lookup.GetConstraintsCount());
162
163 // This is *not* a PN VR => "false" above is *not* used
164 ASSERT_TRUE(lookup.GetConstraint(0).IsCaseSensitive());
165 }
166
167 {
168 DatabaseLookup lookup;
169 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_NAME, "HELLO", true, true);
170 ASSERT_EQ(1u, lookup.GetConstraintsCount());
171 ASSERT_TRUE(lookup.GetConstraint(0).IsCaseSensitive());
172 }
173
174 {
175 DatabaseLookup lookup;
176 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_NAME, "HELLO", false, true);
177 ASSERT_EQ(1u, lookup.GetConstraintsCount());
178
179 // This is a PN VR => "false" above is used
180 ASSERT_FALSE(lookup.GetConstraint(0).IsCaseSensitive());
181 }
182
183 {
184 DatabaseLookup lookup;
185 lookup.AddDicomConstraint(DICOM_TAG_SERIES_DESCRIPTION, "2012-2016", false, true);
186
187 // This is not a data VR
188 ASSERT_EQ(ConstraintType_Equal, lookup.GetConstraint(0).GetConstraintType());
189 }
190
191 {
192 DatabaseLookup lookup;
193 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_BIRTH_DATE, "2012-2016", false, true);
194
195 // This is a data VR => range is effective
196 ASSERT_EQ(2u, lookup.GetConstraintsCount());
197
198 ASSERT_TRUE(lookup.GetConstraint(0).GetConstraintType() != lookup.GetConstraint(1).GetConstraintType());
199
200 for (size_t i = 0; i < 2; i++)
201 {
202 ASSERT_TRUE(lookup.GetConstraint(i).GetConstraintType() == ConstraintType_SmallerOrEqual ||
203 lookup.GetConstraint(i).GetConstraintType() == ConstraintType_GreaterOrEqual);
204 }
205 }
206
207 {
208 DatabaseLookup lookup;
209 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_BIRTH_DATE, "2012-", false, true);
210
211 ASSERT_EQ(1u, lookup.GetConstraintsCount());
212 ASSERT_EQ(ConstraintType_GreaterOrEqual, lookup.GetConstraint(0).GetConstraintType());
213 ASSERT_EQ("2012", lookup.GetConstraint(0).GetValue());
214 }
215
216 {
217 DatabaseLookup lookup;
218 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_BIRTH_DATE, "-2016", false, true);
219
220 ASSERT_EQ(1u, lookup.GetConstraintsCount());
221 ASSERT_EQ(DICOM_TAG_PATIENT_BIRTH_DATE, lookup.GetConstraint(0).GetTag());
222 ASSERT_EQ(ConstraintType_SmallerOrEqual, lookup.GetConstraint(0).GetConstraintType());
223 ASSERT_EQ("2016", lookup.GetConstraint(0).GetValue());
224 }
225
226 {
227 DatabaseLookup lookup;
228 lookup.AddDicomConstraint(DICOM_TAG_MODALITIES_IN_STUDY, "CT\\MR", false, true);
229
230 ASSERT_EQ(1u, lookup.GetConstraintsCount());
231 ASSERT_EQ(DICOM_TAG_MODALITY, lookup.GetConstraint(0).GetTag());
232 ASSERT_EQ(ConstraintType_List, lookup.GetConstraint(0).GetConstraintType());
233
234 const std::set<std::string>& values = lookup.GetConstraint(0).GetValues();
235 ASSERT_EQ(2u, values.size());
236 ASSERT_TRUE(values.find("CT") != values.end());
237 ASSERT_TRUE(values.find("MR") != values.end());
238 ASSERT_TRUE(values.find("nope") == values.end());
239 }
240
241 {
242 DatabaseLookup lookup;
243 lookup.AddDicomConstraint(DICOM_TAG_STUDY_DESCRIPTION, "CT\\MR", false, true);
244
245 ASSERT_EQ(1u, lookup.GetConstraintsCount());
246 ASSERT_EQ(DICOM_TAG_STUDY_DESCRIPTION, lookup.GetConstraint(0).GetTag());
247 ASSERT_EQ(ConstraintType_List, lookup.GetConstraint(0).GetConstraintType());
248
249 const std::set<std::string>& values = lookup.GetConstraint(0).GetValues();
250 ASSERT_EQ(2u, values.size());
251 ASSERT_TRUE(values.find("CT") != values.end());
252 ASSERT_TRUE(values.find("MR") != values.end());
253 ASSERT_TRUE(values.find("nope") == values.end());
254 }
255
256 {
257 DatabaseLookup lookup;
258 lookup.AddDicomConstraint(DICOM_TAG_STUDY_DESCRIPTION, "HE*O", false, true);
259
260 ASSERT_EQ(1u, lookup.GetConstraintsCount());
261 ASSERT_EQ(ConstraintType_Wildcard, lookup.GetConstraint(0).GetConstraintType());
262 }
263
264 {
265 DatabaseLookup lookup;
266 lookup.AddDicomConstraint(DICOM_TAG_STUDY_DESCRIPTION, "HE?O", false, true);
267
268 ASSERT_EQ(1u, lookup.GetConstraintsCount());
269 ASSERT_EQ(ConstraintType_Wildcard, lookup.GetConstraint(0).GetConstraintType());
270 }
271
272 {
273 DatabaseLookup lookup;
274 lookup.AddDicomConstraint(DICOM_TAG_RELATED_FRAME_OF_REFERENCE_UID, "TEST", false, true);
275 lookup.AddDicomConstraint(DICOM_TAG_PATIENT_NAME, "TEST2", false, false);
276 ASSERT_TRUE(lookup.GetConstraint(0).IsMandatory());
277 ASSERT_FALSE(lookup.GetConstraint(1).IsMandatory());
278 }
279 }