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