comparison OrthancServer/Search/IFindConstraint.cpp @ 1791:91a5d39ec665 worklists

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Nov 2015 17:26:00 +0100
parents
children b769623c806c
comparison
equal deleted inserted replaced
1790:bec9edcf0d98 1791:91a5d39ec665
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
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 "../FromDcmtkBridge.h"
37 #include "ListConstraint.h"
38 #include "RangeConstraint.h"
39 #include "ValueConstraint.h"
40 #include "WildcardConstraint.h"
41
42 namespace Orthanc
43 {
44 IFindConstraint* IFindConstraint::ParseDicomConstraint(const DicomTag& tag,
45 const std::string& dicomQuery,
46 bool caseSensitive)
47 {
48 ValueRepresentation vr = FromDcmtkBridge::GetValueRepresentation(tag);
49
50 if ((vr == ValueRepresentation_Date ||
51 vr == ValueRepresentation_DateTime ||
52 vr == ValueRepresentation_Time) &&
53 dicomQuery.find('-') != std::string::npos)
54 {
55 /**
56 * Range matching is only defined for TM, DA and DT value
57 * representations. This code fixes issues 35 and 37.
58 *
59 * Reference: "Range matching is not defined for types of
60 * Attributes other than dates and times", DICOM PS 3.4,
61 * C.2.2.2.5 ("Range Matching").
62 **/
63 size_t separator = dicomQuery.find('-');
64 std::string lower = dicomQuery.substr(0, separator);
65 std::string upper = dicomQuery.substr(separator + 1);
66 return new RangeConstraint(lower, upper, caseSensitive);
67 }
68 else if (dicomQuery.find('\\') != std::string::npos)
69 {
70 std::auto_ptr<ListConstraint> constraint(new ListConstraint(caseSensitive));
71
72 std::vector<std::string> items;
73 Toolbox::TokenizeString(items, dicomQuery, '\\');
74
75 for (size_t i = 0; i < items.size(); i++)
76 {
77 constraint->AddAllowedValue(items[i]);
78 }
79
80 return constraint.release();
81 }
82 else if (dicomQuery.find('*') != std::string::npos ||
83 dicomQuery.find('?') != std::string::npos)
84 {
85 return new WildcardConstraint(dicomQuery, caseSensitive);
86 }
87 else
88 {
89 /**
90 * Case-insensitive match for PN value representation (Patient
91 * Name). Case-senstive match for all the other value
92 * representations.
93 *
94 * Reference: DICOM PS 3.4
95 * - C.2.2.2.1 ("Single Value Matching")
96 * - C.2.2.2.4 ("Wild Card Matching")
97 * http://medical.nema.org/Dicom/2011/11_04pu.pdf
98 *
99 * "Except for Attributes with a PN Value Representation, only
100 * entities with values which match exactly the value specified in the
101 * request shall match. This matching is case-sensitive, i.e.,
102 * sensitive to the exact encoding of the key attribute value in
103 * character sets where a letter may have multiple encodings (e.g.,
104 * based on its case, its position in a word, or whether it is
105 * accented)
106 *
107 * For Attributes with a PN Value Representation (e.g., Patient Name
108 * (0010,0010)), an application may perform literal matching that is
109 * either case-sensitive, or that is insensitive to some or all
110 * aspects of case, position, accent, or other character encoding
111 * variants."
112 *
113 * (0008,0018) UI SOPInstanceUID => Case-sensitive
114 * (0008,0050) SH AccessionNumber => Case-sensitive
115 * (0010,0020) LO PatientID => Case-sensitive
116 * (0020,000D) UI StudyInstanceUID => Case-sensitive
117 * (0020,000E) UI SeriesInstanceUID => Case-sensitive
118 **/
119
120 return new ValueConstraint(dicomQuery, caseSensitive);
121 }
122 }
123 }