annotate OrthancServer/Search/IFindConstraint.cpp @ 2299:03982a0db696

Fix issue #29 (more consistent handling of the "--upgrade" argument)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Jul 2017 15:52:47 +0200
parents a3a65de1840f
children 7284093111b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2244
a3a65de1840f shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2006
diff changeset
5 * Copyright (C) 2017 Osimis, Belgium
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../PrecompiledHeadersServer.h"
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "IFindConstraint.h"
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "ListConstraint.h"
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "RangeConstraint.h"
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "ValueConstraint.h"
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include "WildcardConstraint.h"
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
1792
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1791
diff changeset
42 #include "../FromDcmtkBridge.h"
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1791
diff changeset
43 #include "../../Core/OrthancException.h"
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1791
diff changeset
44
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 namespace Orthanc
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 IFindConstraint* IFindConstraint::ParseDicomConstraint(const DicomTag& tag,
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 const std::string& dicomQuery,
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 bool caseSensitive)
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
51 ValueRepresentation vr = FromDcmtkBridge::LookupValueRepresentation(tag);
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
1792
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1791
diff changeset
53 if (vr == ValueRepresentation_Sequence)
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1791
diff changeset
54 {
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1791
diff changeset
55 throw OrthancException(ErrorCode_ParameterOutOfRange);
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1791
diff changeset
56 }
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1791
diff changeset
57
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 if ((vr == ValueRepresentation_Date ||
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 vr == ValueRepresentation_DateTime ||
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 vr == ValueRepresentation_Time) &&
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 dicomQuery.find('-') != std::string::npos)
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 /**
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 * Range matching is only defined for TM, DA and DT value
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 * representations. This code fixes issues 35 and 37.
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 *
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 * Reference: "Range matching is not defined for types of
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 * Attributes other than dates and times", DICOM PS 3.4,
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 * C.2.2.2.5 ("Range Matching").
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 **/
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 size_t separator = dicomQuery.find('-');
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 std::string lower = dicomQuery.substr(0, separator);
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 std::string upper = dicomQuery.substr(separator + 1);
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 return new RangeConstraint(lower, upper, caseSensitive);
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 else if (dicomQuery.find('\\') != std::string::npos)
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 std::auto_ptr<ListConstraint> constraint(new ListConstraint(caseSensitive));
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 std::vector<std::string> items;
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 Toolbox::TokenizeString(items, dicomQuery, '\\');
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 for (size_t i = 0; i < items.size(); i++)
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 constraint->AddAllowedValue(items[i]);
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 return constraint.release();
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 else if (dicomQuery.find('*') != std::string::npos ||
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 dicomQuery.find('?') != std::string::npos)
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 return new WildcardConstraint(dicomQuery, caseSensitive);
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 else
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 /**
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 * Case-insensitive match for PN value representation (Patient
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 * Name). Case-senstive match for all the other value
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 * representations.
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 *
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 * Reference: DICOM PS 3.4
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 * - C.2.2.2.1 ("Single Value Matching")
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 * - C.2.2.2.4 ("Wild Card Matching")
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 * http://medical.nema.org/Dicom/2011/11_04pu.pdf
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 *
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 * "Except for Attributes with a PN Value Representation, only
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 * entities with values which match exactly the value specified in the
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 * request shall match. This matching is case-sensitive, i.e.,
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 * sensitive to the exact encoding of the key attribute value in
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 * character sets where a letter may have multiple encodings (e.g.,
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 * based on its case, its position in a word, or whether it is
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 * accented)
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 *
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 * For Attributes with a PN Value Representation (e.g., Patient Name
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 * (0010,0010)), an application may perform literal matching that is
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 * either case-sensitive, or that is insensitive to some or all
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 * aspects of case, position, accent, or other character encoding
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 * variants."
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 *
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 * (0008,0018) UI SOPInstanceUID => Case-sensitive
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 * (0008,0050) SH AccessionNumber => Case-sensitive
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 * (0010,0020) LO PatientID => Case-sensitive
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 * (0020,000D) UI StudyInstanceUID => Case-sensitive
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 * (0020,000E) UI SeriesInstanceUID => Case-sensitive
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 **/
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 return new ValueConstraint(dicomQuery, caseSensitive);
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }