Mercurial > hg > orthanc
annotate OrthancServer/Search/IFindConstraint.cpp @ 2562:1e66fe3ddf9f jobs
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 04 May 2018 17:28:47 +0200 |
parents | 878b59270859 |
children | 8fd203510d8b 4e43e67f8ecf |
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 |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
1791 | 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 "../PrecompiledHeadersServer.h" | |
35 #include "IFindConstraint.h" | |
36 | |
37 #include "ListConstraint.h" | |
38 #include "RangeConstraint.h" | |
39 #include "ValueConstraint.h" | |
40 #include "WildcardConstraint.h" | |
41 | |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
42 #include "../../Core/DicomParsing/FromDcmtkBridge.h" |
1792 | 43 #include "../../Core/OrthancException.h" |
44 | |
1791 | 45 namespace Orthanc |
46 { | |
47 IFindConstraint* IFindConstraint::ParseDicomConstraint(const DicomTag& tag, | |
48 const std::string& dicomQuery, | |
49 bool caseSensitive) | |
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 | 52 |
1792 | 53 if (vr == ValueRepresentation_Sequence) |
54 { | |
55 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
56 } | |
57 | |
1791 | 58 if ((vr == ValueRepresentation_Date || |
59 vr == ValueRepresentation_DateTime || | |
60 vr == ValueRepresentation_Time) && | |
61 dicomQuery.find('-') != std::string::npos) | |
62 { | |
63 /** | |
64 * Range matching is only defined for TM, DA and DT value | |
65 * representations. This code fixes issues 35 and 37. | |
66 * | |
67 * Reference: "Range matching is not defined for types of | |
68 * Attributes other than dates and times", DICOM PS 3.4, | |
69 * C.2.2.2.5 ("Range Matching"). | |
70 **/ | |
71 size_t separator = dicomQuery.find('-'); | |
72 std::string lower = dicomQuery.substr(0, separator); | |
73 std::string upper = dicomQuery.substr(separator + 1); | |
74 return new RangeConstraint(lower, upper, caseSensitive); | |
75 } | |
76 else if (dicomQuery.find('\\') != std::string::npos) | |
77 { | |
78 std::auto_ptr<ListConstraint> constraint(new ListConstraint(caseSensitive)); | |
79 | |
80 std::vector<std::string> items; | |
81 Toolbox::TokenizeString(items, dicomQuery, '\\'); | |
82 | |
83 for (size_t i = 0; i < items.size(); i++) | |
84 { | |
85 constraint->AddAllowedValue(items[i]); | |
86 } | |
87 | |
88 return constraint.release(); | |
89 } | |
90 else if (dicomQuery.find('*') != std::string::npos || | |
91 dicomQuery.find('?') != std::string::npos) | |
92 { | |
93 return new WildcardConstraint(dicomQuery, caseSensitive); | |
94 } | |
95 else | |
96 { | |
97 /** | |
98 * Case-insensitive match for PN value representation (Patient | |
99 * Name). Case-senstive match for all the other value | |
100 * representations. | |
101 * | |
102 * Reference: DICOM PS 3.4 | |
103 * - C.2.2.2.1 ("Single Value Matching") | |
104 * - C.2.2.2.4 ("Wild Card Matching") | |
105 * http://medical.nema.org/Dicom/2011/11_04pu.pdf | |
106 * | |
107 * "Except for Attributes with a PN Value Representation, only | |
108 * entities with values which match exactly the value specified in the | |
109 * request shall match. This matching is case-sensitive, i.e., | |
110 * sensitive to the exact encoding of the key attribute value in | |
111 * character sets where a letter may have multiple encodings (e.g., | |
112 * based on its case, its position in a word, or whether it is | |
113 * accented) | |
114 * | |
115 * For Attributes with a PN Value Representation (e.g., Patient Name | |
116 * (0010,0010)), an application may perform literal matching that is | |
117 * either case-sensitive, or that is insensitive to some or all | |
118 * aspects of case, position, accent, or other character encoding | |
119 * variants." | |
120 * | |
121 * (0008,0018) UI SOPInstanceUID => Case-sensitive | |
122 * (0008,0050) SH AccessionNumber => Case-sensitive | |
123 * (0010,0020) LO PatientID => Case-sensitive | |
124 * (0020,000D) UI StudyInstanceUID => Case-sensitive | |
125 * (0020,000E) UI SeriesInstanceUID => Case-sensitive | |
126 **/ | |
127 | |
128 return new ValueConstraint(dicomQuery, caseSensitive); | |
129 } | |
130 } | |
131 } |